2018-08-07 07:17:51 +00:00
|
|
|
#include <nn/hac/NroHeader.h>
|
2018-06-09 15:30:08 +00:00
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
nn::hac::NroHeader::NroHeader()
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
nn::hac::NroHeader::NroHeader(const NroHeader& other)
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
*this = other;
|
2018-06-09 15:30:08 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::NroHeader::operator=(const NroHeader& other)
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
clear();
|
|
|
|
mRoCrt = other.mRoCrt;
|
|
|
|
mNroSize = other.mNroSize;
|
|
|
|
mTextInfo = other.mTextInfo;
|
|
|
|
mTextInfo = other.mTextInfo;
|
|
|
|
mRoInfo = other.mRoInfo;
|
|
|
|
mDataInfo = other.mDataInfo;
|
|
|
|
mBssSize = other.mBssSize;
|
|
|
|
mModuleId = other.mModuleId;
|
|
|
|
mRoEmbeddedInfo = other.mRoEmbeddedInfo;
|
|
|
|
mRoDynStrInfo = other.mRoDynStrInfo;
|
|
|
|
mRoDynSymInfo = other.mRoDynSymInfo;
|
2018-06-09 15:30:08 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
bool nn::hac::NroHeader::operator==(const NroHeader& other) const
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
return (mRoCrt == other.mRoCrt) \
|
|
|
|
&& (mNroSize == other.mNroSize) \
|
|
|
|
&& (mTextInfo == other.mTextInfo) \
|
|
|
|
&& (mTextInfo == other.mTextInfo) \
|
|
|
|
&& (mRoInfo == other.mRoInfo) \
|
|
|
|
&& (mDataInfo == other.mDataInfo) \
|
|
|
|
&& (mBssSize == other.mBssSize) \
|
|
|
|
&& (mModuleId == other.mModuleId) \
|
|
|
|
&& (mRoEmbeddedInfo == other.mRoEmbeddedInfo) \
|
|
|
|
&& (mRoDynStrInfo == other.mRoDynStrInfo) \
|
|
|
|
&& (mRoDynSymInfo == other.mRoDynSymInfo);
|
2018-06-09 15:30:08 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
bool nn::hac::NroHeader::operator!=(const NroHeader& other) const
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
2018-06-10 06:53:53 +00:00
|
|
|
return !(*this == other);
|
2018-06-09 15:30:08 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::NroHeader::toBytes()
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
mRawBinary.alloc(sizeof(sNroHeader));
|
2018-08-07 07:17:51 +00:00
|
|
|
nn::hac::sNroHeader* hdr = (nn::hac::sNroHeader*)mRawBinary.data();
|
2018-06-10 06:53:53 +00:00
|
|
|
|
|
|
|
// set header identifers
|
2018-06-26 04:23:40 +00:00
|
|
|
hdr->st_magic = nro::kNroStructMagic;
|
2018-06-10 06:53:53 +00:00
|
|
|
hdr->format_version = nro::kDefaultFormatVersion;
|
|
|
|
hdr->flags = 0;
|
|
|
|
|
|
|
|
// set ro crt
|
|
|
|
memcpy(hdr->ro_crt, mRoCrt.data, nro::kRoCrtSize);
|
|
|
|
|
|
|
|
// set nro size
|
|
|
|
hdr->size = mNroSize;
|
|
|
|
|
|
|
|
// set text section
|
|
|
|
hdr->text.memory_offset = mTextInfo.memory_offset;
|
|
|
|
hdr->text.size = mTextInfo.size;
|
|
|
|
|
|
|
|
// set ro section
|
|
|
|
hdr->ro.memory_offset = mRoInfo.memory_offset;
|
|
|
|
hdr->ro.size = mRoInfo.size;
|
|
|
|
|
|
|
|
// set data section
|
|
|
|
hdr->data.memory_offset = mDataInfo.memory_offset;
|
|
|
|
hdr->data.size = mDataInfo.size;
|
|
|
|
|
|
|
|
// set bss size
|
|
|
|
hdr->bss_size = mBssSize;
|
|
|
|
|
|
|
|
// set moduleid
|
|
|
|
memcpy(hdr->module_id, mModuleId.data, nro::kModuleIdSize);
|
|
|
|
|
|
|
|
// set ro embedded info
|
|
|
|
hdr->embedded.memory_offset = mRoEmbeddedInfo.memory_offset;
|
|
|
|
hdr->embedded.size = mRoEmbeddedInfo.size;
|
|
|
|
|
|
|
|
// set ro dyn str info
|
|
|
|
hdr->dyn_str.memory_offset = mRoDynStrInfo.memory_offset;
|
|
|
|
hdr->dyn_str.size = mRoDynStrInfo.size;
|
|
|
|
|
|
|
|
// set ro dyn sym info
|
|
|
|
hdr->dyn_sym.memory_offset = mRoDynSymInfo.memory_offset;
|
|
|
|
hdr->dyn_sym.size = mRoDynSymInfo.size;
|
2018-06-09 15:30:08 +00:00
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::NroHeader::fromBytes(const byte_t* data, size_t len)
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
// check input data size
|
|
|
|
if (len < sizeof(sNroHeader))
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "NRO header size is too small");
|
|
|
|
}
|
|
|
|
|
|
|
|
// clear internal members
|
|
|
|
clear();
|
|
|
|
|
|
|
|
// allocate internal local binary copy
|
2018-06-24 08:18:54 +00:00
|
|
|
mRawBinary.alloc(sizeof(sNroHeader));
|
|
|
|
memcpy(mRawBinary.data(), data, mRawBinary.size());
|
2018-06-09 15:30:08 +00:00
|
|
|
|
|
|
|
// get sNroHeader ptr
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::sNroHeader* hdr = (const nn::hac::sNroHeader*)mRawBinary.data();
|
2018-06-09 15:30:08 +00:00
|
|
|
|
|
|
|
// check NRO signature
|
2018-06-26 04:23:40 +00:00
|
|
|
if (hdr->st_magic.get() != nro::kNroStructMagic)
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "NRO header corrupt (unrecognised header signature)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// check NRO format version
|
|
|
|
if (hdr->format_version.get() != nro::kDefaultFormatVersion)
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "NRO header corrupt (unsupported format version)");
|
|
|
|
}
|
|
|
|
|
|
|
|
// check NRO flags
|
|
|
|
if (hdr->flags.get() != 0)
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "NRO header corrupt (unsupported flag)");
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(mRoCrt.data, hdr->ro_crt, nro::kRoCrtSize);
|
|
|
|
mNroSize = hdr->size.get();
|
|
|
|
mTextInfo.memory_offset = hdr->text.memory_offset.get();
|
|
|
|
mTextInfo.size = hdr->text.size.get();
|
|
|
|
mRoInfo.memory_offset = hdr->ro.memory_offset.get();
|
|
|
|
mRoInfo.size = hdr->ro.size.get();
|
|
|
|
mDataInfo.memory_offset = hdr->data.memory_offset.get();
|
|
|
|
mDataInfo.size = hdr->data.size.get();
|
|
|
|
mBssSize = hdr->bss_size.get();
|
|
|
|
memcpy(mModuleId.data, hdr->module_id, nro::kModuleIdSize);
|
|
|
|
|
|
|
|
mRoEmbeddedInfo.memory_offset = hdr->embedded.memory_offset.get();
|
|
|
|
mRoEmbeddedInfo.size = hdr->embedded.size.get();
|
|
|
|
|
|
|
|
mRoDynStrInfo.memory_offset = hdr->dyn_str.memory_offset.get();
|
|
|
|
mRoDynStrInfo.size = hdr->dyn_str.size.get();
|
|
|
|
|
|
|
|
mRoDynSymInfo.memory_offset = hdr->dyn_sym.memory_offset.get();
|
|
|
|
mRoDynSymInfo.size = hdr->dyn_sym.size.get();
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const fnd::Vec<byte_t>& nn::hac::NroHeader::getBytes() const
|
2018-06-24 08:18:54 +00:00
|
|
|
{
|
|
|
|
return mRawBinary;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::NroHeader::clear()
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
2018-06-24 08:18:54 +00:00
|
|
|
mRawBinary.clear();
|
2018-06-09 15:30:08 +00:00
|
|
|
memset(&mRoCrt, 0, sizeof(mRoCrt));
|
|
|
|
memset(&mTextInfo, 0, sizeof(mTextInfo));
|
|
|
|
memset(&mRoInfo, 0, sizeof(mRoInfo));
|
|
|
|
memset(&mDataInfo, 0, sizeof(mDataInfo));
|
|
|
|
mBssSize = 0;
|
|
|
|
memset(&mModuleId, 0, sizeof(mModuleId));
|
|
|
|
memset(&mRoEmbeddedInfo, 0, sizeof(mRoEmbeddedInfo));
|
|
|
|
memset(&mRoDynStrInfo, 0, sizeof(mRoDynStrInfo));
|
|
|
|
memset(&mRoDynSymInfo, 0, sizeof(mRoDynSymInfo));
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::NroHeader::sRoCrt& nn::hac::NroHeader::getRoCrt() const
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
return mRoCrt;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::NroHeader::setRoCrt(const sRoCrt& ro_crt)
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
mRoCrt = ro_crt;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
uint32_t nn::hac::NroHeader::getNroSize() const
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
return mNroSize;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::NroHeader::setNroSize(uint32_t size)
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
mNroSize = size;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::NroHeader::sSection& nn::hac::NroHeader::getTextInfo() const
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
return mTextInfo;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::NroHeader::setTextInfo(const sSection& info)
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
mTextInfo = info;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::NroHeader::sSection& nn::hac::NroHeader::getRoInfo() const
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
return mRoInfo;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::NroHeader::setRoInfo(const sSection& info)
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
mRoInfo = info;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::NroHeader::sSection& nn::hac::NroHeader::getDataInfo() const
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
return mDataInfo;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::NroHeader::setDataInfo(const sSection& info)
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
mDataInfo = info;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
uint32_t nn::hac::NroHeader::getBssSize() const
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
return mBssSize;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::NroHeader::setBssSize(uint32_t size)
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
mBssSize = size;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::NroHeader::sModuleId& nn::hac::NroHeader::getModuleId() const
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
return mModuleId;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::NroHeader::setModuleId(const sModuleId& id)
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
mModuleId = id;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::NroHeader::sSection& nn::hac::NroHeader::getRoEmbeddedInfo() const
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
return mRoEmbeddedInfo;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::NroHeader::setRoEmbeddedInfo(const sSection& info)
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
mRoEmbeddedInfo = info;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::NroHeader::sSection& nn::hac::NroHeader::getRoDynStrInfo() const
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
return mRoDynStrInfo;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::NroHeader::setRoDynStrInfo(const sSection& info)
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
mRoDynStrInfo = info;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const nn::hac::NroHeader::sSection& nn::hac::NroHeader::getRoDynSymInfo() const
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
return mRoDynSymInfo;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::NroHeader::setRoDynSymInfo(const sSection& info)
|
2018-06-09 15:30:08 +00:00
|
|
|
{
|
|
|
|
mRoDynSymInfo = info;
|
|
|
|
}
|