[nx|nstool] Add nro.h and nrr.h.

This commit is contained in:
jakcron 2018-06-04 12:00:28 +08:00
parent 57f91da709
commit aaffe12e8a
8 changed files with 101 additions and 11 deletions

View file

@ -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

View file

@ -0,0 +1,45 @@
#pragma once
#include <fnd/types.h>
#include <crypto/sha.h>
#include <nx/macro.h>
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)
}

View file

@ -0,0 +1,36 @@
#pragma once
#include <fnd/types.h>
#include <crypto/rsa.h>
#include <nx/macro.h>
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)
}

View file

@ -1,9 +1,6 @@
#pragma once
#include <string>
#include <fnd/types.h>
#include <fnd/List.h>
#include <crypto/sha.h>
#include <fnd/ISerialiseableBinary.h>
#include <nx/macro.h>
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;

View file

@ -42,6 +42,7 @@
<ClInclude Include="include\nx\KernelCapability.h" />
<ClInclude Include="include\nx\KernelVersionEntry.h" />
<ClInclude Include="include\nx\KernelVersionHandler.h" />
<ClInclude Include="include\nx\macro.h" />
<ClInclude Include="include\nx\MemoryMappingHandler.h" />
<ClInclude Include="include\nx\MemoryPageEntry.h" />
<ClInclude Include="include\nx\MiscFlagsEntry.h" />
@ -54,6 +55,8 @@
<ClInclude Include="include\nx\NpdmBinary.h" />
<ClInclude Include="include\nx\NpdmHeader.h" />
<ClInclude Include="include\nx\NcaHeader.h" />
<ClInclude Include="include\nx\nro.h" />
<ClInclude Include="include\nx\nrr.h" />
<ClInclude Include="include\nx\nso.h" />
<ClInclude Include="include\nx\NsoHeader.h" />
<ClInclude Include="include\nx\NXCrypto.h" />

View file

@ -165,6 +165,15 @@
<ClInclude Include="include\nx\dynamic_symbol.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\nx\macro.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\nx\nro.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\nx\nrr.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="makefile" />

View file

@ -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();

View file

@ -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");