2017-08-05 13:09:50 +00:00
|
|
|
#include <nx/AciBinary.h>
|
2017-07-15 08:28:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nx::AciBinary::AciBinary()
|
2017-07-17 08:21:39 +00:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
2017-07-15 08:28:41 +00:00
|
|
|
|
|
|
|
nx::AciBinary::AciBinary(const AciBinary & other)
|
|
|
|
{
|
|
|
|
copyFrom(other);
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
nx::AciBinary::AciBinary(const byte_t * bytes, size_t len)
|
2017-07-15 08:28:41 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
const byte_t * nx::AciBinary::getBytes() const
|
2017-07-15 08:28:41 +00:00
|
|
|
{
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
void nx::AciBinary::importBinary(const byte_t * bytes, size_t len)
|
2017-07-15 08:28:41 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|