diff --git a/lib/libhac/include/nn/hac/AddOnContentMetaExtendedHeader.h b/lib/libhac/include/nn/hac/AddOnContentMetaExtendedHeader.h new file mode 100644 index 0000000..89ffcb8 --- /dev/null +++ b/lib/libhac/include/nn/hac/AddOnContentMetaExtendedHeader.h @@ -0,0 +1,46 @@ +#pragma once +#include +#include +#include +#include + +namespace nn +{ +namespace hac +{ + class AddOnContentMetaExtendedHeader : + public fnd::IByteModel + { + public: + AddOnContentMetaExtendedHeader(); + AddOnContentMetaExtendedHeader(const AddOnContentMetaExtendedHeader& other); + + void operator=(const AddOnContentMetaExtendedHeader& other); + bool operator==(const AddOnContentMetaExtendedHeader& other) const; + bool operator!=(const AddOnContentMetaExtendedHeader& other) const; + + // IByteModel + void toBytes(); + void fromBytes(const byte_t* bytes, size_t len); + const fnd::Vec& getBytes() const; + + // variables + void clear(); + + uint64_t getApplicationId() const; + void setApplicationId(uint64_t application_id); + + uint32_t getRequiredApplicationVersion() const; + void setRequiredApplicationVersion(uint32_t app_ver); + private: + const std::string kModuleName = "ADD_ON_CONTENT_META_EXTENDED_HEADER"; + + // binary blob + fnd::Vec mRawBinary; + + // variables + uint64_t mApplicationId; + uint32_t mRequiredApplicationVersion; + }; +} +} \ No newline at end of file diff --git a/lib/libhac/include/nn/hac/ApplicationMetaExtendedHeader.h b/lib/libhac/include/nn/hac/ApplicationMetaExtendedHeader.h new file mode 100644 index 0000000..ca526d6 --- /dev/null +++ b/lib/libhac/include/nn/hac/ApplicationMetaExtendedHeader.h @@ -0,0 +1,46 @@ +#pragma once +#include +#include +#include +#include + +namespace nn +{ +namespace hac +{ + class ApplicationMetaExtendedHeader : + public fnd::IByteModel + { + public: + ApplicationMetaExtendedHeader(); + ApplicationMetaExtendedHeader(const ApplicationMetaExtendedHeader& other); + + void operator=(const ApplicationMetaExtendedHeader& other); + bool operator==(const ApplicationMetaExtendedHeader& other) const; + bool operator!=(const ApplicationMetaExtendedHeader& other) const; + + // IByteModel + void toBytes(); + void fromBytes(const byte_t* bytes, size_t len); + const fnd::Vec& getBytes() const; + + // variables + void clear(); + + uint64_t getPatchId() const; + void setPatchId(uint64_t patch_id); + + uint32_t getRequiredSystemVersion() const; + void setRequiredSystemVersion(uint32_t sys_ver); + private: + const std::string kModuleName = "APPLICATION_META_EXTENDED_HEADER"; + + // binary blob + fnd::Vec mRawBinary; + + // variables + uint64_t mPatchId; + uint32_t mRequiredSystemVersion; + }; +} +} \ No newline at end of file diff --git a/lib/libhac/include/nn/hac/ContentInfo.h b/lib/libhac/include/nn/hac/ContentInfo.h index 6399d7a..d9a86ce 100644 --- a/lib/libhac/include/nn/hac/ContentInfo.h +++ b/lib/libhac/include/nn/hac/ContentInfo.h @@ -2,7 +2,6 @@ #include #include #include -#include #include namespace nn diff --git a/lib/libhac/include/nn/hac/ContentMeta.h b/lib/libhac/include/nn/hac/ContentMeta.h index 5100e63..a48106d 100644 --- a/lib/libhac/include/nn/hac/ContentMeta.h +++ b/lib/libhac/include/nn/hac/ContentMeta.h @@ -6,6 +6,10 @@ #include #include #include +#include +#include +#include +#include namespace nn { @@ -15,95 +19,6 @@ namespace hac public fnd::IByteModel { public: - struct ApplicationMetaExtendedHeader - { - uint64_t patch_id; - uint32_t required_system_version; - - void operator=(const ApplicationMetaExtendedHeader& other) - { - patch_id = other.patch_id; - required_system_version = other.required_system_version; - } - - bool operator==(const ApplicationMetaExtendedHeader& other) const - { - return (patch_id == other.patch_id) \ - && (required_system_version == other.required_system_version); - } - - bool operator!=(const ApplicationMetaExtendedHeader& other) const - { - return !operator==(other); - } - }; - - struct PatchMetaExtendedHeader - { - uint64_t application_id; - uint32_t required_system_version; - - void operator=(const PatchMetaExtendedHeader& other) - { - application_id = other.application_id; - required_system_version = other.required_system_version; - } - - bool operator==(const PatchMetaExtendedHeader& other) const - { - return (application_id == other.application_id) \ - && (required_system_version == other.required_system_version); - } - - bool operator!=(const PatchMetaExtendedHeader& other) const - { - return !operator==(other); - } - }; - - struct AddOnContentMetaExtendedHeader - { - uint64_t application_id; - uint32_t required_application_version; - - void operator=(const AddOnContentMetaExtendedHeader& other) - { - application_id = other.application_id; - required_application_version = other.required_application_version; - } - - bool operator==(const AddOnContentMetaExtendedHeader& other) const - { - return (application_id == other.application_id) \ - && (required_application_version == other.required_application_version); - } - - bool operator!=(const AddOnContentMetaExtendedHeader& other) const - { - return !operator==(other); - } - }; - - struct DeltaMetaExtendedHeader - { - uint64_t application_id; - - void operator=(const DeltaMetaExtendedHeader& other) - { - application_id = other.application_id; - } - - bool operator==(const DeltaMetaExtendedHeader& other) const - { - return (application_id == other.application_id); - } - - bool operator!=(const DeltaMetaExtendedHeader& other) const - { - return !operator==(other); - } - }; - ContentMeta(); ContentMeta(const ContentMeta& other); @@ -125,8 +40,8 @@ namespace hac uint32_t getTitleVersion() const; void setTitleVersion(uint32_t version); - cnmt::ContentMetaType getType() const; - void setType(cnmt::ContentMetaType type); + cnmt::ContentMetaType getContentMetaType() const; + void setContentMetaType(cnmt::ContentMetaType type); byte_t getAttributes() const; void setAttributes(byte_t attributes); @@ -155,8 +70,8 @@ namespace hac const fnd::Vec& getExtendedData() const; void setExtendedData(const fnd::Vec& data); - const nn::hac::cnmt::sDigest& getDigest() const; - void setDigest(const nn::hac::cnmt::sDigest& digest); + const cnmt::sDigest& getDigest() const; + void setDigest(const cnmt::sDigest& digest); private: @@ -178,10 +93,10 @@ namespace hac AddOnContentMetaExtendedHeader mAddOnContentMetaExtendedHeader; DeltaMetaExtendedHeader mDeltaMetaExtendedHeader; - fnd::List mContentInfo; - fnd::List mContentMetaInfo; + fnd::List mContentInfo; + fnd::List mContentMetaInfo; fnd::Vec mExtendedData; - nn::hac::cnmt::sDigest mDigest; + 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 index 2018a2a..4749bf2 100644 --- a/lib/libhac/include/nn/hac/ContentMetaInfo.h +++ b/lib/libhac/include/nn/hac/ContentMetaInfo.h @@ -2,7 +2,6 @@ #include #include #include -#include #include namespace nn @@ -31,8 +30,8 @@ namespace hac uint64_t getTitleId() const; void setTitleId(uint64_t title_id); - uint32_t getVersion() const; - void setVersion(uint32_t ver); + uint32_t getTitleVersion() const; + void setTitleVersion(uint32_t ver); cnmt::ContentMetaType getContentMetaType() const; void setContentMetaType(cnmt::ContentMetaType type); @@ -48,7 +47,7 @@ namespace hac // variables uint64_t mTitleId; - uint32_t mVersion; + uint32_t mTitleVersion; cnmt::ContentMetaType mType; byte_t mAttributes; }; diff --git a/lib/libhac/include/nn/hac/DeltaMetaExtendedHeader.h b/lib/libhac/include/nn/hac/DeltaMetaExtendedHeader.h new file mode 100644 index 0000000..ea8ddb4 --- /dev/null +++ b/lib/libhac/include/nn/hac/DeltaMetaExtendedHeader.h @@ -0,0 +1,47 @@ +#pragma once +#include +#include +#include +#include + +namespace nn +{ +namespace hac +{ + class DeltaMetaExtendedHeader : + public fnd::IByteModel + { + public: + DeltaMetaExtendedHeader(); + DeltaMetaExtendedHeader(const DeltaMetaExtendedHeader& other); + + void operator=(const DeltaMetaExtendedHeader& other); + bool operator==(const DeltaMetaExtendedHeader& other) const; + bool operator!=(const DeltaMetaExtendedHeader& other) const; + + // IByteModel + void toBytes(); + void fromBytes(const byte_t* bytes, size_t len); + const fnd::Vec& getBytes() const; + + // variables + void clear(); + + uint64_t getApplicationId() const; + void setApplicationId(uint64_t application_id); + + uint32_t getExtendedDataSize() const; + void setExtendedDataSize(uint32_t size); + + private: + const std::string kModuleName = "DELTA_META_EXTENDED_HEADER"; + + // binary blob + fnd::Vec mRawBinary; + + // variables + uint64_t mApplicationId; + uint32_t mExtendedDataSize; + }; +} +} diff --git a/lib/libhac/include/nn/hac/PatchMetaExtendedHeader.h b/lib/libhac/include/nn/hac/PatchMetaExtendedHeader.h new file mode 100644 index 0000000..8caede4 --- /dev/null +++ b/lib/libhac/include/nn/hac/PatchMetaExtendedHeader.h @@ -0,0 +1,51 @@ +#pragma once +#include +#include +#include +#include + +namespace nn +{ +namespace hac +{ + class PatchMetaExtendedHeader : + public fnd::IByteModel + { + public: + PatchMetaExtendedHeader(); + PatchMetaExtendedHeader(const PatchMetaExtendedHeader& other); + + void operator=(const PatchMetaExtendedHeader& other); + bool operator==(const PatchMetaExtendedHeader& other) const; + bool operator!=(const PatchMetaExtendedHeader& other) const; + + // IByteModel + void toBytes(); + void fromBytes(const byte_t* bytes, size_t len); + const fnd::Vec& getBytes() const; + + // variables + void clear(); + + uint64_t getApplicationId() const; + void setApplicationId(uint64_t application_id); + + uint32_t getRequiredSystemVersion() const; + void setRequiredSystemVersion(uint32_t sys_ver); + + uint32_t getExtendedDataSize() const; + void setExtendedDataSize(uint32_t size); + + private: + const std::string kModuleName = "PATCH_META_EXTENDED_HEADER"; + + // binary blob + fnd::Vec mRawBinary; + + // variables + uint64_t mApplicationId; + uint32_t mRequiredSystemVersion; + uint32_t mExtendedDataSize; + }; +} +} diff --git a/lib/libhac/libhac.vcxproj b/lib/libhac/libhac.vcxproj index 2544a4d..ff80a4d 100644 --- a/lib/libhac/libhac.vcxproj +++ b/lib/libhac/libhac.vcxproj @@ -25,14 +25,17 @@ + + + @@ -68,6 +71,7 @@ + @@ -85,12 +89,15 @@ + + + @@ -114,6 +121,7 @@ + diff --git a/lib/libhac/libhac.vcxproj.filters b/lib/libhac/libhac.vcxproj.filters index dab39df..b83c0d2 100644 --- a/lib/libhac/libhac.vcxproj.filters +++ b/lib/libhac/libhac.vcxproj.filters @@ -27,6 +27,9 @@ Header Files + + Header Files + Header Files @@ -36,6 +39,9 @@ Header Files + + Header Files + Header Files @@ -51,6 +57,9 @@ Header Files + + Header Files + Header Files @@ -156,6 +165,9 @@ Header Files + + Header Files + Header Files @@ -203,6 +215,9 @@ Source Files + + Source Files + Source Files @@ -212,6 +227,9 @@ Source Files + + Source Files + Source Files @@ -221,6 +239,9 @@ Source Files + + Source Files + Source Files @@ -287,6 +308,9 @@ Source Files + + Source Files + Source Files diff --git a/lib/libhac/source/AddOnContentMetaExtendedHeader.cpp b/lib/libhac/source/AddOnContentMetaExtendedHeader.cpp new file mode 100644 index 0000000..91bf9f0 --- /dev/null +++ b/lib/libhac/source/AddOnContentMetaExtendedHeader.cpp @@ -0,0 +1,84 @@ +#include + +nn::hac::AddOnContentMetaExtendedHeader::AddOnContentMetaExtendedHeader() +{ + clear(); +} + +nn::hac::AddOnContentMetaExtendedHeader::AddOnContentMetaExtendedHeader(const AddOnContentMetaExtendedHeader& other) +{ + *this = other; +} + +void nn::hac::AddOnContentMetaExtendedHeader::operator=(const AddOnContentMetaExtendedHeader& other) +{ + clear(); + mRawBinary = other.mRawBinary; + mApplicationId = other.mApplicationId; + mRequiredApplicationVersion = other.mRequiredApplicationVersion; +} + +bool nn::hac::AddOnContentMetaExtendedHeader::operator==(const AddOnContentMetaExtendedHeader& other) const +{ + return (mApplicationId == other.mApplicationId) \ + && (mRequiredApplicationVersion == other.mRequiredApplicationVersion); +} + +bool nn::hac::AddOnContentMetaExtendedHeader::operator!=(const AddOnContentMetaExtendedHeader& other) const +{ + return !(*this == other); +} + +void nn::hac::AddOnContentMetaExtendedHeader::toBytes() +{ + mRawBinary.alloc(sizeof(sAddOnContentMetaExtendedHeader)); + sAddOnContentMetaExtendedHeader* info = (sAddOnContentMetaExtendedHeader*)mRawBinary.data(); + + info->application_id = mApplicationId; + info->required_application_version = mRequiredApplicationVersion; +} + +void nn::hac::AddOnContentMetaExtendedHeader::fromBytes(const byte_t* bytes, size_t len) +{ + if (len < sizeof(sAddOnContentMetaExtendedHeader)) + { + throw fnd::Exception(kModuleName, "AddOnContentMetaExtendedHeader too small"); + } + + const sAddOnContentMetaExtendedHeader* info = (const sAddOnContentMetaExtendedHeader*)bytes; + + mApplicationId = info->application_id.get(); + mRequiredApplicationVersion = info->required_application_version.get(); +} + +const fnd::Vec& nn::hac::AddOnContentMetaExtendedHeader::getBytes() const +{ + return mRawBinary; +} + +void nn::hac::AddOnContentMetaExtendedHeader::clear() +{ + mRawBinary.clear(); + mApplicationId = 0; + mRequiredApplicationVersion = 0; +} + +uint64_t nn::hac::AddOnContentMetaExtendedHeader::getApplicationId() const +{ + return mApplicationId; +} + +void nn::hac::AddOnContentMetaExtendedHeader::setApplicationId(uint64_t application_id) +{ + mApplicationId = application_id; +} + +uint32_t nn::hac::AddOnContentMetaExtendedHeader::getRequiredApplicationVersion() const +{ + return mRequiredApplicationVersion; +} + +void nn::hac::AddOnContentMetaExtendedHeader::setRequiredApplicationVersion(uint32_t sys_ver) +{ + mRequiredApplicationVersion = sys_ver; +} \ No newline at end of file diff --git a/lib/libhac/source/ApplicationMetaExtendedHeader.cpp b/lib/libhac/source/ApplicationMetaExtendedHeader.cpp new file mode 100644 index 0000000..493ca49 --- /dev/null +++ b/lib/libhac/source/ApplicationMetaExtendedHeader.cpp @@ -0,0 +1,84 @@ +#include + +nn::hac::ApplicationMetaExtendedHeader::ApplicationMetaExtendedHeader() +{ + clear(); +} + +nn::hac::ApplicationMetaExtendedHeader::ApplicationMetaExtendedHeader(const ApplicationMetaExtendedHeader& other) +{ + *this = other; +} + +void nn::hac::ApplicationMetaExtendedHeader::operator=(const ApplicationMetaExtendedHeader& other) +{ + clear(); + mRawBinary = other.mRawBinary; + mPatchId = other.mPatchId; + mRequiredSystemVersion = other.mRequiredSystemVersion; +} + +bool nn::hac::ApplicationMetaExtendedHeader::operator==(const ApplicationMetaExtendedHeader& other) const +{ + return (mPatchId == other.mPatchId) \ + && (mRequiredSystemVersion == other.mRequiredSystemVersion); +} + +bool nn::hac::ApplicationMetaExtendedHeader::operator!=(const ApplicationMetaExtendedHeader& other) const +{ + return !(*this == other); +} + +void nn::hac::ApplicationMetaExtendedHeader::toBytes() +{ + mRawBinary.alloc(sizeof(sApplicationMetaExtendedHeader)); + sApplicationMetaExtendedHeader* info = (sApplicationMetaExtendedHeader*)mRawBinary.data(); + + info->patch_id = mPatchId; + info->required_system_version = mRequiredSystemVersion; +} + +void nn::hac::ApplicationMetaExtendedHeader::fromBytes(const byte_t* bytes, size_t len) +{ + if (len < sizeof(sApplicationMetaExtendedHeader)) + { + throw fnd::Exception(kModuleName, "ApplicationMetaExtendedHeader too small"); + } + + const sApplicationMetaExtendedHeader* info = (const sApplicationMetaExtendedHeader*)bytes; + + mPatchId = info->patch_id.get(); + mRequiredSystemVersion = info->required_system_version.get(); +} + +const fnd::Vec& nn::hac::ApplicationMetaExtendedHeader::getBytes() const +{ + return mRawBinary; +} + +void nn::hac::ApplicationMetaExtendedHeader::clear() +{ + mRawBinary.clear(); + mPatchId = 0; + mRequiredSystemVersion = 0; +} + +uint64_t nn::hac::ApplicationMetaExtendedHeader::getPatchId() const +{ + return mPatchId; +} + +void nn::hac::ApplicationMetaExtendedHeader::setPatchId(uint64_t application_id) +{ + mPatchId = application_id; +} + +uint32_t nn::hac::ApplicationMetaExtendedHeader::getRequiredSystemVersion() const +{ + return mRequiredSystemVersion; +} + +void nn::hac::ApplicationMetaExtendedHeader::setRequiredSystemVersion(uint32_t sys_ver) +{ + mRequiredSystemVersion = sys_ver; +} \ No newline at end of file diff --git a/lib/libhac/source/ContentMeta.cpp b/lib/libhac/source/ContentMeta.cpp index 021f6b3..cd06711 100644 --- a/lib/libhac/source/ContentMeta.cpp +++ b/lib/libhac/source/ContentMeta.cpp @@ -24,7 +24,6 @@ void nn::hac::ContentMeta::operator=(const ContentMeta& other) mType = other.mType; mAttributes = other.mAttributes; mRequiredDownloadSystemVersion = other.mRequiredDownloadSystemVersion; - mExtendedHeader = other.mExtendedHeader; mApplicationMetaExtendedHeader = other.mApplicationMetaExtendedHeader; mPatchMetaExtendedHeader = other.mPatchMetaExtendedHeader; mAddOnContentMetaExtendedHeader = other.mAddOnContentMetaExtendedHeader; @@ -43,7 +42,6 @@ bool nn::hac::ContentMeta::operator==(const ContentMeta& other) const && (mType == other.mType) \ && (mAttributes == other.mAttributes) \ && (mRequiredDownloadSystemVersion == other.mRequiredDownloadSystemVersion) \ - && (mExtendedHeader == other.mExtendedHeader) \ && (mApplicationMetaExtendedHeader == other.mApplicationMetaExtendedHeader) \ && (mPatchMetaExtendedHeader == other.mPatchMetaExtendedHeader) \ && (mAddOnContentMetaExtendedHeader == other.mAddOnContentMetaExtendedHeader) \ @@ -61,7 +59,7 @@ bool nn::hac::ContentMeta::operator!=(const ContentMeta& other) const void nn::hac::ContentMeta::toBytes() { - throw fnd::Exception(kModuleName, "exportBinary() not implemented"); + throw fnd::Exception(kModuleName, "toBytes() not implemented"); } void nn::hac::ContentMeta::fromBytes(const byte_t* data, size_t len) @@ -85,31 +83,29 @@ void nn::hac::ContentMeta::fromBytes(const byte_t* data, size_t len) // save exheader if (hdr->exhdr_size.get() > 0) { - mExtendedHeader.alloc(hdr->exhdr_size.get()); - memcpy(mExtendedHeader.data(), data + getExtendedHeaderOffset(), hdr->exhdr_size.get()); - switch (mType) { case (cnmt::METATYPE_APPLICATION): - mApplicationMetaExtendedHeader.patch_id = ((sApplicationMetaExtendedHeader*)mExtendedHeader.data())->patch_id.get(); - mApplicationMetaExtendedHeader.required_system_version = ((sApplicationMetaExtendedHeader*)mExtendedHeader.data())->required_system_version.get(); + mApplicationMetaExtendedHeader.fromBytes(data + getExtendedHeaderOffset(), hdr->exhdr_size.get()); + exdata_size = 0; break; case (cnmt::METATYPE_PATCH): - mPatchMetaExtendedHeader.application_id = ((sPatchMetaExtendedHeader*)mExtendedHeader.data())->application_id.get(); - mPatchMetaExtendedHeader.required_system_version = ((sPatchMetaExtendedHeader*)mExtendedHeader.data())->required_system_version.get(); + mPatchMetaExtendedHeader.fromBytes(data + getExtendedHeaderOffset(), hdr->exhdr_size.get()); + exdata_size = mPatchMetaExtendedHeader.getExtendedDataSize(); break; case (cnmt::METATYPE_ADD_ON_CONTENT): - mAddOnContentMetaExtendedHeader.application_id = ((sAddOnContentMetaExtendedHeader*)mExtendedHeader.data())->application_id.get(); - mAddOnContentMetaExtendedHeader.required_application_version = ((sAddOnContentMetaExtendedHeader*)mExtendedHeader.data())->required_application_version.get(); + mAddOnContentMetaExtendedHeader.fromBytes(data + getExtendedHeaderOffset(), hdr->exhdr_size.get()); + exdata_size = 0; break; case (cnmt::METATYPE_DELTA): - mDeltaMetaExtendedHeader.application_id = ((sDeltaMetaExtendedHeader*)mExtendedHeader.data())->application_id.get(); + mDeltaMetaExtendedHeader.fromBytes(data + getExtendedHeaderOffset(), hdr->exhdr_size.get()); + exdata_size = mDeltaMetaExtendedHeader.getExtendedDataSize(); break; default: - break; + throw fnd::Exception(kModuleName, "Unhandled extended header for ContentMeta"); + //exdata_size = 0; + //break; } - - exdata_size = getExtendedDataSize(mType, mExtendedHeader.data()); } // save content info @@ -160,11 +156,10 @@ void nn::hac::ContentMeta::clear() mType = cnmt::METATYPE_SYSTEM_PROGRAM; mAttributes = 0; mRequiredDownloadSystemVersion = 0; - mExtendedHeader.clear(); - memset(&mApplicationMetaExtendedHeader, 0, sizeof(mApplicationMetaExtendedHeader)); - memset(&mPatchMetaExtendedHeader, 0, sizeof(mPatchMetaExtendedHeader)); - memset(&mAddOnContentMetaExtendedHeader, 0, sizeof(mAddOnContentMetaExtendedHeader)); - memset(&mDeltaMetaExtendedHeader, 0, sizeof(mDeltaMetaExtendedHeader)); + mApplicationMetaExtendedHeader.clear(); + mPatchMetaExtendedHeader.clear(); + mAddOnContentMetaExtendedHeader.clear(); + mDeltaMetaExtendedHeader.clear(); mContentInfo.clear(); mContentMetaInfo.clear(); mExtendedData.clear(); @@ -191,12 +186,12 @@ void nn::hac::ContentMeta::setTitleVersion(uint32_t version) mTitleVersion = version; } -nn::hac::cnmt::ContentMetaType nn::hac::ContentMeta::getType() const +nn::hac::cnmt::ContentMetaType nn::hac::ContentMeta::getContentMetaType() const { return mType; } -void nn::hac::ContentMeta::setType(cnmt::ContentMetaType type) +void nn::hac::ContentMeta::setContentMetaType(cnmt::ContentMetaType type) { mType = type; } @@ -221,7 +216,7 @@ void nn::hac::ContentMeta::setRequiredDownloadSystemVersion(uint32_t version) mRequiredDownloadSystemVersion = version; } -const nn::hac::ContentMeta::ApplicationMetaExtendedHeader& nn::hac::ContentMeta::getApplicationMetaExtendedHeader() const +const nn::hac::ApplicationMetaExtendedHeader& nn::hac::ContentMeta::getApplicationMetaExtendedHeader() const { return mApplicationMetaExtendedHeader; } @@ -231,7 +226,7 @@ void nn::hac::ContentMeta::setApplicationMetaExtendedHeader(const ApplicationMet mApplicationMetaExtendedHeader = exhdr; } -const nn::hac::ContentMeta::PatchMetaExtendedHeader& nn::hac::ContentMeta::getPatchMetaExtendedHeader() const +const nn::hac::PatchMetaExtendedHeader& nn::hac::ContentMeta::getPatchMetaExtendedHeader() const { return mPatchMetaExtendedHeader; } @@ -241,7 +236,7 @@ void nn::hac::ContentMeta::setPatchMetaExtendedHeader(const PatchMetaExtendedHea mPatchMetaExtendedHeader = exhdr; } -const nn::hac::ContentMeta::AddOnContentMetaExtendedHeader& nn::hac::ContentMeta::getAddOnContentMetaExtendedHeader() const +const nn::hac::AddOnContentMetaExtendedHeader& nn::hac::ContentMeta::getAddOnContentMetaExtendedHeader() const { return mAddOnContentMetaExtendedHeader; } @@ -251,7 +246,7 @@ void nn::hac::ContentMeta::setAddOnContentMetaExtendedHeader(const AddOnContentM mAddOnContentMetaExtendedHeader = exhdr; } -const nn::hac::ContentMeta::DeltaMetaExtendedHeader& nn::hac::ContentMeta::getDeltaMetaExtendedHeader() const +const nn::hac::DeltaMetaExtendedHeader& nn::hac::ContentMeta::getDeltaMetaExtendedHeader() const { return mDeltaMetaExtendedHeader; } diff --git a/lib/libhac/source/ContentMetaInfo.cpp b/lib/libhac/source/ContentMetaInfo.cpp index 1615676..f18592e 100644 --- a/lib/libhac/source/ContentMetaInfo.cpp +++ b/lib/libhac/source/ContentMetaInfo.cpp @@ -15,7 +15,7 @@ void nn::hac::ContentMetaInfo::operator=(const ContentMetaInfo& other) clear(); mRawBinary = other.mRawBinary; mTitleId = other.mTitleId; - mVersion = other.mVersion; + mTitleVersion = other.mTitleVersion; mType = other.mType; mAttributes = other.mAttributes; } @@ -23,7 +23,7 @@ void nn::hac::ContentMetaInfo::operator=(const ContentMetaInfo& other) bool nn::hac::ContentMetaInfo::operator==(const ContentMetaInfo& other) const { return (mTitleId == other.mTitleId) \ - && (mVersion == other.mVersion) \ + && (mTitleVersion == other.mTitleVersion) \ && (mType == other.mType) \ && (mAttributes == other.mAttributes); } @@ -39,7 +39,7 @@ void nn::hac::ContentMetaInfo::toBytes() sContentMetaInfo* info = (sContentMetaInfo*)mRawBinary.data(); info->id = mTitleId; - info->version = mVersion; + info->version = mTitleVersion; info->type = mType; info->attributes = mAttributes; } @@ -54,7 +54,7 @@ void nn::hac::ContentMetaInfo::fromBytes(const byte_t* bytes, size_t len) const sContentMetaInfo* info = (const sContentMetaInfo*)bytes; mTitleId = info->id.get(); - mVersion = info->version.get(); + mTitleVersion = info->version.get(); mType = (cnmt::ContentMetaType)info->type; mAttributes = info->attributes; } @@ -68,7 +68,7 @@ void nn::hac::ContentMetaInfo::clear() { mRawBinary.clear(); mTitleId = 0; - mVersion = 0; + mTitleVersion = 0; mType = cnmt::ContentMetaType::METATYPE_APPLICATION; mAttributes = 0; } @@ -83,14 +83,14 @@ void nn::hac::ContentMetaInfo::setTitleId(uint64_t title_id) mTitleId = title_id; } -uint32_t nn::hac::ContentMetaInfo::getVersion() const +uint32_t nn::hac::ContentMetaInfo::getTitleVersion() const { - return mVersion; + return mTitleVersion; } -void nn::hac::ContentMetaInfo::setVersion(uint32_t ver) +void nn::hac::ContentMetaInfo::setTitleVersion(uint32_t ver) { - mVersion = ver; + mTitleVersion = ver; } nn::hac::cnmt::ContentMetaType nn::hac::ContentMetaInfo::getContentMetaType() const diff --git a/lib/libhac/source/DeltaMetaExtendedHeader.cpp b/lib/libhac/source/DeltaMetaExtendedHeader.cpp new file mode 100644 index 0000000..587e072 --- /dev/null +++ b/lib/libhac/source/DeltaMetaExtendedHeader.cpp @@ -0,0 +1,84 @@ +#include + +nn::hac::DeltaMetaExtendedHeader::DeltaMetaExtendedHeader() +{ + clear(); +} + +nn::hac::DeltaMetaExtendedHeader::DeltaMetaExtendedHeader(const DeltaMetaExtendedHeader& other) +{ + *this = other; +} + +void nn::hac::DeltaMetaExtendedHeader::operator=(const DeltaMetaExtendedHeader& other) +{ + clear(); + mRawBinary = other.mRawBinary; + mApplicationId = other.mApplicationId; + mExtendedDataSize = other.mExtendedDataSize; +} + +bool nn::hac::DeltaMetaExtendedHeader::operator==(const DeltaMetaExtendedHeader& other) const +{ + return (mApplicationId == other.mApplicationId) \ + && (mExtendedDataSize == other.mExtendedDataSize); +} + +bool nn::hac::DeltaMetaExtendedHeader::operator!=(const DeltaMetaExtendedHeader& other) const +{ + return !(*this == other); +} + +void nn::hac::DeltaMetaExtendedHeader::toBytes() +{ + mRawBinary.alloc(sizeof(sDeltaMetaExtendedHeader)); + sDeltaMetaExtendedHeader* info = (sDeltaMetaExtendedHeader*)mRawBinary.data(); + + info->application_id = mApplicationId; + info->extended_data_size = mExtendedDataSize; +} + +void nn::hac::DeltaMetaExtendedHeader::fromBytes(const byte_t* bytes, size_t len) +{ + if (len < sizeof(sDeltaMetaExtendedHeader)) + { + throw fnd::Exception(kModuleName, "DeltaMetaExtendedHeader too small"); + } + + const sDeltaMetaExtendedHeader* info = (const sDeltaMetaExtendedHeader*)bytes; + + mApplicationId = info->application_id.get(); + mExtendedDataSize = info->extended_data_size.get(); +} + +const fnd::Vec& nn::hac::DeltaMetaExtendedHeader::getBytes() const +{ + return mRawBinary; +} + +void nn::hac::DeltaMetaExtendedHeader::clear() +{ + mRawBinary.clear(); + mApplicationId = 0; + mExtendedDataSize = 0; +} + +uint64_t nn::hac::DeltaMetaExtendedHeader::getApplicationId() const +{ + return mApplicationId; +} + +void nn::hac::DeltaMetaExtendedHeader::setApplicationId(uint64_t application_id) +{ + mApplicationId = application_id; +} + +uint32_t nn::hac::DeltaMetaExtendedHeader::getExtendedDataSize() const +{ + return mExtendedDataSize; +} + +void nn::hac::DeltaMetaExtendedHeader::setExtendedDataSize(uint32_t size) +{ + mExtendedDataSize = size; +} \ No newline at end of file diff --git a/lib/libhac/source/PatchMetaExtendedHeader.cpp b/lib/libhac/source/PatchMetaExtendedHeader.cpp new file mode 100644 index 0000000..0aed1df --- /dev/null +++ b/lib/libhac/source/PatchMetaExtendedHeader.cpp @@ -0,0 +1,99 @@ +#include + +nn::hac::PatchMetaExtendedHeader::PatchMetaExtendedHeader() +{ + clear(); +} + +nn::hac::PatchMetaExtendedHeader::PatchMetaExtendedHeader(const PatchMetaExtendedHeader& other) +{ + *this = other; +} + +void nn::hac::PatchMetaExtendedHeader::operator=(const PatchMetaExtendedHeader& other) +{ + clear(); + mRawBinary = other.mRawBinary; + mApplicationId = other.mApplicationId; + mRequiredSystemVersion = other.mRequiredSystemVersion; + mExtendedDataSize = other.mExtendedDataSize; +} + +bool nn::hac::PatchMetaExtendedHeader::operator==(const PatchMetaExtendedHeader& other) const +{ + return (mApplicationId == other.mApplicationId) \ + && (mRequiredSystemVersion == other.mRequiredSystemVersion) \ + && (mExtendedDataSize == other.mExtendedDataSize); +} + +bool nn::hac::PatchMetaExtendedHeader::operator!=(const PatchMetaExtendedHeader& other) const +{ + return !(*this == other); +} + +void nn::hac::PatchMetaExtendedHeader::toBytes() +{ + mRawBinary.alloc(sizeof(sPatchMetaExtendedHeader)); + sPatchMetaExtendedHeader* info = (sPatchMetaExtendedHeader*)mRawBinary.data(); + + info->application_id = mApplicationId; + info->required_system_version = mRequiredSystemVersion; + info->extended_data_size = mExtendedDataSize; +} + +void nn::hac::PatchMetaExtendedHeader::fromBytes(const byte_t* bytes, size_t len) +{ + if (len < sizeof(sPatchMetaExtendedHeader)) + { + throw fnd::Exception(kModuleName, "PatchMetaExtendedHeader too small"); + } + + const sPatchMetaExtendedHeader* info = (const sPatchMetaExtendedHeader*)bytes; + + mApplicationId = info->application_id.get(); + mRequiredSystemVersion = info->required_system_version.get(); + mExtendedDataSize = info->extended_data_size.get(); +} + +const fnd::Vec& nn::hac::PatchMetaExtendedHeader::getBytes() const +{ + return mRawBinary; +} + +void nn::hac::PatchMetaExtendedHeader::clear() +{ + mRawBinary.clear(); + mApplicationId = 0; + mRequiredSystemVersion = 0; + mExtendedDataSize = 0; +} + +uint64_t nn::hac::PatchMetaExtendedHeader::getApplicationId() const +{ + return mApplicationId; +} + +void nn::hac::PatchMetaExtendedHeader::setApplicationId(uint64_t application_id) +{ + mApplicationId = application_id; +} + +uint32_t nn::hac::PatchMetaExtendedHeader::getRequiredSystemVersion() const +{ + return mRequiredSystemVersion; +} + +void nn::hac::PatchMetaExtendedHeader::setRequiredSystemVersion(uint32_t sys_ver) +{ + mRequiredSystemVersion = sys_ver; +} + +uint32_t nn::hac::PatchMetaExtendedHeader::getExtendedDataSize() const +{ + return mExtendedDataSize; +} + +void nn::hac::PatchMetaExtendedHeader::setExtendedDataSize(uint32_t size) +{ + mExtendedDataSize = size; +} \ No newline at end of file diff --git a/programs/nstool/source/CnmtProcess.cpp b/programs/nstool/source/CnmtProcess.cpp index 3d9f4a7..54c7777 100644 --- a/programs/nstool/source/CnmtProcess.cpp +++ b/programs/nstool/source/CnmtProcess.cpp @@ -61,31 +61,31 @@ void CnmtProcess::displayCnmt() std::cout << "[ContentMeta]" << std::endl; std::cout << " TitleId: 0x" << std::hex << std::setw(16) << std::setfill('0') << mCnmt.getTitleId() << std::endl; std::cout << " Version: v" << std::dec << mCnmt.getTitleVersion() << " (" << _SPLIT_VER(mCnmt.getTitleVersion()) << ")"<< std::endl; - std::cout << " Type: " << getContentMetaTypeStr(mCnmt.getType()) << " (" << std::dec << mCnmt.getType() << ")" << std::endl; + std::cout << " Type: " << getContentMetaTypeStr(mCnmt.getContentMetaType()) << " (" << std::dec << mCnmt.getContentMetaType() << ")" << std::endl; std::cout << " Attributes: 0x" << std::hex << (uint32_t)mCnmt.getAttributes() << std::endl; std::cout << " IncludesExFatDriver: " << getBoolStr(_HAS_BIT(mCnmt.getAttributes(), nn::hac::cnmt::ATTRIBUTE_INCLUDES_EX_FAT_DRIVER)) << std::endl; std::cout << " Rebootless: " << getBoolStr(_HAS_BIT(mCnmt.getAttributes(), nn::hac::cnmt::ATTRIBUTE_REBOOTLESS)) << std::endl; std::cout << " RequiredDownloadSystemVersion: v" << mCnmt.getRequiredDownloadSystemVersion() << " (" << _SPLIT_VER(mCnmt.getRequiredDownloadSystemVersion()) << ")"<< std::endl; - switch(mCnmt.getType()) + switch(mCnmt.getContentMetaType()) { case (nn::hac::cnmt::METATYPE_APPLICATION): std::cout << " ApplicationExtendedHeader:" << std::endl; - std::cout << " RequiredSystemVersion: v" << std::dec << mCnmt.getApplicationMetaExtendedHeader().required_system_version << " (" << _SPLIT_VER(mCnmt.getApplicationMetaExtendedHeader().required_system_version) << ")"<< std::endl; - std::cout << " PatchId: 0x" << std::hex << std::setw(16) << std::setfill('0') << mCnmt.getApplicationMetaExtendedHeader().patch_id << std::endl; + std::cout << " RequiredSystemVersion: v" << std::dec << mCnmt.getApplicationMetaExtendedHeader().getRequiredSystemVersion() << " (" << _SPLIT_VER(mCnmt.getApplicationMetaExtendedHeader().getRequiredSystemVersion()) << ")"<< std::endl; + std::cout << " PatchId: 0x" << std::hex << std::setw(16) << std::setfill('0') << mCnmt.getApplicationMetaExtendedHeader().getPatchId() << std::endl; break; case (nn::hac::cnmt::METATYPE_PATCH): std::cout << " PatchMetaExtendedHeader:" << std::endl; - std::cout << " RequiredSystemVersion: v" << std::dec << mCnmt.getPatchMetaExtendedHeader().required_system_version << " (" << _SPLIT_VER(mCnmt.getPatchMetaExtendedHeader().required_system_version) << ")"<< std::endl; - std::cout << " ApplicationId: 0x" << std::hex << std::setw(16) << std::setfill('0') << mCnmt.getPatchMetaExtendedHeader().application_id << std::endl; + std::cout << " RequiredSystemVersion: v" << std::dec << mCnmt.getPatchMetaExtendedHeader().getRequiredSystemVersion() << " (" << _SPLIT_VER(mCnmt.getPatchMetaExtendedHeader().getRequiredSystemVersion()) << ")"<< std::endl; + std::cout << " ApplicationId: 0x" << std::hex << std::setw(16) << std::setfill('0') << mCnmt.getPatchMetaExtendedHeader().getApplicationId() << std::endl; break; case (nn::hac::cnmt::METATYPE_ADD_ON_CONTENT): std::cout << " AddOnContentMetaExtendedHeader:" << std::endl; - std::cout << " RequiredApplicationVersion: v" << std::dec << mCnmt.getAddOnContentMetaExtendedHeader().required_application_version << " (" << _SPLIT_VER(mCnmt.getAddOnContentMetaExtendedHeader().required_application_version) << ")" << std::endl; - std::cout << " ApplicationId: 0x" << std::hex << std::setw(16) << std::setfill('0') << mCnmt.getAddOnContentMetaExtendedHeader().application_id << std::endl; + std::cout << " RequiredApplicationVersion: v" << std::dec << mCnmt.getAddOnContentMetaExtendedHeader().getRequiredApplicationVersion() << " (" << _SPLIT_VER(mCnmt.getAddOnContentMetaExtendedHeader().getRequiredApplicationVersion()) << ")" << std::endl; + std::cout << " ApplicationId: 0x" << std::hex << std::setw(16) << std::setfill('0') << mCnmt.getAddOnContentMetaExtendedHeader().getApplicationId() << std::endl; break; case (nn::hac::cnmt::METATYPE_DELTA): std::cout << " DeltaMetaExtendedHeader:" << std::endl; - std::cout << " ApplicationId: 0x" << std::hex << std::setw(16) << std::setfill('0') << mCnmt.getDeltaMetaExtendedHeader().application_id << std::endl; + std::cout << " ApplicationId: 0x" << std::hex << std::setw(16) << std::setfill('0') << mCnmt.getDeltaMetaExtendedHeader().getApplicationId() << std::endl; break; default: break; @@ -111,7 +111,7 @@ void CnmtProcess::displayCnmt() 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.getTitleId() << std::endl; - std::cout << " Version: v" << std::dec << info.getVersion() << " (" << _SPLIT_VER(info.getVersion()) << ")"<< std::endl; + std::cout << " Version: v" << std::dec << info.getTitleVersion() << " (" << _SPLIT_VER(info.getTitleVersion()) << ")"<< 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;