mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
書き込み後CTR-NAND領域をチェックするように
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@373 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
parent
ed0c6756d9
commit
a4834ca886
@ -135,6 +135,7 @@ typedef enum RestoreState
|
|||||||
RESTORE_IN_PROGRESS, // 書き込み中
|
RESTORE_IN_PROGRESS, // 書き込み中
|
||||||
POST_RESTORE, // 書き込み後の処理
|
POST_RESTORE, // 書き込み後の処理
|
||||||
RESTORE_DONE, // 書き込み完了
|
RESTORE_DONE, // 書き込み完了
|
||||||
|
RESTORE_TEST, // 書き込み後のチェック
|
||||||
REBOOTING, // 再起動を行う
|
REBOOTING, // 再起動を行う
|
||||||
ERASE, // 削除処理を行う
|
ERASE, // 削除処理を行う
|
||||||
RESTORE_CAL, // cfgの一部をcal値で上書きする
|
RESTORE_CAL, // cfgの一部をcal値で上書きする
|
||||||
@ -784,7 +785,6 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case INITIALIZE_CONSOLE:
|
case INITIALIZE_CONSOLE:
|
||||||
{
|
{
|
||||||
COMMON_LOGGER("Initialize Console\n");
|
COMMON_LOGGER("Initialize Console\n");
|
||||||
@ -959,7 +959,6 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case DOWNLOAD_IVS_DONE:
|
case DOWNLOAD_IVS_DONE:
|
||||||
{
|
{
|
||||||
operationMessage.push_back(::std::string("Get SDCI Done."));
|
operationMessage.push_back(::std::string("Get SDCI Done."));
|
||||||
@ -1090,8 +1089,9 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
|
|||||||
{
|
{
|
||||||
if (s_NupOnlyMode)
|
if (s_NupOnlyMode)
|
||||||
{
|
{
|
||||||
ShopOperationSingleTemplate(manager, operationMessage, SHOP_OPERATION_FORCE_UNREGISTER, "Deleting Account",
|
ShopOperationSingleTemplate(manager, operationMessage, SHOP_OPERATION_FORCE_UNREGISTER,
|
||||||
"Delete Account Finished.\n", "Delete Account Failed. Retrying...", DELETE_ACCOUNT_DONE);
|
"Deleting Account", "Delete Account Finished.\n", "Delete Account Failed. Retrying...",
|
||||||
|
DELETE_ACCOUNT_DONE);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1181,7 +1181,6 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
|
|||||||
{
|
{
|
||||||
s_RestoreState = FAIL;
|
s_RestoreState = FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1237,6 +1236,7 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
|
|||||||
// 処理が完了した
|
// 処理が完了した
|
||||||
if (!NeedsAcAdater(manager) && IsImportThreadFinished())
|
if (!NeedsAcAdater(manager) && IsImportThreadFinished())
|
||||||
{
|
{
|
||||||
|
FinalizeImportThread();
|
||||||
if (IsImportSucceeded())
|
if (IsImportSucceeded())
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -1244,7 +1244,7 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
|
|||||||
|
|
||||||
if (GetProgress() > 99)
|
if (GetProgress() > 99)
|
||||||
{
|
{
|
||||||
s_RestoreState = POST_RESTORE;
|
s_RestoreState = RESTORE_TEST;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1288,6 +1288,32 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case RESTORE_TEST:
|
||||||
|
{
|
||||||
|
PutAliveMessage(operationMessage, "Checking Data");
|
||||||
|
|
||||||
|
static bool init = true;
|
||||||
|
if (init)
|
||||||
|
{
|
||||||
|
TestCtrData();
|
||||||
|
init = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsImportThreadFinished())
|
||||||
|
{
|
||||||
|
FinalizeImportThread();
|
||||||
|
if (IsImportSucceeded())
|
||||||
|
{
|
||||||
|
s_RestoreState = POST_RESTORE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s_RestoreState = FAIL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// 書き込み後の処理
|
// 書き込み後の処理
|
||||||
case POST_RESTORE:
|
case POST_RESTORE:
|
||||||
{
|
{
|
||||||
@ -1568,7 +1594,6 @@ void ControlState(common::HardwareStateManager& manager, ::std::vector<std::stri
|
|||||||
nn::ptm::CTR::ShutdownAsync(0, nn::fnd::TimeSpan::FromSeconds(0));
|
nn::ptm::CTR::ShutdownAsync(0, nn::fnd::TimeSpan::FromSeconds(0));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1660,6 +1685,7 @@ u32 GetProgress()
|
|||||||
s_RestoreState == RESTORE_TWL_NAND ||
|
s_RestoreState == RESTORE_TWL_NAND ||
|
||||||
s_RestoreState == RESTORE_IN_PROGRESS ||
|
s_RestoreState == RESTORE_IN_PROGRESS ||
|
||||||
s_RestoreState == POST_RESTORE ||
|
s_RestoreState == POST_RESTORE ||
|
||||||
|
s_RestoreState == RESTORE_TEST ||
|
||||||
s_RestoreState == RESTORE_DONE)
|
s_RestoreState == RESTORE_DONE)
|
||||||
{
|
{
|
||||||
return GetImportProgress();
|
return GetImportProgress();
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
#include <nn.h>
|
#include <nn.h>
|
||||||
#include <nn/fs/CTR/fs_ArchiveTypesForSystem.h>
|
#include <nn/fs/CTR/fs_ArchiveTypesForSystem.h>
|
||||||
#include <nn/fs/CTR/MPCore/fs_FileSystemBasePrivate.h>
|
#include <nn/fs/CTR/MPCore/fs_FileSystemBasePrivate.h>
|
||||||
|
#include <nn/fs/CTR/MPCore/fs_ApiIntegrityVerificationSeed.h>
|
||||||
#include <nn/cfg/CTR/cfg_ApiInit.h>
|
#include <nn/cfg/CTR/cfg_ApiInit.h>
|
||||||
#include <nn/cfg/CTR/cfg_ApiNor.h> // cfg:norの初期化に必要
|
#include <nn/cfg/CTR/cfg_ApiNor.h> // cfg:norの初期化に必要
|
||||||
#include <nn/cfg/CTR/cfg_Api.h>
|
#include <nn/cfg/CTR/cfg_Api.h>
|
||||||
@ -622,6 +623,43 @@ bool InitializeFileSystem()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nn::Result GetNewIvs(void* oldBuf, size_t oldBufSize, void* newBuf, size_t newBufSize, size_t* newIvsSize)
|
||||||
|
{
|
||||||
|
if (oldBufSize < nn::fs::CTR::SIZE_INTEGRITY_VERIFICATION_SEED
|
||||||
|
|| newBufSize < nn::fs::CTR::SIZE_INTEGRITY_VERIFICATION_SEED
|
||||||
|
|| oldBuf == NULL || newBuf == NULL
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return nn::Result(nn::Result::LEVEL_FATAL, nn::Result::SUMMARY_OUT_OF_RESOURCE, nn::Result::MODULE_COMMON,
|
||||||
|
nn::Result::DESCRIPTION_OUT_OF_MEMORY);
|
||||||
|
}
|
||||||
|
|
||||||
|
nn::Result result;
|
||||||
|
result = common::SdMountManager::Mount();
|
||||||
|
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result);
|
||||||
|
|
||||||
|
common::SdReaderWriter sdReader;
|
||||||
|
size_t readSize;
|
||||||
|
result = sdReader.ReadBufWithCmac(common::IVS_PATHNAME, oldBuf, oldBufSize, &readSize);
|
||||||
|
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result);
|
||||||
|
*newIvsSize = readSize;
|
||||||
|
|
||||||
|
// AES復号化する
|
||||||
|
nn::crypto::Initialize();
|
||||||
|
nn::crypto::SwAesCtrContext swAesCtrContest;
|
||||||
|
|
||||||
|
swAesCtrContest.Initialize(common::iv, common::key, sizeof(common::key));
|
||||||
|
result = swAesCtrContest.Decrypt(newBuf, oldBuf, readSize);
|
||||||
|
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result);
|
||||||
|
|
||||||
|
nn::crypto::Finalize();
|
||||||
|
|
||||||
|
result = common::SdMountManager::Unmount();
|
||||||
|
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result);
|
||||||
|
|
||||||
|
return nn::ResultSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
nn::Result ImportIvs()
|
nn::Result ImportIvs()
|
||||||
{
|
{
|
||||||
nn::Result result = nn::ResultSuccess();
|
nn::Result result = nn::ResultSuccess();
|
||||||
@ -732,6 +770,7 @@ void ImportThreadFunc()
|
|||||||
NN_LOG("Import Thread Finalize\n");
|
NN_LOG("Import Thread Finalize\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -1856,6 +1895,72 @@ bool IsImportSucceeded()
|
|||||||
return s_IsImportSucceeded;
|
return s_IsImportSucceeded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
nn::Result GetNewSaveDirRoot(std::wstring& sysSaveRoot)
|
||||||
|
{
|
||||||
|
nn::Result result;
|
||||||
|
|
||||||
|
const size_t BUF_SIZE = 1024;
|
||||||
|
common::HeapManager oldBuf(BUF_SIZE);
|
||||||
|
common::HeapManager newBuf(BUF_SIZE);
|
||||||
|
size_t ivsSize;
|
||||||
|
|
||||||
|
result = GetNewIvs(oldBuf.GetAddr(), BUF_SIZE, newBuf.GetAddr(), BUF_SIZE, &ivsSize);
|
||||||
|
COMMON_LOGGER_RETURN_RESULT_IF_FAILED(result);
|
||||||
|
|
||||||
|
std::string root;
|
||||||
|
common::Util::GetSaveDataDirectoryRoot(root, newBuf.GetAddr(), ivsSize);
|
||||||
|
|
||||||
|
wchar_t rootName[256];
|
||||||
|
std::mbstowcs(rootName, root.c_str(), root.size() + 1);
|
||||||
|
sysSaveRoot = rootName;
|
||||||
|
|
||||||
|
return nn::ResultSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestCtrDataThreadFunc()
|
||||||
|
{
|
||||||
|
nn::Result result;
|
||||||
|
s_IsImportSucceeded = true;
|
||||||
|
|
||||||
|
// 新IVSディレクトリを取得
|
||||||
|
std::wstring sysSaveRoot;
|
||||||
|
result = GetNewSaveDirRoot(sysSaveRoot);
|
||||||
|
COMMON_LOGGER_RETURN_VOID_SET_BOOL_IF_FAILED(result, s_IsImportSucceeded);
|
||||||
|
|
||||||
|
result = nn::fs::MountSpecialArchive(common::NAND_ARCHIVE_NAME, nn::fs::CTR::ARCHIVE_TYPE_CTR_NAND);
|
||||||
|
COMMON_LOGGER_RETURN_VOID_SET_BOOL_IF_FAILED(result, s_IsImportSucceeded);
|
||||||
|
|
||||||
|
u32 fileNum = 0;
|
||||||
|
s64 fileSize = 0;
|
||||||
|
result = common::CalculateFileNum(
|
||||||
|
::std::wstring(common::NAND_DATA_ROOT_PATHNAME_WITH_SLASH) + sysSaveRoot + std::wstring(L"/"), fileNum,
|
||||||
|
fileSize);
|
||||||
|
COMMON_LOGGER_RETURN_VOID_SET_BOOL_IF_FAILED(result, s_IsImportSucceeded);
|
||||||
|
|
||||||
|
common::InitializeTransferProgress(fileSize);
|
||||||
|
|
||||||
|
size_t bufSize = common::GetAllocatableSize(AES_BLOCK_SIZE);
|
||||||
|
common::HeapManager buf(bufSize, AES_BLOCK_SIZE);
|
||||||
|
|
||||||
|
if(!common::TestReadDirectory((std::wstring(common::NAND_DATA_ROOT_PATHNAME_WITH_SLASH) + sysSaveRoot + std::wstring(L"/")).c_str(), buf.GetAddr(), bufSize
|
||||||
|
))
|
||||||
|
{
|
||||||
|
s_IsImportSucceeded = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = nn::fs::Unmount(common::NAND_ARCHIVE_NAME);
|
||||||
|
COMMON_LOGGER_RETURN_VOID_SET_BOOL_IF_FAILED(result, s_IsImportSucceeded);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestCtrData()
|
||||||
|
{
|
||||||
|
COMMON_LOGGER("Test NAND Data Start...\n");
|
||||||
|
s_ImportThread.Start(TestCtrDataThreadFunc, s_ImportThreadStack);
|
||||||
|
}
|
||||||
|
|
||||||
nn::Result ImportData()
|
nn::Result ImportData()
|
||||||
{
|
{
|
||||||
static nn::Result result = nn::ResultSuccess();
|
static nn::Result result = nn::ResultSuccess();
|
||||||
|
|||||||
@ -160,6 +160,9 @@ bool ImportIvsData();
|
|||||||
// 書き込みが成功したかどうか
|
// 書き込みが成功したかどうか
|
||||||
bool IsImportSucceeded();
|
bool IsImportSucceeded();
|
||||||
|
|
||||||
|
// 新たにスレッドを立て、CTR-NAND領域をテストする
|
||||||
|
void TestCtrData();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* IMPORTER_H_ */
|
#endif /* IMPORTER_H_ */
|
||||||
|
|||||||
@ -767,4 +767,88 @@ bool AddPathNameAndUpdateContext(nn::fs::FileOutputStream* file, const wchar_t *
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool TestReadDirectory(const wchar_t* path, void* buf, const size_t bufSize)
|
||||||
|
{
|
||||||
|
nn::fs::Directory dir;
|
||||||
|
nn::fs::DirectoryEntry entry;
|
||||||
|
s32 numread = 0;
|
||||||
|
std::wostringstream targetStream;
|
||||||
|
|
||||||
|
NN_LOG("Read Directory %ls\n", path);
|
||||||
|
nn::Result result = dir.TryInitialize(path);
|
||||||
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
result = dir.TryRead(&numread, &entry, 1);
|
||||||
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
||||||
|
|
||||||
|
if(numread == 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (std::wcscmp(entry.entryName, L".") == 0 || std::wcscmp(entry.entryName, L"..") == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
targetStream.str(L"");
|
||||||
|
targetStream.clear(std::stringstream::goodbit);
|
||||||
|
targetStream << path << entry.entryName;
|
||||||
|
|
||||||
|
// ディレクトリの場合
|
||||||
|
if (entry.attributes.isDirectory)
|
||||||
|
{
|
||||||
|
targetStream << L"/";
|
||||||
|
|
||||||
|
// 再帰処理
|
||||||
|
if (!TestReadDirectory(targetStream.str().c_str(), buf, bufSize))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ファイルの場合
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// ファイル作成
|
||||||
|
nn::fs::FileInputStream file;
|
||||||
|
s64 filesize;
|
||||||
|
s32 readsize;
|
||||||
|
|
||||||
|
NN_LOG("Read File %ls\n", targetStream.str().c_str());
|
||||||
|
|
||||||
|
// 読み込み対象ファイル開く
|
||||||
|
result = file.TryInitialize(targetStream.str().c_str());
|
||||||
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
||||||
|
|
||||||
|
// 読み込み対象ファイルのサイズ取得
|
||||||
|
result = file.TryGetSize(&filesize);
|
||||||
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
||||||
|
|
||||||
|
// ファイル全体を読みきるまでループ
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
result = file.TryRead(&readsize, buf, bufSize);
|
||||||
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
||||||
|
|
||||||
|
if (readsize == 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s_FinishedFileSize += readsize;
|
||||||
|
s_Progress = s_FinishedFileSize * 100 / s_TotalFileSize;
|
||||||
|
NN_LOG(
|
||||||
|
"finish = %lld, total = %lld, progress = %lld\n", s_FinishedFileSize, s_TotalFileSize, s_Progress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,6 +57,9 @@ void InitializeTransferProgress(u64 totalSize);
|
|||||||
// 内部のバッファを使用するためスレッドアンセーフ
|
// 内部のバッファを使用するためスレッドアンセーフ
|
||||||
const char* GetCharStr(const wchar_t* path);
|
const char* GetCharStr(const wchar_t* path);
|
||||||
|
|
||||||
|
// pathで指定したディレクトリ以下を再帰的に読み込んでエラーが発生しないかテストする
|
||||||
|
bool TestReadDirectory(const wchar_t* path, void* buf, const size_t bufSize);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* FILETRANSFER_H_ */
|
#endif /* FILETRANSFER_H_ */
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user