From 4ef93db4235df0dc31eec30f354b6a619363901e Mon Sep 17 00:00:00 2001 From: jakcron Date: Sun, 10 Jun 2018 14:57:57 +0800 Subject: [PATCH] [nstool] Add NRO HB extention AssetHeader support. --- programs/nstool/source/CodeObjectProcess.cpp | 31 ++++++++++++++++++++ programs/nstool/source/CodeObjectProcess.h | 4 +++ 2 files changed, 35 insertions(+) diff --git a/programs/nstool/source/CodeObjectProcess.cpp b/programs/nstool/source/CodeObjectProcess.cpp index fd90f0b..d05259e 100644 --- a/programs/nstool/source/CodeObjectProcess.cpp +++ b/programs/nstool/source/CodeObjectProcess.cpp @@ -46,7 +46,12 @@ void CodeObjectProcess::process() if (mObjType == OBJ_NSO) displayNsoHeader(); else if (mObjType == OBJ_NRO) + { displayNroHeader(); + if (mIsHomebrewNro) + displayNroAssetHeader(); + } + } displayRoMetaData(); } @@ -139,6 +144,18 @@ void CodeObjectProcess::importHeader() mFile->read(scratch.getBytes(), 0, scratch.getSize()); mNroHdr.importBinary(scratch.getBytes(), scratch.getSize()); + + nx::sNroHeader* raw_hdr = (nx::sNroHeader*)scratch.getBytes(); + + if (((le_uint64_t*)raw_hdr->reserved_0)->get() == nx::nro::kNroHomebrewSig) + { + mIsHomebrewNro = true; + scratch.alloc(sizeof(nx::sNroAssetHeader)); + mFile->read(scratch.getBytes(), mNroHdr.getNroSize(), scratch.getSize()); + mNroAssetHdr.importBinary(scratch.getBytes(), scratch.getSize()); + } + else + mIsHomebrewNro = false; } } @@ -393,6 +410,20 @@ void CodeObjectProcess::displayNroHeader() #undef _HEXDUMP_L } +void CodeObjectProcess::displayNroAssetHeader() +{ + printf("[ASET Header]\n"); + printf(" Icon:\n"); + printf(" Offset: 0x%" PRIx64 "\n", mNroAssetHdr.getIconInfo().offset); + printf(" Size: 0x%" PRIx64 "\n", mNroAssetHdr.getIconInfo().size); + printf(" NACP:\n"); + printf(" Offset: 0x%" PRIx64 "\n", mNroAssetHdr.getNacpInfo().offset); + printf(" Size: 0x%" PRIx64 "\n", mNroAssetHdr.getNacpInfo().size); + printf(" RomFS:\n"); + printf(" Offset: 0x%" PRIx64 "\n", mNroAssetHdr.getRomfsInfo().offset); + printf(" Size: 0x%" PRIx64 "\n", mNroAssetHdr.getRomfsInfo().size); +} + void CodeObjectProcess::displayRoMetaData() { if (mApiList.size() > 0 && (mListApi || mCliOutputType > OUTPUT_NORMAL)) diff --git a/programs/nstool/source/CodeObjectProcess.h b/programs/nstool/source/CodeObjectProcess.h index b0861e1..b20903e 100644 --- a/programs/nstool/source/CodeObjectProcess.h +++ b/programs/nstool/source/CodeObjectProcess.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "nstool.h" #include "SdkApiString.h" @@ -57,6 +58,8 @@ private: nx::NsoHeader mNsoHdr; nx::NroHeader mNroHdr; + bool mIsHomebrewNro; + nx::NroAssetHeader mNroAssetHdr; fnd::MemoryBlob mTextBlob, mRoBlob, mDataBlob; std::vector mApiList; DynamicSymbolParser mDynSymbolList; @@ -66,6 +69,7 @@ private: void importApiList(); void displayNsoHeader(); void displayNroHeader(); + void displayNroAssetHeader(); void displayRoMetaData(); const char* getApiTypeStr(SdkApiString::ApiType type) const;