mirror of
https://github.com/jakcron/nstool
synced 2024-12-24 21:51:14 +00:00
[nx] Extract structures and consts from AciHeader.h to aci.h
This commit is contained in:
parent
69c558923d
commit
b81c742e18
3 changed files with 76 additions and 63 deletions
|
@ -3,6 +3,7 @@
|
|||
#include <fnd/types.h>
|
||||
#include <fnd/MemoryBlob.h>
|
||||
#include <fnd/ISerialiseableBinary.h>
|
||||
#include <nx/aci.h>
|
||||
|
||||
namespace nx
|
||||
{
|
||||
|
@ -86,61 +87,6 @@ namespace nx
|
|||
|
||||
private:
|
||||
const std::string kModuleName = "ACI_HEADER";
|
||||
const std::string kAciStructSig = "ACI0";
|
||||
const std::string kAciDescStructSig = "ACID";
|
||||
static const size_t kAciAlignSize = 0x10;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct sAciHeader
|
||||
{
|
||||
private:
|
||||
byte_t signature_[4];
|
||||
uint32_t size_; // includes prefacing signature, set only in ACID made by SDK (it enables easy resigning)
|
||||
byte_t reserved_0[4];
|
||||
uint32_t flags_; // set in ACID only
|
||||
uint64_t program_id_; // set only in ACI0 (since ACID is generic)
|
||||
uint64_t program_id_max_;
|
||||
struct sAciSection
|
||||
{
|
||||
private:
|
||||
uint32_t offset_; // aligned by 0x10 from the last one
|
||||
uint32_t size_;
|
||||
public:
|
||||
uint32_t offset() const { return le_word(offset_); }
|
||||
void set_offset(uint32_t offset) { offset_ = le_word(offset); }
|
||||
|
||||
uint32_t size() const { return le_word(size_); }
|
||||
void set_size(uint32_t size) { size_ = le_word(size); }
|
||||
} fac_, sac_, kc_;
|
||||
public:
|
||||
const char* signature() const { return (const char*)signature_; }
|
||||
void set_signature(const char* signature) { memcpy(signature_, signature, 4); }
|
||||
|
||||
uint32_t size() const { return le_word(size_); }
|
||||
void set_size(uint32_t size) { size_ = le_word(size); }
|
||||
|
||||
uint32_t flags() const { return le_word(flags_); }
|
||||
void set_flags(uint32_t flags) { flags_ = le_word(flags); }
|
||||
|
||||
uint64_t program_id() const { return le_dword(program_id_); }
|
||||
void set_program_id(uint64_t program_id) { program_id_ = le_dword(program_id); }
|
||||
|
||||
uint64_t program_id_min() const { return program_id(); }
|
||||
void set_program_id_min(uint64_t program_id) { set_program_id(program_id); }
|
||||
|
||||
uint64_t program_id_max() const { return le_dword(program_id_max_); }
|
||||
void set_program_id_max(uint64_t program_id) { program_id_max_ = le_dword(program_id); }
|
||||
|
||||
const sAciSection& fac() const { return fac_; }
|
||||
sAciSection& fac() { return fac_; }
|
||||
|
||||
const sAciSection& sac() const { return sac_; }
|
||||
sAciSection& sac() { return sac_; }
|
||||
|
||||
const sAciSection& kc() const { return kc_; }
|
||||
sAciSection& kc() { return kc_; }
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
// raw data
|
||||
fnd::MemoryBlob mBinaryBlob;
|
||||
|
|
67
lib/libnx/include/nx/aci.h
Normal file
67
lib/libnx/include/nx/aci.h
Normal file
|
@ -0,0 +1,67 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
#include <fnd/types.h>
|
||||
#include <crypto/aes.h>
|
||||
#include <crypto/sha.h>
|
||||
#include <fnd/ISerialiseableBinary.h>
|
||||
|
||||
namespace nx
|
||||
{
|
||||
namespace aci
|
||||
{
|
||||
const std::string kAciStructSig = "ACI0";
|
||||
const std::string kAciDescStructSig = "ACID";
|
||||
static const size_t kAciAlignSize = 0x10;
|
||||
}
|
||||
#pragma pack(push,1)
|
||||
struct sAciHeader
|
||||
{
|
||||
private:
|
||||
byte_t signature_[4];
|
||||
uint32_t size_; // includes prefacing signature, set only in ACID made by SDK (it enables easy resigning)
|
||||
byte_t reserved_0[4];
|
||||
uint32_t flags_; // set in ACID only
|
||||
uint64_t program_id_; // set only in ACI0 (since ACID is generic)
|
||||
uint64_t program_id_max_;
|
||||
struct sAciSection
|
||||
{
|
||||
private:
|
||||
uint32_t offset_; // aligned by 0x10 from the last one
|
||||
uint32_t size_;
|
||||
public:
|
||||
uint32_t offset() const { return le_word(offset_); }
|
||||
void set_offset(uint32_t offset) { offset_ = le_word(offset); }
|
||||
|
||||
uint32_t size() const { return le_word(size_); }
|
||||
void set_size(uint32_t size) { size_ = le_word(size); }
|
||||
} fac_, sac_, kc_;
|
||||
public:
|
||||
const char* signature() const { return (const char*)signature_; }
|
||||
void set_signature(const char* signature) { memcpy(signature_, signature, 4); }
|
||||
|
||||
uint32_t size() const { return le_word(size_); }
|
||||
void set_size(uint32_t size) { size_ = le_word(size); }
|
||||
|
||||
uint32_t flags() const { return le_word(flags_); }
|
||||
void set_flags(uint32_t flags) { flags_ = le_word(flags); }
|
||||
|
||||
uint64_t program_id() const { return le_dword(program_id_); }
|
||||
void set_program_id(uint64_t program_id) { program_id_ = le_dword(program_id); }
|
||||
|
||||
uint64_t program_id_min() const { return program_id(); }
|
||||
void set_program_id_min(uint64_t program_id) { set_program_id(program_id); }
|
||||
|
||||
uint64_t program_id_max() const { return le_dword(program_id_max_); }
|
||||
void set_program_id_max(uint64_t program_id) { program_id_max_ = le_dword(program_id); }
|
||||
|
||||
const sAciSection& fac() const { return fac_; }
|
||||
sAciSection& fac() { return fac_; }
|
||||
|
||||
const sAciSection& sac() const { return sac_; }
|
||||
sAciSection& sac() { return sac_; }
|
||||
|
||||
const sAciSection& kc() const { return kc_; }
|
||||
sAciSection& kc() { return kc_; }
|
||||
};
|
||||
#pragma pack(pop)
|
||||
}
|
|
@ -4,9 +4,9 @@ using namespace nx;
|
|||
|
||||
void AciHeader::calculateSectionOffsets()
|
||||
{
|
||||
mFac.offset = align(mHeaderOffset, kAciAlignSize) + align(sizeof(sAciHeader), kAciAlignSize);
|
||||
mSac.offset = mFac.offset + align(mFac.size, kAciAlignSize);
|
||||
mKc.offset = mSac.offset + align(mSac.size, kAciAlignSize);
|
||||
mFac.offset = align(mHeaderOffset, aci::kAciAlignSize) + align(sizeof(sAciHeader), aci::kAciAlignSize);
|
||||
mSac.offset = mFac.offset + align(mFac.size, aci::kAciAlignSize);
|
||||
mKc.offset = mSac.offset + align(mSac.size, aci::kAciAlignSize);
|
||||
}
|
||||
|
||||
bool AciHeader::isEqual(const AciHeader & other) const
|
||||
|
@ -87,10 +87,10 @@ void AciHeader::exportBinary()
|
|||
switch (mType)
|
||||
{
|
||||
case (TYPE_ACI0):
|
||||
hdr->set_signature(kAciStructSig.c_str());
|
||||
hdr->set_signature(aci::kAciStructSig.c_str());
|
||||
break;
|
||||
case (TYPE_ACID):
|
||||
hdr->set_signature(kAciDescStructSig.c_str());
|
||||
hdr->set_signature(aci::kAciDescStructSig.c_str());
|
||||
break;
|
||||
default:
|
||||
throw fnd::Exception(kModuleName, "Unexpected ACI type");
|
||||
|
@ -139,11 +139,11 @@ void AciHeader::importBinary(const byte_t * bytes, size_t len)
|
|||
|
||||
sAciHeader* hdr = (sAciHeader*)mBinaryBlob.getBytes();
|
||||
|
||||
if (memcmp(hdr->signature(), kAciStructSig.c_str(), 4) == 0)
|
||||
if (memcmp(hdr->signature(), aci::kAciStructSig.c_str(), 4) == 0)
|
||||
{
|
||||
mType = TYPE_ACI0;
|
||||
}
|
||||
else if (memcmp(hdr->signature(), kAciDescStructSig.c_str(), 4) == 0)
|
||||
else if (memcmp(hdr->signature(), aci::kAciDescStructSig.c_str(), 4) == 0)
|
||||
{
|
||||
mType = TYPE_ACID;
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ void AciHeader::importBinary(const byte_t * bytes, size_t len)
|
|||
}
|
||||
|
||||
// the header offset is the MIN(sac.offset, fac.offset, kc.offset) - sizeof(sHeader)
|
||||
mHeaderOffset = MAX(MIN(hdr->sac().offset(), MIN(hdr->fac().offset(), hdr->kc().offset())), align(sizeof(sAciHeader), kAciAlignSize)) - align(sizeof(sAciHeader), kAciAlignSize);
|
||||
mHeaderOffset = MAX(MIN(hdr->sac().offset(), MIN(hdr->fac().offset(), hdr->kc().offset())), align(sizeof(sAciHeader), aci::kAciAlignSize)) - align(sizeof(sAciHeader), aci::kAciAlignSize);
|
||||
|
||||
mFac.offset = hdr->fac().offset() - mHeaderOffset;
|
||||
mFac.size = hdr->fac().size();
|
||||
|
|
Loading…
Reference in a new issue