diff --git a/lib/libhac/include/nn/hac/NpdmBinary.h b/lib/libhac/include/nn/hac/MetaBinary.h similarity index 70% rename from lib/libhac/include/nn/hac/NpdmBinary.h rename to lib/libhac/include/nn/hac/MetaBinary.h index 24d16e0..4f981da 100644 --- a/lib/libhac/include/nn/hac/NpdmBinary.h +++ b/lib/libhac/include/nn/hac/MetaBinary.h @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include @@ -10,16 +10,16 @@ namespace nn { namespace hac { - class NpdmBinary : + class MetaBinary : public fnd::ISerialisable { public: - NpdmBinary(); - NpdmBinary(const NpdmBinary& other); + MetaBinary(); + MetaBinary(const MetaBinary& other); - void operator=(const NpdmBinary& other); - bool operator==(const NpdmBinary& other) const; - bool operator!=(const NpdmBinary& other) const; + void operator=(const MetaBinary& other); + bool operator==(const MetaBinary& other) const; + bool operator!=(const MetaBinary& other) const; // export/import binary void toBytes(); @@ -29,11 +29,11 @@ namespace hac // variables void clear(); - npdm::InstructionType getInstructionType() const; - void setInstructionType(npdm::InstructionType type); + meta::InstructionType getInstructionType() const; + void setInstructionType(meta::InstructionType type); - npdm::ProcAddrSpaceType getProcAddressSpaceType() const; - void setProcAddressSpaceType(npdm::ProcAddrSpaceType type); + meta::ProcAddrSpaceType getProcAddressSpaceType() const; + void setProcAddressSpaceType(meta::ProcAddrSpaceType type); byte_t getMainThreadPriority() const; void setMainThreadPriority(byte_t priority); @@ -59,14 +59,14 @@ namespace hac const AccessControlInfoDescBinary& getAcid() const; void setAcid(const AccessControlInfoDescBinary& acid); private: - const std::string kModuleName = "NPDM_BINARY"; + const std::string kModuleName = "META_BINARY"; // raw binary fnd::Vec mRawBinary; // variables - npdm::InstructionType mInstructionType; - npdm::ProcAddrSpaceType mProcAddressSpaceType; + meta::InstructionType mInstructionType; + meta::ProcAddrSpaceType mProcAddressSpaceType; byte_t mMainThreadPriority; byte_t mMainThreadCpuId; uint32_t mVersion; diff --git a/lib/libhac/include/nn/hac/npdm.h b/lib/libhac/include/nn/hac/meta.h similarity index 72% rename from lib/libhac/include/nn/hac/npdm.h rename to lib/libhac/include/nn/hac/meta.h index dbcda23..477a687 100644 --- a/lib/libhac/include/nn/hac/npdm.h +++ b/lib/libhac/include/nn/hac/meta.h @@ -6,9 +6,9 @@ namespace nn { namespace hac { - namespace npdm + namespace meta { - static const uint32_t kNpdmStructMagic = _MAKE_STRUCT_MAGIC_U32("META"); + static const uint32_t kMetaStructMagic = _MAKE_STRUCT_MAGIC_U32("META"); static const size_t kNameMaxLen = 0x10; static const size_t kProductCodeMaxLen = 0x10; static const uint32_t kMaxPriority = BIT(6) - 1; @@ -29,8 +29,13 @@ namespace hac }; } #pragma pack(push,1) + struct sMetaSection + { + le_uint32_t offset; + le_uint32_t size; + }; - struct sNpdmHeader + struct sMetaHeader { le_uint32_t st_magic; byte_t reserved_0[8]; @@ -41,15 +46,11 @@ namespace hac byte_t reserved_2[8]; le_uint32_t version; le_uint32_t main_thread_stack_size; - char name[npdm::kNameMaxLen]; // important - char product_code[npdm::kProductCodeMaxLen]; // can be empty + char name[meta::kNameMaxLen]; // important + char product_code[meta::kProductCodeMaxLen]; // can be empty byte_t reserved_3[48]; - // Access Control Info - struct sNpdmSection - { - le_uint32_t offset; - le_uint32_t size; - } aci, acid; + sMetaSection aci; + sMetaSection acid; }; #pragma pack(pop) diff --git a/lib/libhac/libhac.vcxproj b/lib/libhac/libhac.vcxproj index db66da1..fae1a0e 100644 --- a/lib/libhac/libhac.vcxproj +++ b/lib/libhac/libhac.vcxproj @@ -51,6 +51,8 @@ + + @@ -59,8 +61,6 @@ - - @@ -101,13 +101,13 @@ + - diff --git a/lib/libhac/libhac.vcxproj.filters b/lib/libhac/libhac.vcxproj.filters index 2099435..54f3f31 100644 --- a/lib/libhac/libhac.vcxproj.filters +++ b/lib/libhac/libhac.vcxproj.filters @@ -129,7 +129,7 @@ Header Files - + Header Files @@ -266,7 +266,7 @@ Source Files - + Source Files diff --git a/lib/libhac/source/NpdmBinary.cpp b/lib/libhac/source/MetaBinary.cpp similarity index 59% rename from lib/libhac/source/NpdmBinary.cpp rename to lib/libhac/source/MetaBinary.cpp index fe26c3a..234b916 100644 --- a/lib/libhac/source/NpdmBinary.cpp +++ b/lib/libhac/source/MetaBinary.cpp @@ -1,19 +1,19 @@ -#include +#include #include -nn::hac::NpdmBinary::NpdmBinary() +nn::hac::MetaBinary::MetaBinary() { clear(); } -nn::hac::NpdmBinary::NpdmBinary(const NpdmBinary & other) : - NpdmBinary() +nn::hac::MetaBinary::MetaBinary(const MetaBinary & other) : + MetaBinary() { *this = other; } -void nn::hac::NpdmBinary::operator=(const NpdmBinary & other) +void nn::hac::MetaBinary::operator=(const MetaBinary & other) { mRawBinary = other.mRawBinary; mInstructionType = other.mInstructionType; @@ -28,7 +28,7 @@ void nn::hac::NpdmBinary::operator=(const NpdmBinary & other) mAcid = other.mAcid; } -bool nn::hac::NpdmBinary::operator==(const NpdmBinary & other) const +bool nn::hac::MetaBinary::operator==(const MetaBinary & other) const { return (mInstructionType == other.mInstructionType) \ && (mProcAddressSpaceType == other.mProcAddressSpaceType) \ @@ -42,12 +42,12 @@ bool nn::hac::NpdmBinary::operator==(const NpdmBinary & other) const && (mAcid == other.mAcid); } -bool nn::hac::NpdmBinary::operator!=(const NpdmBinary & other) const +bool nn::hac::MetaBinary::operator!=(const MetaBinary & other) const { return !(*this == other); } -void nn::hac::NpdmBinary::toBytes() +void nn::hac::MetaBinary::toBytes() { if (mAcid.getBytes().size() == 0) mAcid.toBytes(); @@ -61,20 +61,20 @@ void nn::hac::NpdmBinary::toBytes() uint32_t offset, size; } acid, aci; - acid.offset = (uint32_t)align(sizeof(sNpdmHeader), npdm::kSectionAlignSize); + acid.offset = (uint32_t)align(sizeof(sMetaHeader), meta::kSectionAlignSize); acid.size = (uint32_t)mAcid.getBytes().size(); - aci.offset = (uint32_t)(acid.offset + align(acid.size, npdm::kSectionAlignSize)); + aci.offset = (uint32_t)(acid.offset + align(acid.size, meta::kSectionAlignSize)); aci.size = (uint32_t)mAci.getBytes().size(); // get total size - size_t total_size = _MAX(_MAX(acid.offset + acid.size, aci.offset + aci.size), align(sizeof(sNpdmHeader), npdm::kSectionAlignSize)); + size_t total_size = _MAX(_MAX(acid.offset + acid.size, aci.offset + aci.size), align(sizeof(sMetaHeader), meta::kSectionAlignSize)); mRawBinary.alloc(total_size); - sNpdmHeader* hdr = (sNpdmHeader*)mRawBinary.data(); + sMetaHeader* hdr = (sMetaHeader*)mRawBinary.data(); // set type - hdr->st_magic = npdm::kNpdmStructMagic; + hdr->st_magic = meta::kMetaStructMagic; // set variables byte_t flag = ((byte_t)(mInstructionType & 1) | (byte_t)((mProcAddressSpaceType & 3) << 1)) & 0xf; @@ -83,8 +83,8 @@ void nn::hac::NpdmBinary::toBytes() hdr->main_thread_cpu_id = mMainThreadCpuId; hdr->version = mVersion; hdr->main_thread_stack_size = mMainThreadStackSize; - strncpy(hdr->name, mName.c_str(), npdm::kNameMaxLen); - strncpy(hdr->product_code, mProductCode.c_str(), npdm::kProductCodeMaxLen); + strncpy(hdr->name, mName.c_str(), meta::kNameMaxLen); + strncpy(hdr->product_code, mProductCode.c_str(), meta::kProductCodeMaxLen); // set offset/size hdr->aci.offset = aci.offset; @@ -103,45 +103,45 @@ void nn::hac::NpdmBinary::toBytes() } } -void nn::hac::NpdmBinary::fromBytes(const byte_t* data, size_t len) +void nn::hac::MetaBinary::fromBytes(const byte_t* data, size_t len) { // check size - if (len < sizeof(sNpdmHeader)) + if (len < sizeof(sMetaHeader)) { - throw fnd::Exception(kModuleName, "NPDM binary is too small"); + throw fnd::Exception(kModuleName, "META binary is too small"); } // clear variables clear(); // save a copy of the header - sNpdmHeader hdr; - memcpy((void*)&hdr, data, sizeof(sNpdmHeader)); + sMetaHeader hdr; + memcpy((void*)&hdr, data, sizeof(sMetaHeader)); // check magic - if (hdr.st_magic.get() != npdm::kNpdmStructMagic) + if (hdr.st_magic.get() != meta::kMetaStructMagic) { - throw fnd::Exception(kModuleName, "NPDM header corrupt"); + throw fnd::Exception(kModuleName, "META header corrupt (unrecognised struct signature)"); } // save variables byte_t flag = hdr.flags & 0xf; - mInstructionType = (npdm::InstructionType)(flag & 1); - mProcAddressSpaceType = (npdm::ProcAddrSpaceType)((flag >> 1) & 3); + mInstructionType = (meta::InstructionType)(flag & 1); + mProcAddressSpaceType = (meta::ProcAddrSpaceType)((flag >> 1) & 3); mMainThreadPriority = hdr.main_thread_priority; mMainThreadCpuId = hdr.main_thread_cpu_id; mVersion = hdr.version.get(); mMainThreadStackSize = hdr.main_thread_stack_size.get(); - mName = std::string(hdr.name, _MIN(strlen(hdr.name), npdm::kNameMaxLen)); - mProductCode = std::string(hdr.product_code, _MIN(strlen(hdr.product_code), npdm::kProductCodeMaxLen)); + mName = std::string(hdr.name, _MIN(strlen(hdr.name), meta::kNameMaxLen)); + mProductCode = std::string(hdr.product_code, _MIN(strlen(hdr.product_code), meta::kProductCodeMaxLen)); // total size - size_t total_size = _MAX(_MAX(hdr.acid.offset.get() + hdr.acid.size.get(), hdr.aci.offset.get() + hdr.aci.size.get()), sizeof(sNpdmHeader)); + size_t total_size = _MAX(_MAX(hdr.acid.offset.get() + hdr.acid.size.get(), hdr.aci.offset.get() + hdr.aci.size.get()), sizeof(sMetaHeader)); // check size if (total_size > len) { - throw fnd::Exception(kModuleName, "NPDM binary too small"); + throw fnd::Exception(kModuleName, "META binary too small"); } // save local copy @@ -159,16 +159,16 @@ void nn::hac::NpdmBinary::fromBytes(const byte_t* data, size_t len) } } -const fnd::Vec& nn::hac::NpdmBinary::getBytes() const +const fnd::Vec& nn::hac::MetaBinary::getBytes() const { return mRawBinary; } -void nn::hac::NpdmBinary::clear() +void nn::hac::MetaBinary::clear() { mRawBinary.clear(); - mInstructionType = npdm::INSTR_64BIT; - mProcAddressSpaceType = npdm::ADDR_SPACE_64BIT; + mInstructionType = meta::INSTR_64BIT; + mProcAddressSpaceType = meta::ADDR_SPACE_64BIT; mMainThreadPriority = 0; mMainThreadCpuId = 0; mVersion = 0; @@ -179,34 +179,34 @@ void nn::hac::NpdmBinary::clear() mAcid.clear(); } -nn::hac::npdm::InstructionType nn::hac::NpdmBinary::getInstructionType() const +nn::hac::meta::InstructionType nn::hac::MetaBinary::getInstructionType() const { return mInstructionType; } -void nn::hac::NpdmBinary::setInstructionType(npdm::InstructionType type) +void nn::hac::MetaBinary::setInstructionType(meta::InstructionType type) { mInstructionType = type; } -nn::hac::npdm::ProcAddrSpaceType nn::hac::NpdmBinary::getProcAddressSpaceType() const +nn::hac::meta::ProcAddrSpaceType nn::hac::MetaBinary::getProcAddressSpaceType() const { return mProcAddressSpaceType; } -void nn::hac::NpdmBinary::setProcAddressSpaceType(npdm::ProcAddrSpaceType type) +void nn::hac::MetaBinary::setProcAddressSpaceType(meta::ProcAddrSpaceType type) { mProcAddressSpaceType = type; } -byte_t nn::hac::NpdmBinary::getMainThreadPriority() const +byte_t nn::hac::MetaBinary::getMainThreadPriority() const { return mMainThreadPriority; } -void nn::hac::NpdmBinary::setMainThreadPriority(byte_t priority) +void nn::hac::MetaBinary::setMainThreadPriority(byte_t priority) { - if (priority > npdm::kMaxPriority) + if (priority > meta::kMaxPriority) { throw fnd::Exception(kModuleName, "Illegal main thread priority (range 0-63)"); } @@ -214,44 +214,44 @@ void nn::hac::NpdmBinary::setMainThreadPriority(byte_t priority) mMainThreadPriority = priority; } -byte_t nn::hac::NpdmBinary::getMainThreadCpuId() const +byte_t nn::hac::MetaBinary::getMainThreadCpuId() const { return mMainThreadCpuId; } -void nn::hac::NpdmBinary::setMainThreadCpuId(byte_t core_num) +void nn::hac::MetaBinary::setMainThreadCpuId(byte_t core_num) { mMainThreadCpuId = core_num; } -uint32_t nn::hac::NpdmBinary::getVersion() const +uint32_t nn::hac::MetaBinary::getVersion() const { return mVersion; } -void nn::hac::NpdmBinary::setVersion(uint32_t version) +void nn::hac::MetaBinary::setVersion(uint32_t version) { mVersion = version; } -uint32_t nn::hac::NpdmBinary::getMainThreadStackSize() const +uint32_t nn::hac::MetaBinary::getMainThreadStackSize() const { return mMainThreadStackSize; } -void nn::hac::NpdmBinary::setMainThreadStackSize(uint32_t size) +void nn::hac::MetaBinary::setMainThreadStackSize(uint32_t size) { mMainThreadStackSize = size; } -const std::string & nn::hac::NpdmBinary::getName() const +const std::string & nn::hac::MetaBinary::getName() const { return mName; } -void nn::hac::NpdmBinary::setName(const std::string & name) +void nn::hac::MetaBinary::setName(const std::string & name) { - if (name.length() > npdm::kNameMaxLen) + if (name.length() > meta::kNameMaxLen) { throw fnd::Exception(kModuleName, "Name is too long"); } @@ -259,14 +259,14 @@ void nn::hac::NpdmBinary::setName(const std::string & name) mName = name; } -const std::string & nn::hac::NpdmBinary::getProductCode() const +const std::string & nn::hac::MetaBinary::getProductCode() const { return mProductCode; } -void nn::hac::NpdmBinary::setProductCode(const std::string & product_code) +void nn::hac::MetaBinary::setProductCode(const std::string & product_code) { - if (product_code.length() > npdm::kProductCodeMaxLen) + if (product_code.length() > meta::kProductCodeMaxLen) { throw fnd::Exception(kModuleName, "Product Code is too long"); } @@ -274,22 +274,22 @@ void nn::hac::NpdmBinary::setProductCode(const std::string & product_code) mProductCode = product_code; } -const nn::hac::AccessControlInfoBinary & nn::hac::NpdmBinary::getAci() const +const nn::hac::AccessControlInfoBinary & nn::hac::MetaBinary::getAci() const { return mAci; } -void nn::hac::NpdmBinary::setAci(const AccessControlInfoBinary & aci) +void nn::hac::MetaBinary::setAci(const AccessControlInfoBinary & aci) { mAci = aci; } -const nn::hac::AccessControlInfoDescBinary & nn::hac::NpdmBinary::getAcid() const +const nn::hac::AccessControlInfoDescBinary & nn::hac::MetaBinary::getAcid() const { return mAcid; } -void nn::hac::NpdmBinary::setAcid(const AccessControlInfoDescBinary & acid) +void nn::hac::MetaBinary::setAcid(const AccessControlInfoDescBinary & acid) { mAcid = acid; } \ No newline at end of file diff --git a/programs/nstool/nstool.vcxproj b/programs/nstool/nstool.vcxproj index ea08f49..0cec4b7 100644 --- a/programs/nstool/nstool.vcxproj +++ b/programs/nstool/nstool.vcxproj @@ -184,9 +184,9 @@ + - @@ -206,9 +206,9 @@ + - diff --git a/programs/nstool/nstool.vcxproj.filters b/programs/nstool/nstool.vcxproj.filters index 7404275..de89389 100644 --- a/programs/nstool/nstool.vcxproj.filters +++ b/programs/nstool/nstool.vcxproj.filters @@ -37,15 +37,15 @@ Header Files + + Header Files + Header Files Header Files - - Header Files - Header Files @@ -99,15 +99,15 @@ Source Files + + Source Files + Source Files Source Files - - Source Files - Source Files diff --git a/programs/nstool/source/NpdmProcess.cpp b/programs/nstool/source/MetaProcess.cpp similarity index 92% rename from programs/nstool/source/NpdmProcess.cpp rename to programs/nstool/source/MetaProcess.cpp index c397b2e..e67687c 100644 --- a/programs/nstool/source/NpdmProcess.cpp +++ b/programs/nstool/source/MetaProcess.cpp @@ -1,72 +1,72 @@ #include #include -#include "NpdmProcess.h" +#include "MetaProcess.h" -NpdmProcess::NpdmProcess() : +MetaProcess::MetaProcess() : mFile(), mCliOutputMode(_BIT(OUTPUT_BASIC)), mVerify(false) { } -void NpdmProcess::process() +void MetaProcess::process() { - importNpdm(); + importMeta(); if (mVerify) { - validateAcidSignature(mNpdm.getAcid()); - validateAciFromAcid(mNpdm.getAci(), mNpdm.getAcid()); + validateAcidSignature(mMeta.getAcid()); + validateAciFromAcid(mMeta.getAci(), mMeta.getAcid()); } if (_HAS_BIT(mCliOutputMode, OUTPUT_BASIC)) { // npdm binary - displayNpdmHeader(mNpdm); + displayMetaHeader(mMeta); // aci binary - displayAciHdr(mNpdm.getAci()); - displayFac(mNpdm.getAci().getFileSystemAccessControl()); - displaySac(mNpdm.getAci().getServiceAccessControl()); - displayKernelCap(mNpdm.getAci().getKernelCapabilities()); + displayAciHdr(mMeta.getAci()); + displayFac(mMeta.getAci().getFileSystemAccessControl()); + displaySac(mMeta.getAci().getServiceAccessControl()); + displayKernelCap(mMeta.getAci().getKernelCapabilities()); // acid binary if (_HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED)) { - displayAciDescHdr(mNpdm.getAcid()); - displayFac(mNpdm.getAcid().getFileSystemAccessControl()); - displaySac(mNpdm.getAcid().getServiceAccessControl()); - displayKernelCap(mNpdm.getAcid().getKernelCapabilities()); + displayAciDescHdr(mMeta.getAcid()); + displayFac(mMeta.getAcid().getFileSystemAccessControl()); + displaySac(mMeta.getAcid().getServiceAccessControl()); + displayKernelCap(mMeta.getAcid().getKernelCapabilities()); } } } -void NpdmProcess::setInputFile(const fnd::SharedPtr& file) +void MetaProcess::setInputFile(const fnd::SharedPtr& file) { mFile = file; } -void NpdmProcess::setKeyCfg(const KeyConfiguration& keycfg) +void MetaProcess::setKeyCfg(const KeyConfiguration& keycfg) { mKeyCfg = keycfg; } -void NpdmProcess::setCliOutputMode(CliOutputMode type) +void MetaProcess::setCliOutputMode(CliOutputMode type) { mCliOutputMode = type; } -void NpdmProcess::setVerifyMode(bool verify) +void MetaProcess::setVerifyMode(bool verify) { mVerify = verify; } -const nn::hac::NpdmBinary& NpdmProcess::getNpdmBinary() const +const nn::hac::MetaBinary& MetaProcess::getMetaBinary() const { - return mNpdm; + return mMeta; } -void NpdmProcess::importNpdm() +void MetaProcess::importMeta() { fnd::Vec scratch; @@ -78,10 +78,10 @@ void NpdmProcess::importNpdm() scratch.alloc((*mFile)->size()); (*mFile)->read(scratch.data(), 0, scratch.size()); - mNpdm.fromBytes(scratch.data(), scratch.size()); + mMeta.fromBytes(scratch.data(), scratch.size()); } -void NpdmProcess::validateAcidSignature(const nn::hac::AccessControlInfoDescBinary& acid) +void MetaProcess::validateAcidSignature(const nn::hac::AccessControlInfoDescBinary& acid) { try { fnd::rsa::sRsa2048Key acid_sign_key; @@ -96,7 +96,7 @@ void NpdmProcess::validateAcidSignature(const nn::hac::AccessControlInfoDescBina } -void NpdmProcess::validateAciFromAcid(const nn::hac::AccessControlInfoBinary& aci, const nn::hac::AccessControlInfoDescBinary& acid) +void MetaProcess::validateAciFromAcid(const nn::hac::AccessControlInfoBinary& aci, const nn::hac::AccessControlInfoDescBinary& acid) { // check Program ID if (acid.getProgramIdRestrict().min > 0 && aci.getProgramId() < acid.getProgramIdRestrict().min) @@ -287,9 +287,9 @@ void NpdmProcess::validateAciFromAcid(const nn::hac::AccessControlInfoBinary& ac } } -void NpdmProcess::displayNpdmHeader(const nn::hac::NpdmBinary& hdr) +void MetaProcess::displayMetaHeader(const nn::hac::MetaBinary& hdr) { - std::cout << "[NPDM HEADER]" << std::endl; + std::cout << "[Meta Header]" << std::endl; std::cout << " Process Architecture Params:" << std::endl; std::cout << " Ins. Type: " << getInstructionTypeStr(hdr.getInstructionType()) << std::endl; std::cout << " Addr Space: " << getProcAddressSpaceTypeStr(hdr.getProcAddressSpaceType()) << std::endl; @@ -306,13 +306,13 @@ void NpdmProcess::displayNpdmHeader(const nn::hac::NpdmBinary& hdr) } } -void NpdmProcess::displayAciHdr(const nn::hac::AccessControlInfoBinary& aci) +void MetaProcess::displayAciHdr(const nn::hac::AccessControlInfoBinary& aci) { std::cout << "[Access Control Info]" << std::endl; std::cout << " ProgramID: 0x" << std::hex << std::setw(16) << std::setfill('0') << aci.getProgramId() << std::endl; } -void NpdmProcess::displayAciDescHdr(const nn::hac::AccessControlInfoDescBinary& acid) +void MetaProcess::displayAciDescHdr(const nn::hac::AccessControlInfoDescBinary& acid) { std::cout << "[Access Control Info Desc]" << std::endl; if (acid.getFlagList().size() > 0 || _HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED)) @@ -328,7 +328,7 @@ void NpdmProcess::displayAciDescHdr(const nn::hac::AccessControlInfoDescBinary& std::cout << " Max: 0x" << std::hex << std::setw(16) << std::setfill('0') << acid.getProgramIdRestrict().max << std::endl; } -void NpdmProcess::displayFac(const nn::hac::FileSystemAccessControlBinary& fac) +void MetaProcess::displayFac(const nn::hac::FileSystemAccessControlBinary& fac) { std::cout << "[FS Access Control]" << std::endl; std::cout << " Format Version: " << std::dec << (uint32_t)fac.getFormatVersion() << std::endl; @@ -373,7 +373,7 @@ void NpdmProcess::displayFac(const nn::hac::FileSystemAccessControlBinary& fac) } -void NpdmProcess::displaySac(const nn::hac::ServiceAccessControlBinary& sac) +void MetaProcess::displaySac(const nn::hac::ServiceAccessControlBinary& sac) { std::cout << "[Service Access Control]" << std::endl; std::cout << " Service List:" << std::endl; @@ -394,7 +394,7 @@ void NpdmProcess::displaySac(const nn::hac::ServiceAccessControlBinary& sac) std::cout << std::endl; } -void NpdmProcess::displayKernelCap(const nn::hac::KernelCapabilityBinary& kern) +void MetaProcess::displayKernelCap(const nn::hac::KernelCapabilityBinary& kern) { std::cout << "[Kernel Capabilities]" << std::endl; if (kern.getThreadInfo().isSet()) @@ -496,16 +496,16 @@ void NpdmProcess::displayKernelCap(const nn::hac::KernelCapabilityBinary& kern) } } -const char* NpdmProcess::getInstructionTypeStr(nn::hac::npdm::InstructionType type) const +const char* MetaProcess::getInstructionTypeStr(nn::hac::meta::InstructionType type) const { const char* str = nullptr; switch(type) { - case (nn::hac::npdm::INSTR_32BIT): + case (nn::hac::meta::INSTR_32BIT): str = "32Bit"; break; - case (nn::hac::npdm::INSTR_64BIT): + case (nn::hac::meta::INSTR_64BIT): str = "64Bit"; break; default: @@ -516,19 +516,19 @@ const char* NpdmProcess::getInstructionTypeStr(nn::hac::npdm::InstructionType ty return str; } -const char* NpdmProcess::getProcAddressSpaceTypeStr(nn::hac::npdm::ProcAddrSpaceType type) const +const char* MetaProcess::getProcAddressSpaceTypeStr(nn::hac::meta::ProcAddrSpaceType type) const { const char* str = nullptr; switch(type) { - case (nn::hac::npdm::ADDR_SPACE_64BIT): + case (nn::hac::meta::ADDR_SPACE_64BIT): str = "64Bit"; break; - case (nn::hac::npdm::ADDR_SPACE_32BIT): + case (nn::hac::meta::ADDR_SPACE_32BIT): str = "32Bit"; break; - case (nn::hac::npdm::ADDR_SPACE_32BIT_NO_RESERVED): + case (nn::hac::meta::ADDR_SPACE_32BIT_NO_RESERVED): str = "32Bit no reserved"; break; default: @@ -539,7 +539,7 @@ const char* NpdmProcess::getProcAddressSpaceTypeStr(nn::hac::npdm::ProcAddrSpace return str; } -const char* NpdmProcess::getAcidFlagStr(nn::hac::aci::Flag flag) const +const char* MetaProcess::getAcidFlagStr(nn::hac::aci::Flag flag) const { const char* str = nullptr; @@ -559,7 +559,7 @@ const char* NpdmProcess::getAcidFlagStr(nn::hac::aci::Flag flag) const return str; } -const char* NpdmProcess::getMiscFlagStr(nn::hac::MiscFlagsHandler::Flags flag) const +const char* MetaProcess::getMiscFlagStr(nn::hac::MiscFlagsHandler::Flags flag) const { const char* str = nullptr; @@ -579,7 +579,7 @@ const char* NpdmProcess::getMiscFlagStr(nn::hac::MiscFlagsHandler::Flags flag) c return str; } -const char* NpdmProcess::getFsaRightStr(nn::hac::fac::FsAccessFlag flag) const +const char* MetaProcess::getFsaRightStr(nn::hac::fac::FsAccessFlag flag) const { const char* str = nullptr; @@ -659,7 +659,7 @@ const char* NpdmProcess::getFsaRightStr(nn::hac::fac::FsAccessFlag flag) const return str; } -const char* NpdmProcess::getSaveDataOwnerAccessModeStr(nn::hac::fac::SaveDataOwnerIdAccessType type) const +const char* MetaProcess::getSaveDataOwnerAccessModeStr(nn::hac::fac::SaveDataOwnerIdAccessType type) const { const char* str = nullptr; @@ -682,7 +682,7 @@ const char* NpdmProcess::getSaveDataOwnerAccessModeStr(nn::hac::fac::SaveDataOwn return str; } -const char* NpdmProcess::getSystemCallStr(byte_t syscall_id) const +const char* MetaProcess::getSystemCallStr(byte_t syscall_id) const { const char* str = nullptr; @@ -1077,7 +1077,7 @@ const char* NpdmProcess::getSystemCallStr(byte_t syscall_id) const return str; } -const char* NpdmProcess::getMemMapPermStr(nn::hac::MemoryMappingHandler::MemoryPerm type) const +const char* MetaProcess::getMemMapPermStr(nn::hac::MemoryMappingHandler::MemoryPerm type) const { const char* str = nullptr; @@ -1097,7 +1097,7 @@ const char* NpdmProcess::getMemMapPermStr(nn::hac::MemoryMappingHandler::MemoryP return str; } -const char* NpdmProcess::getMemMapTypeStr(nn::hac::MemoryMappingHandler::MappingType type) const +const char* MetaProcess::getMemMapTypeStr(nn::hac::MemoryMappingHandler::MappingType type) const { const char* str = nullptr; diff --git a/programs/nstool/source/NpdmProcess.h b/programs/nstool/source/MetaProcess.h similarity index 80% rename from programs/nstool/source/NpdmProcess.h rename to programs/nstool/source/MetaProcess.h index b4868bd..415656e 100644 --- a/programs/nstool/source/NpdmProcess.h +++ b/programs/nstool/source/MetaProcess.h @@ -3,15 +3,15 @@ #include #include #include -#include +#include #include "KeyConfiguration.h" #include "common.h" -class NpdmProcess +class MetaProcess { public: - NpdmProcess(); + MetaProcess(); void process(); @@ -20,32 +20,32 @@ public: void setCliOutputMode(CliOutputMode type); void setVerifyMode(bool verify); - const nn::hac::NpdmBinary& getNpdmBinary() const; + const nn::hac::MetaBinary& getMetaBinary() const; private: - const std::string kModuleName = "NpdmProcess"; + const std::string kModuleName = "MetaProcess"; fnd::SharedPtr mFile; KeyConfiguration mKeyCfg; CliOutputMode mCliOutputMode; bool mVerify; - nn::hac::NpdmBinary mNpdm; + nn::hac::MetaBinary mMeta; - void importNpdm(); + void importMeta(); void validateAcidSignature(const nn::hac::AccessControlInfoDescBinary& acid); void validateAciFromAcid(const nn::hac::AccessControlInfoBinary& aci, const nn::hac::AccessControlInfoDescBinary& acid); - void displayNpdmHeader(const nn::hac::NpdmBinary& hdr); + void displayMetaHeader(const nn::hac::MetaBinary& hdr); void displayAciHdr(const nn::hac::AccessControlInfoBinary& aci); void displayAciDescHdr(const nn::hac::AccessControlInfoDescBinary& aci); void displayFac(const nn::hac::FileSystemAccessControlBinary& fac); void displaySac(const nn::hac::ServiceAccessControlBinary& sac); void displayKernelCap(const nn::hac::KernelCapabilityBinary& kern); - const char* getInstructionTypeStr(nn::hac::npdm::InstructionType type) const; - const char* getProcAddressSpaceTypeStr(nn::hac::npdm::ProcAddrSpaceType type) const; + const char* getInstructionTypeStr(nn::hac::meta::InstructionType type) const; + const char* getProcAddressSpaceTypeStr(nn::hac::meta::ProcAddrSpaceType type) const; const char* getAcidFlagStr(nn::hac::aci::Flag flag) const; const char* getMiscFlagStr(nn::hac::MiscFlagsHandler::Flags flag) const; const char* getFsaRightStr(nn::hac::fac::FsAccessFlag flag) const; diff --git a/programs/nstool/source/NcaProcess.cpp b/programs/nstool/source/NcaProcess.cpp index 870aa7d..323f5a4 100644 --- a/programs/nstool/source/NcaProcess.cpp +++ b/programs/nstool/source/NcaProcess.cpp @@ -12,7 +12,7 @@ #include "NcaProcess.h" #include "PfsProcess.h" #include "RomfsProcess.h" -#include "NpdmProcess.h" +#include "MetaProcess.h" NcaProcess::NcaProcess() : @@ -410,12 +410,12 @@ void NcaProcess::validateNcaSignatures() { const nn::hac::PfsHeader::sFile& file = exefs.getPfsHeader().getFileList().getElement(kNpdmExefsPath); - NpdmProcess npdm; + MetaProcess npdm; npdm.setInputFile(new fnd::OffsetAdjustedIFile(mPartitions[nn::hac::nca::PARTITION_CODE].reader, file.offset, file.size)); npdm.setCliOutputMode(0); npdm.process(); - if (fnd::rsa::pss::rsaVerify(npdm.getNpdmBinary().getAcid().getNcaHeaderSignature2Key(), fnd::sha::HASH_SHA256, mHdrHash.bytes, mHdrBlock.signature_acid) != 0) + if (fnd::rsa::pss::rsaVerify(npdm.getMetaBinary().getAcid().getNcaHeaderSignature2Key(), fnd::sha::HASH_SHA256, mHdrHash.bytes, mHdrBlock.signature_acid) != 0) { std::cout << "[WARNING] NCA Header ACID Signature: FAIL" << std::endl; } diff --git a/programs/nstool/source/NroProcess.cpp b/programs/nstool/source/NroProcess.cpp index 546e7fa..20951c4 100644 --- a/programs/nstool/source/NroProcess.cpp +++ b/programs/nstool/source/NroProcess.cpp @@ -43,7 +43,7 @@ void NroProcess::setVerifyMode(bool verify) mVerify = verify; } -void NroProcess::setInstructionType(nn::hac::npdm::InstructionType type) +void NroProcess::setInstructionType(nn::hac::meta::InstructionType type) { mRoMeta.setInstructionType(type); } diff --git a/programs/nstool/source/NroProcess.h b/programs/nstool/source/NroProcess.h index 4ddd1eb..c0610b3 100644 --- a/programs/nstool/source/NroProcess.h +++ b/programs/nstool/source/NroProcess.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include "AssetProcess.h" @@ -22,7 +22,7 @@ public: void setCliOutputMode(CliOutputMode type); void setVerifyMode(bool verify); - void setInstructionType(nn::hac::npdm::InstructionType type); + void setInstructionType(nn::hac::meta::InstructionType type); void setListApi(bool listApi); void setListSymbols(bool listSymbols); diff --git a/programs/nstool/source/NsoProcess.cpp b/programs/nstool/source/NsoProcess.cpp index 3012e98..7db1e16 100644 --- a/programs/nstool/source/NsoProcess.cpp +++ b/programs/nstool/source/NsoProcess.cpp @@ -38,7 +38,7 @@ void NsoProcess::setVerifyMode(bool verify) mVerify = verify; } -void NsoProcess::setInstructionType(nn::hac::npdm::InstructionType type) +void NsoProcess::setInstructionType(nn::hac::meta::InstructionType type) { mRoMeta.setInstructionType(type); } diff --git a/programs/nstool/source/NsoProcess.h b/programs/nstool/source/NsoProcess.h index 88170ae..ca738b5 100644 --- a/programs/nstool/source/NsoProcess.h +++ b/programs/nstool/source/NsoProcess.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include "common.h" @@ -21,7 +21,7 @@ public: void setCliOutputMode(CliOutputMode type); void setVerifyMode(bool verify); - void setInstructionType(nn::hac::npdm::InstructionType type); + void setInstructionType(nn::hac::meta::InstructionType type); void setListApi(bool listApi); void setListSymbols(bool listSymbols); @@ -32,7 +32,7 @@ private: fnd::SharedPtr mFile; CliOutputMode mCliOutputMode; bool mVerify; - nn::hac::npdm::InstructionType mInstructionType; + nn::hac::meta::InstructionType mInstructionType; bool mListApi; bool mListSymbols; diff --git a/programs/nstool/source/RoMetadataProcess.cpp b/programs/nstool/source/RoMetadataProcess.cpp index 6d0f4ba..3025fbf 100644 --- a/programs/nstool/source/RoMetadataProcess.cpp +++ b/programs/nstool/source/RoMetadataProcess.cpp @@ -7,7 +7,7 @@ RoMetadataProcess::RoMetadataProcess() : mCliOutputMode(_BIT(OUTPUT_BASIC)), - mInstructionType(nn::hac::npdm::INSTR_64BIT), + mInstructionType(nn::hac::meta::INSTR_64BIT), mListApi(false), mListSymbols(false), mApiInfo(), @@ -57,7 +57,7 @@ void RoMetadataProcess::setCliOutputMode(CliOutputMode type) mCliOutputMode = type; } -void RoMetadataProcess::setInstructionType(nn::hac::npdm::InstructionType type) +void RoMetadataProcess::setInstructionType(nn::hac::meta::InstructionType type) { mInstructionType = type; } @@ -126,7 +126,7 @@ void RoMetadataProcess::importApiList() if (mDynSym.size > 0) { - mSymbolList.parseData(mRoBlob.data() + mDynSym.offset, mDynSym.size, mRoBlob.data() + mDynStr.offset, mDynStr.size, mInstructionType == nn::hac::npdm::INSTR_64BIT); + mSymbolList.parseData(mRoBlob.data() + mDynSym.offset, mDynSym.size, mRoBlob.data() + mDynStr.offset, mDynStr.size, mInstructionType == nn::hac::meta::INSTR_64BIT); } } diff --git a/programs/nstool/source/RoMetadataProcess.h b/programs/nstool/source/RoMetadataProcess.h index 664e06c..616a43e 100644 --- a/programs/nstool/source/RoMetadataProcess.h +++ b/programs/nstool/source/RoMetadataProcess.h @@ -4,7 +4,7 @@ #include #include -#include +#include #include "common.h" #include "SdkApiString.h" @@ -24,7 +24,7 @@ public: void setCliOutputMode(CliOutputMode type); - void setInstructionType(nn::hac::npdm::InstructionType type); + void setInstructionType(nn::hac::meta::InstructionType type); void setListApi(bool listApi); void setListSymbols(bool listSymbols); @@ -37,7 +37,7 @@ private: const std::string kModuleName = "RoMetadataProcess"; CliOutputMode mCliOutputMode; - nn::hac::npdm::InstructionType mInstructionType; + nn::hac::meta::InstructionType mInstructionType; bool mListApi; bool mListSymbols; diff --git a/programs/nstool/source/UserSettings.cpp b/programs/nstool/source/UserSettings.cpp index bf97fb8..955e9ee 100644 --- a/programs/nstool/source/UserSettings.cpp +++ b/programs/nstool/source/UserSettings.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include @@ -52,7 +52,7 @@ void UserSettings::showHelp() printf("\n General Options:\n"); printf(" -d, --dev Use devkit keyset.\n"); printf(" -k, --keyset Specify keyset file.\n"); - printf(" -t, --type Specify input file type. [xci, pfs, romfs, nca, npdm, cnmt, nso, nro, nacp, aset, cert, tik]\n"); + printf(" -t, --type Specify input file type. [xci, pfs, romfs, nca, meta, cnmt, nso, nro, nacp, aset, cert, tik]\n"); printf(" -y, --verify Verify file.\n"); printf("\n Output Options:\n"); printf(" --showkeys Show keys generated.\n"); @@ -133,7 +133,7 @@ bool UserSettings::isListSymbols() const return mListSymbols; } -nn::hac::npdm::InstructionType UserSettings::getInstType() const +nn::hac::meta::InstructionType UserSettings::getInstType() const { return mInstructionType; } @@ -548,7 +548,7 @@ void UserSettings::populateUserSettings(sCmdArgs& args) if (args.inst_type.isSet) mInstructionType = getInstructionTypeFromString(*args.inst_type); else - mInstructionType = nn::hac::npdm::INSTR_64BIT; // default 64bit + mInstructionType = nn::hac::meta::INSTR_64BIT; // default 64bit mListApi = args.list_api.isSet; mListSymbols = args.list_sym.isSet; @@ -602,8 +602,8 @@ FileType UserSettings::getFileTypeFromString(const std::string& type_str) type = FILE_ROMFS; else if (str == "nca") type = FILE_NCA; - else if (str == "npdm") - type = FILE_NPDM; + else if (str == "meta") + type = FILE_META; else if (str == "cnmt") type = FILE_CNMT; else if (str == "nso") @@ -657,8 +657,8 @@ FileType UserSettings::determineFileTypeFromFile(const std::string& path) else if (_ASSERT_SIZE(sizeof(nn::hac::sRomfsHeader)) && _TYPE_PTR(nn::hac::sRomfsHeader)->header_size.get() == sizeof(nn::hac::sRomfsHeader) && _TYPE_PTR(nn::hac::sRomfsHeader)->sections[1].offset.get() == (_TYPE_PTR(nn::hac::sRomfsHeader)->sections[0].offset.get() + _TYPE_PTR(nn::hac::sRomfsHeader)->sections[0].size.get())) file_type = FILE_ROMFS; // test npdm - else if (_ASSERT_SIZE(sizeof(nn::hac::sNpdmHeader)) && _TYPE_PTR(nn::hac::sNpdmHeader)->st_magic.get() == nn::hac::npdm::kNpdmStructMagic) - file_type = FILE_NPDM; + else if (_ASSERT_SIZE(sizeof(nn::hac::sMetaHeader)) && _TYPE_PTR(nn::hac::sMetaHeader)->st_magic.get() == nn::hac::meta::kMetaStructMagic) + file_type = FILE_META; // test nca else if (determineValidNcaFromSample(scratch)) file_type = FILE_NCA; @@ -832,16 +832,16 @@ bool UserSettings::determineValidEsTikFromSample(const fnd::Vec& sample) return true; } -nn::hac::npdm::InstructionType UserSettings::getInstructionTypeFromString(const std::string & type_str) +nn::hac::meta::InstructionType UserSettings::getInstructionTypeFromString(const std::string & type_str) { std::string str = type_str; std::transform(str.begin(), str.end(), str.begin(), ::tolower); - nn::hac::npdm::InstructionType type; + nn::hac::meta::InstructionType type; if (str == "32bit") - type = nn::hac::npdm::INSTR_32BIT; + type = nn::hac::meta::INSTR_32BIT; else if (str == "64bit") - type = nn::hac::npdm::INSTR_64BIT; + type = nn::hac::meta::INSTR_64BIT; else throw fnd::Exception(kModuleName, "Unsupported instruction type: " + str); diff --git a/programs/nstool/source/UserSettings.h b/programs/nstool/source/UserSettings.h index eeddd6f..935c0c5 100644 --- a/programs/nstool/source/UserSettings.h +++ b/programs/nstool/source/UserSettings.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include "common.h" #include "KeyConfiguration.h" @@ -29,7 +29,7 @@ public: bool isListFs() const; bool isListApi() const; bool isListSymbols() const; - nn::hac::npdm::InstructionType getInstType() const; + nn::hac::meta::InstructionType getInstType() const; // specialised paths const sOptional& getXciUpdatePath() const; @@ -110,7 +110,7 @@ private: bool mListApi; bool mListSymbols; - nn::hac::npdm::InstructionType mInstructionType; + nn::hac::meta::InstructionType mInstructionType; void populateCmdArgs(const std::vector& arg_list, sCmdArgs& cmd_args); void populateKeyset(sCmdArgs& args); @@ -122,7 +122,7 @@ private: bool determineValidNacpFromSample(const fnd::Vec& sample) const; bool determineValidEsCertFromSample(const fnd::Vec& sample) const; bool determineValidEsTikFromSample(const fnd::Vec& sample) const; - nn::hac::npdm::InstructionType getInstructionTypeFromString(const std::string& type_str); + nn::hac::meta::InstructionType getInstructionTypeFromString(const std::string& type_str); void getHomePath(std::string& path) const; void getSwitchPath(std::string& path) const; diff --git a/programs/nstool/source/common.h b/programs/nstool/source/common.h index 555e040..0df08c7 100644 --- a/programs/nstool/source/common.h +++ b/programs/nstool/source/common.h @@ -15,7 +15,7 @@ enum FileType FILE_PARTITIONFS, FILE_ROMFS, FILE_NCA, - FILE_NPDM, + FILE_META, FILE_CNMT, FILE_NSO, FILE_NRO, diff --git a/programs/nstool/source/main.cpp b/programs/nstool/source/main.cpp index 0e087c0..4f1776a 100644 --- a/programs/nstool/source/main.cpp +++ b/programs/nstool/source/main.cpp @@ -7,7 +7,7 @@ #include "PfsProcess.h" #include "RomfsProcess.h" #include "NcaProcess.h" -#include "NpdmProcess.h" +#include "MetaProcess.h" #include "CnmtProcess.h" #include "NsoProcess.h" #include "NroProcess.h" @@ -110,9 +110,9 @@ int main(int argc, char** argv) nca.process(); } - else if (user_set.getFileType() == FILE_NPDM) + else if (user_set.getFileType() == FILE_META) { - NpdmProcess npdm; + MetaProcess npdm; npdm.setInputFile(inputFile); npdm.setKeyCfg(user_set.getKeyCfg());