From aaffe12e8a8ad17e26e762b77d78c696ff9d7276 Mon Sep 17 00:00:00 2001 From: jakcron Date: Mon, 4 Jun 2018 12:00:28 +0800 Subject: [PATCH] [nx|nstool] Add nro.h and nrr.h. --- lib/libnx/include/nx/NsoHeader.h | 6 ++-- lib/libnx/include/nx/nro.h | 45 +++++++++++++++++++++++++++ lib/libnx/include/nx/nrr.h | 36 +++++++++++++++++++++ lib/libnx/include/nx/nso.h | 7 ++--- lib/libnx/nx.vcxproj | 3 ++ lib/libnx/nx.vcxproj.filters | 9 ++++++ lib/libnx/source/NsoHeader.cpp | 4 +-- programs/nstool/source/NsoProcess.cpp | 2 +- 8 files changed, 101 insertions(+), 11 deletions(-) create mode 100644 lib/libnx/include/nx/nro.h create mode 100644 lib/libnx/include/nx/nrr.h diff --git a/lib/libnx/include/nx/NsoHeader.h b/lib/libnx/include/nx/NsoHeader.h index acc4981..37cca28 100644 --- a/lib/libnx/include/nx/NsoHeader.h +++ b/lib/libnx/include/nx/NsoHeader.h @@ -12,16 +12,16 @@ namespace nx public: struct sModuleId { - byte_t data[nso::kModuleIdLen]; + byte_t data[nso::kModuleIdSize]; void operator=(const sModuleId& other) { - memcpy(data, other.data, nso::kModuleIdLen); + memcpy(data, other.data, nso::kModuleIdSize); } bool operator==(const sModuleId& other) const { - return memcmp(data, other.data, nso::kModuleIdLen) == 0; + return memcmp(data, other.data, nso::kModuleIdSize) == 0; } bool operator!=(const sModuleId& other) const diff --git a/lib/libnx/include/nx/nro.h b/lib/libnx/include/nx/nro.h new file mode 100644 index 0000000..ff378c8 --- /dev/null +++ b/lib/libnx/include/nx/nro.h @@ -0,0 +1,45 @@ +#pragma once +#include +#include +#include + +namespace nx +{ + namespace nro + { + static const uint32_t kNroSig = _MAKE_STRUCT_SIGNATURE("NRO0"); + + + static const uint32_t kDefaultFormatVersion = 0; + static const size_t kRoCrtSize = 8; + static const size_t kModuleIdSize = 32; + } + +#pragma pack(push,1) + struct sNroSection + { + le_uint32_t memory_offset; + le_uint32_t size; + }; + + struct sNroHeader + { + byte_t ro_crt[nro::kRoCrtSize]; + byte_t reserved_0[8]; + le_uint32_t signature; + le_uint32_t format_version; + le_uint32_t size; + le_uint32_t flags; + sNroSection text; + sNroSection ro; + sNroSection data; + le_uint32_t bss_size; + byte_t reserved_1[4]; + byte_t module_id[nro::kModuleIdSize]; + byte_t reserved_2[8]; + sNroSection embedded; + sNroSection dyn_str; + sNroSection dyn_sym; + }; +#pragma pack(pop) +} diff --git a/lib/libnx/include/nx/nrr.h b/lib/libnx/include/nx/nrr.h new file mode 100644 index 0000000..a11498e --- /dev/null +++ b/lib/libnx/include/nx/nrr.h @@ -0,0 +1,36 @@ +#pragma once +#include +#include +#include + +namespace nx +{ + namespace nrr + { + static const uint32_t kNrrSig = _MAKE_STRUCT_SIGNATURE("NRR0"); + } + +#pragma pack(push,1) + struct sNrrCertificate + { + le_uint64_t application_id_mask; + le_uint64_t application_id_pattern; + byte_t nrr_body_modulus[crypto::rsa::kRsa2048Size]; + byte_t nrr_cert_signature[crypto::rsa::kRsa2048Size]; + }; + + struct sNrrHeader + { + le_uint32_t signature; + byte_t reserved_0[28]; + sNrrCertificate certificate; + byte_t nrr_body_signature[crypto::rsa::kRsa2048Size]; + le_uint64_t application_id; + le_uint32_t size; + byte_t reserved_1[4]; + le_uint32_t hash_offset; + le_uint32_t hash_count; + byte_t reserved_2[8]; + }; +#pragma pack(pop) +} diff --git a/lib/libnx/include/nx/nso.h b/lib/libnx/include/nx/nso.h index 67ed525..8af09e1 100644 --- a/lib/libnx/include/nx/nso.h +++ b/lib/libnx/include/nx/nso.h @@ -1,9 +1,6 @@ #pragma once -#include #include -#include #include -#include #include namespace nx @@ -23,7 +20,7 @@ namespace nx }; static const uint32_t kDefaultFormatVersion = 0; - static const size_t kModuleIdLen = 32; + static const size_t kModuleIdSize = 32; } #pragma pack(push,1) @@ -52,7 +49,7 @@ namespace nx le_uint32_t module_name_size; sNsoCodeSegment data; le_uint32_t bss_size; - byte_t module_id[nso::kModuleIdLen]; + byte_t module_id[nso::kModuleIdSize]; le_uint32_t text_file_size; le_uint32_t ro_file_size; le_uint32_t data_file_size; diff --git a/lib/libnx/nx.vcxproj b/lib/libnx/nx.vcxproj index a4db247..dcd2072 100644 --- a/lib/libnx/nx.vcxproj +++ b/lib/libnx/nx.vcxproj @@ -42,6 +42,7 @@ + @@ -54,6 +55,8 @@ + + diff --git a/lib/libnx/nx.vcxproj.filters b/lib/libnx/nx.vcxproj.filters index 1692fb2..d4d2667 100644 --- a/lib/libnx/nx.vcxproj.filters +++ b/lib/libnx/nx.vcxproj.filters @@ -165,6 +165,15 @@ Header Files + + Header Files + + + Header Files + + + Header Files + diff --git a/lib/libnx/source/NsoHeader.cpp b/lib/libnx/source/NsoHeader.cpp index 77109c9..3b73113 100644 --- a/lib/libnx/source/NsoHeader.cpp +++ b/lib/libnx/source/NsoHeader.cpp @@ -53,7 +53,7 @@ void nx::NsoHeader::exportBinary() uint32_t flags = 0; // set moduleid - memcpy(hdr->module_id, mModuleId.data, nso::kModuleIdLen); + memcpy(hdr->module_id, mModuleId.data, nso::kModuleIdSize); // set bss size hdr->bss_size = mBssSize; @@ -152,7 +152,7 @@ void nx::NsoHeader::importBinary(const byte_t* bytes, size_t len) throw fnd::Exception(kModuleName, "NSO header corrupt (unsupported format version)"); } - memcpy(mModuleId.data, hdr->module_id, nso::kModuleIdLen); + memcpy(mModuleId.data, hdr->module_id, nso::kModuleIdSize); mBssSize = hdr->bss_size.get(); diff --git a/programs/nstool/source/NsoProcess.cpp b/programs/nstool/source/NsoProcess.cpp index 3d9708a..d412c2a 100644 --- a/programs/nstool/source/NsoProcess.cpp +++ b/programs/nstool/source/NsoProcess.cpp @@ -215,7 +215,7 @@ void NsoProcess::displayHeader() printf("[NSO Header]\n"); printf(" ModuleId: "); - _HEXDUMP_L(mHdr.getModuleId().data, nx::nso::kModuleIdLen); + _HEXDUMP_L(mHdr.getModuleId().data, nx::nso::kModuleIdSize); printf("\n"); printf(" Program Segments:\n"); printf(" .module_name:\n");