[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:
N2614 2011-09-29 09:23:05 +00:00
parent c1bafd59f9
commit 9c0c838ba7

View File

@ -376,24 +376,49 @@ bool DecryptDirectory(const wchar_t * from_path, const wchar_t* to_path, void* b
else
{
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)
{
readSize -= totalReadSize - (sdFileSize - nn::crypto::AES_CMAC_MAC_SIZE);
// 最大CMACぶんのサイズを減らす
readSizeforCmac -= totalReadSize - (sdFileSize - nn::crypto::AES_CMAC_MAC_SIZE);
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;
// パディングまで読んでいたら書き込みサイズを減らす
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,
true);
COMMON_LOGGER_RETURN_FALSE_IF_FAILED(result);
@ -438,12 +463,19 @@ void DecryptThreadFunc()
result = common::SdMountManager::Mount();
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::HeapManager heap(bufSize, AES_BLOCK_SIZE * 2);
void* buf = heap.GetAddr();
if (buf != NULL)
{
result = nn::fs::TryDeleteDirectoryRecursively(
DECRYPT_ROOT_DIRECTORY_PATH);
// ディレクトリが無ければ作る
nn::fs::Directory dir;
result = dir.TryInitialize(DECRYPT_ROOT_DIRECTORY_PATH);