diff --git a/branches/work/VerificationFailed/sources/ConsoleBackup/HeapChecker.cpp b/branches/work/VerificationFailed/sources/ConsoleBackup/HeapChecker.cpp index adbb211..f338dd2 100644 --- a/branches/work/VerificationFailed/sources/ConsoleBackup/HeapChecker.cpp +++ b/branches/work/VerificationFailed/sources/ConsoleBackup/HeapChecker.cpp @@ -48,20 +48,60 @@ nn::Result HeapChecker::Check(std::wstring saveRoot, void* buf, size_t& bufSize) } // NANDから読み込む - nn::fs::FileInputStream file; - result = file.TryInitialize(std::wstring(saveRoot + std::wstring(L"sysdata/00010026/00000000")).c_str()); + nn::fs::FileInputStream nandFile; + result = nandFile.TryInitialize(std::wstring(saveRoot + std::wstring(L"sysdata/00010026/00000000")).c_str()); + COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result); + nn::fs::FileStream sdFile; + result = sdFile.TryInitialize(HEAP_CHECKER_FILE, + nn::fs::OPEN_MODE_READ | nn::fs::OPEN_MODE_WRITE | nn::fs::OPEN_MODE_CREATE); COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result); - s32 readSize; - result = file.TryRead(&readSize, buf, bufSize); - COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result); + s32 readSize = 0; + nn::crypto::Sha256Context writeContext; + writeContext.Initialize(); + for(;;) + { + result = nandFile.TryRead(&readSize, buf, bufSize); + COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result); - result = sdReaderWriter.WriteBufWithCmac(HEAP_CHECKER_FILE, buf, bufSize - nn::crypto::SwAesCtrContext::AES_BLOCK_LENGTH); - COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result); + if(readSize == 0) + { + break; + } - size_t totalSize; - result = sdReaderWriter.ReadBufWithCmac(HEAP_CHECKER_FILE, buf, bufSize, &totalSize); - if(result <= nn::fs::ResultVerificationFailed()) + writeContext.Update(buf, readSize); + + s32 writeSize; + result = sdFile.TryWrite(&writeSize, buf, readSize, false); + COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result); + + result = sdFile.TryFlush(); + COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result); + } + + bit8 sha256WriteContext[nn::crypto::Sha256Context::HASH_SIZE]; + writeContext.GetHash(sha256WriteContext); + + nn::crypto::Sha256Context readContext; + readContext.Initialize(); + sdFile.SetPosition(0); + for(;;) + { + result = sdFile.TryRead(&readSize, buf, bufSize); + COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result); + + if(readSize == 0) + { + break; + } + + readContext.Update(buf, readSize); + } + + bit8 sha256ReadContext[nn::crypto::Sha256Context::HASH_SIZE]; + readContext.GetHash(sha256ReadContext); + + if(std::memcmp(sha256WriteContext, sha256ReadContext, sizeof(sha256ReadContext)) != 0) { COMMON_LOGGER("HeapChecker Failure!! HeapSize: %d\n", bufSize); }