mirror of
https://github.com/jakcron/nstool
synced 2024-11-22 21:49:30 +00:00
[nx] Add AciBinary.
This commit is contained in:
parent
20b4984ae3
commit
5af8ec72ae
4 changed files with 224 additions and 0 deletions
156
lib/nx/AciBinary.cpp
Normal file
156
lib/nx/AciBinary.cpp
Normal file
|
@ -0,0 +1,156 @@
|
|||
#include "AciBinary.h"
|
||||
|
||||
|
||||
|
||||
nx::AciBinary::AciBinary()
|
||||
{}
|
||||
|
||||
nx::AciBinary::AciBinary(const AciBinary & other)
|
||||
{
|
||||
copyFrom(other);
|
||||
}
|
||||
|
||||
nx::AciBinary::AciBinary(const u8 * bytes, size_t len)
|
||||
{
|
||||
importBinary(bytes, len);
|
||||
}
|
||||
|
||||
bool nx::AciBinary::operator==(const AciBinary & other) const
|
||||
{
|
||||
return isEqual(other);
|
||||
}
|
||||
|
||||
bool nx::AciBinary::operator!=(const AciBinary & other) const
|
||||
{
|
||||
return !isEqual(other);
|
||||
}
|
||||
|
||||
void nx::AciBinary::operator=(const AciBinary & other)
|
||||
{
|
||||
copyFrom(other);
|
||||
}
|
||||
|
||||
const u8 * nx::AciBinary::getBytes() const
|
||||
{
|
||||
return mBinaryBlob.getBytes();
|
||||
}
|
||||
|
||||
size_t nx::AciBinary::getSize() const
|
||||
{
|
||||
return mBinaryBlob.getSize();
|
||||
}
|
||||
|
||||
void nx::AciBinary::exportBinary()
|
||||
{
|
||||
// export components
|
||||
mFac.exportBinary();
|
||||
mSac.exportBinary();
|
||||
mKc.exportBinary();
|
||||
|
||||
// set sizes
|
||||
setFacSize(mFac.getSize());
|
||||
setSacSize(mSac.getSize());
|
||||
setKcSize(mKc.getSize());
|
||||
|
||||
// export header
|
||||
AciHeader::exportBinary();
|
||||
|
||||
// allocate binary
|
||||
mBinaryBlob.alloc(getAciSize());
|
||||
|
||||
// copy header
|
||||
memcpy(mBinaryBlob.getBytes(), AciHeader::getBytes(), AciHeader::getSize());
|
||||
|
||||
// copy components
|
||||
memcpy(mBinaryBlob.getBytes() + getFacPos().offset, mFac.getBytes(), mFac.getSize());
|
||||
memcpy(mBinaryBlob.getBytes() + getSacPos().offset, mSac.getBytes(), mSac.getSize());
|
||||
memcpy(mBinaryBlob.getBytes() + getKcPos().offset, mKc.getBytes(), mKc.getSize());
|
||||
}
|
||||
|
||||
void nx::AciBinary::importBinary(const u8 * bytes, size_t len)
|
||||
{
|
||||
AciHeader::importBinary(bytes, len);
|
||||
|
||||
if (getAciSize() > len)
|
||||
{
|
||||
throw fnd::Exception(kModuleName, "ACI binary too small");
|
||||
}
|
||||
|
||||
mBinaryBlob.alloc(getAciSize());
|
||||
memcpy(mBinaryBlob.getBytes(), bytes, mBinaryBlob.getSize());
|
||||
|
||||
if (getFacPos().size > 0)
|
||||
{
|
||||
mFac.importBinary(mBinaryBlob.getBytes() + getFacPos().offset, getFacPos().size);
|
||||
}
|
||||
if (getSacPos().size > 0)
|
||||
{
|
||||
mSac.importBinary(mBinaryBlob.getBytes() + getSacPos().offset, getSacPos().size);
|
||||
}
|
||||
if (getKcPos().size > 0)
|
||||
{
|
||||
mKc.importBinary(mBinaryBlob.getBytes() + getKcPos().offset, getKcPos().size);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void nx::AciBinary::clear()
|
||||
{
|
||||
AciHeader::clear();
|
||||
mFac.clear();
|
||||
mSac.clear();
|
||||
mKc.clear();
|
||||
}
|
||||
|
||||
const nx::FacBinary & nx::AciBinary::getFac() const
|
||||
{
|
||||
return mFac;
|
||||
}
|
||||
|
||||
void nx::AciBinary::setFac(const FacBinary & fac)
|
||||
{
|
||||
mFac = fac;
|
||||
}
|
||||
|
||||
const nx::SacBinary & nx::AciBinary::getSac() const
|
||||
{
|
||||
return mSac;
|
||||
}
|
||||
|
||||
void nx::AciBinary::setSac(const SacBinary & sac)
|
||||
{
|
||||
mSac = sac;
|
||||
}
|
||||
|
||||
const nx::KcBinary & nx::AciBinary::getKc() const
|
||||
{
|
||||
return mKc;
|
||||
}
|
||||
|
||||
void nx::AciBinary::setKc(const KcBinary & kc)
|
||||
{
|
||||
mKc = kc;
|
||||
}
|
||||
|
||||
bool nx::AciBinary::isEqual(const AciBinary & other) const
|
||||
{
|
||||
return (AciHeader::operator==(other)) \
|
||||
&& (mFac == other.mFac) \
|
||||
&& (mSac == other.mSac) \
|
||||
&& (mKc == other.mKc);
|
||||
}
|
||||
|
||||
void nx::AciBinary::copyFrom(const AciBinary & other)
|
||||
{
|
||||
if (other.getSize())
|
||||
{
|
||||
importBinary(other.getBytes(), other.getSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
AciHeader::operator=(other);
|
||||
mFac = other.mFac;
|
||||
mSac = other.mSac;
|
||||
mKc = other.mKc;
|
||||
}
|
||||
}
|
60
lib/nx/AciBinary.h
Normal file
60
lib/nx/AciBinary.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
#include <fnd/memory_blob.h>
|
||||
#include <fnd/List.h>
|
||||
#include <nx/ISerialiseableBinary.h>
|
||||
#include <nx/AciHeader.h>
|
||||
#include <nx/FacBinary.h>
|
||||
#include <nx/SacBinary.h>
|
||||
#include <nx/KcBinary.h>
|
||||
|
||||
namespace nx
|
||||
{
|
||||
class AciBinary :
|
||||
public AciHeader
|
||||
{
|
||||
public:
|
||||
AciBinary();
|
||||
AciBinary(const AciBinary& other);
|
||||
AciBinary(const u8* bytes, size_t len);
|
||||
|
||||
bool operator==(const AciBinary& other) const;
|
||||
bool operator!=(const AciBinary& other) const;
|
||||
void operator=(const AciBinary& other);
|
||||
|
||||
// to be used after export
|
||||
const u8* getBytes() const;
|
||||
size_t getSize() const;
|
||||
|
||||
// export/import binary
|
||||
virtual void exportBinary();
|
||||
virtual void importBinary(const u8* bytes, size_t len);
|
||||
|
||||
// variables
|
||||
virtual void clear();
|
||||
|
||||
const FacBinary& getFac() const;
|
||||
void setFac(const FacBinary& fac);
|
||||
|
||||
const SacBinary& getSac() const;
|
||||
void setSac(const SacBinary& sac);
|
||||
|
||||
const KcBinary& getKc() const;
|
||||
void setKc(const KcBinary& kc);
|
||||
|
||||
private:
|
||||
const std::string kModuleName = "ACI_BINARY";
|
||||
|
||||
// raw binary
|
||||
fnd::MemoryBlob mBinaryBlob;
|
||||
|
||||
// variables
|
||||
FacBinary mFac;
|
||||
SacBinary mSac;
|
||||
KcBinary mKc;
|
||||
|
||||
bool isEqual(const AciBinary& other) const;
|
||||
void copyFrom(const AciBinary& other);
|
||||
};
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@
|
|||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="AciBinary.h" />
|
||||
<ClInclude Include="AciHeader.h" />
|
||||
<ClInclude Include="FacBinary.h" />
|
||||
<ClInclude Include="FacHeader.h" />
|
||||
|
@ -49,6 +50,7 @@
|
|||
<ClInclude Include="ThreadInfoHandler.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="AciBinary.cpp" />
|
||||
<ClCompile Include="AciHeader.cpp" />
|
||||
<ClCompile Include="FacBinary.cpp" />
|
||||
<ClCompile Include="FacHeader.cpp" />
|
||||
|
|
|
@ -96,6 +96,9 @@
|
|||
<ClInclude Include="MemoryMappingHandler.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="AciBinary.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="KcBinary.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
@ -173,6 +176,9 @@
|
|||
<ClCompile Include="MemoryMappingHandler.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="AciBinary.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="KcBinary.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
|
Loading…
Reference in a new issue