mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
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
80 lines
2.3 KiB
C++
80 lines
2.3 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(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 */
|