nstool/lib/libnx/include/nx/NcaHeader.h

120 lines
3 KiB
C
Raw Normal View History

2017-07-05 08:57:14 +00:00
#pragma once
#include <nx/nca.h>
#include <fnd/MemoryBlob.h>
#include <fnd/List.h>
#include <fnd/ISerialiseableBinary.h>
2017-07-05 08:57:14 +00:00
2017-07-06 11:17:21 +00:00
namespace nx
2017-07-05 08:57:14 +00:00
{
class NcaHeader :
public fnd::ISerialiseableBinary
2017-07-05 08:57:14 +00:00
{
2017-07-06 11:17:21 +00:00
public:
enum FormatVersion
{
NCA2_FORMAT,
NCA3_FORMAT
};
struct sPartition
{
byte_t index;
2018-03-22 05:26:22 +00:00
uint64_t offset;
uint64_t size;
2017-07-06 11:17:21 +00:00
crypto::sha::sSha256Hash hash;
const sPartition& operator=(const sPartition& other)
2017-07-06 11:17:21 +00:00
{
index = other.index;
2017-07-06 11:17:21 +00:00
offset = other.offset;
size = other.size;
hash = other.hash;
return *this;
}
bool operator==(const sPartition& other) const
2017-07-06 11:17:21 +00:00
{
return (index == other.index) \
&& (offset == other.offset) \
2017-07-06 11:17:21 +00:00
&& (size == other.size) \
&& (hash == other.hash);
}
bool operator!=(const sPartition& other) const
2017-07-06 11:17:21 +00:00
{
2018-03-21 12:29:08 +00:00
return !operator==(other);
2017-07-06 11:17:21 +00:00
}
};
NcaHeader();
NcaHeader(const NcaHeader& other);
2018-03-22 05:26:22 +00:00
NcaHeader(const byte_t* bytes, size_t len);
2017-07-06 11:17:21 +00:00
bool operator==(const NcaHeader& other) const;
bool operator!=(const NcaHeader& other) const;
void operator=(const NcaHeader& other);
// to be used after export
2018-03-22 05:26:22 +00:00
const byte_t* getBytes() const;
2017-07-06 11:17:21 +00:00
size_t getSize() const;
// export/import binary
void exportBinary();
2018-03-22 05:26:22 +00:00
void importBinary(const byte_t* bytes, size_t len);
2017-07-06 11:17:21 +00:00
// variables
void clear();
2018-03-18 09:08:42 +00:00
FormatVersion getFormatVersion() const;
void setFormatVersion(FormatVersion ver);
nca::DistributionType getDistributionType() const;
void setDistributionType(nca::DistributionType type);
nca::ContentType getContentType() const;
void setContentType(nca::ContentType type);
byte_t getKeyGeneration() const;
void setKeyGeneration(byte_t gen);
2018-03-18 09:08:42 +00:00
byte_t getKaekIndex() const;
void setKaekIndex(byte_t index);
uint64_t getContentSize() const;
void setContentSize(uint64_t size);
2018-03-22 05:26:22 +00:00
uint64_t getProgramId() const;
void setProgramId(uint64_t program_id);
uint32_t getContentIndex() const;
void setContentIndex(uint32_t index);
uint32_t getSdkAddonVersion() const;
void setSdkAddonVersion(uint32_t version);
2018-05-01 05:17:25 +00:00
bool hasRightsId() const;
const byte_t* getRightsId() const;
void setRightsId(const byte_t* rights_id);
const fnd::List<sPartition>& getPartitions() const;
void setPartitions(const fnd::List<sPartition>& partitions);
2017-07-18 14:17:32 +00:00
const fnd::List<crypto::aes::sAes128Key>& getEncAesKeys() const;
void setEncAesKeys(const fnd::List<crypto::aes::sAes128Key>& keys);
2017-07-05 08:57:14 +00:00
2017-07-06 11:17:21 +00:00
private:
const std::string kModuleName = "NCA_HEADER";
2017-07-05 08:57:14 +00:00
2017-07-06 11:17:21 +00:00
// binary
fnd::MemoryBlob mBinaryBlob;
// data
2018-03-18 09:08:42 +00:00
FormatVersion mFormatVersion;
nca::DistributionType mDistributionType;
nca::ContentType mContentType;
byte_t mKeyGeneration;
2018-03-18 09:08:42 +00:00
byte_t mKaekIndex;
uint64_t mContentSize;
2018-03-22 05:26:22 +00:00
uint64_t mProgramId;
uint32_t mContentIndex;
uint32_t mSdkAddonVersion;
byte_t mRightsId[nca::kRightsIdLen];
fnd::List<sPartition> mPartitions;
2017-07-18 14:17:32 +00:00
fnd::List<crypto::aes::sAes128Key> mEncAesKeys;
2017-07-06 11:17:21 +00:00
2018-03-22 05:26:22 +00:00
uint64_t blockNumToSize(uint32_t block_num) const;
uint32_t sizeToBlockNum(uint64_t real_size) const;
2017-07-06 11:17:21 +00:00
bool isEqual(const NcaHeader& other) const;
void copyFrom(const NcaHeader& other);
2017-07-05 08:57:14 +00:00
};
2017-07-06 11:17:21 +00:00
}