2018-10-18 12:52:43 +00:00
|
|
|
#include <nn/hac/AccessControlInfo.h>
|
2018-06-27 05:03:46 +00:00
|
|
|
|
2018-10-18 12:52:43 +00:00
|
|
|
nn::hac::AccessControlInfo::AccessControlInfo()
|
2018-06-27 05:03:46 +00:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2018-10-18 12:52:43 +00:00
|
|
|
nn::hac::AccessControlInfo::AccessControlInfo(const AccessControlInfo & other)
|
2018-06-27 05:03:46 +00:00
|
|
|
{
|
|
|
|
*this = other;
|
|
|
|
}
|
|
|
|
|
2018-10-18 12:52:43 +00:00
|
|
|
void nn::hac::AccessControlInfo::operator=(const AccessControlInfo & other)
|
2018-06-27 05:03:46 +00:00
|
|
|
{
|
|
|
|
mRawBinary = other.mRawBinary;
|
|
|
|
mProgramId = other.mProgramId;
|
|
|
|
mFileSystemAccessControl = other.mFileSystemAccessControl;
|
|
|
|
mServiceAccessControl = other.mServiceAccessControl;
|
|
|
|
mKernelCapabilities = other.mKernelCapabilities;
|
|
|
|
}
|
|
|
|
|
2018-10-18 12:52:43 +00:00
|
|
|
bool nn::hac::AccessControlInfo::operator==(const AccessControlInfo & other) const
|
2018-06-27 05:03:46 +00:00
|
|
|
{
|
|
|
|
return (mProgramId == other.mProgramId) \
|
|
|
|
&& (mFileSystemAccessControl == other.mFileSystemAccessControl) \
|
|
|
|
&& (mServiceAccessControl == other.mServiceAccessControl) \
|
|
|
|
&& (mKernelCapabilities == other.mKernelCapabilities);
|
|
|
|
}
|
|
|
|
|
2018-10-18 12:52:43 +00:00
|
|
|
bool nn::hac::AccessControlInfo::operator!=(const AccessControlInfo & other) const
|
2018-06-27 05:03:46 +00:00
|
|
|
{
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
2018-10-18 12:52:43 +00:00
|
|
|
void nn::hac::AccessControlInfo::toBytes()
|
2018-06-27 05:03:46 +00:00
|
|
|
{
|
2018-09-09 11:59:40 +00:00
|
|
|
// serialise the sections
|
|
|
|
mFileSystemAccessControl.toBytes();
|
|
|
|
mServiceAccessControl.toBytes();
|
|
|
|
mKernelCapabilities.toBytes();
|
2018-06-27 05:03:46 +00:00
|
|
|
|
|
|
|
// determine section layout
|
|
|
|
struct sLayout {
|
|
|
|
uint32_t offset, size;
|
|
|
|
} fac, sac, kc;
|
|
|
|
|
2018-07-10 15:23:05 +00:00
|
|
|
fac.offset = (uint32_t)align(sizeof(sAciHeader), aci::kSectionAlignSize);
|
2018-06-27 05:03:46 +00:00
|
|
|
fac.size = (uint32_t)mFileSystemAccessControl.getBytes().size();
|
2018-07-10 15:23:05 +00:00
|
|
|
sac.offset = (uint32_t)align(fac.offset + fac.size, aci::kSectionAlignSize);
|
2018-06-27 05:03:46 +00:00
|
|
|
sac.size = (uint32_t)mServiceAccessControl.getBytes().size();
|
2018-07-10 15:23:05 +00:00
|
|
|
kc.offset = (uint32_t)align(sac.offset + sac.size, aci::kSectionAlignSize);
|
2018-06-27 05:03:46 +00:00
|
|
|
kc.size = (uint32_t)mKernelCapabilities.getBytes().size();
|
|
|
|
|
|
|
|
// get total size
|
|
|
|
size_t total_size = _MAX(_MAX(fac.offset + fac.size, sac.offset + sac.size), kc.offset + kc.size);
|
|
|
|
|
|
|
|
mRawBinary.alloc(total_size);
|
|
|
|
sAciHeader* hdr = (sAciHeader*)mRawBinary.data();
|
|
|
|
|
|
|
|
// set type
|
|
|
|
hdr->st_magic = aci::kAciStructMagic;
|
|
|
|
|
|
|
|
// set program id
|
|
|
|
hdr->program_id = mProgramId;
|
|
|
|
|
|
|
|
// set offset/size
|
|
|
|
hdr->fac.offset = fac.offset;
|
|
|
|
hdr->fac.size = fac.size;
|
|
|
|
hdr->sac.offset = sac.offset;
|
|
|
|
hdr->sac.size = sac.size;
|
|
|
|
hdr->kc.offset = kc.offset;
|
|
|
|
hdr->kc.size = kc.size;
|
2018-09-09 11:59:40 +00:00
|
|
|
|
|
|
|
// write data
|
|
|
|
memcpy(mRawBinary.data() + fac.offset, mFileSystemAccessControl.getBytes().data(), fac.size);
|
|
|
|
memcpy(mRawBinary.data() + sac.offset, mServiceAccessControl.getBytes().data(), sac.size);
|
|
|
|
memcpy(mRawBinary.data() + kc.offset, mKernelCapabilities.getBytes().data(), kc.size);
|
2018-06-27 05:03:46 +00:00
|
|
|
}
|
|
|
|
|
2018-10-18 12:52:43 +00:00
|
|
|
void nn::hac::AccessControlInfo::fromBytes(const byte_t* data, size_t len)
|
2018-06-27 05:03:46 +00:00
|
|
|
{
|
|
|
|
// check size
|
|
|
|
if (len < sizeof(sAciHeader))
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "AccessControlInfo binary is too small");
|
|
|
|
}
|
|
|
|
|
|
|
|
// clear variables
|
|
|
|
clear();
|
|
|
|
|
|
|
|
// save a copy of the header
|
|
|
|
sAciHeader hdr;
|
|
|
|
memcpy((void*)&hdr, data, sizeof(sAciHeader));
|
|
|
|
|
|
|
|
// check magic
|
|
|
|
if (hdr.st_magic.get() != aci::kAciStructMagic)
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "AccessControlInfo header corrupt");
|
|
|
|
}
|
|
|
|
|
|
|
|
// get total size
|
|
|
|
size_t total_size = _MAX(_MAX(hdr.fac.offset.get() + hdr.fac.size.get(), hdr.sac.offset.get() + hdr.sac.size.get()), hdr.kc.offset.get() + hdr.kc.size.get());
|
|
|
|
|
|
|
|
// validate binary size
|
|
|
|
if (len < total_size)
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "AccessControlInfo binary is too small");
|
|
|
|
}
|
|
|
|
|
|
|
|
// allocate memory for header
|
|
|
|
mRawBinary.alloc(total_size);
|
|
|
|
memcpy(mRawBinary.data(), data, mRawBinary.size());
|
|
|
|
|
|
|
|
// save variables
|
|
|
|
mProgramId = hdr.program_id.get();
|
|
|
|
mFileSystemAccessControl.fromBytes(mRawBinary.data() + hdr.fac.offset.get(), hdr.fac.size.get());
|
|
|
|
mServiceAccessControl.fromBytes(mRawBinary.data() + hdr.sac.offset.get(), hdr.sac.size.get());
|
|
|
|
mKernelCapabilities.fromBytes(mRawBinary.data() + hdr.kc.offset.get(), hdr.kc.size.get());
|
|
|
|
}
|
|
|
|
|
2018-10-18 12:52:43 +00:00
|
|
|
const fnd::Vec<byte_t>& nn::hac::AccessControlInfo::getBytes() const
|
2018-06-27 05:03:46 +00:00
|
|
|
{
|
|
|
|
return mRawBinary;
|
|
|
|
}
|
|
|
|
|
2018-10-18 12:52:43 +00:00
|
|
|
void nn::hac::AccessControlInfo::clear()
|
2018-06-27 05:03:46 +00:00
|
|
|
{
|
|
|
|
mRawBinary.clear();
|
|
|
|
mProgramId = 0;
|
|
|
|
mFileSystemAccessControl.clear();
|
|
|
|
mServiceAccessControl.clear();
|
|
|
|
mKernelCapabilities.clear();
|
|
|
|
}
|
|
|
|
|
2018-10-18 12:52:43 +00:00
|
|
|
uint64_t nn::hac::AccessControlInfo::getProgramId() const
|
2018-06-27 05:03:46 +00:00
|
|
|
{
|
|
|
|
return mProgramId;
|
|
|
|
}
|
|
|
|
|
2018-10-18 12:52:43 +00:00
|
|
|
void nn::hac::AccessControlInfo::setProgramId(uint64_t program_id)
|
2018-06-27 05:03:46 +00:00
|
|
|
{
|
|
|
|
mProgramId = program_id;
|
|
|
|
}
|
|
|
|
|
2018-10-22 13:30:49 +00:00
|
|
|
const nn::hac::FileSystemAccessControl& nn::hac::AccessControlInfo::getFileSystemAccessControl() const
|
2018-06-27 05:03:46 +00:00
|
|
|
{
|
|
|
|
return mFileSystemAccessControl;
|
|
|
|
}
|
|
|
|
|
2018-10-22 13:30:49 +00:00
|
|
|
void nn::hac::AccessControlInfo::setFileSystemAccessControl(const nn::hac::FileSystemAccessControl& fac)
|
2018-06-27 05:03:46 +00:00
|
|
|
{
|
|
|
|
mFileSystemAccessControl = fac;
|
|
|
|
}
|
|
|
|
|
2018-10-22 13:30:49 +00:00
|
|
|
const nn::hac::ServiceAccessControl& nn::hac::AccessControlInfo::getServiceAccessControl() const
|
2018-06-27 05:03:46 +00:00
|
|
|
{
|
|
|
|
return mServiceAccessControl;
|
|
|
|
}
|
|
|
|
|
2018-10-22 13:30:49 +00:00
|
|
|
void nn::hac::AccessControlInfo::setServiceAccessControl(const nn::hac::ServiceAccessControl& sac)
|
2018-06-27 05:03:46 +00:00
|
|
|
{
|
|
|
|
mServiceAccessControl = sac;
|
|
|
|
}
|
|
|
|
|
2018-10-22 13:30:49 +00:00
|
|
|
const nn::hac::KernelCapabilityControl& nn::hac::AccessControlInfo::getKernelCapabilities() const
|
2018-06-27 05:03:46 +00:00
|
|
|
{
|
|
|
|
return mKernelCapabilities;
|
|
|
|
}
|
|
|
|
|
2018-10-22 13:30:49 +00:00
|
|
|
void nn::hac::AccessControlInfo::setKernelCapabilities(const nn::hac::KernelCapabilityControl& kc)
|
2018-06-27 05:03:46 +00:00
|
|
|
{
|
|
|
|
mKernelCapabilities = kc;
|
|
|
|
}
|