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

121 lines
3 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 ContentArchiveHeader :
public fnd::IByteModel
2017-07-05 08:57:14 +00:00
{
2017-07-06 11:17:21 +00:00
public:
struct sPartitionEntry
{
byte_t header_index;
2018-03-22 05:26:22 +00:00
uint64_t offset;
uint64_t size;
fnd::sha::sSha256Hash fs_header_hash;
2017-07-06 11:17:21 +00:00
const sPartitionEntry& operator=(const sPartitionEntry& other)
2017-07-06 11:17:21 +00:00
{
header_index = other.header_index;
2017-07-06 11:17:21 +00:00
offset = other.offset;
size = other.size;
fs_header_hash = other.fs_header_hash;
2017-07-06 11:17:21 +00:00
return *this;
}
bool operator==(const sPartitionEntry& other) const
2017-07-06 11:17:21 +00:00
{
return (header_index == other.header_index) \
&& (offset == other.offset) \
2017-07-06 11:17:21 +00:00
&& (size == other.size) \
&& (fs_header_hash == other.fs_header_hash);
2017-07-06 11:17:21 +00:00
}
bool operator!=(const sPartitionEntry& 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
}
};
ContentArchiveHeader();
ContentArchiveHeader(const ContentArchiveHeader& other);
2017-07-06 11:17:21 +00:00
void operator=(const ContentArchiveHeader& other);
bool operator==(const ContentArchiveHeader& other) const;
bool operator!=(const ContentArchiveHeader& other) const;
2017-07-06 11:17:21 +00:00
// 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();
byte_t getFormatVersion() const;
void setFormatVersion(byte_t 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);
byte_t getKeyAreaEncryptionKeyIndex() const;
void setKeyAreaEncryptionKeyIndex(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);
2018-03-22 05:26:22 +00:00
uint32_t getContentIndex() const;
void setContentIndex(uint32_t index);
2018-03-22 05:26:22 +00:00
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<sPartitionEntry>& getPartitionEntryList() const;
void setPartitionEntryList(const fnd::List<sPartitionEntry>& partition_entry_list);
const byte_t* getKeyArea() const;
void setKeyArea(const byte_t* key_area);
2017-07-05 08:57:14 +00:00
2017-07-06 11:17:21 +00:00
private:
const std::string kModuleName = "CONTENT_ARCHIVE_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
byte_t 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;
fnd::Vec<byte_t> mRightsId;
fnd::List<sPartitionEntry> mPartitionEntryList;
fnd::Vec<byte_t> mKeyArea;
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
}