ctr_Repair/branches/work/VerificationFailed/sources/ConsoleBackup/HeapChecker.cpp
N2614 4133476962 cecdのシステムセーブデータが無い場合は何もしない
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@524 385bec56-5757-e545-9c3a-d8741f4650f1
2011-11-24 07:53:22 +00:00

138 lines
4.2 KiB
C++

/*---------------------------------------------------------------------------*
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(std::wstring saveRoot, void* buf, size_t& bufSize)
{
nn::Result result;
common::SdReaderWriter sdReaderWriter;
// cecdセーブデータが存在しない場合は値を変更せずreturnする
{
nn::fs::FileInputStream nandFile;
result = nandFile.TryInitialize(std::wstring(saveRoot + std::wstring(L"sysdata/00010026/00000000")).c_str());
if (result <= nn::fs::ResultNotFound())
{
return nn::ResultSuccess();
}
}
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);
}
// NANDから読み込む
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 = 0;
nn::crypto::Sha256Context writeContext;
writeContext.Initialize();
for(;;)
{
result = nandFile.TryRead(&readSize, buf, bufSize);
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result);
if(readSize == 0)
{
break;
}
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("MemoryChecker Failure!! MemrySize: %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 */