2018-06-10 15:48:04 +00:00
|
|
|
#include <nx/AssetHeader.h>
|
|
|
|
|
|
|
|
nx::AssetHeader::AssetHeader()
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
nx::AssetHeader::AssetHeader(const AssetHeader& other)
|
|
|
|
{
|
2018-06-24 04:52:06 +00:00
|
|
|
*this = other;
|
2018-06-10 15:48:04 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 05:21:52 +00:00
|
|
|
void nx::AssetHeader::operator=(const AssetHeader& other)
|
|
|
|
{
|
|
|
|
mRawBinary = other.mRawBinary;
|
|
|
|
mIconInfo = other.mIconInfo;
|
|
|
|
mNacpInfo = other.mNacpInfo;
|
|
|
|
mRomfsInfo = other.mRomfsInfo;
|
|
|
|
}
|
|
|
|
|
2018-06-10 15:48:04 +00:00
|
|
|
bool nx::AssetHeader::operator==(const AssetHeader& other) const
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool nx::AssetHeader::operator!=(const AssetHeader& other) const
|
|
|
|
{
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
2018-06-24 04:52:06 +00:00
|
|
|
void nx::AssetHeader::toBytes()
|
2018-06-10 15:48:04 +00:00
|
|
|
{
|
2018-06-24 04:52:06 +00:00
|
|
|
mRawBinary.alloc(sizeof(sAssetHeader));
|
|
|
|
nx::sAssetHeader* hdr = (nx::sAssetHeader*)mRawBinary.data();
|
2018-06-10 15:48:04 +00:00
|
|
|
|
|
|
|
// set header identifers
|
|
|
|
hdr->signature = aset::kAssetSig;
|
|
|
|
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-06-24 04:52:06 +00:00
|
|
|
void nx::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-06-24 04:52:06 +00:00
|
|
|
const nx::sAssetHeader* hdr = (const nx::sAssetHeader*)mRawBinary.data();
|
2018-06-10 15:48:04 +00:00
|
|
|
|
|
|
|
// check NRO signature
|
|
|
|
if (hdr->signature.get() != aset::kAssetSig)
|
|
|
|
{
|
|
|
|
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-06-24 04:52:06 +00:00
|
|
|
const fnd::Vec<byte_t>& nx::AssetHeader::getBytes() const
|
|
|
|
{
|
|
|
|
return mRawBinary;
|
|
|
|
}
|
|
|
|
|
2018-06-10 15:48:04 +00:00
|
|
|
void nx::AssetHeader::clear()
|
|
|
|
{
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
const nx::AssetHeader::sSection& nx::AssetHeader::getIconInfo() const
|
|
|
|
{
|
|
|
|
return mIconInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nx::AssetHeader::setIconInfo(const nx::AssetHeader::sSection& info)
|
|
|
|
{
|
|
|
|
mIconInfo = info;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nx::AssetHeader::sSection& nx::AssetHeader::getNacpInfo() const
|
|
|
|
{
|
|
|
|
return mNacpInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nx::AssetHeader::setNacpInfo(const sSection& info)
|
|
|
|
{
|
|
|
|
mNacpInfo = info;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nx::AssetHeader::sSection& nx::AssetHeader::getRomfsInfo() const
|
|
|
|
{
|
|
|
|
return mRomfsInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nx::AssetHeader::setRomfsInfo(const sSection& info)
|
|
|
|
{
|
|
|
|
mRomfsInfo = info;
|
|
|
|
}
|