Merge pull request #31 from jakcron/npdm-development

[nx|nstool] Fixed processing of Fac ContentOwnerId and SaveDataOwnerI…
This commit is contained in:
Jack 2018-07-10 22:55:42 +08:00 committed by GitHub
commit e97f621979
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 81 additions and 38 deletions

View file

@ -11,6 +11,29 @@ namespace nx
class FileSystemAccessControlBinary : public fnd::ISerialisable
{
public:
struct sSaveDataOwnerId
{
nx::fac::SaveDataOwnerIdAccessType access_type;
uint64_t id;
void operator=(const sSaveDataOwnerId& other)
{
access_type = other.access_type;
id = other.id;
}
bool operator==(const sSaveDataOwnerId& other) const
{
return (access_type == other.access_type) \
&& (id == other.id);
}
bool operator!=(const sSaveDataOwnerId& other) const
{
return !(*this == other);
}
};
FileSystemAccessControlBinary();
FileSystemAccessControlBinary(const FileSystemAccessControlBinary& other);
@ -32,11 +55,11 @@ namespace nx
const fnd::List<fac::FsAccessFlag>& getFsaRightsList() const;
void setFsaRightsList(const fnd::List<fac::FsAccessFlag>& list);
const fnd::List<uint32_t>& getContentOwnerIdList() const;
void setContentOwnerIdList(const fnd::List<uint32_t>& list);
const fnd::List<uint64_t>& getContentOwnerIdList() const;
void setContentOwnerIdList(const fnd::List<uint64_t>& list);
const fnd::List<uint32_t>& getSaveDataOwnerIdList() const;
void setSaveDataOwnerIdList(const fnd::List<uint32_t>& list);
const fnd::List<sSaveDataOwnerId>& getSaveDataOwnerIdList() const;
void setSaveDataOwnerIdList(const fnd::List<sSaveDataOwnerId>& list);
private:
const std::string kModuleName = "FILE_SYSTEM_ACCESS_CONTROL_BINARY";
@ -46,7 +69,7 @@ namespace nx
// variables
uint32_t mVersion;
fnd::List<fac::FsAccessFlag> mFsaRights;
fnd::List<uint32_t> mContentOwnerIdList;
fnd::List<uint32_t> mSaveDataOwnerIdList;
fnd::List<uint64_t> mContentOwnerIdList;
fnd::List<sSaveDataOwnerId> mSaveDataOwnerIdList;
};
}

View file

@ -33,6 +33,13 @@ namespace nx
FSA_DEBUG = 62,
FSA_FULL_PERMISSION = 63,
};
enum SaveDataOwnerIdAccessType
{
SDO_READ = 1,
SDO_WRITE,
SDO_READWRITE
};
}
#pragma pack(push,1)
@ -42,8 +49,8 @@ namespace nx
le_uint64_t fac_flags;
struct sFacSection
{
le_uint32_t start;
le_uint32_t end;
le_uint32_t offset;
le_uint32_t size;
} content_owner_ids, save_data_owner_ids; // the data for these follow later in binary. start/end relative to base of FacData instance
};
#pragma pack(pop)

View file

