2017-07-05 08:57:14 +00:00
|
|
|
#pragma once
|
2018-08-07 07:17:51 +00:00
|
|
|
#include <nn/hac/nca.h>
|
2018-06-24 15:01:16 +00:00
|
|
|
#include <fnd/ISerialisable.h>
|
2017-07-06 10:55:58 +00:00
|
|
|
#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
|
|
|
{
|
2017-07-21 10:30:16 +00:00
|
|
|
class NcaHeader :
|
2018-06-24 15:01:16 +00:00
|
|
|
public fnd::ISerialisable
|
2017-07-05 08:57:14 +00:00
|
|
|
{
|
2017-07-06 11:17:21 +00:00
|
|
|
public:
|
2018-03-17 12:01:19 +00:00
|
|
|
enum FormatVersion
|
|
|
|
{
|
|
|
|
NCA2_FORMAT,
|
|
|
|
NCA3_FORMAT
|
|
|
|
};
|
|
|
|
|
2018-04-07 08:01:11 +00:00
|
|
|
struct sPartition
|
2017-07-06 10:55:58 +00:00
|
|
|
{
|
2018-04-07 08:01:11 +00:00
|
|
|
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;
|
|
|
|
|
2018-04-07 08:01:11 +00:00
|
|
|
const sPartition& operator=(const sPartition& other)
|
2017-07-06 11:17:21 +00:00
|
|
|
{
|
2018-04-07 08:01:11 +00:00
|
|
|
index = other.index;
|
2017-07-06 11:17:21 +00:00
|
|
|
offset = other.offset;
|
|
|
|
size = other.size;
|
|
|
|
hash = other.hash;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-04-07 08:01:11 +00:00
|
|
|
bool operator==(const sPartition& other) const
|
2017-07-06 11:17:21 +00:00
|
|
|
{
|
2018-04-07 08:01:11 +00:00
|
|
|
return (index == other.index) \
|
|
|
|
&& (offset == other.offset) \
|
2017-07-06 11:17:21 +00:00
|
|
|
&& (size == other.size) \
|
|
|
|
&& (hash == other.hash);
|
|
|
|
}
|
|
|
|
|
2018-04-07 08:01:11 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
// to be used after export
|
|
|
|
size_t getSize() const;
|
|
|
|
|
|
|
|
// export/import binary
|
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
|
2017-07-15 08:28:01 +00:00
|
|
|
void clear();
|
2018-03-18 09:08:42 +00:00
|
|
|
FormatVersion getFormatVersion() const;
|
|
|
|
void setFormatVersion(FormatVersion ver);
|
2018-04-07 08:01:11 +00:00
|
|
|
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);
|
2018-04-07 08:01:11 +00:00
|
|
|
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;
|
2018-04-07 08:01:11 +00:00
|
|
|
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;
|
2018-04-07 08:01:11 +00:00
|
|
|
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
|
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;
|
2018-04-07 08:01:11 +00:00
|
|
|
nca::DistributionType mDistributionType;
|
|
|
|
nca::ContentType mContentType;
|
|
|
|
byte_t mKeyGeneration;
|
2018-03-18 09:08:42 +00:00
|
|
|
byte_t mKaekIndex;
|
2018-04-07 08:01:11 +00:00
|
|
|
uint64_t mContentSize;
|
2018-03-22 05:26:22 +00:00
|
|
|
uint64_t mProgramId;
|
|
|
|
uint32_t mContentIndex;
|
|
|
|
uint32_t mSdkAddonVersion;
|
2018-04-07 08:01:11 +00:00
|
|
|
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-05 08:57:14 +00:00
|
|
|
};
|
2018-08-07 07:17:51 +00:00
|
|
|
}
|
2017-07-06 11:17:21 +00:00
|
|
|
}
|