From 769162e95c8c7148f9ccf0c49923e3c283ad194d Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Fri, 7 Aug 2020 08:55:38 +0800 Subject: [PATCH] ncch_container: Fix progress report in DecryptToFile The total size should now be correct --- src/core/ncch/ncch_container.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/core/ncch/ncch_container.cpp b/src/core/ncch/ncch_container.cpp index 6acd7ed..322568e 100644 --- a/src/core/ncch/ncch_container.cpp +++ b/src/core/ncch/ncch_container.cpp @@ -447,17 +447,14 @@ ResultStatus NCCHContainer::DecryptToFile(std::shared_ptr dest return ret ? ResultStatus::Success : ResultStatus::Error; } - auto total_size = file->GetSize() - sizeof(NCCH_Header); - // These are written directly instead of using the decryptor - if (has_exheader) { - total_size -= sizeof(ExHeader_Header); - } - if (has_exefs) { - total_size -= sizeof(ExeFs_Header); - } - decryptor.Reset(total_size); + const auto total_size = file->GetSize(); + decryptor.Reset(total_size); // This is inaccurate but doesn't really matter as we don't use it std::size_t written{}; + const auto decryptor_callback = [total_size, &written, &callback](std::size_t current, + std::size_t /*total*/) { + callback(written + current, total_size); + }; // Write NCCH header NCCH_Header modified_header = ncch_header; @@ -509,8 +506,10 @@ ResultStatus NCCHContainer::DecryptToFile(std::shared_ptr dest if (aborted.exchange(false)) { return false; } - if (!decryptor.DecryptAndWriteFile(file, size, dest_file, callback, decrypt, key, ctr, - aes_seek_pos)) { + + written = offset; + if (!decryptor.DecryptAndWriteFile(file, size, dest_file, decryptor_callback, decrypt, key, + ctr, aes_seek_pos)) { LOG_ERROR(Core, "Could not write {}", name); return false; } @@ -561,7 +560,7 @@ ResultStatus NCCHContainer::DecryptToFile(std::shared_ptr dest ncch_header.romfs_size * 0x200, true, secondary_key, romfs_ctr)) { return ResultStatus::Error; } - if (written < file->GetSize()) { + if (written < total_size) { LOG_WARNING(Core, "Data after {} ignored", written); }