diff --git a/branches/work/VerificationFailed/sources/ConsoleBackup/Exporter.cpp b/branches/work/VerificationFailed/sources/ConsoleBackup/Exporter.cpp index b7e6470..3fc9a1a 100644 --- a/branches/work/VerificationFailed/sources/ConsoleBackup/Exporter.cpp +++ b/branches/work/VerificationFailed/sources/ConsoleBackup/Exporter.cpp @@ -46,6 +46,7 @@ #include "Aes_define.h" #include "VersionDetect.h" #include "Util.h" +#include "HeapChecker.h" namespace ConsoleBackup { @@ -778,6 +779,15 @@ void ExportThreadFunc() void* buf = writeHeap.GetAddr(); if (buf != NULL) { + NN_LOG("HeapCheck Start : %lld\n", nn::os::Tick::GetSystemCurrent().ToTimeSpan().GetMilliSeconds()); + HeapChecker heapChecker; + result = heapChecker.Check(buf, bufSize); + if(result.IsFailure()) + { + s_IsExportSucceeded = false; + return; + } + NN_LOG("HeapCheck End : %lld\n", nn::os::Tick::GetSystemCurrent().ToTimeSpan().GetMilliSeconds()); nn::fs::FileOutputStream list; result = list.TryInitialize(common::FILE_LIST_PATHNAME, true); COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result); diff --git a/branches/work/VerificationFailed/sources/ConsoleBackup/HeapChecker.cpp b/branches/work/VerificationFailed/sources/ConsoleBackup/HeapChecker.cpp new file mode 100644 index 0000000..754fe6c --- /dev/null +++ b/branches/work/VerificationFailed/sources/ConsoleBackup/HeapChecker.cpp @@ -0,0 +1,79 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: HeapChecker.cpp + + Copyright 2009-2011 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Rev$ + *---------------------------------------------------------------------------*/ + +#include + +#include "HeapChecker.h" +#include "SdReaderWriter.h" +#include "CommonLogger.h" + +namespace ConsoleBackup +{ + +HeapChecker::HeapChecker() +{ + // TODO 自動生成されたコンストラクター・スタブ + +} + +HeapChecker::~HeapChecker() +{ + // TODO Auto-generated destructor stub +} + +nn::Result HeapChecker::Check(void* buf, size_t& bufSize) +{ + nn::Result result; + common::SdReaderWriter sdReaderWriter; + + + for(; HEAP_SIZE_MIN < bufSize; bufSize /= 2) + { + result = nn::fs::TryDeleteFile(HEAP_CHECKER_FILE); + if(!(result <= nn::fs::ResultNotFound())) + { + 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); + + size_t totalSize; + result = sdReaderWriter.ReadBufWithCmac(HEAP_CHECKER_FILE, buf, bufSize, &totalSize); + if(result <= nn::fs::ResultVerificationFailed()) + { + COMMON_LOGGER("HeapChecker Failure!! HeapSize: %d\n", bufSize); + } + else + { + // チェックOK + break; + } + } + + nn::fs::TryDeleteFile(HEAP_CHECKER_FILE); + + if(bufSize == HEAP_SIZE_MIN) + { + return nn::Result(nn::Result::LEVEL_FATAL, nn::Result::SUMMARY_OUT_OF_RESOURCE, nn::Result::MODULE_APPLICATION, + nn::Result::DESCRIPTION_OUT_OF_MEMORY); + } + else + { + return nn::ResultSuccess(); + } +} + +} /* namespace ConsoleBackup */ diff --git a/branches/work/VerificationFailed/sources/ConsoleBackup/HeapChecker.h b/branches/work/VerificationFailed/sources/ConsoleBackup/HeapChecker.h new file mode 100644 index 0000000..eafccf6 --- /dev/null +++ b/branches/work/VerificationFailed/sources/ConsoleBackup/HeapChecker.h @@ -0,0 +1,52 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: HeapChecker.h + + Copyright 2009-2011 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Rev$ + *---------------------------------------------------------------------------*/ + +#ifndef HEAPCHECKER_H_ +#define HEAPCHECKER_H_ + +#include + +namespace ConsoleBackup +{ + +//! @brief チェックするヒープサイズの下限です。 +const size_t HEAP_SIZE_MIN = 1024; + +//! @brief チェックに使うファイルへのパスです。 +const wchar_t* const HEAP_CHECKER_FILE = L"sdmc:/CTR_Console_Repair/Check"; + +class HeapChecker +{ +public: + HeapChecker(); + virtual ~HeapChecker(); + + /*! + @brief 与えられたバッファを使ってSDカードに書き出し、データが正しく書き込めているかチェックします。 + データが正しく書き込めていない場合、バッファサイズを半分にして繰り返しチェックします。 + 正しく書き込めた最大のbufSizeが設定されます。 + + @param[in] buf バッファ + @param[inout] buSize バッファサイズ + + @return ResultOutofMemory データが正しく書き込めるバッファが存在しない場合に返されます。 + @return ResultSuccess 上記以外 + */ + + nn::Result Check(void* buf, size_t& bufSize); +}; + +} /* namespace ConsoleBackup */ +#endif /* HEAPCHECKER_H_ */ diff --git a/branches/work/VerificationFailed/sources/ConsoleBackup/OMakefile b/branches/work/VerificationFailed/sources/ConsoleBackup/OMakefile index 535a191..a1c414d 100644 --- a/branches/work/VerificationFailed/sources/ConsoleBackup/OMakefile +++ b/branches/work/VerificationFailed/sources/ConsoleBackup/OMakefile @@ -31,6 +31,7 @@ SOURCES[] = Exporter.cpp Checker.cpp SavedataChecker.cpp + HeapChecker.cpp ../common/Util.cpp ../common/DrawSystemState.cpp ../common/FileTransfer.cpp