mirror of
https://github.com/jakcron/nstool
synced 2024-11-22 21:49:30 +00:00
[nx] Added nx namespace.
This commit is contained in:
parent
01162b8187
commit
7b34bd404d
14 changed files with 450 additions and 420 deletions
|
@ -1,5 +1,7 @@
|
|||
#include "AciHeader.h"
|
||||
|
||||
using namespace nx;
|
||||
|
||||
void AciHeader::clearVariables()
|
||||
{
|
||||
mType = TYPE_ACI0;
|
||||
|
|
|
@ -4,106 +4,109 @@
|
|||
#include <fnd/memory_blob.h>
|
||||
#include <nx/ISerialiseableBinary.h>
|
||||
|
||||
class AciHeader : public ISerialiseableBinary
|
||||
namespace nx
|
||||
{
|
||||
public:
|
||||
enum AciType
|
||||
class AciHeader : public ISerialiseableBinary
|
||||
{
|
||||
TYPE_ACI0, // for Access Control Info
|
||||
TYPE_ACID // for Access Control Info Desc
|
||||
};
|
||||
public:
|
||||
enum AciType
|
||||
{
|
||||
TYPE_ACI0, // for Access Control Info
|
||||
TYPE_ACID // for Access Control Info Desc
|
||||
};
|
||||
|
||||
struct sSection
|
||||
{
|
||||
size_t offset;
|
||||
size_t size;
|
||||
};
|
||||
struct sSection
|
||||
{
|
||||
size_t offset;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
AciHeader();
|
||||
AciHeader(const AciHeader& other);
|
||||
AciHeader(const u8* bytes);
|
||||
AciHeader();
|
||||
AciHeader(const AciHeader& other);
|
||||
AciHeader(const u8* bytes);
|
||||
|
||||
bool operator==(const AciHeader& other) const;
|
||||
bool operator!=(const AciHeader& other) const;
|
||||
void operator=(const AciHeader& other);
|
||||
bool operator==(const AciHeader& other) const;
|
||||
bool operator!=(const AciHeader& other) const;
|
||||
void operator=(const AciHeader& other);
|
||||
|
||||
// to be used after export
|
||||
const u8* getBytes() const;
|
||||
size_t getSize() const;
|
||||
// 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);
|
||||
// export/import binary
|
||||
void exportBinary();
|
||||
void importBinary(const u8* bytes);
|
||||
void importBinary(const u8* bytes, size_t len);
|
||||
|
||||
// variables
|
||||
AciType getAciType() const;
|
||||
void setAciType(AciType type);
|
||||
u64 getProgramId() const;
|
||||
void setProgramId(u64 program_id);
|
||||
const sSection& getFileAccessControl() const;
|
||||
void setFileAccessControl(u32 size);
|
||||
const sSection& getServiceAccessControl() const;
|
||||
void setServiceAccessControl(u32 size);
|
||||
const sSection& getKernelCapabilities() const;
|
||||
void setKernelCapabilities(u32 size);
|
||||
// variables
|
||||
AciType getAciType() const;
|
||||
void setAciType(AciType type);
|
||||
u64 getProgramId() const;
|
||||
void setProgramId(u64 program_id);
|
||||
const sSection& getFileAccessControl() const;
|
||||
void setFileAccessControl(u32 size);
|
||||
const sSection& getServiceAccessControl() const;
|
||||
void setServiceAccessControl(u32 size);
|
||||
const sSection& getKernelCapabilities() const;
|
||||
void setKernelCapabilities(u32 size);
|
||||
|
||||
private:
|
||||
const std::string kModuleName = "ACI_HEADER";
|
||||
const std::string kAciStructSig = "ACI0";
|
||||
const std::string kAciDescStructSig = "ACID";
|
||||
static const size_t kAciAlignSize = 0x10;
|
||||
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:
|
||||
u8 signature_[4];
|
||||
u8 reserved_1[12];
|
||||
u64 program_id_;
|
||||
u8 reserved_2[8];
|
||||
struct sAciSection
|
||||
struct sAciHeader
|
||||
{
|
||||
private:
|
||||
u32 offset_; // aligned by 0x10 from the last one
|
||||
u32 mSize;
|
||||
u8 signature_[4];
|
||||
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:
|
||||
u32 offset() const { return le_word(offset_); }
|
||||
void set_offset(u32 offset) { offset_ = le_word(offset); }
|
||||
const char* signature() const { return (const char*)signature_; }
|
||||
void set_signature(const char* signature) { memcpy(signature_, signature, 4); }
|
||||
|
||||
u32 size() const { return le_word(mSize); }
|
||||
void set_size(u32 size) { mSize = le_word(size); }
|
||||
} 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_); }
|
||||
void set_program_id(u64 program_id) { program_id_ = le_dword(program_id); }
|
||||
|
||||
u64 program_id() const { return le_dword(program_id_); }
|
||||
void set_program_id(u64 program_id) { program_id_ = le_dword(program_id); }
|
||||
const sAciSection& fac() const { return fac_; }
|
||||
sAciSection& fac() { return fac_; }
|
||||
|
||||
const sAciSection& fac() const { return fac_; }
|
||||
sAciSection& fac() { return fac_; }
|
||||
const sAciSection& sac() const { return sac_; }
|
||||
sAciSection& sac() { return sac_; }
|
||||
|
||||
const sAciSection& sac() const { return sac_; }
|
||||
sAciSection& sac() { return sac_; }
|
||||
|
||||
const sAciSection& kc() const { return kc_; }
|
||||
sAciSection& kc() { return kc_; }
|
||||
};
|
||||
const sAciSection& kc() const { return kc_; }
|
||||
sAciSection& kc() { return kc_; }
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
// raw data
|
||||
fnd::MemoryBlob mBinaryBlob;
|
||||
// raw data
|
||||
fnd::MemoryBlob mBinaryBlob;
|
||||
|
||||
// variables
|
||||
AciType mType;
|
||||
u64 mProgramId;
|
||||
sSection mFac, mSac, mKc;
|
||||
// variables
|
||||
AciType mType;
|
||||
u64 mProgramId;
|
||||
sSection mFac, mSac, mKc;
|
||||
|
||||
void clearVariables();
|
||||
void calculateSectionOffsets();
|
||||
bool isEqual(const AciHeader& other) const;
|
||||
void copyFrom(const AciHeader& other);
|
||||
};
|
||||
void clearVariables();
|
||||
void calculateSectionOffsets();
|
||||
bool isEqual(const AciHeader& other) const;
|
||||
void copyFrom(const AciHeader& other);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "FacBinary.h"
|
||||
|
||||
|
||||
using namespace nx;
|
||||
|
||||
FacBinary::FacBinary() :
|
||||
mHeader()
|
||||
|
|
|
@ -5,77 +5,80 @@
|
|||
#include <nx/ISerialiseableBinary.h>
|
||||
#include <nx/FacHeader.h>
|
||||
|
||||
class FacBinary :
|
||||
public ISerialiseableBinary
|
||||
namespace nx
|
||||
{
|
||||
public:
|
||||
enum FsAccessFlag
|
||||
class FacBinary :
|
||||
public ISerialiseableBinary
|
||||
{
|
||||
FSA_APPLICATION_INFO = BIT(0),
|
||||
FSA_BOOT_MODE_CONTROL = BIT(1),
|
||||
FSA_CALIBRATION = BIT(2),
|
||||
FSA_SYSTEM_SAVE_DATA = BIT(3),
|
||||
FSA_GAME_CARD = BIT(4),
|
||||
FSA_SAVE_DATA_BACKUP = BIT(5),
|
||||
FSA_SAVE_DATA_MANAGEMENT = BIT(6),
|
||||
FSA_BIS_ALL_RAW = BIT(7),
|
||||
FSA_GAME_CARD_RAW = BIT(8),
|
||||
FSA_GAME_CARD_PRIVATE = BIT(9),
|
||||
FSA_SET_TIME = BIT(10),
|
||||
FSA_CONTENT_MANAGER = BIT(11),
|
||||
FSA_IMAGE_MANAGER = BIT(12),
|
||||
FSA_CREATE_SAVE_DATA = BIT(13),
|
||||
FSA_SYSTEM_SAVE_DATA_MANAGEMENT = BIT(14),
|
||||
FSA_BIS_FILE_SYSTEM = BIT(15),
|
||||
FSA_SYSTEM_UPDATE = BIT(16),
|
||||
FSA_SAVE_DATA_META = BIT(17),
|
||||
FSA_DEVICE_SAVE_CONTROL = BIT(19),
|
||||
FSA_SETTINGS_CONTROL = BIT(20),
|
||||
FSA_DEBUG = BIT(62),
|
||||
FSA_FULL_PERMISSION = BIT(63),
|
||||
public:
|
||||
enum FsAccessFlag
|
||||
{
|
||||
FSA_APPLICATION_INFO = BIT(0),
|
||||
FSA_BOOT_MODE_CONTROL = BIT(1),
|
||||
FSA_CALIBRATION = BIT(2),
|
||||
FSA_SYSTEM_SAVE_DATA = BIT(3),
|
||||
FSA_GAME_CARD = BIT(4),
|
||||
FSA_SAVE_DATA_BACKUP = BIT(5),
|
||||
FSA_SAVE_DATA_MANAGEMENT = BIT(6),
|
||||
FSA_BIS_ALL_RAW = BIT(7),
|
||||
FSA_GAME_CARD_RAW = BIT(8),
|
||||
FSA_GAME_CARD_PRIVATE = BIT(9),
|
||||
FSA_SET_TIME = BIT(10),
|
||||
FSA_CONTENT_MANAGER = BIT(11),
|
||||
FSA_IMAGE_MANAGER = BIT(12),
|
||||
FSA_CREATE_SAVE_DATA = BIT(13),
|
||||
FSA_SYSTEM_SAVE_DATA_MANAGEMENT = BIT(14),
|
||||
FSA_BIS_FILE_SYSTEM = BIT(15),
|
||||
FSA_SYSTEM_UPDATE = BIT(16),
|
||||
FSA_SAVE_DATA_META = BIT(17),
|
||||
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);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "FacHeader.h"
|
||||
|
||||
|
||||
using namespace nx;
|
||||
|
||||
FacHeader::FacHeader()
|
||||
{
|
||||
|
|
|
@ -3,91 +3,95 @@
|
|||
#include <fnd/memory_blob.h>
|
||||
#include <nx/ISerialiseableBinary.h>
|
||||
|
||||
class FacHeader :
|
||||
public ISerialiseableBinary
|
||||
namespace nx
|
||||
{
|
||||
public:
|
||||
FacHeader();
|
||||
FacHeader(const FacHeader& other);
|
||||
FacHeader(const u8* bytes);
|
||||
class FacHeader :
|
||||
public ISerialiseableBinary
|
||||
{
|
||||
public:
|
||||
FacHeader();
|
||||
FacHeader(const FacHeader& other);
|
||||
FacHeader(const u8* bytes);
|
||||
|
||||
bool operator==(const FacHeader& other) const;
|
||||
bool operator!=(const FacHeader& other) const;
|
||||
void operator=(const FacHeader& other);
|
||||
bool operator==(const FacHeader& other) const;
|
||||
bool operator!=(const FacHeader& other) const;
|
||||
void operator=(const FacHeader& other);
|
||||
|
||||
// to be used after export
|
||||
const u8* getBytes() const;
|
||||
size_t getSize() const;
|
||||
// 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);
|
||||
// export/import binary
|
||||
void exportBinary();
|
||||
void importBinary(const u8* bytes);
|
||||
void importBinary(const u8* bytes, size_t len);
|
||||
|
||||
// variables
|
||||
u64 getFacSize() const;
|
||||
// variables
|
||||
u64 getFacSize() const;
|
||||
|
||||
u64 getFsaRights() const;
|
||||
void setFsaRights(u64 flag);
|
||||
u64 getFsaRights() const;
|
||||
void setFsaRights(u64 flag);
|
||||
|
||||
size_t getContentOwnerIdOffset() const;
|
||||
size_t getContentOwnerIdSize() const;
|
||||
void setContentOwnerIdSize(size_t size);
|
||||
size_t getContentOwnerIdOffset() const;
|
||||
size_t getContentOwnerIdSize() const;
|
||||
void setContentOwnerIdSize(size_t size);
|
||||
|
||||
size_t getSaveDataOwnerIdOffset() const;
|
||||
size_t getSaveDataOwnerIdSize() const;
|
||||
void setSaveDataOwnerIdSize(size_t size);
|
||||
size_t getSaveDataOwnerIdOffset() const;
|
||||
size_t getSaveDataOwnerIdSize() const;
|
||||
void setSaveDataOwnerIdSize(size_t size);
|
||||
|
||||
private:
|
||||
const std::string kModuleName = "FAC_HEADER";
|
||||
static const u32 kFacFormatVersion = 1;
|
||||
private:
|
||||
const std::string kModuleName = "FAC_HEADER";
|
||||
static const u32 kFacFormatVersion = 1;
|
||||
|
||||
#pragma pack (push, 1)
|
||||
struct sFacHeader
|
||||
{
|
||||
private:
|
||||
u32 version_; // default 1
|
||||
u64 fac_flags_;
|
||||
struct sFacSection
|
||||
struct sFacHeader
|
||||
{
|
||||
private:
|
||||
u32 start_;
|
||||
u32 end_;
|
||||
u32 version_; // default 1
|
||||
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:
|
||||
u32 start() const { return le_word(start_); }
|
||||
void set_start(u32 start) { start_ = le_word(start); }
|
||||
u32 version() const { return le_word(version_); }
|
||||
void set_version(u32 version) { version_ = le_word(version); }
|
||||
|
||||
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:
|
||||
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_); }
|
||||
void set_fac_flags(u64 fac_flags) { fac_flags_ = le_dword(fac_flags); }
|
||||
|
||||
u64 fac_flags() const { return le_dword(fac_flags_); }
|
||||
void set_fac_flags(u64 fac_flags) { fac_flags_ = le_dword(fac_flags); }
|
||||
const sFacSection& content_owner_ids() const { return content_owner_ids_; }
|
||||
sFacSection& content_owner_ids() { return content_owner_ids_; }
|
||||
|
||||
const sFacSection& content_owner_ids() const { return content_owner_ids_; }
|
||||
sFacSection& content_owner_ids() { return content_owner_ids_; }
|
||||
|
||||
const sFacSection& save_data_owner_ids() const { return save_data_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)
|
||||
|
||||
// raw binary
|
||||
fnd::MemoryBlob mBinaryBlob;
|
||||
// raw binary
|
||||
fnd::MemoryBlob mBinaryBlob;
|
||||
|
||||
// variables
|
||||
u64 mFsaRights;
|
||||
struct sSection {
|
||||
size_t offset;
|
||||
size_t size;
|
||||
} mContentOwnerIdPos, mSaveDataOwnerIdPos;
|
||||
// variables
|
||||
u64 mFsaRights;
|
||||
struct sSection
|
||||
{
|
||||
size_t offset;
|
||||
size_t size;
|
||||
} mContentOwnerIdPos, mSaveDataOwnerIdPos;
|
||||
|
||||
void clearVariables();
|
||||
void calculateOffsets();
|
||||
bool isEqual(const FacHeader& other) const;
|
||||
void copyFrom(const FacHeader& other);
|
||||
};
|
||||
void clearVariables();
|
||||
void calculateOffsets();
|
||||
bool isEqual(const FacHeader& other) const;
|
||||
void copyFrom(const FacHeader& other);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
#pragma once
|
||||
#include <fnd/types.h>
|
||||
|
||||
class ISerialiseableBinary
|
||||
namespace nx
|
||||
{
|
||||
public:
|
||||
//virtual bool operator==(const ISerialiseableBinary& other) = 0;
|
||||
//virtual void operator=(const ISerialiseableBinary& other) = 0;
|
||||
class ISerialiseableBinary
|
||||
{
|
||||
public:
|
||||
//virtual bool operator==(const ISerialiseableBinary& other) = 0;
|
||||
//virtual void operator=(const ISerialiseableBinary& other) = 0;
|
||||
|
||||
virtual const u8* getBytes() const = 0;
|
||||
virtual size_t getSize() const = 0;
|
||||
virtual const u8* getBytes() const = 0;
|
||||
virtual size_t getSize() const = 0;
|
||||
|
||||
virtual void exportBinary() = 0;
|
||||
virtual void importBinary(const u8* bytes) = 0;
|
||||
virtual void importBinary(const u8* bytes, size_t len) = 0;
|
||||
};
|
||||
virtual void exportBinary() = 0;
|
||||
virtual void importBinary(const u8* bytes) = 0;
|
||||
virtual void importBinary(const u8* bytes, size_t len) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
#include "NcaHeader.h"
|
||||
#include <fnd/exception.h>
|
||||
|
||||
using namespace nx;
|
||||
|
||||
|
||||
void NcaHeader::exportBinary()
|
||||
{
|
||||
mBinaryBlob.alloc(sizeof(sNcaHeader));
|
||||
|
|
|
@ -7,149 +7,153 @@
|
|||
#include <crypto/sha.h>
|
||||
#include <nx/ISerialiseableBinary.h>
|
||||
|
||||
class NcaHeader : public ISerialiseableBinary
|
||||
namespace nx
|
||||
{
|
||||
public:
|
||||
struct sSection
|
||||
class NcaHeader : public ISerialiseableBinary
|
||||
{
|
||||
u64 offset;
|
||||
u64 size;
|
||||
u8 key_type;
|
||||
crypto::sha::sSha256Hash hash;
|
||||
|
||||
const sSection& operator=(const sSection& other)
|
||||
public:
|
||||
struct sSection
|
||||
{
|
||||
offset = other.offset;
|
||||
size = other.size;
|
||||
key_type = other.key_type;
|
||||
hash = other.hash;
|
||||
u64 offset;
|
||||
u64 size;
|
||||
u8 key_type;
|
||||
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 (offset == other.offset) \
|
||||
&& (size == other.size) \
|
||||
&& (key_type == other.key_type) \
|
||||
&& (hash == other.hash);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator!=(const sSection& other) const
|
||||
{
|
||||
return operator==(other);
|
||||
}
|
||||
};
|
||||
bool operator==(const sSection& other) const
|
||||
{
|
||||
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();
|
||||
NcaHeader(const NcaHeader& other);
|
||||
NcaHeader(const u8* bytes);
|
||||
static const size_t kDefaultBlockSize = 0x200;
|
||||
|
||||
bool operator==(const NcaHeader& other) const;
|
||||
bool operator!=(const NcaHeader& other) const;
|
||||
void operator=(const NcaHeader& other);
|
||||
NcaHeader();
|
||||
NcaHeader(const NcaHeader& other);
|
||||
NcaHeader(const u8* bytes);
|
||||
|
||||
// to be used after export
|
||||
const u8* getBytes() const;
|
||||
size_t getSize() const;
|
||||
bool operator==(const NcaHeader& other) const;
|
||||
bool operator!=(const NcaHeader& other) const;
|
||||
void operator=(const NcaHeader& other);
|
||||
|
||||
// export/import binary
|
||||
void exportBinary();
|
||||
void importBinary(const u8* bytes);
|
||||
void importBinary(const u8* bytes, size_t len);
|
||||
// to be used after export
|
||||
const u8* getBytes() const;
|
||||
size_t getSize() const;
|
||||
|
||||
// variables
|
||||
u64 getNcaSize() const;
|
||||
void setNcaSize(u64 size);
|
||||
u64 getProgramId() const;
|
||||
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);
|
||||
// export/import binary
|
||||
void exportBinary();
|
||||
void importBinary(const u8* bytes);
|
||||
void importBinary(const u8* bytes, size_t len);
|
||||
|
||||
private:
|
||||
const std::string kModuleName = "NCA_HEADER";
|
||||
const std::string kNcaSig = "NCA2";
|
||||
static const size_t kSectionNum = 4;
|
||||
static const size_t kAesKeyNum = 4;
|
||||
// variables
|
||||
u64 getNcaSize() const;
|
||||
void setNcaSize(u64 size);
|
||||
u64 getProgramId() const;
|
||||
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)
|
||||
|
||||
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
|
||||
struct sNcaHeader
|
||||
{
|
||||
private:
|
||||
u32 start_; // block units
|
||||
u32 end_; // block units
|
||||
u8 key_type_;
|
||||
u8 reserved[7];
|
||||
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:
|
||||
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:
|
||||
u32 start() const { return le_word(start_); }
|
||||
void set_start(u32 offset) { start_ = le_word(offset); }
|
||||
const char* signature() const { return (const char*)signature_; }
|
||||
void set_signature(const char* signature) { memcpy(signature_, signature, 4); }
|
||||
|
||||
u32 end() const { return le_word(end_); }
|
||||
void set_end(u32 offset) { end_ = le_word(offset); }
|
||||
u16 block_size() const { return le_hword(block_size_); }
|
||||
void set_block_size(u16 block_size) { block_size_ = le_hword(block_size); }
|
||||
|
||||
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:
|
||||
const char* signature() const { return (const char*)signature_; }
|
||||
void set_signature(const char* signature) { memcpy(signature_, signature, 4); }
|
||||
u64 nca_size() const { return le_dword(nca_size_); }
|
||||
void set_nca_size(u64 nca_size) { nca_size_ = le_dword(nca_size); }
|
||||
|
||||
u16 block_size() const { return le_hword(block_size_); }
|
||||
void set_block_size(u16 block_size) { block_size_ = le_hword(block_size); }
|
||||
u64 program_id() const { return le_dword(program_id_); }
|
||||
void set_program_id(u64 program_id) { program_id_ = le_dword(program_id); }
|
||||
|
||||
u64 nca_size() const { return le_dword(nca_size_); }
|
||||
void set_nca_size(u64 nca_size) { nca_size_ = le_dword(nca_size); }
|
||||
u32 unk0() const { return le_word(unk_0_); }
|
||||
void set_unk0(u32 val) { unk_0_ = le_word(val); }
|
||||
|
||||
u64 program_id() const { return le_dword(program_id_); }
|
||||
void set_program_id(u64 program_id) { program_id_ = le_dword(program_id); }
|
||||
const sNcaSection& section(u8 index) const { return section_[index%kSectionNum]; }
|
||||
sNcaSection& section(u8 index) { return section_[index%kSectionNum]; }
|
||||
|
||||
u32 unk0() const { return le_word(unk_0_); }
|
||||
void set_unk0(u32 val) { unk_0_ = le_word(val); }
|
||||
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 sNcaSection& section(u8 index) const { return section_[index%kSectionNum]; }
|
||||
sNcaSection& section(u8 index) { return section_[index%kSectionNum]; }
|
||||
|
||||
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]; }
|
||||
};
|
||||
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)
|
||||
|
||||
// binary
|
||||
fnd::MemoryBlob mBinaryBlob;
|
||||
// binary
|
||||
fnd::MemoryBlob mBinaryBlob;
|
||||
|
||||
// data
|
||||
u16 mBlockSize;
|
||||
u64 mNcaSize;
|
||||
u64 mProgramId;
|
||||
u32 mUnk0;
|
||||
fnd::List<sSection> mSections;
|
||||
fnd::List<crypto::aes::sAes128Key> mAesKeys;
|
||||
// data
|
||||
u16 mBlockSize;
|
||||
u64 mNcaSize;
|
||||
u64 mProgramId;
|
||||
u32 mUnk0;
|
||||
fnd::List<sSection> mSections;
|
||||
fnd::List<crypto::aes::sAes128Key> mAesKeys;
|
||||
|
||||
void clearVariables();
|
||||
u64 blockNumToSize(u32 block_num) const;
|
||||
u32 sizeToBlockNum(u64 real_size) const;
|
||||
bool isEqual(const NcaHeader& other) const;
|
||||
void copyFrom(const NcaHeader& other);
|
||||
};
|
||||
void clearVariables();
|
||||
u64 blockNumToSize(u32 block_num) const;
|
||||
u32 sizeToBlockNum(u64 real_size) const;
|
||||
bool isEqual(const NcaHeader& other) const;
|
||||
void copyFrom(const NcaHeader& other);
|
||||
};
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
#include "SacBinary.h"
|
||||
|
||||
|
||||
using namespace nx;
|
||||
|
||||
SacBinary::SacBinary()
|
||||
{
|
||||
|
|
|
@ -6,41 +6,44 @@
|
|||
#include <nx/ISerialiseableBinary.h>
|
||||
#include <nx/SacEntry.h>
|
||||
|
||||
class SacBinary :
|
||||
public ISerialiseableBinary
|
||||
namespace nx
|
||||
{
|
||||
public:
|
||||
SacBinary();
|
||||
SacBinary(const SacBinary& other);
|
||||
SacBinary(const u8* bytes, size_t len);
|
||||
class SacBinary :
|
||||
public ISerialiseableBinary
|
||||
{
|
||||
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;
|
||||
void operator=(const SacBinary& other);
|
||||
bool operator==(const SacBinary& other) const;
|
||||
bool operator!=(const SacBinary& other) const;
|
||||
void operator=(const SacBinary& other);
|
||||
|
||||
// to be used after export
|
||||
const u8* getBytes() const;
|
||||
size_t getSize() const;
|
||||
// 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);
|
||||
// export/import binary
|
||||
void exportBinary();
|
||||
void importBinary(const u8* bytes);
|
||||
void importBinary(const u8* bytes, size_t len);
|
||||
|
||||
// variables
|
||||
const fnd::List<SacEntry>& getServiceList() const;
|
||||
void addService(const SacEntry& service);
|
||||
private:
|
||||
const std::string kModuleName = "SAC_BINARY";
|
||||
// variables
|
||||
const fnd::List<SacEntry>& getServiceList() const;
|
||||
void addService(const SacEntry& service);
|
||||
private:
|
||||
const std::string kModuleName = "SAC_BINARY";
|
||||
|
||||
// raw binary
|
||||
fnd::MemoryBlob mBinaryBlob;
|
||||
// raw binary
|
||||
fnd::MemoryBlob mBinaryBlob;
|
||||
|
||||
// variables
|
||||
fnd::List<SacEntry> mServices;
|
||||
// variables
|
||||
fnd::List<SacEntry> mServices;
|
||||
|
||||
void clearVariables();
|
||||
bool isEqual(const SacBinary& other) const;
|
||||
void copyFrom(const SacBinary& other);
|
||||
};
|
||||
void clearVariables();
|
||||
bool isEqual(const SacBinary& other) const;
|
||||
void copyFrom(const SacBinary& other);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "SacEntry.h"
|
||||
|
||||
using namespace nx;
|
||||
|
||||
SacEntry::SacEntry() :
|
||||
mIsServer(false),
|
||||
mName("")
|
||||
|
|
|
@ -4,48 +4,51 @@
|
|||
#include <fnd/memory_blob.h>
|
||||
#include <nx/ISerialiseableBinary.h>
|
||||
|
||||
class SacEntry : public ISerialiseableBinary
|
||||
namespace nx
|
||||
{
|
||||
public:
|
||||
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
|
||||
class SacEntry : public ISerialiseableBinary
|
||||
{
|
||||
SAC_IS_SERVER = BIT(7),
|
||||
SAC_NAME_LEN_MASK = BIT(7)-1
|
||||
public:
|
||||
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);
|
||||
};
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
#include <nx/NcaHeader.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)
|
||||
{
|
||||
|
@ -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]);
|
||||
|
||||
NcaHeader hdr;
|
||||
nx::NcaHeader hdr;
|
||||
hdr.importBinary(sector);
|
||||
|
||||
printf("[NCA Header]\n");
|
||||
|
@ -79,7 +79,7 @@ int main(int argc, char** argv)
|
|||
printf(" Sections:\n");
|
||||
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(" Start Blk: %" PRId32 "\n", section.start_blk);
|
||||
//printf(" End Blk: %" PRId32 "\n", section.end_blk);
|
||||
|
|
Loading…
Reference in a new issue