nstool/lib/libhac/include/nn/hac/NsoHeader.h

149 lines
3.2 KiB
C
Raw Normal View History

2018-05-27 12:33:21 +00:00
#pragma once
2018-08-07 09:31:06 +00:00
#include <cstring>
2018-08-07 07:17:51 +00:00
#include <nn/hac/nso.h>
2018-06-24 08:18:54 +00:00
#include <fnd/ISerialisable.h>
2018-05-27 12:33:21 +00:00
#include <fnd/List.h>
2018-08-07 07:17:51 +00:00
namespace nn
{
namespace hac
2018-05-27 12:33:21 +00:00
{
class NsoHeader :
2018-06-24 08:18:54 +00:00
public fnd::ISerialisable
2018-05-27 12:33:21 +00:00
{
public:
struct sModuleId
{
2018-06-04 04:00:28 +00:00
byte_t data[nso::kModuleIdSize];
void operator=(const sModuleId& other)
{
2018-06-04 04:00:28 +00:00
memcpy(data, other.data, nso::kModuleIdSize);
}
bool operator==(const sModuleId& other) const
{
2018-06-04 04:00:28 +00:00
return memcmp(data, other.data, nso::kModuleIdSize) == 0;
}
bool operator!=(const sModuleId& other) const
{
return !(*this == other);
}
};
struct sLayout
{
uint32_t offset;
uint32_t size;
void operator=(const sLayout& other)
{
offset = other.offset;
size = other.size;
}
bool operator==(const sLayout& other) const
{
return (offset == other.offset) \
&& (size == other.size);
}
bool operator!=(const sLayout& other) const
{
return !(*this == other);
}
};
struct sCodeSegment
{
sLayout file_layout;
sLayout memory_layout;
bool is_compressed;
bool is_hashed;
fnd::sha::sSha256Hash hash;
void operator=(const sCodeSegment& other)
{
file_layout = other.file_layout;
memory_layout = other.memory_layout;
is_compressed = other.is_compressed;
is_hashed = other.is_hashed;
hash = other.hash;
}
bool operator==(const sCodeSegment& other) const
{
return (file_layout == other.file_layout) \
&& (memory_layout == other.memory_layout) \
&& (is_compressed == other.is_compressed) \
&& (is_hashed == other.is_hashed) \
&& (hash == other.hash);
}
bool operator!=(const sCodeSegment& other) const
{
return !(*this == other);
}
};
2018-05-27 12:33:21 +00:00
NsoHeader();
NsoHeader(const NsoHeader& other);
2018-06-24 08:18:54 +00:00
void operator=(const NsoHeader& other);
2018-05-27 12:33:21 +00:00
bool operator==(const NsoHeader& other) const;
bool operator!=(const NsoHeader& other) const;
// export/import binary
2018-06-24 08:18:54 +00:00
void toBytes();
void fromBytes(const byte_t* bytes, size_t len);
const fnd::Vec<byte_t>& getBytes() const;
2018-05-27 12:33:21 +00:00
// variables
void clear();
const sModuleId& getModuleId() const;
void setModuleId(const sModuleId& id);
uint32_t getBssSize() const;
void setBssSize(uint32_t size);
const sCodeSegment& getTextSegmentInfo() const;
void setTextSegmentInfo(const sCodeSegment& info);
const sCodeSegment& getRoSegmentInfo() const;
void setRoSegmentInfo(const sCodeSegment& info);
const sCodeSegment& getDataSegmentInfo() const;
void setDataSegmentInfo(const sCodeSegment& info);
const sLayout& getModuleNameInfo() const;
void setModuleNameInfo(const sLayout& info);
const sLayout& getRoEmbeddedInfo() const;
void setRoEmbeddedInfo(const sLayout& info);
const sLayout& getRoDynStrInfo() const;
void setRoDynStrInfo(const sLayout& info);
2018-05-27 12:33:21 +00:00
const sLayout& getRoDynSymInfo() const;
void setRoDynSymInfo(const sLayout& info);
2018-05-27 12:33:21 +00:00
private:
const std::string kModuleName = "NSO_HEADER";
// binary
2018-06-24 08:18:54 +00:00
fnd::Vec<byte_t> mRawBinary;
2018-05-27 12:33:21 +00:00
// data
sModuleId mModuleId;
uint32_t mBssSize;
sCodeSegment mTextSegmentInfo;
sCodeSegment mRoSegmentInfo;
sCodeSegment mDataSegmentInfo;
sLayout mModuleNameInfo;
sLayout mRoEmbeddedInfo;
sLayout mRoDynStrInfo;
sLayout mRoDynSymInfo;
2018-05-27 12:33:21 +00:00
};
2018-08-07 07:17:51 +00:00
}
2018-05-27 12:33:21 +00:00
}