citra-emu
/
citra
Archived
1
0
Fork 0

Merge pull request #3120 from shinyquagsire23/ncch-container-offsets

file_sys/ncch_container: Expose ncch_offset during instantiation and in OpenFile
This commit is contained in:
Sebastian Valle 2017-11-28 11:48:46 -05:00 committed by GitHub
commit dc5d7a802f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -95,12 +95,14 @@ static bool LZSS_Decompress(const u8* compressed, u32 compressed_size, u8* decom
return true;
}
NCCHContainer::NCCHContainer(const std::string& filepath) : filepath(filepath) {
NCCHContainer::NCCHContainer(const std::string& filepath, u32 ncch_offset)
: filepath(filepath), ncch_offset(ncch_offset) {
file = FileUtil::IOFile(filepath, "rb");
}
Loader::ResultStatus NCCHContainer::OpenFile(const std::string& filepath) {
Loader::ResultStatus NCCHContainer::OpenFile(const std::string& filepath, u32 ncch_offset) {
this->filepath = filepath;
this->ncch_offset = ncch_offset;
file = FileUtil::IOFile(filepath, "rb");
if (!file.IsOpen()) {
@ -118,7 +120,7 @@ Loader::ResultStatus NCCHContainer::Load() {
if (file.IsOpen()) {
// Reset read pointer in case this file has been read before.
file.Seek(0, SEEK_SET);
file.Seek(ncch_offset, SEEK_SET);
if (file.ReadBytes(&ncch_header, sizeof(NCCH_Header)) != sizeof(NCCH_Header))
return Loader::ResultStatus::Error;
@ -126,7 +128,7 @@ Loader::ResultStatus NCCHContainer::Load() {
// Skip NCSD header and load first NCCH (NCSD is just a container of NCCH files)...
if (Loader::MakeMagic('N', 'C', 'S', 'D') == ncch_header.magic) {
LOG_DEBUG(Service_FS, "Only loading the first (bootable) NCCH within the NCSD file!");
ncch_offset = 0x4000;
ncch_offset += 0x4000;
file.Seek(ncch_offset, SEEK_SET);
file.ReadBytes(&ncch_header, sizeof(NCCH_Header));
}

View File

@ -168,10 +168,10 @@ namespace FileSys {
*/
class NCCHContainer {
public:
NCCHContainer(const std::string& filepath);
NCCHContainer(const std::string& filepath, u32 ncch_offset = 0);
NCCHContainer() {}
Loader::ResultStatus OpenFile(const std::string& filepath);
Loader::ResultStatus OpenFile(const std::string& filepath, u32 ncch_offset = 0);
/**
* Ensure ExeFS and exheader is loaded and ready for reading sections
@ -263,7 +263,7 @@ private:
bool is_loaded = false;
bool is_compressed = false;
u32 ncch_offset = 0; // Offset to NCCH header, can be 0 or after NCSD header
u32 ncch_offset = 0; // Offset to NCCH header, can be 0 for NCCHs or non-zero for CIAs/NCSDs
u32 exefs_offset = 0;
std::string filepath;