Properly set crypto flags as GodMode9 does; remove pointless zeroing

This commit is contained in:
Pengfei
2021-07-09 20:32:08 +08:00
parent b90fb11109
commit 23226b2b37
+7 -14
View File
@@ -465,8 +465,13 @@ ResultStatus NCCHContainer::DecryptToFile(std::shared_ptr<FileUtil::IOFile> dest
// Write NCCH header
NCCH_Header modified_header = ncch_header;
modified_header.raw_crypto_flags = 0x4; // No crypto
// Set flags (equivalent to GodMode9 behaviour)
modified_header.secondary_key_slot = 0;
modified_header.fixed_key.Assign(0);
modified_header.no_crypto.Assign(1);
modified_header.seed_crypto.Assign(0);
if (dest_file->WriteBytes(&modified_header, sizeof(modified_header)) !=
sizeof(modified_header)) {
LOG_ERROR(Core, "Could not write NCCH header to file");
@@ -495,20 +500,8 @@ ResultStatus NCCHContainer::DecryptToFile(std::shared_ptr<FileUtil::IOFile> dest
return false;
}
ASSERT_MSG(written <= offset, "Offsets are not in increasing order");
// Zero out the gap
const std::array<u8, 1024> zeroes{};
std::size_t zeroes_left = offset - written;
while (zeroes_left > 0) {
const auto to_write = std::min(zeroes.size(), zeroes_left);
if (dest_file->WriteBytes(zeroes.data(), to_write) != to_write) {
LOG_ERROR(Core, "Could not write zeroes before {}", name);
return false;
}
zeroes_left -= to_write;
}
file->Seek(offset, SEEK_SET);
dest_file->Seek(offset, SEEK_SET);
if (aborted.exchange(false)) {
return false;