diff --git a/lib/libhac/include/nn/hac/ContentInfo.h b/lib/libhac/include/nn/hac/ContentInfo.h new file mode 100644 index 0000000..6399d7a --- /dev/null +++ b/lib/libhac/include/nn/hac/ContentInfo.h @@ -0,0 +1,60 @@ +#pragma once +#include +#include +#include +#include +#include + +namespace nn +{ +namespace hac +{ + class ContentInfo : + public fnd::IByteModel + { + public: + ContentInfo(); + ContentInfo(const ContentInfo& other); + + void operator=(const ContentInfo& other); + bool operator==(const ContentInfo& other) const; + bool operator!=(const ContentInfo& other) const; + + // IByteModel + void toBytes(); + void fromBytes(const byte_t* bytes, size_t len); + const fnd::Vec& getBytes() const; + + // variables + void clear(); + + const fnd::sha::sSha256Hash& getContentHash() const; + void setContentHash(const fnd::sha::sSha256Hash& hash); + + const cnmt::sContentId& getContentId() const; + void setContentId(const cnmt::sContentId& content_id); + + size_t getContentSize() const; + void setContentSize(size_t size); + + cnmt::ContentType getContentType() const; + void setContentType(cnmt::ContentType type); + + byte_t getIdOffset() const; + void setIdOffset(byte_t id_offset); + + private: + const std::string kModuleName = "CONTENT_INFO"; + + // binary blob + fnd::Vec mRawBinary; + + // variables + fnd::sha::sSha256Hash mHash; + cnmt::sContentId mContentId; + size_t mSize; + cnmt::ContentType mType; + byte_t mIdOffset; + }; +} +} \ No newline at end of file diff --git a/lib/libhac/include/nn/hac/ContentMetaBinary.h b/lib/libhac/include/nn/hac/ContentMeta.h similarity index 71% rename from lib/libhac/include/nn/hac/ContentMetaBinary.h rename to lib/libhac/include/nn/hac/ContentMeta.h index d4d3b93..5100e63 100644 --- a/lib/libhac/include/nn/hac/ContentMetaBinary.h +++ b/lib/libhac/include/nn/hac/ContentMeta.h @@ -4,73 +4,17 @@ #include #include #include +#include +#include namespace nn { namespace hac { - class ContentMetaBinary : + class ContentMeta : public fnd::IByteModel { public: - struct ContentInfo - { - fnd::sha::sSha256Hash hash; - byte_t nca_id[cnmt::kContentIdLen]; - size_t size; - cnmt::ContentType type; - - void operator=(const ContentInfo& other) - { - hash = other.hash; - memcpy(nca_id, other.nca_id, cnmt::kContentIdLen); - size = other.size; - type = other.type; - } - - bool operator==(const ContentInfo& other) const - { - return (hash == other.hash) \ - && (memcmp(nca_id, other.nca_id, cnmt::kContentIdLen) == 0) \ - && (size == other.size) \ - && (type == other.type); - } - - bool operator!=(const ContentInfo& other) const - { - return !operator==(other); - } - }; - - struct ContentMetaInfo - { - uint64_t id; - uint32_t version; - cnmt::ContentMetaType type; - byte_t attributes; - - void operator=(const ContentMetaInfo& other) - { - id = other.id; - version = other.version; - type = other.type; - attributes = other.attributes; - } - - bool operator==(const ContentMetaInfo& other) const - { - return (id == other.id) \ - && (version == other.version) \ - && (type == other.type) \ - && (attributes == other.attributes); - } - - bool operator!=(const ContentMetaInfo& other) const - { - return !operator==(other); - } - }; - struct ApplicationMetaExtendedHeader { uint64_t patch_id; @@ -160,14 +104,14 @@ namespace hac } }; - ContentMetaBinary(); - ContentMetaBinary(const ContentMetaBinary& other); + ContentMeta(); + ContentMeta(const ContentMeta& other); - void operator=(const ContentMetaBinary& other); - bool operator==(const ContentMetaBinary& other) const; - bool operator!=(const ContentMetaBinary& other) const; + void operator=(const ContentMeta& other); + bool operator==(const ContentMeta& other) const; + bool operator!=(const ContentMeta& other) const; - // export/import binary + // IByteModel void toBytes(); void fromBytes(const byte_t* bytes, size_t len); const fnd::Vec& getBytes() const; @@ -202,21 +146,21 @@ namespace hac const DeltaMetaExtendedHeader& getDeltaMetaExtendedHeader() const; void setDeltaMetaExtendedHeader(const DeltaMetaExtendedHeader& exhdr); - const fnd::List& getContentInfo() const; - void setContentInfo(const fnd::List& info); + const fnd::List& getContentInfo() const; + void setContentInfo(const fnd::List& info); - const fnd::List& getContentMetaInfo() const; - void setContentMetaInfo(const fnd::List& info); + const fnd::List& getContentMetaInfo() const; + void setContentMetaInfo(const fnd::List& info); const fnd::Vec& getExtendedData() const; void setExtendedData(const fnd::Vec& data); - const nn::hac::sDigest& getDigest() const; - void setDigest(const nn::hac::sDigest& digest); + const nn::hac::cnmt::sDigest& getDigest() const; + void setDigest(const nn::hac::cnmt::sDigest& digest); private: - const std::string kModuleName = "CONTENT_META_BINARY"; + const std::string kModuleName = "CONTENT_META"; // binary blob fnd::Vec mRawBinary; @@ -234,10 +178,10 @@ namespace hac AddOnContentMetaExtendedHeader mAddOnContentMetaExtendedHeader; DeltaMetaExtendedHeader mDeltaMetaExtendedHeader; - fnd::List mContentInfo; - fnd::List mContentMetaInfo; + fnd::List mContentInfo; + fnd::List mContentMetaInfo; fnd::Vec mExtendedData; - nn::hac::sDigest mDigest; + nn::hac::cnmt::sDigest mDigest; inline size_t getExtendedHeaderOffset() const { return sizeof(sContentMetaHeader); } inline size_t getContentInfoOffset(size_t exhdrSize) const { return getExtendedHeaderOffset() + exhdrSize; } diff --git a/lib/libhac/include/nn/hac/ContentMetaInfo.h b/lib/libhac/include/nn/hac/ContentMetaInfo.h new file mode 100644 index 0000000..2018a2a --- /dev/null +++ b/lib/libhac/include/nn/hac/ContentMetaInfo.h @@ -0,0 +1,56 @@ +#pragma once +#include +#include +#include +#include +#include + +namespace nn +{ +namespace hac +{ + class ContentMetaInfo : + public fnd::IByteModel + { + public: + ContentMetaInfo(); + ContentMetaInfo(const ContentMetaInfo& other); + + void operator=(const ContentMetaInfo& other); + bool operator==(const ContentMetaInfo& other) const; + bool operator!=(const ContentMetaInfo& other) const; + + // IByteModel + void toBytes(); + void fromBytes(const byte_t* bytes, size_t len); + const fnd::Vec& getBytes() const; + + // variables + void clear(); + + uint64_t getTitleId() const; + void setTitleId(uint64_t title_id); + + uint32_t getVersion() const; + void setVersion(uint32_t ver); + + cnmt::ContentMetaType getContentMetaType() const; + void setContentMetaType(cnmt::ContentMetaType type); + + byte_t getAttributes() const; + void setAttributes(byte_t attr); + + private: + const std::string kModuleName = "CONTENT_META_INFO"; + + // byte model + fnd::Vec mRawBinary; + + // variables + uint64_t mTitleId; + uint32_t mVersion; + cnmt::ContentMetaType mType; + byte_t mAttributes; + }; +} +} \ No newline at end of file diff --git a/lib/libhac/include/nn/hac/cnmt.h b/lib/libhac/include/nn/hac/cnmt.h index 81871c0..8af81b5 100644 --- a/lib/libhac/include/nn/hac/cnmt.h +++ b/lib/libhac/include/nn/hac/cnmt.h @@ -46,10 +46,58 @@ namespace hac ATTRIBUTE_REBOOTLESS }; - static const uint32_t kRequiredSystemVersion = 335544320; - static const uint32_t kDefaultVersion = 335545344; static const size_t kContentIdLen = 0x10; static const size_t kDigestLen = 0x20; + + struct sContentId + { + byte_t data[kContentIdLen]; + + void set(const byte_t content_id[kContentIdLen]) + { + memcpy(this->data, content_id, kContentIdLen); + } + + void operator=(const sContentId& other) + { + set(other.data); + } + + bool operator==(const sContentId& other) const + { + return memcmp(this->data, other.data, kContentIdLen) == 0; + } + + bool operator!=(const sContentId& other) const + { + return !(*this == other); + } + }; + + struct sDigest + { + byte_t data[kDigestLen]; + + void set(const byte_t digest[kDigestLen]) + { + memcpy(this->data, digest, kDigestLen); + } + + void operator=(const sDigest& other) + { + set(other.data); + } + + bool operator==(const sDigest& other) const + { + return memcmp(this->data, other.data, kDigestLen) == 0; + } + + bool operator!=(const sDigest& other) const + { + return !(*this == other); + } + }; } @@ -84,7 +132,7 @@ namespace hac struct sContentInfo { fnd::sha::sSha256Hash content_hash; - byte_t content_id[cnmt::kContentIdLen]; + cnmt::sContentId content_id; le_uint32_t size_lower; le_uint16_t size_higher; byte_t content_type; @@ -128,11 +176,6 @@ namespace hac le_uint32_t extended_data_size; byte_t reserved[4]; }; - - struct sDigest - { - byte_t data[cnmt::kDigestLen]; - }; #pragma pack(pop) } } \ No newline at end of file diff --git a/lib/libhac/source/ContentInfo.cpp b/lib/libhac/source/ContentInfo.cpp new file mode 100644 index 0000000..fa34917 --- /dev/null +++ b/lib/libhac/source/ContentInfo.cpp @@ -0,0 +1,123 @@ +#include + +nn::hac::ContentInfo::ContentInfo() +{ + clear(); +} + +nn::hac::ContentInfo::ContentInfo(const ContentInfo& other) +{ + *this = other; +} + +void nn::hac::ContentInfo::operator=(const ContentInfo& other) +{ + clear(); + mRawBinary = other.mRawBinary; + mHash = other.mHash; + mContentId = other.mContentId; + mSize = other.mSize; + mType = other.mType; +} + +bool nn::hac::ContentInfo::operator==(const ContentInfo& other) const +{ + return (mHash == other.mHash) \ + && (mContentId == other.mContentId) \ + && (mSize == other.mSize) \ + && (mType == other.mType); +} + +bool nn::hac::ContentInfo::operator!=(const ContentInfo& other) const +{ + return !(*this == other); +} + +void nn::hac::ContentInfo::toBytes() +{ + mRawBinary.alloc(sizeof(sContentInfo)); + sContentInfo* info = (sContentInfo*)mRawBinary.data(); + + info->content_hash = mHash; + info->content_id = mContentId; + info->size_lower = mSize & (uint32_t)(-1); + info->size_higher = (mSize >> 32) & (uint16_t)(-1); + info->content_type = mType; + info->id_offset = mIdOffset; +} + +void nn::hac::ContentInfo::fromBytes(const byte_t* bytes, size_t len) +{ + if (len < sizeof(sContentInfo)) + { + throw fnd::Exception(kModuleName, "ContentInfo too small"); + } + + const sContentInfo* info = (const sContentInfo*)bytes; + + mHash = info->content_hash; + mContentId = info->content_id; + mSize = (uint64_t)(info->size_lower.get()) | (uint64_t)(info->size_higher.get()) << 32; + mType = (cnmt::ContentType)info->content_type; + mIdOffset = info->id_offset; +} + +const fnd::Vec& nn::hac::ContentInfo::getBytes() const +{ + return mRawBinary; +} + +void nn::hac::ContentInfo::clear() +{ + mRawBinary.clear(); +} + +const fnd::sha::sSha256Hash& nn::hac::ContentInfo::getContentHash() const +{ + return mHash; +} + +void nn::hac::ContentInfo::setContentHash(const fnd::sha::sSha256Hash& hash) +{ + mHash = hash; +} + +const nn::hac::cnmt::sContentId& nn::hac::ContentInfo::getContentId() const +{ + return mContentId; +} + +void nn::hac::ContentInfo::setContentId(const cnmt::sContentId& content_id) +{ + mContentId = content_id; +} + +size_t nn::hac::ContentInfo::getContentSize() const +{ + return mSize; +} + +void nn::hac::ContentInfo::setContentSize(size_t size) +{ + mSize = size; +} + +nn::hac::cnmt::ContentType nn::hac::ContentInfo::getContentType() const +{ + return mType; +} + +void nn::hac::ContentInfo::setContentType(cnmt::ContentType type) +{ + mType = type; +} + +byte_t nn::hac::ContentInfo::getIdOffset() const +{ + return mIdOffset; +} + +void nn::hac::ContentInfo::setIdOffset(byte_t id_offset) +{ + mIdOffset = id_offset; +} \ No newline at end of file diff --git a/lib/libhac/source/ContentMetaBinary.cpp b/lib/libhac/source/ContentMeta.cpp similarity index 68% rename from lib/libhac/source/ContentMetaBinary.cpp rename to lib/libhac/source/ContentMeta.cpp index 7ebd628..021f6b3 100644 --- a/lib/libhac/source/ContentMetaBinary.cpp +++ b/lib/libhac/source/ContentMeta.cpp @@ -1,16 +1,16 @@ -#include +#include -nn::hac::ContentMetaBinary::ContentMetaBinary() +nn::hac::ContentMeta::ContentMeta() { clear(); } -nn::hac::ContentMetaBinary::ContentMetaBinary(const ContentMetaBinary & other) +nn::hac::ContentMeta::ContentMeta(const ContentMeta & other) { *this = other; } -void nn::hac::ContentMetaBinary::operator=(const ContentMetaBinary& other) +void nn::hac::ContentMeta::operator=(const ContentMeta& other) { if (other.getBytes().size() > 0) { @@ -36,7 +36,7 @@ void nn::hac::ContentMetaBinary::operator=(const ContentMetaBinary& other) } } -bool nn::hac::ContentMetaBinary::operator==(const ContentMetaBinary& other) const +bool nn::hac::ContentMeta::operator==(const ContentMeta& other) const { return (mTitleId == other.mTitleId) \ && (mTitleVersion == other.mTitleVersion) \ @@ -54,17 +54,17 @@ bool nn::hac::ContentMetaBinary::operator==(const ContentMetaBinary& other) cons && (memcmp(mDigest.data, other.mDigest.data, cnmt::kDigestLen) == 0); } -bool nn::hac::ContentMetaBinary::operator!=(const ContentMetaBinary& other) const +bool nn::hac::ContentMeta::operator!=(const ContentMeta& other) const { return !(*this == other); } -void nn::hac::ContentMetaBinary::toBytes() +void nn::hac::ContentMeta::toBytes() { throw fnd::Exception(kModuleName, "exportBinary() not implemented"); } -void nn::hac::ContentMetaBinary::fromBytes(const byte_t* data, size_t len) +void nn::hac::ContentMeta::fromBytes(const byte_t* data, size_t len) { // clear member variables clear(); @@ -119,10 +119,7 @@ void nn::hac::ContentMetaBinary::fromBytes(const byte_t* data, size_t len) ContentInfo cinfo; for (size_t i = 0; i < hdr->content_count.get(); i++) { - cinfo.hash = info[i].content_hash; - memcpy(cinfo.nca_id, info[i].content_id, cnmt::kContentIdLen); - cinfo.size = (uint64_t)(info[i].size_lower.get()) | (uint64_t)(info[i].size_higher.get()) << 32; - cinfo.type = (cnmt::ContentType)info[i].content_type; + cinfo.fromBytes((const byte_t*)&info[i], sizeof(sContentInfo)); mContentInfo.addElement(cinfo); } } @@ -134,10 +131,7 @@ void nn::hac::ContentMetaBinary::fromBytes(const byte_t* data, size_t len) ContentMetaInfo cmeta; for (size_t i = 0; i < hdr->content_meta_count.get(); i++) { - cmeta.id = info[i].id.get(); - cmeta.version = info[i].version.get(); - cmeta.type = (cnmt::ContentMetaType)info[i].type; - cmeta.attributes = info[i].attributes; + cmeta.fromBytes((const byte_t*)&info[i], sizeof(sContentMetaInfo)); mContentMetaInfo.addElement(cmeta); } } @@ -153,12 +147,12 @@ void nn::hac::ContentMetaBinary::fromBytes(const byte_t* data, size_t len) memcpy(mDigest.data, data + getDigestOffset(hdr->exhdr_size.get(), hdr->content_count.get(), hdr->content_meta_count.get(), exdata_size), cnmt::kDigestLen); } -const fnd::Vec& nn::hac::ContentMetaBinary::getBytes() const +const fnd::Vec& nn::hac::ContentMeta::getBytes() const { return mRawBinary; } -void nn::hac::ContentMetaBinary::clear() +void nn::hac::ContentMeta::clear() { mRawBinary.clear(); mTitleId = 0; @@ -177,138 +171,137 @@ void nn::hac::ContentMetaBinary::clear() memset(mDigest.data, 0, cnmt::kDigestLen); } -uint64_t nn::hac::ContentMetaBinary::getTitleId() const +uint64_t nn::hac::ContentMeta::getTitleId() const { return mTitleId; } -void nn::hac::ContentMetaBinary::setTitleId(uint64_t title_id) +void nn::hac::ContentMeta::setTitleId(uint64_t title_id) { mTitleId = title_id; } -uint32_t nn::hac::ContentMetaBinary::getTitleVersion() const +uint32_t nn::hac::ContentMeta::getTitleVersion() const { return mTitleVersion; } -void nn::hac::ContentMetaBinary::setTitleVersion(uint32_t version) +void nn::hac::ContentMeta::setTitleVersion(uint32_t version) { mTitleVersion = version; } -nn::hac::cnmt::ContentMetaType nn::hac::ContentMetaBinary::getType() const +nn::hac::cnmt::ContentMetaType nn::hac::ContentMeta::getType() const { return mType; } -void nn::hac::ContentMetaBinary::setType(cnmt::ContentMetaType type) +void nn::hac::ContentMeta::setType(cnmt::ContentMetaType type) { mType = type; } -byte_t nn::hac::ContentMetaBinary::getAttributes() const +byte_t nn::hac::ContentMeta::getAttributes() const { return mAttributes; } -void nn::hac::ContentMetaBinary::setAttributes(byte_t attributes) +void nn::hac::ContentMeta::setAttributes(byte_t attributes) { mAttributes = attributes; } -uint32_t nn::hac::ContentMetaBinary::getRequiredDownloadSystemVersion() const +uint32_t nn::hac::ContentMeta::getRequiredDownloadSystemVersion() const { return mRequiredDownloadSystemVersion; } -void nn::hac::ContentMetaBinary::setRequiredDownloadSystemVersion(uint32_t version) +void nn::hac::ContentMeta::setRequiredDownloadSystemVersion(uint32_t version) { mRequiredDownloadSystemVersion = version; } -const nn::hac::ContentMetaBinary::ApplicationMetaExtendedHeader& nn::hac::ContentMetaBinary::getApplicationMetaExtendedHeader() const +const nn::hac::ContentMeta::ApplicationMetaExtendedHeader& nn::hac::ContentMeta::getApplicationMetaExtendedHeader() const { return mApplicationMetaExtendedHeader; } -void nn::hac::ContentMetaBinary::setApplicationMetaExtendedHeader(const ApplicationMetaExtendedHeader& exhdr) +void nn::hac::ContentMeta::setApplicationMetaExtendedHeader(const ApplicationMetaExtendedHeader& exhdr) { mApplicationMetaExtendedHeader = exhdr; } -const nn::hac::ContentMetaBinary::PatchMetaExtendedHeader& nn::hac::ContentMetaBinary::getPatchMetaExtendedHeader() const +const nn::hac::ContentMeta::PatchMetaExtendedHeader& nn::hac::ContentMeta::getPatchMetaExtendedHeader() const { return mPatchMetaExtendedHeader; } -void nn::hac::ContentMetaBinary::setPatchMetaExtendedHeader(const PatchMetaExtendedHeader& exhdr) +void nn::hac::ContentMeta::setPatchMetaExtendedHeader(const PatchMetaExtendedHeader& exhdr) { mPatchMetaExtendedHeader = exhdr; } -const nn::hac::ContentMetaBinary::AddOnContentMetaExtendedHeader& nn::hac::ContentMetaBinary::getAddOnContentMetaExtendedHeader() const +const nn::hac::ContentMeta::AddOnContentMetaExtendedHeader& nn::hac::ContentMeta::getAddOnContentMetaExtendedHeader() const { return mAddOnContentMetaExtendedHeader; } -void nn::hac::ContentMetaBinary::setAddOnContentMetaExtendedHeader(const AddOnContentMetaExtendedHeader& exhdr) +void nn::hac::ContentMeta::setAddOnContentMetaExtendedHeader(const AddOnContentMetaExtendedHeader& exhdr) { mAddOnContentMetaExtendedHeader = exhdr; } -const nn::hac::ContentMetaBinary::DeltaMetaExtendedHeader& nn::hac::ContentMetaBinary::getDeltaMetaExtendedHeader() const +const nn::hac::ContentMeta::DeltaMetaExtendedHeader& nn::hac::ContentMeta::getDeltaMetaExtendedHeader() const { return mDeltaMetaExtendedHeader; } -void nn::hac::ContentMetaBinary::setDeltaMetaExtendedHeader(const DeltaMetaExtendedHeader& exhdr) +void nn::hac::ContentMeta::setDeltaMetaExtendedHeader(const DeltaMetaExtendedHeader& exhdr) { mDeltaMetaExtendedHeader = exhdr; } -const fnd::List& nn::hac::ContentMetaBinary::getContentInfo() const +const fnd::List& nn::hac::ContentMeta::getContentInfo() const { return mContentInfo; } -void nn::hac::ContentMetaBinary::setContentInfo(const fnd::List& info) +void nn::hac::ContentMeta::setContentInfo(const fnd::List& info) { mContentInfo = info; } -const fnd::List& nn::hac::ContentMetaBinary::getContentMetaInfo() const +const fnd::List& nn::hac::ContentMeta::getContentMetaInfo() const { return mContentMetaInfo; } -void nn::hac::ContentMetaBinary::setContentMetaInfo(const fnd::List& info) +void nn::hac::ContentMeta::setContentMetaInfo(const fnd::List& info) { mContentMetaInfo = info; } -const fnd::Vec & nn::hac::ContentMetaBinary::getExtendedData() const +const fnd::Vec & nn::hac::ContentMeta::getExtendedData() const { return mExtendedData; } -void nn::hac::ContentMetaBinary::setExtendedData(const fnd::Vec & data) +void nn::hac::ContentMeta::setExtendedData(const fnd::Vec& data) { mExtendedData = data; } -const nn::hac::sDigest & nn::hac::ContentMetaBinary::getDigest() const +const nn::hac::cnmt::sDigest & nn::hac::ContentMeta::getDigest() const { return mDigest; } -void nn::hac::ContentMetaBinary::setDigest(const nn::hac::sDigest & digest) +void nn::hac::ContentMeta::setDigest(const nn::hac::cnmt::sDigest& digest) { - - memcpy(mDigest.data, digest.data, cnmt::kDigestLen); + mDigest = digest; } -bool nn::hac::ContentMetaBinary::validateExtendedHeaderSize(cnmt::ContentMetaType type, size_t exhdrSize) const +bool nn::hac::ContentMeta::validateExtendedHeaderSize(cnmt::ContentMetaType type, size_t exhdrSize) const { bool validSize = false; @@ -333,7 +326,7 @@ bool nn::hac::ContentMetaBinary::validateExtendedHeaderSize(cnmt::ContentMetaTyp return validSize; } -size_t nn::hac::ContentMetaBinary::getExtendedDataSize(cnmt::ContentMetaType type, const byte_t * data) const +size_t nn::hac::ContentMeta::getExtendedDataSize(cnmt::ContentMetaType type, const byte_t * data) const { size_t exdata_len = 0; if (type == cnmt::METATYPE_PATCH) @@ -349,7 +342,7 @@ size_t nn::hac::ContentMetaBinary::getExtendedDataSize(cnmt::ContentMetaType typ return exdata_len; } -void nn::hac::ContentMetaBinary::validateBinary(const byte_t * data, size_t len) const +void nn::hac::ContentMeta::validateBinary(const byte_t * data, size_t len) const { // check if it is large enough to read the header if (len < sizeof(sContentMetaHeader)) diff --git a/lib/libhac/source/ContentMetaInfo.cpp b/lib/libhac/source/ContentMetaInfo.cpp new file mode 100644 index 0000000..1615676 --- /dev/null +++ b/lib/libhac/source/ContentMetaInfo.cpp @@ -0,0 +1,114 @@ +#include + +nn::hac::ContentMetaInfo::ContentMetaInfo() +{ + clear(); +} + +nn::hac::ContentMetaInfo::ContentMetaInfo(const ContentMetaInfo& other) +{ + *this = other; +} + +void nn::hac::ContentMetaInfo::operator=(const ContentMetaInfo& other) +{ + clear(); + mRawBinary = other.mRawBinary; + mTitleId = other.mTitleId; + mVersion = other.mVersion; + mType = other.mType; + mAttributes = other.mAttributes; +} + +bool nn::hac::ContentMetaInfo::operator==(const ContentMetaInfo& other) const +{ + return (mTitleId == other.mTitleId) \ + && (mVersion == other.mVersion) \ + && (mType == other.mType) \ + && (mAttributes == other.mAttributes); +} + +bool nn::hac::ContentMetaInfo::operator!=(const ContentMetaInfo& other) const +{ + return !(*this == other); +} + +void nn::hac::ContentMetaInfo::toBytes() +{ + mRawBinary.alloc(sizeof(sContentMetaInfo)); + sContentMetaInfo* info = (sContentMetaInfo*)mRawBinary.data(); + + info->id = mTitleId; + info->version = mVersion; + info->type = mType; + info->attributes = mAttributes; +} + +void nn::hac::ContentMetaInfo::fromBytes(const byte_t* bytes, size_t len) +{ + if (len < sizeof(sContentMetaInfo)) + { + throw fnd::Exception(kModuleName, "ContentMetaInfo too small"); + } + + const sContentMetaInfo* info = (const sContentMetaInfo*)bytes; + + mTitleId = info->id.get(); + mVersion = info->version.get(); + mType = (cnmt::ContentMetaType)info->type; + mAttributes = info->attributes; +} + +const fnd::Vec& nn::hac::ContentMetaInfo::getBytes() const +{ + return mRawBinary; +} + +void nn::hac::ContentMetaInfo::clear() +{ + mRawBinary.clear(); + mTitleId = 0; + mVersion = 0; + mType = cnmt::ContentMetaType::METATYPE_APPLICATION; + mAttributes = 0; +} + +uint64_t nn::hac::ContentMetaInfo::getTitleId() const +{ + return mTitleId; +} + +void nn::hac::ContentMetaInfo::setTitleId(uint64_t title_id) +{ + mTitleId = title_id; +} + +uint32_t nn::hac::ContentMetaInfo::getVersion() const +{ + return mVersion; +} + +void nn::hac::ContentMetaInfo::setVersion(uint32_t ver) +{ + mVersion = ver; +} + +nn::hac::cnmt::ContentMetaType nn::hac::ContentMetaInfo::getContentMetaType() const +{ + return mType; +} + +void nn::hac::ContentMetaInfo::setContentMetaType(cnmt::ContentMetaType type) +{ + mType = type; +} + +byte_t nn::hac::ContentMetaInfo::getAttributes() const +{ + return mAttributes; +} + +void nn::hac::ContentMetaInfo::setAttributes(byte_t attr) +{ + mAttributes = attr; +} diff --git a/programs/nstool/source/CnmtProcess.cpp b/programs/nstool/source/CnmtProcess.cpp index e49093d..3d9f4a7 100644 --- a/programs/nstool/source/CnmtProcess.cpp +++ b/programs/nstool/source/CnmtProcess.cpp @@ -34,7 +34,7 @@ void CnmtProcess::setVerifyMode(bool verify) mVerify = verify; } -const nn::hac::ContentMetaBinary& CnmtProcess::getContentMetaBinary() const +const nn::hac::ContentMeta& CnmtProcess::getContentMeta() const { return mCnmt; } @@ -95,12 +95,12 @@ void CnmtProcess::displayCnmt() printf(" ContentInfo:\n"); for (size_t i = 0; i < mCnmt.getContentInfo().size(); i++) { - const nn::hac::ContentMetaBinary::ContentInfo& info = mCnmt.getContentInfo()[i]; + const nn::hac::ContentInfo& info = mCnmt.getContentInfo()[i]; std::cout << " " << std::dec << i << std::endl; - std::cout << " Type: " << getContentTypeStr(info.type) << " (" << std::dec << info.type << ")" << std::endl; - std::cout << " Id: " << fnd::SimpleTextOutput::arrayToString(info.nca_id, nn::hac::cnmt::kContentIdLen, false, "") << std::endl; - std::cout << " Size: 0x" << std::hex << info.size << std::endl; - std::cout << " Hash: " << fnd::SimpleTextOutput::arrayToString(info.hash.bytes, sizeof(info.hash), false, "") << std::endl; + std::cout << " Type: " << getContentTypeStr(info.getContentType()) << " (" << std::dec << info.getContentType() << ")" << std::endl; + std::cout << " Id: " << fnd::SimpleTextOutput::arrayToString(info.getContentId().data, nn::hac::cnmt::kContentIdLen, false, "") << std::endl; + std::cout << " Size: 0x" << std::hex << info.getContentSize() << std::endl; + std::cout << " Hash: " << fnd::SimpleTextOutput::arrayToString(info.getContentHash().bytes, sizeof(info.getContentHash()), false, "") << std::endl; } } if (mCnmt.getContentMetaInfo().size() > 0) @@ -108,14 +108,14 @@ void CnmtProcess::displayCnmt() std::cout << " ContentMetaInfo:" << std::endl; for (size_t i = 0; i < mCnmt.getContentMetaInfo().size(); i++) { - const nn::hac::ContentMetaBinary::ContentMetaInfo& info = mCnmt.getContentMetaInfo()[i]; + const nn::hac::ContentMetaInfo& info = mCnmt.getContentMetaInfo()[i]; std::cout << " " << std::dec << i << std::endl; - std::cout << " Id: 0x" << std::hex << std::setw(16) << std::setfill('0') << info.id << std::endl; - std::cout << " Version: v" << std::dec << info.version << " (" << _SPLIT_VER(info.version) << ")"<< std::endl; - std::cout << " Type: " << getContentMetaTypeStr(info.type) << " (" << std::dec << info.type << ")" << std::endl; - std::cout << " Attributes: 0x" << std::hex << (uint32_t)info.attributes << std::endl; - std::cout << " IncludesExFatDriver: " << getBoolStr(_HAS_BIT(info.attributes, nn::hac::cnmt::ATTRIBUTE_INCLUDES_EX_FAT_DRIVER)) << std::endl; - std::cout << " Rebootless: " << getBoolStr(_HAS_BIT(info.attributes, nn::hac::cnmt::ATTRIBUTE_REBOOTLESS)) << std::endl; + std::cout << " Id: 0x" << std::hex << std::setw(16) << std::setfill('0') << info.getTitleId() << std::endl; + std::cout << " Version: v" << std::dec << info.getVersion() << " (" << _SPLIT_VER(info.getVersion()) << ")"<< std::endl; + std::cout << " Type: " << getContentMetaTypeStr(info.getContentMetaType()) << " (" << std::dec << info.getContentMetaType() << ")" << std::endl; + std::cout << " Attributes: 0x" << std::hex << (uint32_t)info.getAttributes() << std::endl; + std::cout << " IncludesExFatDriver: " << getBoolStr(_HAS_BIT(info.getAttributes(), nn::hac::cnmt::ATTRIBUTE_INCLUDES_EX_FAT_DRIVER)) << std::endl; + std::cout << " Rebootless: " << getBoolStr(_HAS_BIT(info.getAttributes(), nn::hac::cnmt::ATTRIBUTE_REBOOTLESS)) << std::endl; } } diff --git a/programs/nstool/source/CnmtProcess.h b/programs/nstool/source/CnmtProcess.h index 4fa561c..a9834fa 100644 --- a/programs/nstool/source/CnmtProcess.h +++ b/programs/nstool/source/CnmtProcess.h @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include "common.h" @@ -18,7 +18,7 @@ public: void setCliOutputMode(CliOutputMode type); void setVerifyMode(bool verify); - const nn::hac::ContentMetaBinary& getContentMetaBinary() const; + const nn::hac::ContentMeta& getContentMeta() const; private: const std::string kModuleName = "CnmtProcess"; @@ -27,7 +27,7 @@ private: CliOutputMode mCliOutputMode; bool mVerify; - nn::hac::ContentMetaBinary mCnmt; + nn::hac::ContentMeta mCnmt; void importCnmt(); void displayCnmt();