2017-07-05 15:39:41 +00:00
|
|
|
#pragma once
|
2017-07-06 03:30:27 +00:00
|
|
|
#include <string>
|
2017-07-05 15:39:41 +00:00
|
|
|
#include <fnd/types.h>
|
|
|
|
#include <fnd/memory_blob.h>
|
2017-07-21 10:30:16 +00:00
|
|
|
#include <fnd/ISerialiseableBinary.h>
|
2017-07-05 15:39:41 +00:00
|
|
|
|
2017-07-06 11:17:21 +00:00
|
|
|
namespace nx
|
2017-07-05 15:39:41 +00:00
|
|
|
{
|
2017-07-21 10:30:16 +00:00
|
|
|
class AciHeader :
|
|
|
|
public fnd::ISerialiseableBinary
|
2017-07-05 15:39:41 +00:00
|
|
|
{
|
2017-07-06 11:17:21 +00:00
|
|
|
public:
|
|
|
|
enum AciType
|
|
|
|
{
|
|
|
|
TYPE_ACI0, // for Access Control Info
|
|
|
|
TYPE_ACID // for Access Control Info Desc
|
|
|
|
};
|
2017-07-05 15:39:41 +00:00
|
|
|
|
2017-07-06 11:17:21 +00:00
|
|
|
struct sSection
|
|
|
|
{
|
|
|
|
size_t offset;
|
|
|
|
size_t size;
|
2017-07-06 23:56:49 +00:00
|
|
|
|
|
|
|
void operator=(const sSection& other)
|
|
|
|
{
|
|
|
|
offset = other.offset;
|
|
|
|
size = other.size;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const sSection& other) const
|
|
|
|
{
|
|
|
|
return (offset == other.offset) \
|
|
|
|
&& (size == other.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const sSection& other) const
|
|
|
|
{
|
|
|
|
return !operator==(other);
|
|
|
|
}
|
2017-07-06 11:17:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
AciHeader();
|
|
|
|
AciHeader(const AciHeader& other);
|
2017-07-15 08:28:01 +00:00
|
|
|
AciHeader(const u8* bytes, size_t len);
|
2017-07-06 11:17:21 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
// export/import binary
|
2017-07-15 08:28:01 +00:00
|
|
|
virtual void exportBinary();
|
|
|
|
virtual void importBinary(const u8* bytes, size_t len);
|
2017-07-06 11:17:21 +00:00
|
|
|
|
|
|
|
// variables
|
2017-07-15 08:28:01 +00:00
|
|
|
virtual void clear();
|
|
|
|
size_t getAciSize() const;
|
|
|
|
|
|
|
|
// ACI0 only
|
2017-07-06 11:17:21 +00:00
|
|
|
u64 getProgramId() const;
|
|
|
|
void setProgramId(u64 program_id);
|
2017-07-15 08:28:01 +00:00
|
|
|
|
|
|
|
// ACID only
|
|
|
|
size_t getAcidSize() const;
|
2017-07-17 08:21:39 +00:00
|
|
|
//void setAcidSize(size_t size);
|
2017-07-15 08:28:01 +00:00
|
|
|
u64 getProgramIdMin() const;
|
|
|
|
void setProgramIdMin(u64 program_id);
|
|
|
|
u64 getProgramIdMax() const;
|
|
|
|
void setProgramIdMax(u64 program_id);
|
|
|
|
|
|
|
|
// ACID & ACI0
|
2017-07-17 08:21:39 +00:00
|
|
|
void setHeaderOffset(size_t offset);
|
2017-07-15 08:28:01 +00:00
|
|
|
AciType getAciType() const;
|
|
|
|
void setAciType(AciType type);
|
2017-07-21 10:30:16 +00:00
|
|
|
bool isProduction() const;
|
|
|
|
void setIsProduction(bool isProduction);
|
2017-07-15 08:28:01 +00:00
|
|
|
const sSection& getFacPos() const;
|
2017-07-17 08:21:39 +00:00
|
|
|
void setFacSize(size_t size);
|
2017-07-15 08:28:01 +00:00
|
|
|
const sSection& getSacPos() const;
|
2017-07-17 08:21:39 +00:00
|
|
|
void setSacSize(size_t size);
|
2017-07-15 08:28:01 +00:00
|
|
|
const sSection& getKcPos() const;
|
2017-07-17 08:21:39 +00:00
|
|
|
void setKcSize(size_t size);
|
2017-07-05 15:39:41 +00:00
|
|
|
|
2017-07-06 11:17:21 +00:00
|
|
|
private:
|
|
|
|
const std::string kModuleName = "ACI_HEADER";
|
|
|
|
const std::string kAciStructSig = "ACI0";
|
|
|
|
const std::string kAciDescStructSig = "ACID";
|
|
|
|
static const size_t kAciAlignSize = 0x10;
|
2017-07-05 15:39:41 +00:00
|
|
|
|
|
|
|
#pragma pack(push, 1)
|
2017-07-06 11:17:21 +00:00
|
|
|
struct sAciHeader
|
2017-07-05 15:39:41 +00:00
|
|
|
{
|
|
|
|
private:
|
2017-07-06 11:17:21 +00:00
|
|
|
u8 signature_[4];
|
2017-07-21 10:30:16 +00:00
|
|
|
u32 size_; // includes prefacing signature, set only in ACID made by SDK (it enables easy resigning)
|
2017-07-17 08:21:39 +00:00
|
|
|
u8 reserved_0[4];
|
2017-07-21 10:30:16 +00:00
|
|
|
u32 flags_; // set in ACID only
|
2017-07-06 23:56:49 +00:00
|
|
|
u64 program_id_; // set only in ACI0 (since ACID is generic)
|
2017-07-15 08:28:01 +00:00
|
|
|
u64 program_id_max_;
|
2017-07-06 11:17:21 +00:00
|
|
|
struct sAciSection
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
u32 offset_; // aligned by 0x10 from the last one
|
2017-07-06 23:56:49 +00:00
|
|
|
u32 size_;
|
2017-07-06 11:17:21 +00:00
|
|
|
public:
|
|
|
|
u32 offset() const { return le_word(offset_); }
|
|
|
|
void set_offset(u32 offset) { offset_ = le_word(offset); }
|
|
|
|
|
2017-07-06 23:56:49 +00:00
|
|
|
u32 size() const { return le_word(size_); }
|
|
|
|
void set_size(u32 size) { size_ = le_word(size); }
|
2017-07-17 08:21:39 +00:00
|
|
|
} fac_, sac_, kc_;
|
2017-07-05 15:39:41 +00:00
|
|
|
public:
|
2017-07-06 11:17:21 +00:00
|
|
|
const char* signature() const { return (const char*)signature_; }
|
|
|
|
void set_signature(const char* signature) { memcpy(signature_, signature, 4); }
|
2017-07-05 15:39:41 +00:00
|
|
|
|
2017-07-06 23:56:49 +00:00
|
|
|
u32 size() const { return le_word(size_); }
|
|
|
|
void set_size(u32 size) { size_ = le_word(size); }
|
|
|
|
|
2017-07-21 10:30:16 +00:00
|
|
|
u32 flags() const { return le_word(flags_); }
|
|
|
|
void set_flags(u32 flags) { flags_ = le_word(flags); }
|
2017-07-15 08:28:01 +00:00
|
|
|
|
2017-07-06 11:17:21 +00:00
|
|
|
u64 program_id() const { return le_dword(program_id_); }
|
|
|
|
void set_program_id(u64 program_id) { program_id_ = le_dword(program_id); }
|
2017-07-05 15:39:41 +00:00
|
|
|
|
2017-07-15 08:28:01 +00:00
|
|
|
u64 program_id_min() const { return program_id(); }
|
|
|
|
void set_program_id_min(u64 program_id) { set_program_id(program_id); }
|
|
|
|
|
|
|
|
u64 program_id_max() const { return le_dword(program_id_max_); }
|
|
|
|
void set_program_id_max(u64 program_id) { program_id_max_ = le_dword(program_id); }
|
|
|
|
|
2017-07-06 11:17:21 +00:00
|
|
|
const sAciSection& fac() const { return fac_; }
|
|
|
|
sAciSection& fac() { return fac_; }
|
2017-07-05 15:39:41 +00:00
|
|
|
|
2017-07-06 11:17:21 +00:00
|
|
|
const sAciSection& sac() const { return sac_; }
|
|
|
|
sAciSection& sac() { return sac_; }
|
2017-07-05 15:39:41 +00:00
|
|
|
|
2017-07-06 11:17:21 +00:00
|
|
|
const sAciSection& kc() const { return kc_; }
|
|
|
|
sAciSection& kc() { return kc_; }
|
|
|
|
};
|
2017-07-05 15:39:41 +00:00
|
|
|
#pragma pack(pop)
|
|
|
|
|
2017-07-06 11:17:21 +00:00
|
|
|
// raw data
|
|
|
|
fnd::MemoryBlob mBinaryBlob;
|
2017-07-05 15:39:41 +00:00
|
|
|
|
2017-07-15 08:28:01 +00:00
|
|
|
// ACI variables
|
2017-07-06 11:17:21 +00:00
|
|
|
u64 mProgramId;
|
2017-07-15 08:28:01 +00:00
|
|
|
|
|
|
|
// ACID variables
|
|
|
|
size_t mAcidSize;
|
|
|
|
u64 mProgramIdMin;
|
|
|
|
u64 mProgramIdMax;
|
|
|
|
|
|
|
|
// ACI(D) variables
|
2017-07-17 08:21:39 +00:00
|
|
|
size_t mHeaderOffset;
|
2017-07-15 08:28:01 +00:00
|
|
|
AciType mType;
|
2017-07-21 10:30:16 +00:00
|
|
|
bool mIsProduction;
|
2017-07-06 11:17:21 +00:00
|
|
|
sSection mFac, mSac, mKc;
|
2017-07-21 10:30:16 +00:00
|
|
|
|
2017-07-06 11:17:21 +00:00
|
|
|
void calculateSectionOffsets();
|
|
|
|
bool isEqual(const AciHeader& other) const;
|
|
|
|
void copyFrom(const AciHeader& other);
|
|
|
|
};
|
|
|
|
}
|
2017-07-05 15:39:41 +00:00
|
|
|
|