2018-08-07 07:17:51 +00:00
|
|
|
#include <nn/hac/FileSystemAccessControlBinary.h>
|
2018-06-28 16:20:56 +00:00
|
|
|
|
|
|
|
#include <fnd/SimpleTextOutput.h>
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
nn::hac::FileSystemAccessControlBinary::FileSystemAccessControlBinary()
|
2018-06-28 16:20:56 +00:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
nn::hac::FileSystemAccessControlBinary::FileSystemAccessControlBinary(const FileSystemAccessControlBinary & other)
|
2018-06-28 16:20:56 +00:00
|
|
|
{
|
|
|
|
*this = other;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::FileSystemAccessControlBinary::operator=(const FileSystemAccessControlBinary & other)
|
2018-06-28 16:20:56 +00:00
|
|
|
{
|
|
|
|
mRawBinary = other.mRawBinary;
|
|
|
|
mVersion = other.mVersion;
|
|
|
|
mFsaRights = other.mFsaRights;
|
|
|
|
mContentOwnerIdList = other.mContentOwnerIdList;
|
|
|
|
mSaveDataOwnerIdList = other.mSaveDataOwnerIdList;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
bool nn::hac::FileSystemAccessControlBinary::operator==(const FileSystemAccessControlBinary & other) const
|
2018-06-28 16:20:56 +00:00
|
|
|
{
|
|
|
|
return (mVersion == other.mVersion) \
|
|
|
|
&& (mFsaRights == other.mFsaRights) \
|
|
|
|
&& (mContentOwnerIdList == other.mContentOwnerIdList) \
|
|
|
|
&& (mSaveDataOwnerIdList == other.mSaveDataOwnerIdList);
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
bool nn::hac::FileSystemAccessControlBinary::operator!=(const FileSystemAccessControlBinary & other) const
|
2018-06-28 16:20:56 +00:00
|
|
|
{
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::FileSystemAccessControlBinary::toBytes()
|
2018-06-28 16:20:56 +00:00
|
|
|
{
|
|
|
|
// determine section layout
|
|
|
|
struct sLayout {
|
|
|
|
uint32_t offset, size;
|
|
|
|
} content, savedata;
|
|
|
|
|
2018-07-10 15:23:05 +00:00
|
|
|
content.offset = (uint32_t)align(sizeof(sFacHeader), fac::kSectionAlignSize);
|
2018-07-10 14:55:04 +00:00
|
|
|
content.size = (uint32_t)(sizeof(uint32_t) + mContentOwnerIdList.size() * sizeof(uint64_t));
|
2018-07-10 15:23:05 +00:00
|
|
|
savedata.offset = (uint32_t)(content.offset + (content.size > 0 ? align(content.size, fac::kSectionAlignSize) : 0));
|
2018-07-10 14:55:04 +00:00
|
|
|
savedata.size = (uint32_t)(sizeof(uint32_t) + align(mSaveDataOwnerIdList.size(), fac::kSectionAlignSize) + mSaveDataOwnerIdList.size() * sizeof(uint64_t));
|
2018-06-28 16:20:56 +00:00
|
|
|
|
|
|
|
// get total size
|
|
|
|
size_t total_size = _MAX(_MAX(content.offset + content.size, savedata.offset + savedata.size), align(sizeof(sFacHeader), fac::kSectionAlignSize));
|
|
|
|
|
|
|
|
mRawBinary.alloc(total_size);
|
|
|
|
sFacHeader* hdr = (sFacHeader*)mRawBinary.data();
|
|
|
|
|
|
|
|
// set type
|
|
|
|
hdr->version = mVersion;
|
|
|
|
|
|
|
|
// flags
|
|
|
|
uint64_t flag = 0;
|
|
|
|
for (size_t i = 0; i < mFsaRights.size(); i++)
|
|
|
|
{
|
|
|
|
flag |= _BIT((uint64_t)mFsaRights[i]);
|
|
|
|
}
|
|
|
|
hdr->fac_flags = flag;
|
|
|
|
|
|
|
|
// set offset/size
|
2018-07-10 14:55:04 +00:00
|
|
|
hdr->content_owner_ids.offset = content.offset;
|
2018-06-28 16:20:56 +00:00
|
|
|
if (content.size > 0)
|
2018-07-10 14:55:04 +00:00
|
|
|
hdr->content_owner_ids.size = content.size;
|
|
|
|
hdr->save_data_owner_ids.offset = savedata.offset;
|
2018-06-28 16:20:56 +00:00
|
|
|
if (savedata.size > 0)
|
2018-07-10 14:55:04 +00:00
|
|
|
hdr->save_data_owner_ids.size = savedata.size;
|
2018-06-28 16:20:56 +00:00
|
|
|
|
|
|
|
// set ids
|
2018-07-10 14:55:04 +00:00
|
|
|
le_uint32_t* content_owner_id_num = (le_uint32_t*)(mRawBinary.data() + content.offset);
|
|
|
|
le_uint64_t* content_owner_ids = (le_uint64_t*)(mRawBinary.data() + content.offset + sizeof(uint32_t));
|
2018-07-10 15:23:05 +00:00
|
|
|
content_owner_id_num->set((uint32_t)mContentOwnerIdList.size());
|
2018-06-28 16:20:56 +00:00
|
|
|
for (size_t i = 0; i < mContentOwnerIdList.size(); i++)
|
|
|
|
{
|
|
|
|
content_owner_ids[i] = mContentOwnerIdList[i];
|
|
|
|
}
|
|
|
|
|
2018-07-10 14:55:04 +00:00
|
|
|
le_uint32_t* save_data_owner_id_num = (le_uint32_t*)(mRawBinary.data() + savedata.offset);
|
|
|
|
byte_t* save_data_owner_id_accessibility_array = (mRawBinary.data() + savedata.offset + sizeof(uint32_t));
|
|
|
|
le_uint64_t* save_data_owner_ids = (le_uint64_t*)(mRawBinary.data() + savedata.offset + sizeof(uint32_t) + align(mSaveDataOwnerIdList.size(), sizeof(uint32_t)));
|
2018-07-10 15:23:05 +00:00
|
|
|
save_data_owner_id_num->set((uint32_t)mSaveDataOwnerIdList.size());
|
2018-06-28 16:20:56 +00:00
|
|
|
for (size_t i = 0; i < mSaveDataOwnerIdList.size(); i++)
|
|
|
|
{
|
2018-07-10 14:55:04 +00:00
|
|
|
save_data_owner_id_accessibility_array[i] = mSaveDataOwnerIdList[i].access_type;
|
|
|
|
save_data_owner_ids[i] = mSaveDataOwnerIdList[i].id;
|
2018-06-28 16:20:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::FileSystemAccessControlBinary::fromBytes(const byte_t* data, size_t len)
|
2018-06-28 16:20:56 +00:00
|
|
|
{
|
|
|
|
// check size
|
|
|
|
if (len < sizeof(sFacHeader))
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "FileSystemAccessControlInfo binary is too small");
|
|
|
|
}
|
|
|
|
|
|
|
|
// clear variables
|
|
|
|
clear();
|
|
|
|
|
|
|
|
// save a copy of the header
|
|
|
|
sFacHeader hdr;
|
|
|
|
memcpy((void*)&hdr, data, sizeof(sFacHeader));
|
|
|
|
|
|
|
|
// check format version
|
|
|
|
if (hdr.version.get() != fac::kFacFormatVersion)
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "FileSystemAccessControlInfo format version unsupported");
|
|
|
|
}
|
|
|
|
|
|
|
|
// get total size
|
2018-07-10 14:55:04 +00:00
|
|
|
size_t total_size = _MAX(_MAX(hdr.content_owner_ids.offset.get() + hdr.content_owner_ids.size.get(), hdr.save_data_owner_ids.offset.get() + hdr.save_data_owner_ids.size.get()), align(sizeof(sFacHeader), fac::kSectionAlignSize));
|
2018-06-28 16:20:56 +00:00
|
|
|
|
|
|
|
// validate binary size
|
|
|
|
if (len < total_size)
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "FileSystemAccessControlInfo binary is too small");
|
|
|
|
}
|
|
|
|
|
|
|
|
// allocate memory
|
|
|
|
mRawBinary.alloc(total_size);
|
|
|
|
memcpy(mRawBinary.data(), data, mRawBinary.size());
|
|
|
|
|
|
|
|
// save variables
|
|
|
|
mVersion = hdr.version.get();
|
|
|
|
for (size_t i = 0; i < 64; i++)
|
|
|
|
{
|
|
|
|
if (_HAS_BIT(hdr.fac_flags.get(), i))
|
|
|
|
{
|
|
|
|
mFsaRights.addElement((fac::FsAccessFlag)i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// save ids
|
2018-07-10 14:55:04 +00:00
|
|
|
if (hdr.content_owner_ids.size.get() > 0)
|
2018-06-28 16:20:56 +00:00
|
|
|
{
|
2018-07-10 14:55:04 +00:00
|
|
|
size_t content_owner_id_num = ((le_uint32_t*)(mRawBinary.data() + hdr.content_owner_ids.offset.get()))->get();
|
|
|
|
le_uint64_t* content_owner_ids = (le_uint64_t*)(mRawBinary.data() + hdr.content_owner_ids.offset.get() + sizeof(uint32_t));
|
2018-06-28 16:20:56 +00:00
|
|
|
for (size_t i = 0; i < content_owner_id_num; i++)
|
|
|
|
{
|
|
|
|
mContentOwnerIdList.addElement(content_owner_ids[i].get());
|
|
|
|
}
|
|
|
|
}
|
2018-07-10 14:55:04 +00:00
|
|
|
if (hdr.save_data_owner_ids.size.get() > 0)
|
2018-06-28 16:20:56 +00:00
|
|
|
{
|
2018-07-10 14:55:04 +00:00
|
|
|
size_t save_data_owner_id_num = ((le_uint32_t*)(mRawBinary.data() + hdr.save_data_owner_ids.offset.get()))->get();
|
|
|
|
byte_t* save_data_owner_id_accessibility_array = (mRawBinary.data() + hdr.save_data_owner_ids.offset.get() + sizeof(uint32_t));
|
|
|
|
le_uint64_t* save_data_owner_ids = (le_uint64_t*)(mRawBinary.data() + hdr.save_data_owner_ids.offset.get() + sizeof(uint32_t) + align(save_data_owner_id_num, fac::kSectionAlignSize));
|
2018-06-28 16:20:56 +00:00
|
|
|
for (size_t i = 0; i < save_data_owner_id_num; i++)
|
|
|
|
{
|
2018-07-10 14:55:04 +00:00
|
|
|
mSaveDataOwnerIdList.addElement({ (fac::SaveDataOwnerIdAccessType)save_data_owner_id_accessibility_array[i], save_data_owner_ids[i].get() });
|
2018-06-28 16:20:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const fnd::Vec<byte_t>& nn::hac::FileSystemAccessControlBinary::getBytes() const
|
2018-06-28 16:20:56 +00:00
|
|
|
{
|
|
|
|
return mRawBinary;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::FileSystemAccessControlBinary::clear()
|
2018-06-28 16:20:56 +00:00
|
|
|
{
|
|
|
|
mRawBinary.clear();
|
|
|
|
mVersion = 0;
|
|
|
|
mFsaRights.clear();
|
|
|
|
mContentOwnerIdList.clear();
|
|
|
|
mSaveDataOwnerIdList.clear();
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
uint32_t nn::hac::FileSystemAccessControlBinary::getFormatVersion() const
|
2018-06-28 16:20:56 +00:00
|
|
|
{
|
|
|
|
return mVersion;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::FileSystemAccessControlBinary::setFormatVersion(uint32_t format_version)
|
2018-06-28 16:20:56 +00:00
|
|
|
{
|
|
|
|
mVersion = format_version;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const fnd::List<nn::hac::fac::FsAccessFlag>& nn::hac::FileSystemAccessControlBinary::getFsaRightsList() const
|
2018-06-28 16:20:56 +00:00
|
|
|
{
|
|
|
|
return mFsaRights;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::FileSystemAccessControlBinary::setFsaRightsList(const fnd::List<fac::FsAccessFlag>& list)
|
2018-06-28 16:20:56 +00:00
|
|
|
{
|
|
|
|
mFsaRights = list;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const fnd::List<uint64_t>& nn::hac::FileSystemAccessControlBinary::getContentOwnerIdList() const
|
2018-06-28 16:20:56 +00:00
|
|
|
{
|
|
|
|
return mContentOwnerIdList;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::FileSystemAccessControlBinary::setContentOwnerIdList(const fnd::List<uint64_t>& list)
|
2018-06-28 16:20:56 +00:00
|
|
|
{
|
|
|
|
mContentOwnerIdList = list;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
const fnd::List<nn::hac::FileSystemAccessControlBinary::sSaveDataOwnerId>& nn::hac::FileSystemAccessControlBinary::getSaveDataOwnerIdList() const
|
2018-06-28 16:20:56 +00:00
|
|
|
{
|
|
|
|
return mSaveDataOwnerIdList;
|
|
|
|
}
|
|
|
|
|
2018-08-07 07:17:51 +00:00
|
|
|
void nn::hac::FileSystemAccessControlBinary::setSaveDataOwnerIdList(const fnd::List<sSaveDataOwnerId>& list)
|
2018-06-28 16:20:56 +00:00
|
|
|
{
|
|
|
|
mSaveDataOwnerIdList = list;
|
|
|
|
}
|