ncch_container: support encrypted games

This commit is contained in:
wwylele
2018-07-28 18:30:54 +03:00
parent b92660435c
commit d4a808c885
17 changed files with 319 additions and 103 deletions

View File

@ -0,0 +1,22 @@
#include <algorithm>
#include <cryptopp/aes.h>
#include <cryptopp/modes.h>
#include "core/file_sys/romfs_reader.h"
namespace FileSys {
std::size_t RomFSReader::ReadFile(std::size_t offset, std::size_t length, u8* buffer) {
if (length == 0)
return 0; // Crypto++ does not like zero size buffer
file.Seek(file_offset + offset, SEEK_SET);
std::size_t read_length = std::min(length, data_size - offset);
read_length = file.ReadBytes(buffer, read_length);
if (is_encrypted) {
CryptoPP::CTR_Mode<CryptoPP::AES>::Decryption d(key.data(), key.size(), ctr.data());
d.Seek(crypto_offset + offset);
d.ProcessData(buffer, buffer, read_length);
}
return read_length;
}
} // namespace FileSys