nstool/lib/libhac/source/KernelCapabilityBinary.cpp

231 lines
6.2 KiB
C++
Raw Normal View History

2018-08-07 07:17:51 +00:00
#include <nn/hac/KernelCapabilityBinary.h>
2018-08-07 07:17:51 +00:00
nn::hac::KernelCapabilityBinary::KernelCapabilityBinary()
{}
2018-08-07 07:17:51 +00:00
nn::hac::KernelCapabilityBinary::KernelCapabilityBinary(const KernelCapabilityBinary & other)
{
2018-06-24 08:18:54 +00:00
*this = other;
}
2018-08-07 07:17:51 +00:00
void nn::hac::KernelCapabilityBinary::operator=(const KernelCapabilityBinary & other)
{
2018-06-24 08:18:54 +00:00
clear();
mRawBinary = other.mRawBinary;
2018-06-24 08:18:54 +00:00
mThreadInfo = other.mThreadInfo;
mSystemCalls = other.mSystemCalls;
mMemoryMap = other.mMemoryMap;
mInterupts = other.mInterupts;
mMiscParams = other.mMiscParams;
mKernelVersion = other.mKernelVersion;
mHandleTableSize = other.mHandleTableSize;
mMiscFlags = other.mMiscFlags;
}
2018-08-07 07:17:51 +00:00
bool nn::hac::KernelCapabilityBinary::operator==(const KernelCapabilityBinary & other) const
{
2018-06-24 08:18:54 +00:00
return (mThreadInfo == other.mThreadInfo) \
&& (mSystemCalls == other.mSystemCalls) \
&& (mMemoryMap == other.mMemoryMap) \
&& (mInterupts == other.mInterupts) \
&& (mMiscParams == other.mMiscParams) \
&& (mKernelVersion == other.mKernelVersion) \
&& (mHandleTableSize == other.mHandleTableSize) \
&& (mMiscFlags == other.mMiscFlags);
}
2018-08-07 07:17:51 +00:00
bool nn::hac::KernelCapabilityBinary::operator!=(const KernelCapabilityBinary & other) const
{
2018-06-24 08:18:54 +00:00
return !(*this == other);
}
2018-08-07 07:17:51 +00:00
void nn::hac::KernelCapabilityBinary::toBytes()
{
fnd::List<KernelCapabilityEntry> caps;
// get kernel capabiliteis
mThreadInfo.exportKernelCapabilityList(caps);
mSystemCalls.exportKernelCapabilityList(caps);
mMemoryMap.exportKernelCapabilityList(caps);
mInterupts.exportKernelCapabilityList(caps);
mMiscParams.exportKernelCapabilityList(caps);
mKernelVersion.exportKernelCapabilityList(caps);
mHandleTableSize.exportKernelCapabilityList(caps);
mMiscFlags.exportKernelCapabilityList(caps);
// allocate memory
2018-06-24 08:18:54 +00:00
mRawBinary.alloc(caps.size() * sizeof(uint32_t));
// write to binary
2018-06-24 08:18:54 +00:00
uint32_t* raw_caps = (uint32_t*)mRawBinary.data();
for (size_t i = 0; i < caps.size(); i++)
{
raw_caps[i] = le_word(caps[i].getCap());
}
}
2018-08-07 07:17:51 +00:00
void nn::hac::KernelCapabilityBinary::fromBytes(const byte_t * data, size_t len)
{
2018-03-22 05:26:22 +00:00
if ((len % sizeof(uint32_t)) != 0)
{
throw fnd::Exception(kModuleName, "KernelCapabilityEntry list must be aligned to 4 bytes");
}
// save copy of KernelCapabilityBinary
2018-06-24 08:18:54 +00:00
mRawBinary.alloc(len);
memcpy(mRawBinary.data(), data, len);
fnd::List<KernelCapabilityEntry> threadInfoCaps;
fnd::List<KernelCapabilityEntry> systemCallCaps;
fnd::List<KernelCapabilityEntry> memoryMapCaps;
fnd::List<KernelCapabilityEntry> interuptCaps;
fnd::List<KernelCapabilityEntry> miscParamCaps;
fnd::List<KernelCapabilityEntry> kernelVersionCaps;
fnd::List<KernelCapabilityEntry> handleTableSizeCaps;
fnd::List<KernelCapabilityEntry> miscFlagsCaps;
2018-06-24 08:18:54 +00:00
const uint32_t* raw_caps = (const uint32_t*)mRawBinary.data();
size_t cap_num = mRawBinary.size() / sizeof(uint32_t);
KernelCapabilityEntry cap;
for (size_t i = 0; i < cap_num; i++)
{
cap.setCap(le_word(raw_caps[i]));
switch (cap.getType())
{
case (kc::KC_THREAD_INFO) :
threadInfoCaps.addElement(cap);
break;
case (kc::KC_ENABLE_SYSTEM_CALLS):
systemCallCaps.addElement(cap);
break;
case (kc::KC_MEMORY_MAP):
case (kc::KC_IO_MEMORY_MAP):
memoryMapCaps.addElement(cap);
break;
case (kc::KC_ENABLE_INTERUPTS):
interuptCaps.addElement(cap);
break;
case (kc::KC_MISC_PARAMS):
miscParamCaps.addElement(cap);
break;
case (kc::KC_KERNEL_VERSION):
kernelVersionCaps.addElement(cap);
break;
case (kc::KC_HANDLE_TABLE_SIZE):
handleTableSizeCaps.addElement(cap);
break;
case (kc::KC_MISC_FLAGS):
miscFlagsCaps.addElement(cap);
break;
default:
throw fnd::Exception(kModuleName, "Unsupported kernel capability type");
}
}
mThreadInfo.importKernelCapabilityList(threadInfoCaps);
mSystemCalls.importKernelCapabilityList(systemCallCaps);
mMemoryMap.importKernelCapabilityList(memoryMapCaps);
mInterupts.importKernelCapabilityList(interuptCaps);
mMiscParams.importKernelCapabilityList(miscParamCaps);
mKernelVersion.importKernelCapabilityList(kernelVersionCaps);
mHandleTableSize.importKernelCapabilityList(handleTableSizeCaps);
mMiscFlags.importKernelCapabilityList(miscFlagsCaps);
}
2018-08-07 07:17:51 +00:00
const fnd::Vec<byte_t>& nn::hac::KernelCapabilityBinary::getBytes() const
2018-06-24 08:18:54 +00:00
{
return mRawBinary;
}
2018-08-07 07:17:51 +00:00
void nn::hac::KernelCapabilityBinary::clear()
{
2018-06-24 08:18:54 +00:00
mRawBinary.clear();
mThreadInfo.clear();
mSystemCalls.clear();
mMemoryMap.clear();
mInterupts.clear();
mMiscParams.clear();
mKernelVersion.clear();
mHandleTableSize.clear();
mMiscFlags.clear();
}
2018-08-07 07:17:51 +00:00
const nn::hac::ThreadInfoHandler & nn::hac::KernelCapabilityBinary::getThreadInfo() const
{
return mThreadInfo;
}
2018-08-07 07:17:51 +00:00
nn::hac::ThreadInfoHandler & nn::hac::KernelCapabilityBinary::getThreadInfo()
{
return mThreadInfo;
}
2018-08-07 07:17:51 +00:00
const nn::hac::SystemCallHandler & nn::hac::KernelCapabilityBinary::getSystemCalls() const
{
return mSystemCalls;
}
2018-08-07 07:17:51 +00:00
nn::hac::SystemCallHandler & nn::hac::KernelCapabilityBinary::getSystemCalls()
{
return mSystemCalls;
}
2018-08-07 07:17:51 +00:00
const nn::hac::MemoryMappingHandler & nn::hac::KernelCapabilityBinary::getMemoryMaps() const
{
return mMemoryMap;
}
2018-08-07 07:17:51 +00:00
nn::hac::MemoryMappingHandler & nn::hac::KernelCapabilityBinary::getMemoryMaps()
{
return mMemoryMap;
}
2018-08-07 07:17:51 +00:00
const nn::hac::InteruptHandler & nn::hac::KernelCapabilityBinary::getInterupts() const
{
return mInterupts;
}
2018-08-07 07:17:51 +00:00
nn::hac::InteruptHandler & nn::hac::KernelCapabilityBinary::getInterupts()
{
return mInterupts;
}
2018-08-07 07:17:51 +00:00
const nn::hac::MiscParamsHandler & nn::hac::KernelCapabilityBinary::getMiscParams() const
{
return mMiscParams;
}
2018-08-07 07:17:51 +00:00
nn::hac::MiscParamsHandler & nn::hac::KernelCapabilityBinary::getMiscParams()
{
return mMiscParams;
}
2018-08-07 07:17:51 +00:00
const nn::hac::KernelVersionHandler & nn::hac::KernelCapabilityBinary::getKernelVersion() const
{
return mKernelVersion;
}
2018-08-07 07:17:51 +00:00
nn::hac::KernelVersionHandler & nn::hac::KernelCapabilityBinary::getKernelVersion()
{
return mKernelVersion;
}
2018-08-07 07:17:51 +00:00
const nn::hac::HandleTableSizeHandler & nn::hac::KernelCapabilityBinary::getHandleTableSize() const
{
return mHandleTableSize;
}
2018-08-07 07:17:51 +00:00
nn::hac::HandleTableSizeHandler & nn::hac::KernelCapabilityBinary::getHandleTableSize()
{
return mHandleTableSize;
}
2018-08-07 07:17:51 +00:00
const nn::hac::MiscFlagsHandler & nn::hac::KernelCapabilityBinary::getMiscFlags() const
{
return mMiscFlags;
}
2018-08-07 07:17:51 +00:00
nn::hac::MiscFlagsHandler & nn::hac::KernelCapabilityBinary::getMiscFlags()
{
return mMiscFlags;
2018-06-24 08:18:54 +00:00
}