[nx] Added nx namespace.

This commit is contained in:
jakcron 2017-07-06 21:17:21 +10:00
parent 01162b8187
commit 7b34bd404d
14 changed files with 450 additions and 420 deletions

View file

@ -1,5 +1,7 @@
#include "AciHeader.h" #include "AciHeader.h"
using namespace nx;
void AciHeader::clearVariables() void AciHeader::clearVariables()
{ {
mType = TYPE_ACI0; mType = TYPE_ACI0;

View file

@ -4,106 +4,109 @@
#include <fnd/memory_blob.h> #include <fnd/memory_blob.h>
#include <nx/ISerialiseableBinary.h> #include <nx/ISerialiseableBinary.h>
class AciHeader : public ISerialiseableBinary namespace nx
{ {
public: class AciHeader : public ISerialiseableBinary
enum AciType
{ {
TYPE_ACI0, // for Access Control Info public:
TYPE_ACID // for Access Control Info Desc enum AciType
}; {
TYPE_ACI0, // for Access Control Info
TYPE_ACID // for Access Control Info Desc
};
struct sSection struct sSection
{ {
size_t offset; size_t offset;
size_t size; size_t size;
}; };
AciHeader(); AciHeader();
AciHeader(const AciHeader& other); AciHeader(const AciHeader& other);
AciHeader(const u8* bytes); AciHeader(const u8* bytes);
bool operator==(const AciHeader& other) const; bool operator==(const AciHeader& other) const;
bool operator!=(const AciHeader& other) const; bool operator!=(const AciHeader& other) const;
void operator=(const AciHeader& other); void operator=(const AciHeader& other);
// to be used after export // to be used after export
const u8* getBytes() const; const u8* getBytes() const;
size_t getSize() const; size_t getSize() const;
// export/import binary // export/import binary
void exportBinary(); void exportBinary();
void importBinary(const u8* bytes); void importBinary(const u8* bytes);
void importBinary(const u8* bytes, size_t len); void importBinary(const u8* bytes, size_t len);
// variables // variables
AciType getAciType() const; AciType getAciType() const;
void setAciType(AciType type); void setAciType(AciType type);
u64 getProgramId() const; u64 getProgramId() const;
void setProgramId(u64 program_id); void setProgramId(u64 program_id);
const sSection& getFileAccessControl() const; const sSection& getFileAccessControl() const;
void setFileAccessControl(u32 size); void setFileAccessControl(u32 size);
const sSection& getServiceAccessControl() const; const sSection& getServiceAccessControl() const;
void setServiceAccessControl(u32 size); void setServiceAccessControl(u32 size);
const sSection& getKernelCapabilities() const; const sSection& getKernelCapabilities() const;
void setKernelCapabilities(u32 size); void setKernelCapabilities(u32 size);
private: private:
const std::string kModuleName = "ACI_HEADER"; const std::string kModuleName = "ACI_HEADER";
const std::string kAciStructSig = "ACI0"; const std::string kAciStructSig = "ACI0";
const std::string kAciDescStructSig = "ACID"; const std::string kAciDescStructSig = "ACID";
static const size_t kAciAlignSize = 0x10; static const size_t kAciAlignSize = 0x10;
#pragma pack(push, 1) #pragma pack(push, 1)
struct sAciHeader struct sAciHeader
{
private:
u8 signature_[4];
u8 reserved_1[12];
u64 program_id_;
u8 reserved_2[8];
struct sAciSection
{ {
private: private:
u32 offset_; // aligned by 0x10 from the last one u8 signature_[4];
u32 mSize; u8 reserved_1[12];
u64 program_id_;
u8 reserved_2[8];
struct sAciSection
{
private:
u32 offset_; // aligned by 0x10 from the last one
u32 mSize;
public:
u32 offset() const { return le_word(offset_); }
void set_offset(u32 offset) { offset_ = le_word(offset); }
u32 size() const { return le_word(mSize); }
void set_size(u32 size) { mSize = le_word(size); }
} fac_, sac_, kc_;
u8 reserved_3[8];
public: public:
u32 offset() const { return le_word(offset_); } const char* signature() const { return (const char*)signature_; }
void set_offset(u32 offset) { offset_ = le_word(offset); } void set_signature(const char* signature) { memcpy(signature_, signature, 4); }
u32 size() const { return le_word(mSize); } u64 program_id() const { return le_dword(program_id_); }
void set_size(u32 size) { mSize = le_word(size); } void set_program_id(u64 program_id) { program_id_ = le_dword(program_id); }
} fac_, sac_, kc_;
u8 reserved_3[8];
public:
const char* signature() const { return (const char*)signature_; }
void set_signature(const char* signature) { memcpy(signature_, signature, 4); }
u64 program_id() const { return le_dword(program_id_); } const sAciSection& fac() const { return fac_; }
void set_program_id(u64 program_id) { program_id_ = le_dword(program_id); } sAciSection& fac() { return fac_; }
const sAciSection& fac() const { return fac_; } const sAciSection& sac() const { return sac_; }
sAciSection& fac() { return fac_; } sAciSection& sac() { return sac_; }
const sAciSection& sac() const { return sac_; } const sAciSection& kc() const { return kc_; }
sAciSection& sac() { return sac_; } sAciSection& kc() { return kc_; }
};
const sAciSection& kc() const { return kc_; }
sAciSection& kc() { return kc_; }
};
#pragma pack(pop) #pragma pack(pop)
// raw data // raw data
fnd::MemoryBlob mBinaryBlob; fnd::MemoryBlob mBinaryBlob;
// variables // variables
AciType mType; AciType mType;
u64 mProgramId; u64 mProgramId;
sSection mFac, mSac, mKc; sSection mFac, mSac, mKc;
void clearVariables(); void clearVariables();
void calculateSectionOffsets(); void calculateSectionOffsets();
bool isEqual(const AciHeader& other) const; bool isEqual(const AciHeader& other) const;
void copyFrom(const AciHeader& other); void copyFrom(const AciHeader& other);
}; };
}

View file

@ -1,6 +1,6 @@
#include "FacBinary.h" #include "FacBinary.h"
using namespace nx;
FacBinary::FacBinary() : FacBinary::FacBinary() :
mHeader() mHeader()

View file

@ -5,77 +5,80 @@
#include <nx/ISerialiseableBinary.h> #include <nx/ISerialiseableBinary.h>
#include <nx/FacHeader.h> #include <nx/FacHeader.h>
class FacBinary : namespace nx
public ISerialiseableBinary
{ {
public: class FacBinary :
enum FsAccessFlag public ISerialiseableBinary
{ {
FSA_APPLICATION_INFO = BIT(0), public:
FSA_BOOT_MODE_CONTROL = BIT(1), enum FsAccessFlag
FSA_CALIBRATION = BIT(2), {
FSA_SYSTEM_SAVE_DATA = BIT(3), FSA_APPLICATION_INFO = BIT(0),
FSA_GAME_CARD = BIT(4), FSA_BOOT_MODE_CONTROL = BIT(1),
FSA_SAVE_DATA_BACKUP = BIT(5), FSA_CALIBRATION = BIT(2),
FSA_SAVE_DATA_MANAGEMENT = BIT(6), FSA_SYSTEM_SAVE_DATA = BIT(3),
FSA_BIS_ALL_RAW = BIT(7), FSA_GAME_CARD = BIT(4),
FSA_GAME_CARD_RAW = BIT(8), FSA_SAVE_DATA_BACKUP = BIT(5),
FSA_GAME_CARD_PRIVATE = BIT(9), FSA_SAVE_DATA_MANAGEMENT = BIT(6),
FSA_SET_TIME = BIT(10), FSA_BIS_ALL_RAW = BIT(7),
FSA_CONTENT_MANAGER = BIT(11), FSA_GAME_CARD_RAW = BIT(8),
FSA_IMAGE_MANAGER = BIT(12), FSA_GAME_CARD_PRIVATE = BIT(9),
FSA_CREATE_SAVE_DATA = BIT(13), FSA_SET_TIME = BIT(10),
FSA_SYSTEM_SAVE_DATA_MANAGEMENT = BIT(14), FSA_CONTENT_MANAGER = BIT(11),
FSA_BIS_FILE_SYSTEM = BIT(15), FSA_IMAGE_MANAGER = BIT(12),
FSA_SYSTEM_UPDATE = BIT(16), FSA_CREATE_SAVE_DATA = BIT(13),
FSA_SAVE_DATA_META = BIT(17), FSA_SYSTEM_SAVE_DATA_MANAGEMENT = BIT(14),
FSA_DEVICE_SAVE_CONTROL = BIT(19), FSA_BIS_FILE_SYSTEM = BIT(15),
FSA_SETTINGS_CONTROL = BIT(20), FSA_SYSTEM_UPDATE = BIT(16),
FSA_DEBUG = BIT(62), FSA_SAVE_DATA_META = BIT(17),
FSA_FULL_PERMISSION = BIT(63), FSA_DEVICE_SAVE_CONTROL = BIT(19),
FSA_SETTINGS_CONTROL = BIT(20),
FSA_DEBUG = BIT(62),
FSA_FULL_PERMISSION = BIT(63),
};
FacBinary();
FacBinary(const FacBinary& other);
FacBinary(const u8* bytes, size_t len);
bool operator==(const FacBinary& other) const;
bool operator!=(const FacBinary& other) const;
void operator=(const FacBinary& other);
// to be used after export
const u8* getBytes() const;
size_t getSize() const;
// export/import binary
void exportBinary();
void importBinary(const u8* bytes);
void importBinary(const u8* bytes, size_t len);
// variables
bool isPermissionSet(FsAccessFlag flag) const;
void addPermission(FsAccessFlag flag);
void removePermission(FsAccessFlag flag);
const fnd::List<u32>& getContentOwnerIds() const;
void addContentOwnerId(u32 id);
const fnd::List<u32>& getSaveDataOwnerIds() const;
void addSaveDataOwnerId(u32 id);
private:
const std::string kModuleName = "FAC_BINARY";
// raw binary
fnd::MemoryBlob mBinaryBlob;
// variables
FacHeader mHeader;
u64 mFsaRights;
fnd::List<u32> mContentOwnerIds;
fnd::List<u32> mSaveDataOwnerIds;
void clearVariables();
bool isEqual(const FacBinary& other) const;
void copyFrom(const FacBinary& other);
}; };
}
FacBinary();
FacBinary(const FacBinary& other);
FacBinary(const u8* bytes, size_t len);
bool operator==(const FacBinary& other) const;
bool operator!=(const FacBinary& other) const;
void operator=(const FacBinary& other);
// to be used after export
const u8* getBytes() const;
size_t getSize() const;
// export/import binary
void exportBinary();
void importBinary(const u8* bytes);
void importBinary(const u8* bytes, size_t len);
// variables
bool isPermissionSet(FsAccessFlag flag) const;
void addPermission(FsAccessFlag flag);
void removePermission(FsAccessFlag flag);
const fnd::List<u32>& getContentOwnerIds() const;
void addContentOwnerId(u32 id);
const fnd::List<u32>& getSaveDataOwnerIds() const;
void addSaveDataOwnerId(u32 id);
private:
const std::string kModuleName = "FAC_BINARY";
// raw binary
fnd::MemoryBlob mBinaryBlob;
// variables
FacHeader mHeader;
u64 mFsaRights;
fnd::List<u32> mContentOwnerIds;
fnd::List<u32> mSaveDataOwnerIds;
void clearVariables();
bool isEqual(const FacBinary& other) const;
void copyFrom(const FacBinary& other);
};

View file

@ -1,6 +1,6 @@
#include "FacHeader.h" #include "FacHeader.h"
using namespace nx;
FacHeader::FacHeader() FacHeader::FacHeader()
{ {

View file

@ -3,91 +3,95 @@
#include <fnd/memory_blob.h> #include <fnd/memory_blob.h>
#include <nx/ISerialiseableBinary.h> #include <nx/ISerialiseableBinary.h>
class FacHeader : namespace nx
public ISerialiseableBinary
{ {
public: class FacHeader :
FacHeader(); public ISerialiseableBinary
FacHeader(const FacHeader& other); {
FacHeader(const u8* bytes); public:
FacHeader();
FacHeader(const FacHeader& other);
FacHeader(const u8* bytes);
bool operator==(const FacHeader& other) const; bool operator==(const FacHeader& other) const;
bool operator!=(const FacHeader& other) const; bool operator!=(const FacHeader& other) const;
void operator=(const FacHeader& other); void operator=(const FacHeader& other);
// to be used after export // to be used after export
const u8* getBytes() const; const u8* getBytes() const;
size_t getSize() const; size_t getSize() const;
// export/import binary // export/import binary
void exportBinary(); void exportBinary();
void importBinary(const u8* bytes); void importBinary(const u8* bytes);
void importBinary(const u8* bytes, size_t len); void importBinary(const u8* bytes, size_t len);
// variables // variables
u64 getFacSize() const; u64 getFacSize() const;
u64 getFsaRights() const; u64 getFsaRights() const;
void setFsaRights(u64 flag); void setFsaRights(u64 flag);
size_t getContentOwnerIdOffset() const;
size_t getContentOwnerIdSize() const;
void setContentOwnerIdSize(size_t size);
size_t getSaveDataOwnerIdOffset() const; size_t getContentOwnerIdOffset() const;
size_t getSaveDataOwnerIdSize() const; size_t getContentOwnerIdSize() const;
void setSaveDataOwnerIdSize(size_t size); void setContentOwnerIdSize(size_t size);
private: size_t getSaveDataOwnerIdOffset() const;
const std::string kModuleName = "FAC_HEADER"; size_t getSaveDataOwnerIdSize() const;
static const u32 kFacFormatVersion = 1; void setSaveDataOwnerIdSize(size_t size);
private:
const std::string kModuleName = "FAC_HEADER";
static const u32 kFacFormatVersion = 1;
#pragma pack (push, 1) #pragma pack (push, 1)
struct sFacHeader struct sFacHeader
{
private:
u32 version_; // default 1
u64 fac_flags_;
struct sFacSection
{ {
private: private:
u32 start_; u32 version_; // default 1
u32 end_; u64 fac_flags_;
struct sFacSection
{
private:
u32 start_;
u32 end_;
public:
u32 start() const { return le_word(start_); }
void set_start(u32 start) { start_ = le_word(start); }
u32 end() const { return le_word(end_); }
void set_end(u32 end) { end_ = le_word(end); }
} content_owner_ids_, save_data_owner_ids_; // the data for these follow later in binary. start/end relative to base of FacData instance
public: public:
u32 start() const { return le_word(start_); } u32 version() const { return le_word(version_); }
void set_start(u32 start) { start_ = le_word(start); } void set_version(u32 version) { version_ = le_word(version); }
u32 end() const { return le_word(end_); } u64 fac_flags() const { return le_dword(fac_flags_); }
void set_end(u32 end) { end_ = le_word(end); } void set_fac_flags(u64 fac_flags) { fac_flags_ = le_dword(fac_flags); }
} content_owner_ids_, save_data_owner_ids_; // the data for these follow later in binary. start/end relative to base of FacData instance
public:
u32 version() const { return le_word(version_); }
void set_version(u32 version) { version_ = le_word(version); }
u64 fac_flags() const { return le_dword(fac_flags_); } const sFacSection& content_owner_ids() const { return content_owner_ids_; }
void set_fac_flags(u64 fac_flags) { fac_flags_ = le_dword(fac_flags); } sFacSection& content_owner_ids() { return content_owner_ids_; }
const sFacSection& content_owner_ids() const { return content_owner_ids_; } const sFacSection& save_data_owner_ids() const { return save_data_owner_ids_; }
sFacSection& content_owner_ids() { return content_owner_ids_; } sFacSection& save_data_owner_ids() { return save_data_owner_ids_; }
};
const sFacSection& save_data_owner_ids() const { return save_data_owner_ids_; }
sFacSection& save_data_owner_ids() { return save_data_owner_ids_; }
};
#pragma pack (pop) #pragma pack (pop)
// raw binary // raw binary
fnd::MemoryBlob mBinaryBlob; fnd::MemoryBlob mBinaryBlob;
// variables // variables
u64 mFsaRights; u64 mFsaRights;
struct sSection { struct sSection
size_t offset; {
size_t size; size_t offset;
} mContentOwnerIdPos, mSaveDataOwnerIdPos; size_t size;
} mContentOwnerIdPos, mSaveDataOwnerIdPos;
void clearVariables(); void clearVariables();
void calculateOffsets(); void calculateOffsets();
bool isEqual(const FacHeader& other) const; bool isEqual(const FacHeader& other) const;
void copyFrom(const FacHeader& other); void copyFrom(const FacHeader& other);
}; };
}

View file

@ -1,17 +1,20 @@
#pragma once #pragma once
#include <fnd/types.h> #include <fnd/types.h>
class ISerialiseableBinary namespace nx
{ {
public: class ISerialiseableBinary
//virtual bool operator==(const ISerialiseableBinary& other) = 0; {
//virtual void operator=(const ISerialiseableBinary& other) = 0; public:
//virtual bool operator==(const ISerialiseableBinary& other) = 0;
//virtual void operator=(const ISerialiseableBinary& other) = 0;
virtual const u8* getBytes() const = 0; virtual const u8* getBytes() const = 0;
virtual size_t getSize() const = 0; virtual size_t getSize() const = 0;
virtual void exportBinary() = 0; virtual void exportBinary() = 0;
virtual void importBinary(const u8* bytes) = 0; virtual void importBinary(const u8* bytes) = 0;
virtual void importBinary(const u8* bytes, size_t len) = 0; virtual void importBinary(const u8* bytes, size_t len) = 0;
}; };
}

View file

@ -1,6 +1,9 @@
#include "NcaHeader.h" #include "NcaHeader.h"
#include <fnd/exception.h> #include <fnd/exception.h>
using namespace nx;
void NcaHeader::exportBinary() void NcaHeader::exportBinary()
{ {
mBinaryBlob.alloc(sizeof(sNcaHeader)); mBinaryBlob.alloc(sizeof(sNcaHeader));

View file

@ -7,149 +7,153 @@
#include <crypto/sha.h> #include <crypto/sha.h>
#include <nx/ISerialiseableBinary.h> #include <nx/ISerialiseableBinary.h>
class NcaHeader : public ISerialiseableBinary namespace nx
{ {
public: class NcaHeader : public ISerialiseableBinary
struct sSection
{ {
u64 offset; public:
u64 size; struct sSection
u8 key_type;
crypto::sha::sSha256Hash hash;
const sSection& operator=(const sSection& other)
{ {
offset = other.offset; u64 offset;
size = other.size; u64 size;
key_type = other.key_type; u8 key_type;
hash = other.hash; crypto::sha::sSha256Hash hash;
return *this; const sSection& operator=(const sSection& other)
} {
offset = other.offset;
size = other.size;
key_type = other.key_type;
hash = other.hash;
bool operator==(const sSection& other) const return *this;
{ }
return (offset == other.offset) \
&& (size == other.size) \
&& (key_type == other.key_type) \
&& (hash == other.hash);
}
bool operator!=(const sSection& other) const bool operator==(const sSection& other) const
{ {
return operator==(other); return (offset == other.offset) \
} && (size == other.size) \
}; && (key_type == other.key_type) \
&& (hash == other.hash);
}
static const size_t kDefaultBlockSize = 0x200; bool operator!=(const sSection& other) const
{
return operator==(other);
}
};
NcaHeader(); static const size_t kDefaultBlockSize = 0x200;
NcaHeader(const NcaHeader& other);
NcaHeader(const u8* bytes);
bool operator==(const NcaHeader& other) const; NcaHeader();
bool operator!=(const NcaHeader& other) const; NcaHeader(const NcaHeader& other);
void operator=(const NcaHeader& other); NcaHeader(const u8* bytes);
// to be used after export bool operator==(const NcaHeader& other) const;
const u8* getBytes() const; bool operator!=(const NcaHeader& other) const;
size_t getSize() const; void operator=(const NcaHeader& other);
// export/import binary // to be used after export
void exportBinary(); const u8* getBytes() const;
void importBinary(const u8* bytes); size_t getSize() const;
void importBinary(const u8* bytes, size_t len);
// variables // export/import binary
u64 getNcaSize() const; void exportBinary();
void setNcaSize(u64 size); void importBinary(const u8* bytes);
u64 getProgramId() const; void importBinary(const u8* bytes, size_t len);
void setProgramId(u64 program_id);
u32 getUnk() const;
const fnd::List<sSection>& getSections() const;
void addSection(const sSection& section);
const fnd::List<crypto::aes::sAes128Key>& getAesKeys() const;
void addKey(const crypto::aes::sAes128Key& key);
private: // variables
const std::string kModuleName = "NCA_HEADER"; u64 getNcaSize() const;
const std::string kNcaSig = "NCA2"; void setNcaSize(u64 size);
static const size_t kSectionNum = 4; u64 getProgramId() const;
static const size_t kAesKeyNum = 4; void setProgramId(u64 program_id);
u32 getUnk() const;
const fnd::List<sSection>& getSections() const;
void addSection(const sSection& section);
const fnd::List<crypto::aes::sAes128Key>& getAesKeys() const;
void addKey(const crypto::aes::sAes128Key& key);
private:
const std::string kModuleName = "NCA_HEADER";
const std::string kNcaSig = "NCA2";
static const size_t kSectionNum = 4;
static const size_t kAesKeyNum = 4;
#pragma pack (push, 1) #pragma pack (push, 1)
struct sNcaHeader struct sNcaHeader
{
private:
u8 signature_[4];
u8 reserved_0[2];
u16 block_size_;
u64 nca_size_;
u64 program_id_;
u8 reserved_1[4];
u32 unk_0_;
u8 reserved_2[0x20];
struct sNcaSection
{ {
private: private:
u32 start_; // block units u8 signature_[4];
u32 end_; // block units u8 reserved_0[2];
u8 key_type_; u16 block_size_;
u8 reserved[7]; u64 nca_size_;
u64 program_id_;
u8 reserved_1[4];
u32 unk_0_;
u8 reserved_2[0x20];
struct sNcaSection
{
private:
u32 start_; // block units
u32 end_; // block units
u8 key_type_;
u8 reserved[7];
public:
u32 start() const { return le_word(start_); }
void set_start(u32 offset) { start_ = le_word(offset); }
u32 end() const { return le_word(end_); }
void set_end(u32 offset) { end_ = le_word(offset); }
u8 key_type() const { return key_type_; }
void set_key_type(u8 key_type) { key_type_ = key_type; }
} section_[kSectionNum];
crypto::sha::sSha256Hash section_hash_[kSectionNum];
crypto::aes::sAes128Key aes_keys_[kAesKeyNum];
public: public:
u32 start() const { return le_word(start_); } const char* signature() const { return (const char*)signature_; }
void set_start(u32 offset) { start_ = le_word(offset); } void set_signature(const char* signature) { memcpy(signature_, signature, 4); }
u32 end() const { return le_word(end_); } u16 block_size() const { return le_hword(block_size_); }
void set_end(u32 offset) { end_ = le_word(offset); } void set_block_size(u16 block_size) { block_size_ = le_hword(block_size); }
u8 key_type() const { return key_type_; } u64 nca_size() const { return le_dword(nca_size_); }
void set_key_type(u8 key_type) { key_type_ = key_type; } void set_nca_size(u64 nca_size) { nca_size_ = le_dword(nca_size); }
} section_[kSectionNum];
crypto::sha::sSha256Hash section_hash_[kSectionNum];
crypto::aes::sAes128Key aes_keys_[kAesKeyNum];
public:
const char* signature() const { return (const char*)signature_; }
void set_signature(const char* signature) { memcpy(signature_, signature, 4); }
u16 block_size() const { return le_hword(block_size_); } u64 program_id() const { return le_dword(program_id_); }
void set_block_size(u16 block_size) { block_size_ = le_hword(block_size); } void set_program_id(u64 program_id) { program_id_ = le_dword(program_id); }
u64 nca_size() const { return le_dword(nca_size_); } u32 unk0() const { return le_word(unk_0_); }
void set_nca_size(u64 nca_size) { nca_size_ = le_dword(nca_size); } void set_unk0(u32 val) { unk_0_ = le_word(val); }
u64 program_id() const { return le_dword(program_id_); } const sNcaSection& section(u8 index) const { return section_[index%kSectionNum]; }
void set_program_id(u64 program_id) { program_id_ = le_dword(program_id); } sNcaSection& section(u8 index) { return section_[index%kSectionNum]; }
u32 unk0() const { return le_word(unk_0_); } const crypto::sha::sSha256Hash& section_hash(u8 index) const { return section_hash_[index%kSectionNum]; }
void set_unk0(u32 val) { unk_0_ = le_word(val); } crypto::sha::sSha256Hash& section_hash(u8 index) { return section_hash_[index%kSectionNum]; }
const sNcaSection& section(u8 index) const { return section_[index%kSectionNum]; } const crypto::aes::sAes128Key& aes_key(u8 index) const { return aes_keys_[index%kAesKeyNum]; }
sNcaSection& section(u8 index) { return section_[index%kSectionNum]; } crypto::aes::sAes128Key& aes_key(u8 index) { return aes_keys_[index%kAesKeyNum]; }
};
const crypto::sha::sSha256Hash& section_hash(u8 index) const { return section_hash_[index%kSectionNum]; }
crypto::sha::sSha256Hash& section_hash(u8 index) { return section_hash_[index%kSectionNum]; }
const crypto::aes::sAes128Key& aes_key(u8 index) const { return aes_keys_[index%kAesKeyNum]; }
crypto::aes::sAes128Key& aes_key(u8 index) { return aes_keys_[index%kAesKeyNum]; }
};
#pragma pack (pop) #pragma pack (pop)
// binary // binary
fnd::MemoryBlob mBinaryBlob; fnd::MemoryBlob mBinaryBlob;
// data // data
u16 mBlockSize; u16 mBlockSize;
u64 mNcaSize; u64 mNcaSize;
u64 mProgramId; u64 mProgramId;
u32 mUnk0; u32 mUnk0;
fnd::List<sSection> mSections; fnd::List<sSection> mSections;
fnd::List<crypto::aes::sAes128Key> mAesKeys; fnd::List<crypto::aes::sAes128Key> mAesKeys;
void clearVariables(); void clearVariables();
u64 blockNumToSize(u32 block_num) const; u64 blockNumToSize(u32 block_num) const;
u32 sizeToBlockNum(u64 real_size) const; u32 sizeToBlockNum(u64 real_size) const;
bool isEqual(const NcaHeader& other) const; bool isEqual(const NcaHeader& other) const;
void copyFrom(const NcaHeader& other); void copyFrom(const NcaHeader& other);
}; };
}

View file

@ -1,6 +1,6 @@
#include "SacBinary.h" #include "SacBinary.h"
using namespace nx;
SacBinary::SacBinary() SacBinary::SacBinary()
{ {

View file

@ -6,41 +6,44 @@
#include <nx/ISerialiseableBinary.h> #include <nx/ISerialiseableBinary.h>
#include <nx/SacEntry.h> #include <nx/SacEntry.h>
class SacBinary : namespace nx
public ISerialiseableBinary
{ {
public: class SacBinary :
SacBinary(); public ISerialiseableBinary
SacBinary(const SacBinary& other); {
SacBinary(const u8* bytes, size_t len); public:
SacBinary();
SacBinary(const SacBinary& other);
SacBinary(const u8* bytes, size_t len);
bool operator==(const SacBinary& other) const; bool operator==(const SacBinary& other) const;
bool operator!=(const SacBinary& other) const; bool operator!=(const SacBinary& other) const;
void operator=(const SacBinary& other); void operator=(const SacBinary& other);
// to be used after export // to be used after export
const u8* getBytes() const; const u8* getBytes() const;
size_t getSize() const; size_t getSize() const;
// export/import binary // export/import binary
void exportBinary(); void exportBinary();
void importBinary(const u8* bytes); void importBinary(const u8* bytes);
void importBinary(const u8* bytes, size_t len); void importBinary(const u8* bytes, size_t len);
// variables // variables
const fnd::List<SacEntry>& getServiceList() const; const fnd::List<SacEntry>& getServiceList() const;
void addService(const SacEntry& service); void addService(const SacEntry& service);
private: private:
const std::string kModuleName = "SAC_BINARY"; const std::string kModuleName = "SAC_BINARY";
// raw binary // raw binary
fnd::MemoryBlob mBinaryBlob; fnd::MemoryBlob mBinaryBlob;
// variables // variables
fnd::List<SacEntry> mServices; fnd::List<SacEntry> mServices;
void clearVariables(); void clearVariables();
bool isEqual(const SacBinary& other) const; bool isEqual(const SacBinary& other) const;
void copyFrom(const SacBinary& other); void copyFrom(const SacBinary& other);
}; };
}

View file

@ -1,5 +1,7 @@
#include "SacEntry.h" #include "SacEntry.h"
using namespace nx;
SacEntry::SacEntry() : SacEntry::SacEntry() :
mIsServer(false), mIsServer(false),
mName("") mName("")

View file

@ -4,48 +4,51 @@
#include <fnd/memory_blob.h> #include <fnd/memory_blob.h>
#include <nx/ISerialiseableBinary.h> #include <nx/ISerialiseableBinary.h>
class SacEntry : public ISerialiseableBinary namespace nx
{ {
public: class SacEntry : public ISerialiseableBinary
SacEntry();
SacEntry(const std::string& name, bool isServer);
SacEntry(const SacEntry& other);
bool operator==(const SacEntry& other) const;
bool operator!=(const SacEntry& other) const;
void operator=(const SacEntry& other);
// to be used after export
const u8* getBytes() const;
size_t getSize() const;
// export/import binary
void exportBinary();
void importBinary(const u8* bytes);
void importBinary(const u8* bytes, size_t len);
// variables
bool isServer() const;
void setIsServer(bool isServer);
const std::string& getName() const;
void setName(const std::string& name);
private:
const std::string kModuleName = "SAC_ENTRY";
static const size_t kMaxServiceNameLen = 8;
enum SacEntryFlag
{ {
SAC_IS_SERVER = BIT(7), public:
SAC_NAME_LEN_MASK = BIT(7)-1 SacEntry();
SacEntry(const std::string& name, bool isServer);
SacEntry(const SacEntry& other);
bool operator==(const SacEntry& other) const;
bool operator!=(const SacEntry& other) const;
void operator=(const SacEntry& other);
// to be used after export
const u8* getBytes() const;
size_t getSize() const;
// export/import binary
void exportBinary();
void importBinary(const u8* bytes);
void importBinary(const u8* bytes, size_t len);
// variables
bool isServer() const;
void setIsServer(bool isServer);
const std::string& getName() const;
void setName(const std::string& name);
private:
const std::string kModuleName = "SAC_ENTRY";
static const size_t kMaxServiceNameLen = 8;
enum SacEntryFlag
{
SAC_IS_SERVER = BIT(7),
SAC_NAME_LEN_MASK = BIT(7) - 1
};
// raw binary
fnd::MemoryBlob mBinaryBlob;
// variables
bool mIsServer;
std::string mName;
bool isEqual(const SacEntry& other) const;
void copyFrom(const SacEntry& other);
}; };
}
// raw binary
fnd::MemoryBlob mBinaryBlob;
// variables
bool mIsServer;
std::string mName;
bool isEqual(const SacEntry& other) const;
void copyFrom(const SacEntry& other);
};

View file

@ -6,7 +6,7 @@
#include <nx/NcaHeader.h> #include <nx/NcaHeader.h>
#include <inttypes.h> #include <inttypes.h>
const size_t kNcaSectorSize = NcaHeader::kDefaultBlockSize; const size_t kNcaSectorSize = nx::NcaHeader::kDefaultBlockSize;
void initNcaCtr(u8 ctr[crypto::aes::kAesBlockSize], u32 generation) void initNcaCtr(u8 ctr[crypto::aes::kAesBlockSize], u32 generation)
{ {
@ -69,7 +69,7 @@ int main(int argc, char** argv)
{ {
decryptNcaSectorXts(nca, sector, 1, nx::crypto::aes::nca_header_key[0], nx::crypto::aes::nca_header_key[1]); decryptNcaSectorXts(nca, sector, 1, nx::crypto::aes::nca_header_key[0], nx::crypto::aes::nca_header_key[1]);
NcaHeader hdr; nx::NcaHeader hdr;
hdr.importBinary(sector); hdr.importBinary(sector);
printf("[NCA Header]\n"); printf("[NCA Header]\n");
@ -79,7 +79,7 @@ int main(int argc, char** argv)
printf(" Sections:\n"); printf(" Sections:\n");
for (size_t i = 0; i < hdr.getSections().getSize(); i++) for (size_t i = 0; i < hdr.getSections().getSize(); i++)
{ {
const NcaHeader::sSection& section = hdr.getSections()[i]; const nx::NcaHeader::sSection& section = hdr.getSections()[i];
printf(" %lu:\n", i); printf(" %lu:\n", i);
//printf(" Start Blk: %" PRId32 "\n", section.start_blk); //printf(" Start Blk: %" PRId32 "\n", section.start_blk);
//printf(" End Blk: %" PRId32 "\n", section.end_blk); //printf(" End Blk: %" PRId32 "\n", section.end_blk);