2018-08-07 09:31:06 +00:00
|
|
|
#include <cstring>
|
2018-08-07 07:17:51 +00:00
|
|
|
#include <nn/hac/AssetHeader.h>
|
2018-06-10 15:48:04 +00:00
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
nn::hac::AssetHeader::AssetHeader()
|
2018-06-10 15:48:04 +00:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
nn::hac::AssetHeader::AssetHeader(const AssetHeader& other)
|
2018-06-10 15:48:04 +00:00
|
|
|
{
|
2018-06-24 04:52:06 +00:00
|
|
|
*this = other;
|
2018-06-10 15:48:04 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::AssetHeader::operator=(const AssetHeader& other)
|
2018-06-24 05:21:52 +00:00
|
|
|
{
|
|
|
|
mRawBinary = other.mRawBinary;
|
|
|
|
mIconInfo = other.mIconInfo;
|
|
|
|
mNacpInfo = other.mNacpInfo;
|
|
|
|
mRomfsInfo = other.mRomfsInfo;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
bool nn::hac::AssetHeader::operator==(const AssetHeader& other) const
|
2018-06-10 15:48:04 +00:00
|
|
|
{
|
2018-06-24 04:52:06 +00:00
|
|
|
return (mIconInfo == other.mIconInfo) \
|
|
|
|
&& (mNacpInfo == other.mNacpInfo) \
|
|
|
|
&& (mRomfsInfo == other.mRomfsInfo);
|
2018-06-10 15:48:04 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
bool nn::hac::AssetHeader::operator!=(const AssetHeader& other) const
|
2018-06-10 15:48:04 +00:00
|
|
|
{
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::AssetHeader::toBytes()
|
2018-06-10 15:48:04 +00:00
|
|
|
{
|
2018-06-24 04:52:06 +00:00
|
|
|
mRawBinary.alloc(sizeof(sAssetHeader));
|
2018-08-07 07:17:51 +00:00
|
|
|
nn::hac::sAssetHeader* hdr = (nn::hac::sAssetHeader*)mRawBinary.data();
|
2018-06-10 15:48:04 +00:00
|
|
|
|
|
|
|
// set header identifers
|
2018-06-26 04:23:40 +00:00
|
|
|
hdr->st_magic = aset::kAssetStructMagic;
|
2018-06-10 15:48:04 +00:00
|
|
|
hdr->format_version = aset::kDefaultAssetFormatVersion;
|
|
|
|
|
|
|
|
// set icon section
|
|
|
|
hdr->icon.offset = mIconInfo.offset;
|
|
|
|
hdr->icon.size = mIconInfo.size;
|
|
|
|
|
|
|
|
// set nacp section
|
|
|
|
hdr->nacp.offset = mNacpInfo.offset;
|
|
|
|
hdr->nacp.size = mNacpInfo.size;
|
|
|
|
|
|
|
|
// set romfs section
|
|
|
|
hdr->romfs.offset = mRomfsInfo.offset;
|
|
|
|
hdr->romfs.size = mRomfsInfo.size;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::AssetHeader::fromBytes(const byte_t* bytes, size_t len)
|
2018-06-10 15:48:04 +00:00
|
|
|
{
|
|
|
|
// check input data size
|
|
|
|
if (len < sizeof(sAssetHeader))
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "ASET header size is too small");
|
|
|
|
}
|
|
|
|
|
|
|
|
// clear internal members
|
|
|
|
clear();
|
|
|
|
|
|
|
|
// allocate internal local binary copy
|
2018-06-24 04:52:06 +00:00
|
|
|
mRawBinary.alloc(sizeof(sAssetHeader));
|
|
|
|
memcpy(mRawBinary.data(), bytes, mRawBinary.size());
|
2018-06-10 15:48:04 +00:00
|
|
|
|
|
|
|
// get sAssetHeader ptr
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::sAssetHeader* hdr = (const nn::hac::sAssetHeader*)mRawBinary.data();
|
2018-06-10 15:48:04 +00:00
|
|
|
|
|
|
|
// check NRO signature
|
2018-06-26 04:23:40 +00:00
|
|
|
if (hdr->st_magic.get() != aset::kAssetStructMagic)
|
2018-06-10 15:48:04 +00:00
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "ASET header corrupt (unrecognised header signature)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// check NRO format version
|
|
|
|
if (hdr->format_version.get() != aset::kDefaultAssetFormatVersion)
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "ASET header corrupt (unsupported format version)");
|
|
|
|
}
|
|
|
|
|
|
|
|
mIconInfo.offset = hdr->icon.offset.get();
|
|
|
|
mIconInfo.size = hdr->icon.size.get();
|
|
|
|
mNacpInfo.offset = hdr->nacp.offset.get();
|
|
|
|
mNacpInfo.size = hdr->nacp.size.get();
|
|
|
|
mRomfsInfo.offset = hdr->romfs.offset.get();
|
|
|
|
mRomfsInfo.size = hdr->romfs.size.get();
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const fnd::Vec<byte_t>& nn::hac::AssetHeader::getBytes() const
|
2018-06-24 04:52:06 +00:00
|
|
|
{
|
|
|
|
return mRawBinary;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::AssetHeader::clear()
|
2018-06-10 15:48:04 +00:00
|
|
|
{
|
2018-06-24 04:52:06 +00:00
|
|
|
mRawBinary.clear();
|
2018-06-10 15:48:04 +00:00
|
|
|
memset(&mIconInfo, 0, sizeof(mIconInfo));
|
|
|
|
memset(&mNacpInfo, 0, sizeof(mNacpInfo));
|
|
|
|
memset(&mRomfsInfo, 0, sizeof(mRomfsInfo));
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::AssetHeader::sSection& nn::hac::AssetHeader::getIconInfo() const
|
2018-06-10 15:48:04 +00:00
|
|
|
{
|
|
|
|
return mIconInfo;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::AssetHeader::setIconInfo(const nn::hac::AssetHeader::sSection& info)
|
2018-06-10 15:48:04 +00:00
|
|
|
{
|
|
|
|
mIconInfo = info;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::AssetHeader::sSection& nn::hac::AssetHeader::getNacpInfo() const
|
2018-06-10 15:48:04 +00:00
|
|
|
{
|
|
|
|
return mNacpInfo;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::AssetHeader::setNacpInfo(const sSection& info)
|
2018-06-10 15:48:04 +00:00
|
|
|
{
|
|
|
|
mNacpInfo = info;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::AssetHeader::sSection& nn::hac::AssetHeader::getRomfsInfo() const
|
2018-06-10 15:48:04 +00:00
|
|
|
{
|
|
|
|
return mRomfsInfo;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::AssetHeader::setRomfsInfo(const sSection& info)
|
2018-06-10 15:48:04 +00:00
|
|
|
{
|
|
|
|
mRomfsInfo = info;
|
|
|
|
}
|