nstool/lib/libhac/include/nn/hac/NcaHeader.h

115 lines
2.8 KiB
C
Raw Normal View History

2017-07-05 08:57:14 +00:00
#pragma once
#include <nn/hac/define/nca.h>
#include <fnd/IByteModel.h>
#include <fnd/List.h>
2017-07-05 08:57:14 +00:00
2018-08-07 07:17:51 +00:00
namespace nn
{
namespace hac
2017-07-05 08:57:14 +00:00
{
class NcaHeader :
public fnd::IByteModel
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;
fnd::sha::sSha256Hash hash;
2017-07-06 11:17:21 +00:00
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-06-24 08:18:54 +00:00
void operator=(const NcaHeader& other);
2017-07-06 11:17:21 +00:00
bool operator==(const NcaHeader& other) const;
bool operator!=(const NcaHeader& other) const;
// IByteModel
2018-06-24 08:18:54 +00:00
void toBytes();
void fromBytes(const byte_t* bytes, size_t len);
const fnd::Vec<byte_t>& getBytes() const;
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);
const fnd::List<fnd::aes::sAes128Key>& getEncAesKeys() const;
void setEncAesKeys(const fnd::List<fnd::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
2018-06-24 08:18:54 +00:00
fnd::Vec<byte_t> mRawBinary;
2017-07-06 11:17:21 +00:00
// 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;
fnd::List<fnd::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-05 08:57:14 +00:00
};
2018-08-07 07:17:51 +00:00
}
2017-07-06 11:17:21 +00:00
}