From 23bda04f35058757114992ae227e150a30ba1dba Mon Sep 17 00:00:00 2001 From: jakcron Date: Sun, 24 Jun 2018 12:52:06 +0800 Subject: [PATCH] [nx-hb] Update to libfnd redesign. --- lib/libnx-hb/include/nx/AssetHeader.h | 38 +++-------------- lib/libnx-hb/source/AssetHeader.cpp | 61 +++++++++------------------ 2 files changed, 27 insertions(+), 72 deletions(-) diff --git a/lib/libnx-hb/include/nx/AssetHeader.h b/lib/libnx-hb/include/nx/AssetHeader.h index 17da642..5deb472 100644 --- a/lib/libnx-hb/include/nx/AssetHeader.h +++ b/lib/libnx-hb/include/nx/AssetHeader.h @@ -1,53 +1,31 @@ #pragma once #include -#include #include -#include +#include namespace nx { class AssetHeader : - public fnd::ISerialiseableBinary + public fnd::ISerialisable { public: struct sSection { uint64_t offset; uint64_t size; - - void operator=(const sSection& other) - { - offset = other.offset; - size = other.size; - } - - bool operator==(const sSection& other) const - { - return (offset == other.offset) \ - && (size == other.size); - } - - bool operator!=(const sSection& other) const - { - return !(*this == other); - } }; AssetHeader(); AssetHeader(const AssetHeader& other); - AssetHeader(const byte_t* bytes, size_t len); bool operator==(const AssetHeader& other) const; bool operator!=(const AssetHeader& other) const; void operator=(const AssetHeader& other); - // to be used after export - const byte_t* getBytes() const; - size_t getSize() const; - // export/import binary - void exportBinary(); - void importBinary(const byte_t* bytes, size_t len); + void toBytes(); + void fromBytes(const byte_t* bytes, size_t len); + const fnd::Vec& getBytes() const; // variables void clear(); @@ -64,16 +42,12 @@ namespace nx const std::string kModuleName = "NRO_ASSET_HEADER"; // binary - fnd::MemoryBlob mBinaryBlob; + fnd::Vec mRawBinary; // data sSection mIconInfo; sSection mNacpInfo; sSection mRomfsInfo; - - // helpers - bool isEqual(const AssetHeader& other) const; - void copyFrom(const AssetHeader& other); }; } \ No newline at end of file diff --git a/lib/libnx-hb/source/AssetHeader.cpp b/lib/libnx-hb/source/AssetHeader.cpp index 3d61036..7ddb714 100644 --- a/lib/libnx-hb/source/AssetHeader.cpp +++ b/lib/libnx-hb/source/AssetHeader.cpp @@ -7,17 +7,14 @@ nx::AssetHeader::AssetHeader() nx::AssetHeader::AssetHeader(const AssetHeader& other) { - copyFrom(other); -} - -nx::AssetHeader::AssetHeader(const byte_t* bytes, size_t len) -{ - importBinary(bytes, len); + *this = other; } bool nx::AssetHeader::operator==(const AssetHeader& other) const { - return isEqual(other); + return (mIconInfo == other.mIconInfo) \ + && (mNacpInfo == other.mNacpInfo) \ + && (mRomfsInfo == other.mRomfsInfo); } bool nx::AssetHeader::operator!=(const AssetHeader& other) const @@ -27,23 +24,16 @@ bool nx::AssetHeader::operator!=(const AssetHeader& other) const void nx::AssetHeader::operator=(const AssetHeader& other) { - copyFrom(other); + mRawBinary = other.mRawBinary; + mIconInfo = other.mIconInfo; + mNacpInfo = other.mNacpInfo; + mRomfsInfo = other.mRomfsInfo; } -const byte_t* nx::AssetHeader::getBytes() const +void nx::AssetHeader::toBytes() { - return mBinaryBlob.getBytes(); -} - -size_t nx::AssetHeader::getSize() const -{ - return mBinaryBlob.getSize(); -} - -void nx::AssetHeader::exportBinary() -{ - mBinaryBlob.alloc(sizeof(sAssetHeader)); - nx::sAssetHeader* hdr = (nx::sAssetHeader*)mBinaryBlob.getBytes(); + mRawBinary.alloc(sizeof(sAssetHeader)); + nx::sAssetHeader* hdr = (nx::sAssetHeader*)mRawBinary.data(); // set header identifers hdr->signature = aset::kAssetSig; @@ -62,7 +52,7 @@ void nx::AssetHeader::exportBinary() hdr->romfs.size = mRomfsInfo.size; } -void nx::AssetHeader::importBinary(const byte_t* bytes, size_t len) +void nx::AssetHeader::fromBytes(const byte_t* bytes, size_t len) { // check input data size if (len < sizeof(sAssetHeader)) @@ -74,11 +64,11 @@ void nx::AssetHeader::importBinary(const byte_t* bytes, size_t len) clear(); // allocate internal local binary copy - mBinaryBlob.alloc(sizeof(sAssetHeader)); - memcpy(mBinaryBlob.getBytes(), bytes, mBinaryBlob.getSize()); + mRawBinary.alloc(sizeof(sAssetHeader)); + memcpy(mRawBinary.data(), bytes, mRawBinary.size()); // get sAssetHeader ptr - const nx::sAssetHeader* hdr = (const nx::sAssetHeader*)mBinaryBlob.getBytes(); + const nx::sAssetHeader* hdr = (const nx::sAssetHeader*)mRawBinary.data(); // check NRO signature if (hdr->signature.get() != aset::kAssetSig) @@ -100,9 +90,14 @@ void nx::AssetHeader::importBinary(const byte_t* bytes, size_t len) mRomfsInfo.size = hdr->romfs.size.get(); } +const fnd::Vec& nx::AssetHeader::getBytes() const +{ + return mRawBinary; +} + void nx::AssetHeader::clear() { - mBinaryBlob.clear(); + mRawBinary.clear(); memset(&mIconInfo, 0, sizeof(mIconInfo)); memset(&mNacpInfo, 0, sizeof(mNacpInfo)); memset(&mRomfsInfo, 0, sizeof(mRomfsInfo)); @@ -136,18 +131,4 @@ const nx::AssetHeader::sSection& nx::AssetHeader::getRomfsInfo() const void nx::AssetHeader::setRomfsInfo(const sSection& info) { mRomfsInfo = info; -} - -bool nx::AssetHeader::isEqual(const AssetHeader& other) const -{ - return (mIconInfo == other.mIconInfo) \ - && (mNacpInfo == other.mNacpInfo) \ - && (mRomfsInfo == other.mRomfsInfo); -} - -void nx::AssetHeader::copyFrom(const AssetHeader& other) -{ - mIconInfo = other.mIconInfo; - mNacpInfo = other.mNacpInfo; - mRomfsInfo = other.mRomfsInfo; } \ No newline at end of file