mirror of
https://github.com/rvtr/ctr_Repair.git
synced 2025-10-31 13:51:08 -04:00
[Decrypter]ヒープを8MBまでしか使わないように
パディングの処理を正しく git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@436 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
parent
c1bafd59f9
commit
9c0c838ba7
@ -376,24 +376,49 @@ bool DecryptDirectory(const wchar_t * from_path, const wchar_t* to_path, void* b
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool readDone = false;;
|
bool readDone = false;;
|
||||||
// CMACまで読んだかどうか
|
|
||||||
|
// 復号化
|
||||||
|
result = swAesCtrContext.Decrypt(reinterpret_cast<bit8*>(buf) + bufSize / 2, buf, readSize);
|
||||||
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
||||||
|
|
||||||
|
// SHA256Hash確認のためCMACまで読んだかどうか調べる
|
||||||
|
s32 readSizeforCmac = readSize;
|
||||||
if (sdFileSize - nn::crypto::AES_CMAC_MAC_SIZE < totalReadSize)
|
if (sdFileSize - nn::crypto::AES_CMAC_MAC_SIZE < totalReadSize)
|
||||||
{
|
{
|
||||||
readSize -= totalReadSize - (sdFileSize - nn::crypto::AES_CMAC_MAC_SIZE);
|
// 最大CMACぶんのサイズを減らす
|
||||||
|
readSizeforCmac -= totalReadSize - (sdFileSize - nn::crypto::AES_CMAC_MAC_SIZE);
|
||||||
readDone = true;
|
readDone = true;
|
||||||
}
|
}
|
||||||
context.Update(buf, readSize);
|
|
||||||
|
if (readSizeforCmac != 0)
|
||||||
|
{
|
||||||
|
context.Update(buf, readSizeforCmac);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret_value = CalculateAndCompareCmac(&context, sdCmac);
|
||||||
|
if (!ret_value)
|
||||||
|
{
|
||||||
|
COMMON_LOGGER(
|
||||||
|
"********** Verification Failed ********** %s\n", common::GetCharStr(target_from.str().c_str()));
|
||||||
|
s_VerifyFail++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
COMMON_LOGGER("Success %s\n", common::GetCharStr(target_from.str().c_str()));
|
||||||
|
s_VerifySuccess++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
s32 sdWriteSize = readSize;
|
s32 sdWriteSize = readSize;
|
||||||
// パディングまで読んでいたら書き込みサイズを減らす
|
// パディングまで読んでいたら書き込みサイズを減らす
|
||||||
if (dec.size + sizeof(dec) < totalReadSize)
|
if (dec.size + sizeof(dec) < totalReadSize)
|
||||||
{
|
{
|
||||||
sdWriteSize -= totalReadSize - dec.size;
|
sdWriteSize -= totalReadSize - (dec.size + sizeof(dec));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 復号化して書き込み
|
// 書き込み
|
||||||
result = swAesCtrContext.Decrypt(reinterpret_cast<bit8*>(buf) + bufSize / 2, buf, readSize);
|
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
|
||||||
result = sdOutFile.TryWrite(&writeSize, reinterpret_cast<bit8*>(buf) + bufSize / 2, sdWriteSize,
|
result = sdOutFile.TryWrite(&writeSize, reinterpret_cast<bit8*>(buf) + bufSize / 2, sdWriteSize,
|
||||||
true);
|
true);
|
||||||
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
|
||||||
@ -438,12 +463,19 @@ void DecryptThreadFunc()
|
|||||||
result = common::SdMountManager::Mount();
|
result = common::SdMountManager::Mount();
|
||||||
|
|
||||||
size_t bufSize = common::GetAllocatableSize(AES_BLOCK_SIZE * 2);
|
size_t bufSize = common::GetAllocatableSize(AES_BLOCK_SIZE * 2);
|
||||||
|
if(bufSize > common::FILE_COPY_HEAP_SIZE)
|
||||||
|
{
|
||||||
|
bufSize = common::FILE_COPY_HEAP_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
common::SdReaderWriter sdWriter;
|
common::SdReaderWriter sdWriter;
|
||||||
common::HeapManager heap(bufSize, AES_BLOCK_SIZE * 2);
|
common::HeapManager heap(bufSize, AES_BLOCK_SIZE * 2);
|
||||||
void* buf = heap.GetAddr();
|
void* buf = heap.GetAddr();
|
||||||
if (buf != NULL)
|
if (buf != NULL)
|
||||||
{
|
{
|
||||||
|
result = nn::fs::TryDeleteDirectoryRecursively(
|
||||||
|
DECRYPT_ROOT_DIRECTORY_PATH);
|
||||||
|
|
||||||
// ディレクトリが無ければ作る
|
// ディレクトリが無ければ作る
|
||||||
nn::fs::Directory dir;
|
nn::fs::Directory dir;
|
||||||
result = dir.TryInitialize(DECRYPT_ROOT_DIRECTORY_PATH);
|
result = dir.TryInitialize(DECRYPT_ROOT_DIRECTORY_PATH);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user