mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
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:
parent
0360e4446a
commit
92cc6658c2
@ -46,6 +46,7 @@
|
|||||||
#include "Aes_define.h"
|
#include "Aes_define.h"
|
||||||
#include "VersionDetect.h"
|
#include "VersionDetect.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
|
#include "HeapChecker.h"
|
||||||
|
|
||||||
namespace ConsoleBackup
|
namespace ConsoleBackup
|
||||||
{
|
{
|
||||||
@ -778,6 +779,15 @@ void ExportThreadFunc()
|
|||||||
void* buf = writeHeap.GetAddr();
|
void* buf = writeHeap.GetAddr();
|
||||||
if (buf != NULL)
|
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;
|
nn::fs::FileOutputStream list;
|
||||||
result = list.TryInitialize(common::FILE_LIST_PATHNAME, true);
|
result = list.TryInitialize(common::FILE_LIST_PATHNAME, true);
|
||||||
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
|
||||||
|
|||||||
@ -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 */
|
||||||
@ -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_ */
|
||||||
@ -31,6 +31,7 @@ SOURCES[] =
|
|||||||
Exporter.cpp
|
Exporter.cpp
|
||||||
Checker.cpp
|
Checker.cpp
|
||||||
SavedataChecker.cpp
|
SavedataChecker.cpp
|
||||||
|
HeapChecker.cpp
|
||||||
../common/Util.cpp
|
../common/Util.cpp
|
||||||
../common/DrawSystemState.cpp
|
../common/DrawSystemState.cpp
|
||||||
../common/FileTransfer.cpp
|
../common/FileTransfer.cpp
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user