SD吸出し前にSD書き出しを使ってヒープをチェックするように

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@521 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
N2614 2011-11-21 04:57:08 +00:00
parent 0360e4446a
commit 92cc6658c2
4 changed files with 142 additions and 0 deletions

View File

@ -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);

View File

@ -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 <nn/crypto/crypto_SwAesCtrContext.h>
#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 */

View File

@ -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 <nn.h>
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_ */

View File

@ -31,6 +31,7 @@ SOURCES[] =
Exporter.cpp
Checker.cpp
SavedataChecker.cpp
HeapChecker.cpp
../common/Util.cpp
../common/DrawSystemState.cpp
../common/FileTransfer.cpp