@ -42,9 +42,9 @@ void nx::FileSystemAccessControlBinary::toBytes()
} content, savedata;
content.offset = align(sizeof(sFacHeader), fac::kSectionAlignSize);
content.size = (uint32_t)(mContentOwnerIdList.size() * sizeof(uint32_t));
savedata.offset = content.offset + align(content.size, fac::kSectionAlignSize);
savedata.size = (uint32_t)(mSaveDataOwnerIdList.size() * sizeof(uint32_t));
content.size = (uint32_t)(sizeof(uint32_t) + mContentOwnerIdList.size() * sizeof(uint64_t));
savedata.offset = content.offset + (content.size > 0 ? align(content.size, fac::kSectionAlignSize) : 0);
savedata.size = (uint32_t)(sizeof(uint32_t) + align(mSaveDataOwnerIdList.size(), fac::kSectionAlignSize) + mSaveDataOwnerIdList.size() * sizeof(uint64_t));
// get total size
size_t total_size = _MAX(_MAX(content.offset + content.size, savedata.offset + savedata.size), align(sizeof(sFacHeader), fac::kSectionAlignSize));
@ -64,24 +64,30 @@ void nx::FileSystemAccessControlBinary::toBytes()
hdr->fac_flags = flag;
// set offset/size
hdr->content_owner_ids.start = content.offset;
hdr->content_owner_ids.offset = content.offset;
if (content.size > 0)
hdr->content_owner_ids.end = content.offset + content.size;
hdr->save_data_owner_ids.start = savedata.offset;
hdr->content_owner_ids.size = content.size;
hdr->save_data_owner_ids.offset = savedata.offset;
if (savedata.size > 0)
hdr->save_data_owner_ids.end = savedata.offset + savedata.size;
hdr->save_data_owner_ids.size = savedata.size;
// set ids
le_uint32_t* content_owner_ids = (le_uint32_t*)(mRawBinary.data() + content.offset);
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));
content_owner_id_num->set(mContentOwnerIdList.size());
for (size_t i = 0; i < mContentOwnerIdList.size(); i++)
{
content_owner_ids[i] = mContentOwnerIdList[i];
}
le_uint32_t* save_data_owner_ids = (le_uint32_t*)(mRawBinary.data() + savedata.offset);
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)));
save_data_owner_id_num->set(mSaveDataOwnerIdList.size());
for (size_t i = 0; i < mSaveDataOwnerIdList.size(); i++)
{
save_data_owner_ids[i] = mSaveDataOwnerIdList[i];
save_data_owner_id_accessibility_array[i] = mSaveDataOwnerIdList[i].access_type;
save_data_owner_ids[i] = mSaveDataOwnerIdList[i].id;
}
}
@ -107,7 +113,7 @@ void nx::FileSystemAccessControlBinary::fromBytes(const byte_t* data, size_t len
}
// get total size
size_t total_size = _MAX(_MAX(hdr.content_owner_ids.end.get(), hdr.save_data_owner_ids.end.get()), align(sizeof(sFacHeader), fac::kSectionAlignSize));
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));
// validate binary size
if (len < total_size)
@ -130,22 +136,23 @@ void nx::FileSystemAccessControlBinary::fromBytes(const byte_t* data, size_t len
}
// save ids
if (hdr.content_owner_ids.end.get() > hdr.content_owner_ids.start.get())
if (hdr.content_owner_ids.size.get() > 0)
{
le_uint32_t* content_owner_ids = (le_uint32_t*)(mRawBinary.data() + hdr.content_owner_ids.start.get());
size_t content_owner_id_num = (hdr.content_owner_ids.end.get() - hdr.content_owner_ids.start.get()) / sizeof(uint32_t);
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));
for (size_t i = 0; i < content_owner_id_num; i++)
{
mContentOwnerIdList.addElement(content_owner_ids[i].get());
}
}
if (hdr.save_data_owner_ids.end.get() > hdr.save_data_owner_ids.start.get())
if (hdr.save_data_owner_ids.size.get() > 0)
{
le_uint32_t* save_data_owner_ids = (le_uint32_t*)(mRawBinary.data() + hdr.save_data_owner_ids.start.get());
size_t save_data_owner_id_num = (hdr.save_data_owner_ids.end.get() - hdr.save_data_owner_ids.start.get()) / sizeof(uint32_t);
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));
for (size_t i = 0; i < save_data_owner_id_num; i++)
{
mSaveDataOwnerIdList.addElement(save_data_owner_ids[i].get());
mSaveDataOwnerIdList.addElement({ (fac::SaveDataOwnerIdAccessType)save_data_owner_id_accessibility_array[i], save_data_owner_ids[i].get() });
}
}
}
@ -184,22 +191,22 @@ void nx::FileSystemAccessControlBinary::setFsaRightsList(const fnd::List<fac::Fs
mFsaRights = list;
}
const fnd::List<uint32_t>& nx::FileSystemAccessControlBinary::getContentOwnerIdList() const
const fnd::List<uint64_t>& nx::FileSystemAccessControlBinary::getContentOwnerIdList() const
{
return mContentOwnerIdList;
}
void nx::FileSystemAccessControlBinary::setContentOwnerIdList(const fnd::List<uint32_t>& list)
void nx::FileSystemAccessControlBinary::setContentOwnerIdList(const fnd::List<uint64_t>& list)
{
mContentOwnerIdList = list;
}
const fnd::List<uint32_t>& nx::FileSystemAccessControlBinary::getSaveDataOwnerIdList() const
const fnd::List<nx::FileSystemAccessControlBinary::sSaveDataOwnerId>& nx::FileSystemAccessControlBinary::getSaveDataOwnerIdList() const
{
return mSaveDataOwnerIdList;
}
void nx::FileSystemAccessControlBinary::setSaveDataOwnerIdList(const fnd::List<uint32_t>& list)
void nx::FileSystemAccessControlBinary::setSaveDataOwnerIdList(const fnd::List<sSaveDataOwnerId>& list)
{
mSaveDataOwnerIdList = list;
}

