mirror of
https://github.com/jakcron/nstool
synced 2024-11-15 02:06:40 +00:00
[ns|nxtool] Update SacBinary/SacEntry
This commit is contained in:
parent
efe0655f05
commit
65b39483dc
12 changed files with 160 additions and 167 deletions
|
@ -4,7 +4,7 @@
|
|||
#include <fnd/ISerialisable.h>
|
||||
#include <nx/aci.h>
|
||||
#include <nx/FileSystemAccessControlBinary.h>
|
||||
#include <nx/SacBinary.h>
|
||||
#include <nx/ServiceAccessControlBinary.h>
|
||||
#include <nx/KcBinary.h>
|
||||
|
||||
namespace nx
|
||||
|
@ -33,8 +33,8 @@ namespace nx
|
|||
const nx::FileSystemAccessControlBinary& getFileSystemAccessControl() const;
|
||||
void setFileSystemAccessControl(const FileSystemAccessControlBinary& fac);
|
||||
|
||||
const nx::SacBinary& getServiceAccessControl() const;
|
||||
void setServiceAccessControl(const SacBinary& sac);
|
||||
const nx::ServiceAccessControlBinary& getServiceAccessControl() const;
|
||||
void setServiceAccessControl(const ServiceAccessControlBinary& sac);
|
||||
|
||||
const nx::KcBinary& getKernelCapabilities() const;
|
||||
void setKernelCapabilities(const KcBinary& kc);
|
||||
|
@ -47,7 +47,7 @@ namespace nx
|
|||
// variables
|
||||
uint64_t mProgramId;
|
||||
nx::FileSystemAccessControlBinary mFileSystemAccessControl;
|
||||
nx::SacBinary mServiceAccessControl;
|
||||
nx::ServiceAccessControlBinary mServiceAccessControl;
|
||||
nx::KcBinary mKernelCapabilities;
|
||||
};
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
#include <fnd/ISerialisable.h>
|
||||
#include <nx/aci.h>
|
||||
#include <nx/FileSystemAccessControlBinary.h>
|
||||
#include <nx/SacBinary.h>
|
||||
#include <nx/ServiceAccessControlBinary.h>
|
||||
#include <nx/KcBinary.h>
|
||||
|
||||
namespace nx
|
||||
|
@ -66,8 +66,8 @@ namespace nx
|
|||
const nx::FileSystemAccessControlBinary& getFileSystemAccessControl() const;
|
||||
void setFileSystemAccessControl(const FileSystemAccessControlBinary& fac);
|
||||
|
||||
const nx::SacBinary& getServiceAccessControl() const;
|
||||
void setServiceAccessControl(const SacBinary& sac);
|
||||
const nx::ServiceAccessControlBinary& getServiceAccessControl() const;
|
||||
void setServiceAccessControl(const ServiceAccessControlBinary& sac);
|
||||
|
||||
const nx::KcBinary& getKernelCapabilities() const;
|
||||
void setKernelCapabilities(const KcBinary& kc);
|
||||
|
@ -82,7 +82,7 @@ namespace nx
|
|||
fnd::List<aci::Flag> mFlags;
|
||||
sProgramIdRestrict mProgramIdRestrict;
|
||||
nx::FileSystemAccessControlBinary mFileSystemAccessControl;
|
||||
nx::SacBinary mServiceAccessControl;
|
||||
nx::ServiceAccessControlBinary mServiceAccessControl;
|
||||
nx::KcBinary mKernelCapabilities;
|
||||
};
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fnd/ISerialisable.h>
|
||||
#include <fnd/List.h>
|
||||
#include <nx/SacEntry.h>
|
||||
|
||||
namespace nx
|
||||
{
|
||||
class SacBinary :
|
||||
public fnd::ISerialisable
|
||||
{
|
||||
public:
|
||||
SacBinary();
|
||||
SacBinary(const SacBinary& other);
|
||||
|
||||
void operator=(const SacBinary& other);
|
||||
bool operator==(const SacBinary& other) const;
|
||||
bool operator!=(const SacBinary& other) const;
|
||||
|
||||
// export/import binary
|
||||
void toBytes();
|
||||
void fromBytes(const byte_t* bytes, size_t len);
|
||||
const fnd::Vec<byte_t>& getBytes() const;
|
||||
|
||||
// variables
|
||||
void clear();
|
||||
const fnd::List<SacEntry>& getServiceList() const;
|
||||
void addService(const SacEntry& service);
|
||||
private:
|
||||
const std::string kModuleName = "SAC_BINARY";
|
||||
|
||||
// raw binary
|
||||
fnd::Vec<byte_t> mRawBinary;
|
||||
|
||||
// variables
|
||||
fnd::List<SacEntry> mServices;
|
||||
};
|
||||
|
||||
}
|
40
lib/libnx/include/nx/ServiceAccessControlBinary.h
Normal file
40
lib/libnx/include/nx/ServiceAccessControlBinary.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fnd/ISerialisable.h>
|
||||
#include <fnd/List.h>
|
||||
#include <nx/ServiceAccessControlEntry.h>
|
||||
|
||||
namespace nx
|
||||
{
|
||||
class ServiceAccessControlBinary :
|
||||
public fnd::ISerialisable
|
||||
{
|
||||
public:
|
||||
ServiceAccessControlBinary();
|
||||
ServiceAccessControlBinary(const ServiceAccessControlBinary& other);
|
||||
|
||||
void operator=(const ServiceAccessControlBinary& other);
|
||||
bool operator==(const ServiceAccessControlBinary& other) const;
|
||||
bool operator!=(const ServiceAccessControlBinary& other) const;
|
||||
|
||||
// export/import binary
|
||||
void toBytes();
|
||||
void fromBytes(const byte_t* bytes, size_t len);
|
||||
const fnd::Vec<byte_t>& getBytes() const;
|
||||
|
||||
// variables
|
||||
void clear();
|
||||
const fnd::List<ServiceAccessControlEntry>& getServiceList() const;
|
||||
void addService(const ServiceAccessControlEntry& service);
|
||||
private:
|
||||
const std::string kModuleName = "SERVICE_ACCESS_CONTROL_BINARY";
|
||||
|
||||
// raw binary
|
||||
fnd::Vec<byte_t> mRawBinary;
|
||||
|
||||
// variables
|
||||
fnd::List<ServiceAccessControlEntry> mServices;
|
||||
};
|
||||
|
||||
}
|
|
@ -5,17 +5,17 @@
|
|||
|
||||
namespace nx
|
||||
{
|
||||
class SacEntry :
|
||||
class ServiceAccessControlEntry :
|
||||
public fnd::ISerialisable
|
||||
{
|
||||
public:
|
||||
SacEntry();
|
||||
SacEntry(const std::string& name, bool isServer);
|
||||
SacEntry(const SacEntry& other);
|
||||
ServiceAccessControlEntry();
|
||||
ServiceAccessControlEntry(const std::string& name, bool isServer);
|
||||
ServiceAccessControlEntry(const ServiceAccessControlEntry& other);
|
||||
|
||||
void operator=(const SacEntry& other);
|
||||
bool operator==(const SacEntry& other) const;
|
||||
bool operator!=(const SacEntry& other) const;
|
||||
void operator=(const ServiceAccessControlEntry& other);
|
||||
bool operator==(const ServiceAccessControlEntry& other) const;
|
||||
bool operator!=(const ServiceAccessControlEntry& other) const;
|
||||
|
||||
// export/import binary
|
||||
void toBytes();
|
||||
|
@ -29,10 +29,10 @@ namespace nx
|
|||
const std::string& getName() const;
|
||||
void setName(const std::string& name);
|
||||
private:
|
||||
const std::string kModuleName = "SAC_ENTRY";
|
||||
const std::string kModuleName = "SERVICE_ACCESS_CONTROL_ENTRY";
|
||||
static const size_t kMaxServiceNameLen = 8;
|
||||
|
||||
enum SacEntryFlag
|
||||
enum ServiceAccessControlEntryFlag
|
||||
{
|
||||
SAC_IS_SERVER = _BIT(7),
|
||||
SAC_NAME_LEN_MASK = _BIT(7) - 1
|
||||
|
@ -45,7 +45,7 @@ namespace nx
|
|||
bool mIsServer;
|
||||
std::string mName;
|
||||
|
||||
bool isEqual(const SacEntry& other) const;
|
||||
void copyFrom(const SacEntry& other);
|
||||
bool isEqual(const ServiceAccessControlEntry& other) const;
|
||||
void copyFrom(const ServiceAccessControlEntry& other);
|
||||
};
|
||||
}
|
|
@ -151,12 +151,12 @@ void nx::AccessControlInfoBinary::setFileSystemAccessControl(const nx::FileSyste
|
|||
mFileSystemAccessControl = fac;
|
||||
}
|
||||
|
||||
const nx::SacBinary& nx::AccessControlInfoBinary::getServiceAccessControl() const
|
||||
const nx::ServiceAccessControlBinary& nx::AccessControlInfoBinary::getServiceAccessControl() const
|
||||
{
|
||||
return mServiceAccessControl;
|
||||
}
|
||||
|
||||
void nx::AccessControlInfoBinary::setServiceAccessControl(const nx::SacBinary& sac)
|
||||
void nx::AccessControlInfoBinary::setServiceAccessControl(const nx::ServiceAccessControlBinary& sac)
|
||||
{
|
||||
mServiceAccessControl = sac;
|
||||
}
|
||||
|
|
|
@ -229,12 +229,12 @@ void nx::AccessControlInfoDescBinary::setFileSystemAccessControl(const nx::FileS
|
|||
mFileSystemAccessControl = fac;
|
||||
}
|
||||
|
||||
const nx::SacBinary& nx::AccessControlInfoDescBinary::getServiceAccessControl() const
|
||||
const nx::ServiceAccessControlBinary& nx::AccessControlInfoDescBinary::getServiceAccessControl() const
|
||||
{
|
||||
return mServiceAccessControl;
|
||||
}
|
||||
|
||||
void nx::AccessControlInfoDescBinary::setServiceAccessControl(const nx::SacBinary& sac)
|
||||
void nx::AccessControlInfoDescBinary::setServiceAccessControl(const nx::ServiceAccessControlBinary& sac)
|
||||
{
|
||||
mServiceAccessControl = sac;
|
||||
}
|
||||
|
|
|
@ -1,85 +0,0 @@
|
|||
#include <nx/SacBinary.h>
|
||||
|
||||
nx::SacBinary::SacBinary()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
nx::SacBinary::SacBinary(const SacBinary & other)
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
|
||||
void nx::SacBinary::operator=(const SacBinary & other)
|
||||
{
|
||||
if (other.getBytes().data())
|
||||
{
|
||||
fromBytes(other.getBytes().data(), other.getBytes().size());
|
||||
}
|
||||
else
|
||||
{
|
||||
clear();
|
||||
mServices = other.mServices;
|
||||
}
|
||||
}
|
||||
|
||||
bool nx::SacBinary::operator==(const SacBinary & other) const
|
||||
{
|
||||
return (mServices == other.mServices);
|
||||
}
|
||||
|
||||
bool nx::SacBinary::operator!=(const SacBinary & other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
void nx::SacBinary::toBytes()
|
||||
{
|
||||
size_t totalSize = 0;
|
||||
for (size_t i = 0; i < mServices.size(); i++)
|
||||
{
|
||||
mServices[i].toBytes();
|
||||
totalSize += mServices[i].getBytes().size();
|
||||
}
|
||||
|
||||
mRawBinary.alloc(totalSize);
|
||||
for (size_t i = 0, pos = 0; i < mServices.size(); pos += mServices[i].getBytes().size(), i++)
|
||||
{
|
||||
memcpy((mRawBinary.data() + pos), mServices[i].getBytes().data(), mServices[i].getBytes().size());
|
||||
}
|
||||
}
|
||||
|
||||
void nx::SacBinary::fromBytes(const byte_t* data, size_t len)
|
||||
{
|
||||
clear();
|
||||
mRawBinary.alloc(len);
|
||||
memcpy(mRawBinary.data(), data, mRawBinary.size());
|
||||
|
||||
SacEntry sac;
|
||||
for (size_t pos = 0; pos < len; pos += mServices.atBack().getBytes().size())
|
||||
{
|
||||
sac.fromBytes((const byte_t*)(mRawBinary.data() + pos), len - pos);
|
||||
mServices.addElement(sac);
|
||||
}
|
||||
}
|
||||
|
||||
const fnd::Vec<byte_t>& nx::SacBinary::getBytes() const
|
||||
{
|
||||
return mRawBinary;
|
||||
}
|
||||
|
||||
void nx::SacBinary::clear()
|
||||
{
|
||||
mRawBinary.clear();
|
||||
mServices.clear();
|
||||
}
|
||||
|
||||
const fnd::List<nx::SacEntry>& nx::SacBinary::getServiceList() const
|
||||
{
|
||||
return mServices;
|
||||
}
|
||||
|
||||
void nx::SacBinary::addService(const SacEntry& service)
|
||||
{
|
||||
mServices.addElement(service);
|
||||
}
|
78
lib/libnx/source/ServiceAccessControlBinary.cpp
Normal file
78
lib/libnx/source/ServiceAccessControlBinary.cpp
Normal file
|
@ -0,0 +1,78 @@
|
|||
#include <nx/ServiceAccessControlBinary.h>
|
||||
|
||||
nx::ServiceAccessControlBinary::ServiceAccessControlBinary()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
nx::ServiceAccessControlBinary::ServiceAccessControlBinary(const ServiceAccessControlBinary & other)
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
|
||||
void nx::ServiceAccessControlBinary::operator=(const ServiceAccessControlBinary & other)
|
||||
{
|
||||
mRawBinary = other.mRawBinary;
|
||||
mServices = other.mServices;
|
||||
}
|
||||
|
||||
bool nx::ServiceAccessControlBinary::operator==(const ServiceAccessControlBinary & other) const
|
||||
{
|
||||
return (mServices == other.mServices);
|
||||
}
|
||||
|
||||
bool nx::ServiceAccessControlBinary::operator!=(const ServiceAccessControlBinary & other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
void nx::ServiceAccessControlBinary::toBytes()
|
||||
{
|
||||
size_t totalSize = 0;
|
||||
for (size_t i = 0; i < mServices.size(); i++)
|
||||
{
|
||||
mServices[i].toBytes();
|
||||
totalSize += mServices[i].getBytes().size();
|
||||
}
|
||||
|
||||
mRawBinary.alloc(totalSize);
|
||||
for (size_t i = 0, pos = 0; i < mServices.size(); pos += mServices[i].getBytes().size(), i++)
|
||||
{
|
||||
memcpy((mRawBinary.data() + pos), mServices[i].getBytes().data(), mServices[i].getBytes().size());
|
||||
}
|
||||
}
|
||||
|
||||
void nx::ServiceAccessControlBinary::fromBytes(const byte_t* data, size_t len)
|
||||
{
|
||||
clear();
|
||||
mRawBinary.alloc(len);
|
||||
memcpy(mRawBinary.data(), data, mRawBinary.size());
|
||||
|
||||
ServiceAccessControlEntry sac;
|
||||
for (size_t pos = 0; pos < len; pos += mServices.atBack().getBytes().size())
|
||||
{
|
||||
sac.fromBytes((const byte_t*)(mRawBinary.data() + pos), len - pos);
|
||||
mServices.addElement(sac);
|
||||
}
|
||||
}
|
||||
|
||||
const fnd::Vec<byte_t>& nx::ServiceAccessControlBinary::getBytes() const
|
||||
{
|
||||
return mRawBinary;
|
||||
}
|
||||
|
||||
void nx::ServiceAccessControlBinary::clear()
|
||||
{
|
||||
mRawBinary.clear();
|
||||
mServices.clear();
|
||||
}
|
||||
|
||||
const fnd::List<nx::ServiceAccessControlEntry>& nx::ServiceAccessControlBinary::getServiceList() const
|
||||
{
|
||||
return mServices;
|
||||
}
|
||||
|
||||
void nx::ServiceAccessControlBinary::addService(const ServiceAccessControlEntry& service)
|
||||
{
|
||||
mServices.addElement(service);
|
||||
}
|
|
@ -1,23 +1,23 @@
|
|||
#include <nx/SacEntry.h>
|
||||
#include <nx/ServiceAccessControlEntry.h>
|
||||
|
||||
nx::SacEntry::SacEntry()
|
||||
nx::ServiceAccessControlEntry::ServiceAccessControlEntry()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
nx::SacEntry::SacEntry(const std::string & name, bool isServer) :
|
||||
nx::ServiceAccessControlEntry::ServiceAccessControlEntry(const std::string & name, bool isServer) :
|
||||
mIsServer(isServer),
|
||||
mName(name)
|
||||
{
|
||||
toBytes();
|
||||
}
|
||||
|
||||
nx::SacEntry::SacEntry(const SacEntry & other)
|
||||
nx::ServiceAccessControlEntry::ServiceAccessControlEntry(const ServiceAccessControlEntry & other)
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
|
||||
void nx::SacEntry::operator=(const SacEntry & other)
|
||||
void nx::ServiceAccessControlEntry::operator=(const ServiceAccessControlEntry & other)
|
||||
{
|
||||
if (other.getBytes().size())
|
||||
{
|
||||
|
@ -31,26 +31,26 @@ void nx::SacEntry::operator=(const SacEntry & other)
|
|||
}
|
||||
}
|
||||
|
||||
bool nx::SacEntry::operator==(const SacEntry & other) const
|
||||
bool nx::ServiceAccessControlEntry::operator==(const ServiceAccessControlEntry & other) const
|
||||
{
|
||||
return (mIsServer == other.mIsServer) \
|
||||
&& (mName == other.mName);
|
||||
}
|
||||
|
||||
bool nx::SacEntry::operator!=(const SacEntry & other) const
|
||||
bool nx::ServiceAccessControlEntry::operator!=(const ServiceAccessControlEntry & other) const
|
||||
{
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
|
||||
void nx::SacEntry::toBytes()
|
||||
void nx::ServiceAccessControlEntry::toBytes()
|
||||
{
|
||||
try {
|
||||
mRawBinary.alloc(mName.size() + 1);
|
||||
}
|
||||
catch (const fnd::Exception& e)
|
||||
{
|
||||
throw fnd::Exception(kModuleName, "Failed to allocate memory for SacEntry: " + std::string(e.what()));
|
||||
throw fnd::Exception(kModuleName, "Failed to allocate memory for ServiceAccessControlEntry: " + std::string(e.what()));
|
||||
}
|
||||
|
||||
if (mName.length() == 0)
|
||||
|
@ -68,7 +68,7 @@ void nx::SacEntry::toBytes()
|
|||
memcpy(mRawBinary.data() + 1, mName.c_str(), mName.length());
|
||||
}
|
||||
|
||||
void nx::SacEntry::fromBytes(const byte_t* data, size_t len)
|
||||
void nx::ServiceAccessControlEntry::fromBytes(const byte_t* data, size_t len)
|
||||
{
|
||||
bool isServer = (data[0] & SAC_IS_SERVER) == SAC_IS_SERVER;
|
||||
size_t nameLen = (data[0] & SAC_NAME_LEN_MASK) + 1; // bug?
|
||||
|
@ -94,33 +94,33 @@ void nx::SacEntry::fromBytes(const byte_t* data, size_t len)
|
|||
mName = std::string((const char*)(mRawBinary.data() + 1), nameLen);
|
||||
}
|
||||
|
||||
const fnd::Vec<byte_t>& nx::SacEntry::getBytes() const
|
||||
const fnd::Vec<byte_t>& nx::ServiceAccessControlEntry::getBytes() const
|
||||
{
|
||||
return mRawBinary;
|
||||
}
|
||||
|
||||
void nx::SacEntry::clear()
|
||||
void nx::ServiceAccessControlEntry::clear()
|
||||
{
|
||||
mIsServer = false;
|
||||
mName.clear();
|
||||
}
|
||||
|
||||
bool nx::SacEntry::isServer() const
|
||||
bool nx::ServiceAccessControlEntry::isServer() const
|
||||
{
|
||||
return mIsServer;
|
||||
}
|
||||
|
||||
void nx::SacEntry::setIsServer(bool isServer)
|
||||
void nx::ServiceAccessControlEntry::setIsServer(bool isServer)
|
||||
{
|
||||
mIsServer = isServer;
|
||||
}
|
||||
|
||||
const std::string & nx::SacEntry::getName() const
|
||||
const std::string & nx::ServiceAccessControlEntry::getName() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
void nx::SacEntry::setName(const std::string & name)
|
||||
void nx::ServiceAccessControlEntry::setName(const std::string & name)
|
||||
{
|
||||
if (name.length() > kMaxServiceNameLen)
|
||||
{
|
|
@ -586,7 +586,7 @@ void NpdmProcess::displayFac(const nx::FileSystemAccessControlBinary& fac)
|
|||
}
|
||||
printf("%s", kFsaFlag[fac.getFsaRightsList()[i]].c_str());
|
||||
if (_HAS_BIT(mCliOutputMode, OUTPUT_EXTENDED))
|
||||
printf(" (mask 0x%" PRIx64 ")", _BIT(fac.getFsaRightsList()[i]));
|
||||
printf(" (bit %" PRId32 ")", fac.getFsaRightsList()[i]);
|
||||
printf("%s", fac.getFsaRightsList()[i] != fac.getFsaRightsList().atBack() ? ", " : "\n");
|
||||
|
||||
|
||||
|
@ -616,7 +616,7 @@ void NpdmProcess::displayFac(const nx::FileSystemAccessControlBinary& fac)
|
|||
|
||||
}
|
||||
|
||||
void NpdmProcess::displaySac(const nx::SacBinary& sac)
|
||||
void NpdmProcess::displaySac(const nx::ServiceAccessControlBinary& sac)
|
||||
{
|
||||
printf("[Service Access Control]\n");
|
||||
printf(" Service List:\n");
|
||||
|
|
|
@ -39,6 +39,6 @@ private:
|
|||
void displayAciHdr(const nx::AccessControlInfoBinary& aci);
|
||||
void displayAciDescHdr(const nx::AccessControlInfoDescBinary& aci);
|
||||
void displayFac(const nx::FileSystemAccessControlBinary& fac);
|
||||
void displaySac(const nx::SacBinary& sac);
|
||||
void displaySac(const nx::ServiceAccessControlBinary& sac);
|
||||
void displayKernelCap(const nx::KcBinary& kern);
|
||||
};
|
Loading…
Reference in a new issue