From 9c0c838ba7002c3543e704d12345430d6ddfc779 Mon Sep 17 00:00:00 2001 From: N2614 Date: Thu, 29 Sep 2011 09:23:05 +0000 Subject: [PATCH] =?UTF-8?q?[Decrypter]=E3=83=92=E3=83=BC=E3=83=97=E3=82=92?= =?UTF-8?q?8MB=E3=81=BE=E3=81=A7=E3=81=97=E3=81=8B=E4=BD=BF=E3=82=8F?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB=20=E3=83=91?= =?UTF-8?q?=E3=83=87=E3=82=A3=E3=83=B3=E3=82=B0=E3=81=AE=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92=E6=AD=A3=E3=81=97=E3=81=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@436 385bec56-5757-e545-9c3a-d8741f4650f1 --- .../tools/ExportedDataDecrypter/main.cpp | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/trunk/ConsoleDataMigration/sources/tools/ExportedDataDecrypter/main.cpp b/trunk/ConsoleDataMigration/sources/tools/ExportedDataDecrypter/main.cpp index 3e7c6da..d07c99f 100644 --- a/trunk/ConsoleDataMigration/sources/tools/ExportedDataDecrypter/main.cpp +++ b/trunk/ConsoleDataMigration/sources/tools/ExportedDataDecrypter/main.cpp @@ -376,24 +376,49 @@ bool DecryptDirectory(const wchar_t * from_path, const wchar_t* to_path, void* b else { bool readDone = false;; - // CMACまで読んだかどうか + + // 復号化 + result = swAesCtrContext.Decrypt(reinterpret_cast(buf) + bufSize / 2, buf, readSize); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + + // SHA256Hash確認のためCMACまで読んだかどうか調べる + s32 readSizeforCmac = readSize; if (sdFileSize - nn::crypto::AES_CMAC_MAC_SIZE < totalReadSize) { - readSize -= totalReadSize - (sdFileSize - nn::crypto::AES_CMAC_MAC_SIZE); + // 最大CMACぶんのサイズを減らす + readSizeforCmac -= totalReadSize - (sdFileSize - nn::crypto::AES_CMAC_MAC_SIZE); readDone = true; } - context.Update(buf, readSize); + + if (readSizeforCmac != 0) + { + context.Update(buf, readSizeforCmac); + } + else + { + ret_value = CalculateAndCompareCmac(&context, sdCmac); + if (!ret_value) + { + COMMON_LOGGER( + "********** Verification Failed ********** %s\n", common::GetCharStr(target_from.str().c_str())); + s_VerifyFail++; + } + else + { + COMMON_LOGGER("Success %s\n", common::GetCharStr(target_from.str().c_str())); + s_VerifySuccess++; + } + break; + } s32 sdWriteSize = readSize; // パディングまで読んでいたら書き込みサイズを減らす if (dec.size + sizeof(dec) < totalReadSize) { - sdWriteSize -= totalReadSize - dec.size; + sdWriteSize -= totalReadSize - (dec.size + sizeof(dec)); } - // 復号化して書き込み - result = swAesCtrContext.Decrypt(reinterpret_cast(buf) + bufSize / 2, buf, readSize); - COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); + // 書き込み result = sdOutFile.TryWrite(&writeSize, reinterpret_cast(buf) + bufSize / 2, sdWriteSize, true); COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); @@ -438,12 +463,19 @@ void DecryptThreadFunc() result = common::SdMountManager::Mount(); size_t bufSize = common::GetAllocatableSize(AES_BLOCK_SIZE * 2); + if(bufSize > common::FILE_COPY_HEAP_SIZE) + { + bufSize = common::FILE_COPY_HEAP_SIZE; + } common::SdReaderWriter sdWriter; common::HeapManager heap(bufSize, AES_BLOCK_SIZE * 2); void* buf = heap.GetAddr(); if (buf != NULL) { + result = nn::fs::TryDeleteDirectoryRecursively( + DECRYPT_ROOT_DIRECTORY_PATH); + // ディレクトリが無ければ作る nn::fs::Directory dir; result = dir.TryInitialize(DECRYPT_ROOT_DIRECTORY_PATH);