View file

@ -190,6 +190,15 @@ const std::string kFsaFlag[64] =
"Debug",
"FullPermission"
};
const std::string kSaveDataOwnerAccessMode[4] =
{
"IllegalAccessCondition",
"Read",
"Write",
"ReadWrite"
};
const std::string kSysCall[0x80] =
{
"svc00",
@ -378,7 +387,7 @@ void NpdmProcess::validateAciFromAcid(const nx::AccessControlInfoBinary& aci, co
if (rightFound == false)
{
printf("[WARNING] ACI/FAC ContentOwnerId: FAIL (%08x not permitted)\n", aci.getFileSystemAccessControl().getContentOwnerIdList()[i]);
printf("[WARNING] ACI/FAC ContentOwnerId: FAIL (%016" PRIx64 " not permitted)\n", aci.getFileSystemAccessControl().getContentOwnerIdList()[i]);
}
}
@ -394,7 +403,7 @@ void NpdmProcess::validateAciFromAcid(const nx::AccessControlInfoBinary& aci, co
if (rightFound == false)
{
printf("[WARNING] ACI/FAC ContentOwnerId: FAIL (%08x not permitted)\n", aci.getFileSystemAccessControl().getSaveDataOwnerIdList()[i]);
printf("[WARNING] ACI/FAC ContentOwnerId: FAIL (%016" PRIx64 "(%d) not permitted)\n", aci.getFileSystemAccessControl().getSaveDataOwnerIdList()[i].id, aci.getFileSystemAccessControl().getSaveDataOwnerIdList()[i].access_type);
}
}
@ -590,25 +599,22 @@ void NpdmProcess::displayFac(const nx::FileSystemAccessControlBinary& fac)
printf("%s", fac.getFsaRightsList()[i] != fac.getFsaRightsList().atBack() ? ", " : "\n");
}
}
else
{
printf(" FS Rights: NONE\n");
}
if (fac.getContentOwnerIdList().size())
{
printf(" Content Owner IDs:\n");
for (size_t i = 0; i < fac.getContentOwnerIdList().size(); i++)
{
printf(" 0x%08x\n", fac.getContentOwnerIdList()[i]);
printf(" 0x%016" PRIx64 "\n", fac.getContentOwnerIdList()[i]);
}
}
if (fac.getSaveDataOwnerIdList().size())
{
printf(" Save Data Owner IDs:\n");
for (size_t i = 0; i < fac.getSaveDataOwnerIdList().size(); i++)
{
printf(" 0x%08x\n", fac.getSaveDataOwnerIdList()[i]);
printf(" 0x%016" PRIx64 " (%s)\n", fac.getSaveDataOwnerIdList()[i].id, kSaveDataOwnerAccessMode[fac.getSaveDataOwnerIdList()[i].access_type].c_str());
}
}