2017-07-05 08:57:14 +00:00
|
|
|
#pragma once
|
2018-04-07 08:01:11 +00:00
|
|
|
#include <nx/nca.h>
|
2017-08-05 13:09:50 +00:00
|
|
|
#include <fnd/MemoryBlob.h>
|
2017-07-06 10:55:58 +00:00
|
|
|
#include <fnd/List.h>
|
2017-07-21 10:30:16 +00:00
|
|
|
#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
|
|
|
{
|
2017-07-21 10:30:16 +00:00
|
|
|
class NcaHeader :
|
|
|
|
public fnd::ISerialiseableBinary
|
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-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
|
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-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";
|
2018-04-07 08:01:11 +00:00
|
|
|
|
|
|
|
//static const uint32_t kDefaultSdkAddonVersion = 721920;
|
2017-07-18 14:17:32 +00:00
|
|
|
|
|
|
|
enum ProgramPartitionId
|
|
|
|
{
|
2018-04-07 08:01:11 +00:00
|
|
|
PARTITION_CODE,
|
|
|
|
PARTITION_DATA,
|
|
|
|
PARTITION_LOGO,
|
2017-07-06 11:17:21 +00:00
|
|
|
};
|
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;
|
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-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
|
|
|
}
|