2018-08-07 07:17:51 +00:00
|
|
|
#include <nn/hac/ContentMetaBinary.h>
|
2018-05-12 09:36:50 +00:00
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
nn::hac::ContentMetaBinary::ContentMetaBinary()
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
nn::hac::ContentMetaBinary::ContentMetaBinary(const ContentMetaBinary & other)
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
2018-06-24 15:01:16 +00:00
|
|
|
*this = other;
|
2018-05-12 09:36:50 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::ContentMetaBinary::operator=(const ContentMetaBinary& other)
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
2018-06-24 15:01:16 +00:00
|
|
|
if (other.getBytes().size() > 0)
|
|
|
|
{
|
|
|
|
fromBytes(other.getBytes().data(), other.getBytes().size());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
mTitleId = other.mTitleId;
|
|
|
|
mTitleVersion = other.mTitleVersion;
|
|
|
|
mType = other.mType;
|
|
|
|
mAttributes = other.mAttributes;
|
|
|
|
mRequiredDownloadSystemVersion = other.mRequiredDownloadSystemVersion;
|
|
|
|
mExtendedHeader = other.mExtendedHeader;
|
|
|
|
mApplicationMetaExtendedHeader = other.mApplicationMetaExtendedHeader;
|
|
|
|
mPatchMetaExtendedHeader = other.mPatchMetaExtendedHeader;
|
|
|
|
mAddOnContentMetaExtendedHeader = other.mAddOnContentMetaExtendedHeader;
|
|
|
|
mDeltaMetaExtendedHeader = other.mDeltaMetaExtendedHeader;
|
|
|
|
mContentInfo = other.mContentInfo;
|
|
|
|
mContentMetaInfo = other.mContentMetaInfo;
|
|
|
|
mExtendedData = other.mExtendedData;
|
|
|
|
memcpy(mDigest.data, other.mDigest.data, cnmt::kDigestLen);
|
|
|
|
}
|
2018-05-12 09:36:50 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
bool nn::hac::ContentMetaBinary::operator==(const ContentMetaBinary& other) const
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
2018-06-24 15:01:16 +00:00
|
|
|
return (mTitleId == other.mTitleId) \
|
|
|
|
&& (mTitleVersion == other.mTitleVersion) \
|
|
|
|
&& (mType == other.mType) \
|
|
|
|
&& (mAttributes == other.mAttributes) \
|
|
|
|
&& (mRequiredDownloadSystemVersion == other.mRequiredDownloadSystemVersion) \
|
|
|
|
&& (mExtendedHeader == other.mExtendedHeader) \
|
|
|
|
&& (mApplicationMetaExtendedHeader == other.mApplicationMetaExtendedHeader) \
|
|
|
|
&& (mPatchMetaExtendedHeader == other.mPatchMetaExtendedHeader) \
|
|
|
|
&& (mAddOnContentMetaExtendedHeader == other.mAddOnContentMetaExtendedHeader) \
|
|
|
|
&& (mDeltaMetaExtendedHeader == other.mDeltaMetaExtendedHeader) \
|
|
|
|
&& (mContentInfo == other.mContentInfo) \
|
|
|
|
&& (mContentMetaInfo == other.mContentMetaInfo) \
|
|
|
|
&& (mExtendedData == other.mExtendedData) \
|
|
|
|
&& (memcmp(mDigest.data, other.mDigest.data, cnmt::kDigestLen) == 0);
|
2018-05-12 09:36:50 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
bool nn::hac::ContentMetaBinary::operator!=(const ContentMetaBinary& other) const
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
2018-06-24 15:01:16 +00:00
|
|
|
return !(*this == other);
|
2018-05-12 09:36:50 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::ContentMetaBinary::toBytes()
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "exportBinary() not implemented");
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::ContentMetaBinary::fromBytes(const byte_t* data, size_t len)
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
// clear member variables
|
|
|
|
clear();
|
|
|
|
|
|
|
|
// validate layout
|
2018-06-24 15:01:16 +00:00
|
|
|
validateBinary(data, len);
|
2018-05-12 09:36:50 +00:00
|
|
|
|
|
|
|
// get pointer to header structure
|
2018-06-24 15:01:16 +00:00
|
|
|
const sContentMetaHeader* hdr = (const sContentMetaHeader*)data;
|
2018-05-12 09:36:50 +00:00
|
|
|
|
|
|
|
mTitleId = hdr->id.get();
|
|
|
|
mTitleVersion = hdr->version.get();
|
2018-05-12 15:02:53 +00:00
|
|
|
mType = (cnmt::ContentMetaType)hdr->type;
|
2018-05-12 09:36:50 +00:00
|
|
|
mAttributes = hdr->attributes;
|
2018-05-12 15:02:53 +00:00
|
|
|
mRequiredDownloadSystemVersion = hdr->required_download_system_version.get();
|
2018-05-12 09:36:50 +00:00
|
|
|
size_t exdata_size = 0;
|
|
|
|
|
|
|
|
// save exheader
|
|
|
|
if (hdr->exhdr_size.get() > 0)
|
|
|
|
{
|
|
|
|
mExtendedHeader.alloc(hdr->exhdr_size.get());
|
2018-06-24 15:01:16 +00:00
|
|
|
memcpy(mExtendedHeader.data(), data + getExtendedHeaderOffset(), hdr->exhdr_size.get());
|
2018-05-12 09:36:50 +00:00
|
|
|
|
2018-05-12 15:02:53 +00:00
|
|
|
switch (mType)
|
|
|
|
{
|
|
|
|
case (cnmt::METATYPE_APPLICATION):
|
2018-06-24 15:01:16 +00:00
|
|
|
mApplicationMetaExtendedHeader.patch_id = ((sApplicationMetaExtendedHeader*)mExtendedHeader.data())->patch_id.get();
|
|
|
|
mApplicationMetaExtendedHeader.required_system_version = ((sApplicationMetaExtendedHeader*)mExtendedHeader.data())->required_system_version.get();
|
2018-05-12 15:02:53 +00:00
|
|
|
break;
|
|
|
|
case (cnmt::METATYPE_PATCH):
|
2018-06-24 15:01:16 +00:00
|
|
|
mPatchMetaExtendedHeader.application_id = ((sPatchMetaExtendedHeader*)mExtendedHeader.data())->application_id.get();
|
|
|
|
mPatchMetaExtendedHeader.required_system_version = ((sPatchMetaExtendedHeader*)mExtendedHeader.data())->required_system_version.get();
|
2018-05-12 15:02:53 +00:00
|
|
|
break;
|
|
|
|
case (cnmt::METATYPE_ADD_ON_CONTENT):
|
2018-06-24 15:01:16 +00:00
|
|
|
mAddOnContentMetaExtendedHeader.application_id = ((sAddOnContentMetaExtendedHeader*)mExtendedHeader.data())->application_id.get();
|
2018-09-10 08:52:23 +00:00
|
|
|
mAddOnContentMetaExtendedHeader.required_application_version = ((sAddOnContentMetaExtendedHeader*)mExtendedHeader.data())->required_application_version.get();
|
2018-05-12 15:02:53 +00:00
|
|
|
break;
|
|
|
|
case (cnmt::METATYPE_DELTA):
|
2018-06-24 15:01:16 +00:00
|
|
|
mDeltaMetaExtendedHeader.application_id = ((sDeltaMetaExtendedHeader*)mExtendedHeader.data())->application_id.get();
|
2018-05-12 15:02:53 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-06-24 15:01:16 +00:00
|
|
|
exdata_size = getExtendedDataSize(mType, mExtendedHeader.data());
|
2018-05-12 09:36:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// save content info
|
|
|
|
if (hdr->content_count.get() > 0)
|
|
|
|
{
|
2018-06-24 15:01:16 +00:00
|
|
|
const sContentInfo* info = (const sContentInfo*)(data + getContentInfoOffset(hdr->exhdr_size.get()));
|
2018-06-29 06:59:48 +00:00
|
|
|
ContentInfo cinfo;
|
2018-05-12 09:36:50 +00:00
|
|
|
for (size_t i = 0; i < hdr->content_count.get(); i++)
|
|
|
|
{
|
2018-06-29 06:59:48 +00:00
|
|
|
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;
|
|
|
|
mContentInfo.addElement(cinfo);
|
2018-05-12 09:36:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// save content meta info
|
|
|
|
if (hdr->content_meta_count.get() > 0)
|
|
|
|
{
|
2018-06-24 15:01:16 +00:00
|
|
|
const sContentMetaInfo* info = (const sContentMetaInfo*)(data + getContentMetaInfoOffset(hdr->exhdr_size.get(), hdr->content_count.get()));
|
2018-06-29 06:59:48 +00:00
|
|
|
ContentMetaInfo cmeta;
|
2018-05-12 09:36:50 +00:00
|
|
|
for (size_t i = 0; i < hdr->content_meta_count.get(); i++)
|
2018-06-29 06:59:48 +00:00
|
|
|
{
|
|
|
|
cmeta.id = info[i].id.get();
|
|
|
|
cmeta.version = info[i].version.get();
|
|
|
|
cmeta.type = (cnmt::ContentMetaType)info[i].type;
|
|
|
|
cmeta.attributes = info[i].attributes;
|
|
|
|
mContentMetaInfo.addElement(cmeta);
|
2018-05-12 09:36:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// save exdata
|
|
|
|
if (exdata_size > 0)
|
|
|
|
{
|
|
|
|
mExtendedData.alloc(exdata_size);
|
2018-06-24 15:01:16 +00:00
|
|
|
memcpy(mExtendedData.data(), data + getExtendedDataOffset(hdr->exhdr_size.get(), hdr->content_count.get(), hdr->content_meta_count.get()), exdata_size);
|
2018-05-12 09:36:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// save digest
|
2018-06-24 15:01:16 +00:00
|
|
|
memcpy(mDigest.data, data + getDigestOffset(hdr->exhdr_size.get(), hdr->content_count.get(), hdr->content_meta_count.get(), exdata_size), cnmt::kDigestLen);
|
2018-05-12 09:36:50 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const fnd::Vec<byte_t>& nn::hac::ContentMetaBinary::getBytes() const
|
2018-06-24 15:01:16 +00:00
|
|
|
{
|
|
|
|
return mRawBinary;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::ContentMetaBinary::clear()
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
mRawBinary.clear();
|
2018-05-12 09:36:50 +00:00
|
|
|
mTitleId = 0;
|
|
|
|
mTitleVersion = 0;
|
2018-05-12 15:02:53 +00:00
|
|
|
mType = cnmt::METATYPE_SYSTEM_PROGRAM;
|
|
|
|
mAttributes = 0;
|
|
|
|
mRequiredDownloadSystemVersion = 0;
|
2018-05-12 09:36:50 +00:00
|
|
|
mExtendedHeader.clear();
|
2018-05-12 15:02:53 +00:00
|
|
|
memset(&mApplicationMetaExtendedHeader, 0, sizeof(mApplicationMetaExtendedHeader));
|
|
|
|
memset(&mPatchMetaExtendedHeader, 0, sizeof(mPatchMetaExtendedHeader));
|
|
|
|
memset(&mAddOnContentMetaExtendedHeader, 0, sizeof(mAddOnContentMetaExtendedHeader));
|
|
|
|
memset(&mDeltaMetaExtendedHeader, 0, sizeof(mDeltaMetaExtendedHeader));
|
2018-05-12 09:36:50 +00:00
|
|
|
mContentInfo.clear();
|
|
|
|
mContentMetaInfo.clear();
|
|
|
|
mExtendedData.clear();
|
2018-05-12 15:02:53 +00:00
|
|
|
memset(mDigest.data, 0, cnmt::kDigestLen);
|
2018-05-12 09:36:50 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
uint64_t nn::hac::ContentMetaBinary::getTitleId() const
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
return mTitleId;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::ContentMetaBinary::setTitleId(uint64_t title_id)
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
mTitleId = title_id;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
uint32_t nn::hac::ContentMetaBinary::getTitleVersion() const
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
return mTitleVersion;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::ContentMetaBinary::setTitleVersion(uint32_t version)
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
mTitleVersion = version;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
nn::hac::cnmt::ContentMetaType nn::hac::ContentMetaBinary::getType() const
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
return mType;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::ContentMetaBinary::setType(cnmt::ContentMetaType type)
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
mType = type;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
byte_t nn::hac::ContentMetaBinary::getAttributes() const
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
return mAttributes;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::ContentMetaBinary::setAttributes(byte_t attributes)
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
mAttributes = attributes;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
uint32_t nn::hac::ContentMetaBinary::getRequiredDownloadSystemVersion() const
|
2018-05-12 15:02:53 +00:00
|
|
|
{
|
|
|
|
return mRequiredDownloadSystemVersion;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::ContentMetaBinary::setRequiredDownloadSystemVersion(uint32_t version)
|
2018-05-12 15:02:53 +00:00
|
|
|
{
|
|
|
|
mRequiredDownloadSystemVersion = version;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::ContentMetaBinary::ApplicationMetaExtendedHeader& nn::hac::ContentMetaBinary::getApplicationMetaExtendedHeader() const
|
2018-05-12 15:02:53 +00:00
|
|
|
{
|
|
|
|
return mApplicationMetaExtendedHeader;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::ContentMetaBinary::setApplicationMetaExtendedHeader(const ApplicationMetaExtendedHeader& exhdr)
|
2018-05-12 15:02:53 +00:00
|
|
|
{
|
|
|
|
mApplicationMetaExtendedHeader = exhdr;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::ContentMetaBinary::PatchMetaExtendedHeader& nn::hac::ContentMetaBinary::getPatchMetaExtendedHeader() const
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
2018-05-12 15:02:53 +00:00
|
|
|
return mPatchMetaExtendedHeader;
|
2018-05-12 09:36:50 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::ContentMetaBinary::setPatchMetaExtendedHeader(const PatchMetaExtendedHeader& exhdr)
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
2018-05-12 15:02:53 +00:00
|
|
|
mPatchMetaExtendedHeader = exhdr;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::ContentMetaBinary::AddOnContentMetaExtendedHeader& nn::hac::ContentMetaBinary::getAddOnContentMetaExtendedHeader() const
|
2018-05-12 15:02:53 +00:00
|
|
|
{
|
|
|
|
return mAddOnContentMetaExtendedHeader;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::ContentMetaBinary::setAddOnContentMetaExtendedHeader(const AddOnContentMetaExtendedHeader& exhdr)
|
2018-05-12 15:02:53 +00:00
|
|
|
{
|
|
|
|
mAddOnContentMetaExtendedHeader = exhdr;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::ContentMetaBinary::DeltaMetaExtendedHeader& nn::hac::ContentMetaBinary::getDeltaMetaExtendedHeader() const
|
2018-05-12 15:02:53 +00:00
|
|
|
{
|
|
|
|
return mDeltaMetaExtendedHeader;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::ContentMetaBinary::setDeltaMetaExtendedHeader(const DeltaMetaExtendedHeader& exhdr)
|
2018-05-12 15:02:53 +00:00
|
|
|
{
|
|
|
|
mDeltaMetaExtendedHeader = exhdr;
|
2018-05-12 09:36:50 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const fnd::List<nn::hac::ContentMetaBinary::ContentInfo>& nn::hac::ContentMetaBinary::getContentInfo() const
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
return mContentInfo;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::ContentMetaBinary::setContentInfo(const fnd::List<nn::hac::ContentMetaBinary::ContentInfo>& info)
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
mContentInfo = info;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const fnd::List<nn::hac::ContentMetaBinary::ContentMetaInfo>& nn::hac::ContentMetaBinary::getContentMetaInfo() const
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
return mContentMetaInfo;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::ContentMetaBinary::setContentMetaInfo(const fnd::List<nn::hac::ContentMetaBinary::ContentMetaInfo>& info)
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
mContentMetaInfo = info;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const fnd::Vec<byte_t> & nn::hac::ContentMetaBinary::getExtendedData() const
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
return mExtendedData;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::ContentMetaBinary::setExtendedData(const fnd::Vec<byte_t> & data)
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
mExtendedData = data;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::sDigest & nn::hac::ContentMetaBinary::getDigest() const
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
return mDigest;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::ContentMetaBinary::setDigest(const nn::hac::sDigest & digest)
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
|
2018-05-12 15:02:53 +00:00
|
|
|
memcpy(mDigest.data, digest.data, cnmt::kDigestLen);
|
2018-05-12 09:36:50 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
bool nn::hac::ContentMetaBinary::validateExtendedHeaderSize(cnmt::ContentMetaType type, size_t exhdrSize) const
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
bool validSize = false;
|
|
|
|
|
2018-05-12 15:02:53 +00:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case (cnmt::METATYPE_APPLICATION):
|
|
|
|
validSize = (exhdrSize == sizeof(sApplicationMetaExtendedHeader));
|
|
|
|
break;
|
|
|
|
case (cnmt::METATYPE_PATCH):
|
|
|
|
validSize = (exhdrSize == sizeof(sPatchMetaExtendedHeader));
|
|
|
|
break;
|
|
|
|
case (cnmt::METATYPE_ADD_ON_CONTENT):
|
|
|
|
validSize = (exhdrSize == sizeof(sAddOnContentMetaExtendedHeader));
|
|
|
|
break;
|
|
|
|
case (cnmt::METATYPE_DELTA):
|
|
|
|
validSize = (exhdrSize == sizeof(sDeltaMetaExtendedHeader));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
validSize = (exhdrSize == 0);
|
|
|
|
}
|
2018-05-12 09:36:50 +00:00
|
|
|
|
|
|
|
return validSize;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
size_t nn::hac::ContentMetaBinary::getExtendedDataSize(cnmt::ContentMetaType type, const byte_t * data) const
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
size_t exdata_len = 0;
|
2018-05-12 15:02:53 +00:00
|
|
|
if (type == cnmt::METATYPE_PATCH)
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
const sPatchMetaExtendedHeader* exhdr = (const sPatchMetaExtendedHeader*)(data);
|
|
|
|
exdata_len = exhdr->extended_data_size.get();
|
|
|
|
}
|
2018-05-12 15:02:53 +00:00
|
|
|
else if (type == cnmt::METATYPE_DELTA)
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
const sDeltaMetaExtendedHeader* exhdr = (const sDeltaMetaExtendedHeader*)(data);
|
|
|
|
exdata_len = exhdr->extended_data_size.get();
|
|
|
|
}
|
|
|
|
return exdata_len;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::ContentMetaBinary::validateBinary(const byte_t * data, size_t len) const
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
// check if it is large enough to read the header
|
|
|
|
if (len < sizeof(sContentMetaHeader))
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "Binary too small");
|
|
|
|
}
|
|
|
|
|
|
|
|
// get pointer to header structure
|
2018-06-24 15:01:16 +00:00
|
|
|
const sContentMetaHeader* hdr = (const sContentMetaHeader*)data;
|
2018-05-12 09:36:50 +00:00
|
|
|
|
|
|
|
// validate extended header size
|
2018-05-12 15:02:53 +00:00
|
|
|
if (validateExtendedHeaderSize((cnmt::ContentMetaType)hdr->type, hdr->exhdr_size.get()) == false)
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "Invalid extended header size");
|
|
|
|
}
|
|
|
|
|
|
|
|
// check binary size again for new minimum size
|
|
|
|
if (len < getTotalSize(hdr->exhdr_size.get(), hdr->content_count.get(), hdr->content_meta_count.get(), 0))
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "Binary too small");
|
|
|
|
}
|
|
|
|
|
|
|
|
// check binary size again with extended data size
|
2018-06-24 15:01:16 +00:00
|
|
|
if (len < getTotalSize(hdr->exhdr_size.get(), hdr->content_count.get(), hdr->content_meta_count.get(), getExtendedDataSize((cnmt::ContentMetaType)hdr->type, data + getExtendedHeaderOffset())))
|
2018-05-12 09:36:50 +00:00
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "Binary too small");
|
|
|
|
}
|
2018-06-24 15:01:16 +00:00
|
|
|
}
|