From f1b229ee78aabd0130fef8a6ac123cd97f900887 Mon Sep 17 00:00:00 2001 From: N2614 Date: Thu, 17 Nov 2011 01:29:52 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9A=97=E5=8F=B7=E5=8C=96=E7=84=A1=E5=8A=B9?= =?UTF-8?q?=E3=81=AB=E3=80=82=E3=83=90=E3=83=83=E3=83=95=E3=82=A1=E3=81=AE?= =?UTF-8?q?=E5=BE=8C=E5=8D=8A=E5=8D=8A=E5=88=86=E3=81=AB=E3=81=9D=E3=81=AE?= =?UTF-8?q?=E3=81=BE=E3=81=BE=E3=83=87=E3=83=BC=E3=82=BF=E3=82=92=E3=82=B3?= =?UTF-8?q?=E3=83=94=E3=83=BC=E3=81=97=E3=81=A6=E6=9B=B8=E3=81=8D=E8=BE=BC?= =?UTF-8?q?=E3=82=80=E3=82=88=E3=81=86=E3=81=AB?= 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@519 385bec56-5757-e545-9c3a-d8741f4650f1 --- .../sources/ConsoleBackup/OMakefile | 3 ++ .../sources/common/FileTransfer.cpp | 46 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/branches/work/VerificationFailed/sources/ConsoleBackup/OMakefile b/branches/work/VerificationFailed/sources/ConsoleBackup/OMakefile index dfa19be..535a191 100644 --- a/branches/work/VerificationFailed/sources/ConsoleBackup/OMakefile +++ b/branches/work/VerificationFailed/sources/ConsoleBackup/OMakefile @@ -22,6 +22,9 @@ SAMPLED_DEMOS_COMMON_INCLUDE_DIR = $(dir $(HORIZON_ROOT)/../CTR/SampleDemos/co INCLUDES += $(SAMPLED_DEMOS_COMMON_INCLUDE_DIR) \ ../common +# ˆÃ†‰»‚ÆCMAC•t‰Á‚𖳌ø‚É‚·‚éꇗLŒø‚É‚·‚é +CCFLAGS += -DSKIP_VERIFY + SOURCES[] = ConsoleBackup.cpp Controller.cpp diff --git a/branches/work/VerificationFailed/sources/common/FileTransfer.cpp b/branches/work/VerificationFailed/sources/common/FileTransfer.cpp index 5474037..d25a4a3 100644 --- a/branches/work/VerificationFailed/sources/common/FileTransfer.cpp +++ b/branches/work/VerificationFailed/sources/common/FileTransfer.cpp @@ -162,12 +162,16 @@ bool ExportTwlSaveFile(const wchar_t* from_path, const wchar_t* to_path, void* b return false; } +#ifndef SKIP_VERIFY nn::crypto::SwAesCtrContext swAesCtrContext; swAesCtrContext.Initialize(iv, common::key, sizeof(key)); +#endif size_t totalReadSize = 0; +#ifndef SKIP_VERIFY nn::crypto::Sha256Context context; context.Initialize(); +#endif // ãƒ•ã‚¡ã‚¤ãƒ«ã‚µã‚¤ã‚ºã‚’ãƒ˜ãƒƒãƒ€ã«æ›¸ã„ã¦ãŠã // 書ãè¾¼ã¿å¯¾è±¡ãƒ•ã‚¡ã‚¤ãƒ«ä½œæˆ @@ -177,6 +181,7 @@ bool ExportTwlSaveFile(const wchar_t* from_path, const wchar_t* to_path, void* b nn::fs::OPEN_MODE_READ | nn::fs::OPEN_MODE_WRITE | nn::fs::OPEN_MODE_CREATE); COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); +#ifndef SKIP_VERIFY // フルパスをãƒãƒƒã‚·ãƒ¥ã«å«ã‚ã‚‹ context.Update(from_path, std::wcslen(from_path) * sizeof(wchar_t)); @@ -191,6 +196,7 @@ bool ExportTwlSaveFile(const wchar_t* from_path, const wchar_t* to_path, void* b s32 writeSize; result = to_file.TryWrite(&writeSize, &enc, sizeof(enc), false); COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); +#endif while (1) { @@ -203,6 +209,7 @@ bool ExportTwlSaveFile(const wchar_t* from_path, const wchar_t* to_path, void* b if (readsize == 0) { +#ifndef SKIP_VERIFY NN_LOG("Add CMAC %ls\n", from_path); // SHA256を計算ã—ã¦CMACを付加ã™ã‚‹ bit8 sha256Hash[nn::crypto::Sha256Context::HASH_SIZE]; @@ -217,6 +224,7 @@ bool ExportTwlSaveFile(const wchar_t* from_path, const wchar_t* to_path, void* b COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); result = to_file.TryFlush(); COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); +#endif break; } @@ -224,6 +232,7 @@ bool ExportTwlSaveFile(const wchar_t* from_path, const wchar_t* to_path, void* b { NN_LOG("EncryptSize = %d\n", readsize); +#ifndef SKIP_VERIFY u8 paddingSize = 0; AddPkcsPadding(&paddingSize, reinterpret_cast(buf), bufSize / 2, &readsize); @@ -237,6 +246,13 @@ bool ExportTwlSaveFile(const wchar_t* from_path, const wchar_t* to_path, void* b // 事å‰è¨ˆç®—ã—ãŸãƒ•ァイルサイズã«ä¸€è‡´ã•ã›ã‚‹ãŸã‚パディング分減算 readsize -= paddingSize; +#else + // 後åŠåŠåˆ†ã«ã‚³ãƒ”ーã—ã¦ã‹ã‚‰æ›¸ã込む + std::memcpy(reinterpret_cast(buf) + bufSize / 2, buf, readsize); + + result = to_file.TryWrite(&writesize, reinterpret_cast(buf) + bufSize / 2, readsize, false); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); +#endif s_FinishedFileSize += readsize; s_Progress = s_FinishedFileSize * 100 / s_TotalFileSize; @@ -345,7 +361,9 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc nn::fs::FileInputStream from_file; nn::fs::FileStream to_file; s64 filesize; +#ifndef SKIP_VERIFY s64 fileSizeWithoutHeaderAndFooter; +#endif s32 readsize; s32 writesize; @@ -367,12 +385,16 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc } } +#ifndef SKIP_VERIFY nn::crypto::SwAesCtrContext swAesCtrContext; swAesCtrContext.Initialize(iv, common::key, sizeof(key)); +#endif size_t totalReadSize = 0; +#ifndef SKIP_VERIFY nn::crypto::Sha256Context context; context.Initialize(); +#endif // ãƒ•ã‚¡ã‚¤ãƒ«ã‚µã‚¤ã‚ºã‚’ãƒ˜ãƒƒãƒ€ã«æ›¸ã„ã¦ãŠã if (encode) @@ -384,6 +406,7 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc nn::fs::OPEN_MODE_READ | nn::fs::OPEN_MODE_WRITE | nn::fs::OPEN_MODE_CREATE); COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); +#ifndef SKIP_VERIFY // フルパスをãƒãƒƒã‚·ãƒ¥ã«å«ã‚ã‚‹ context.Update(target_from.str().c_str(), target_from.str().size() * sizeof(wchar_t)); @@ -398,9 +421,11 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc s32 writeSize; result = to_file.TryWrite(&writeSize, &enc, sizeof(enc), false); COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); +#endif } else { +#ifndef SKIP_VERIFY // ヘッダを読む // ãƒãƒƒã‚·ãƒ¥ã®è¨ˆç®—ã¯çµ‚ã‚ã£ã¦ã„ã‚‹ã®ã§å¾©å·åŒ–ã®ã¿ BackupDataHeader header; @@ -418,6 +443,7 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc // 書ãè¾¼ã¿å¯¾è±¡ãƒ•ã‚¡ã‚¤ãƒ«ä½œæˆ result = nn::fs::TryCreateFile(target_tmp.str().c_str(), fileSizeWithoutHeaderAndFooter); COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); +#endif result = to_file.TryInitialize(target_tmp.str().c_str(), nn::fs::OPEN_MODE_READ | nn::fs::OPEN_MODE_WRITE | nn::fs::OPEN_MODE_CREATE); COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); @@ -435,6 +461,7 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc { if (encode) { +#ifndef SKIP_VERIFY NN_LOG("Add CMAC %ls\n", target_from.str().c_str()); // SHA256を計算ã—ã¦CMACを付加ã™ã‚‹ bit8 sha256Hash[nn::crypto::Sha256Context::HASH_SIZE]; @@ -447,11 +474,13 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc result = to_file.TryWrite(&writesize, cmac, sizeof(cmac)); COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); +#endif } result = to_file.TryFlush(); COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); +#ifndef SKIP_VERIFY // 復巿¸ˆã¿ãªã‚‰æ¤œè¨¼ã™ã‚‹ if (!encode) { @@ -461,6 +490,7 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc return false; } } +#endif break; } @@ -468,6 +498,7 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc { if (encode) { +#ifndef SKIP_VERIFY NN_LOG("EncryptSize = %d\n", readsize); u8 paddingSize = 0; @@ -484,7 +515,13 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc // 事å‰è¨ˆç®—ã—ãŸãƒ•ァイルサイズã«ä¸€è‡´ã•ã›ã‚‹ãŸã‚パディング分減算 readsize -= paddingSize; +#else + // 後åŠåŠåˆ†ã«ã‚³ãƒ”ーã—ã¦ã‹ã‚‰æ›¸ã込む + std::memcpy(reinterpret_cast(buf) + bufSize / 2, buf, readsize); + result = to_file.TryWrite(&writesize, reinterpret_cast(buf) + bufSize / 2, readsize, false); + COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); +#endif s_FinishedFileSize += readsize; s_Progress = s_FinishedFileSize * 100 / s_TotalFileSize; NN_LOG( @@ -492,6 +529,7 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc } else { +#ifndef SKIP_VERIFY // ãƒãƒƒã‚·ãƒ¥æ¤œè¨¼ã¯é€šã£ã¦ã„ã‚‹ã®ã§å¾©å·åŒ–ã—ã¤ã¤æ›¸ã込㿠// パディング以é™ã¯æ›¸ãè¾¼ã¾ãªã„ã‚ˆã†æ›¸ãè¾¼ã¿ã‚µã‚¤ã‚ºã‚’変更ã™ã‚‹ @@ -510,12 +548,19 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc result = to_file.TryWrite(&writesize, reinterpret_cast(buf) + bufSize / 2, readsize, false); +#else + // 後åŠåŠåˆ†ã«ã‚³ãƒ”ーã—ã¦ã‹ã‚‰æ›¸ã込む + std::memcpy(reinterpret_cast(buf) + bufSize / 2, buf, readsize); + + result = to_file.TryWrite(&writesize, reinterpret_cast(buf) + bufSize / 2, readsize, false); +#endif COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result); s_FinishedFileSize += readsize; s_Progress = s_FinishedFileSize * 100 / s_TotalFileSize; NN_LOG( "finish = %lld, total = %lld, progress = %lld\n", s_FinishedFileSize, s_TotalFileSize, s_Progress); +#ifndef SKIP_VERIFY // 読ã¿ãã£ãŸã®ã§æ¬¡ã®ãƒ•ァイル㸠if (readDone) { @@ -530,6 +575,7 @@ bool CopyDirectory(ImportDataList* fileList, const wchar_t * from_path, const wc } break; } +#endif } COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);