2017-07-07 00:18:33 +00:00
|
|
|
#pragma once
|
|
|
|
#include <string>
|
|
|
|
#include <fnd/types.h>
|
2017-08-05 13:09:50 +00:00
|
|
|
#include <fnd/MemoryBlob.h>
|
2017-07-21 10:30:16 +00:00
|
|
|
#include <fnd/ISerialiseableBinary.h>
|
2018-04-21 09:36:09 +00:00
|
|
|
#include <nx/npdm.h>
|
2017-07-07 00:18:33 +00:00
|
|
|
|
|
|
|
namespace nx
|
|
|
|
{
|
|
|
|
class NpdmHeader :
|
2017-07-21 10:30:16 +00:00
|
|
|
public fnd::ISerialiseableBinary
|
2017-07-07 00:18:33 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct sSection
|
|
|
|
{
|
|
|
|
size_t offset;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
void operator=(const sSection& other)
|
|
|
|
{
|
|
|
|
offset = other.offset;
|
|
|
|
size = other.size;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const sSection& other) const
|
|
|
|
{
|
|
|
|
return (offset == other.offset) \
|
|
|
|
&& (size == other.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator!=(const sSection& other) const
|
|
|
|
{
|
|
|
|
return !operator==(other);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
NpdmHeader();
|
|
|
|
NpdmHeader(const NpdmHeader& other);
|
2018-03-22 05:26:22 +00:00
|
|
|
NpdmHeader(const byte_t* bytes, size_t len);
|
2017-07-07 00:18:33 +00:00
|
|
|
|
|
|
|
bool operator==(const NpdmHeader& other) const;
|
|
|
|
bool operator!=(const NpdmHeader& other) const;
|
|
|
|
void operator=(const NpdmHeader& other);
|
|
|
|
|
|
|
|
// to be used after export
|
2018-03-22 05:26:22 +00:00
|
|
|
const byte_t* getBytes() const;
|
2017-07-07 00:18:33 +00:00
|
|
|
size_t getSize() const;
|
|
|
|
|
|
|
|
// export/import binary
|
|
|
|
void exportBinary();
|
2018-03-22 05:26:22 +00:00
|
|
|
void importBinary(const byte_t* bytes, size_t len);
|
2017-07-07 00:18:33 +00:00
|
|
|
|
|
|
|
// variables
|
2017-07-15 08:28:01 +00:00
|
|
|
void clear();
|
2017-07-07 00:18:33 +00:00
|
|
|
size_t getNpdmSize() const;
|
|
|
|
|
2018-04-21 09:36:09 +00:00
|
|
|
npdm::InstructionType getInstructionType() const;
|
|
|
|
void setInstructionType(npdm::InstructionType type);
|
2017-07-07 00:18:33 +00:00
|
|
|
|
2018-04-21 09:36:09 +00:00
|
|
|
npdm::ProcAddrSpaceType getProcAddressSpaceType() const;
|
|
|
|
void setProcAddressSpaceType(npdm::ProcAddrSpaceType type);
|
2017-07-07 00:18:33 +00:00
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
byte_t getMainThreadPriority() const;
|
|
|
|
void setMainThreadPriority(byte_t priority);
|
2017-07-07 00:18:33 +00:00
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
byte_t getMainThreadCpuId() const;
|
|
|
|
void setMainThreadCpuId(byte_t cpu_id);
|
2017-07-07 00:18:33 +00:00
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
uint32_t getVersion() const;
|
|
|
|
void setVersion(uint32_t version);
|
2017-07-07 00:18:33 +00:00
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
uint32_t getMainThreadStackSize() const;
|
|
|
|
void setMainThreadStackSize(uint32_t size);
|
2017-07-07 00:18:33 +00:00
|
|
|
|
|
|
|
const std::string& getName() const;
|
|
|
|
void setName(const std::string& name);
|
|
|
|
|
|
|
|
const std::string& getProductCode() const;
|
|
|
|
void setProductCode(const std::string& product_code);
|
|
|
|
|
|
|
|
const sSection& getAciPos() const;
|
2017-07-17 08:21:39 +00:00
|
|
|
void setAciSize(size_t size);
|
2017-07-07 00:18:33 +00:00
|
|
|
|
|
|
|
const sSection& getAcidPos() const;
|
2017-07-17 08:21:39 +00:00
|
|
|
void setAcidSize(size_t size);
|
2017-07-07 00:18:33 +00:00
|
|
|
private:
|
|
|
|
const std::string kModuleName = "NPDM_HEADER";
|
2018-04-21 09:36:09 +00:00
|
|
|
|
2017-07-07 00:18:33 +00:00
|
|
|
// raw binary
|
|
|
|
fnd::MemoryBlob mBinaryBlob;
|
|
|
|
|
|
|
|
// variables
|
2018-04-21 09:36:09 +00:00
|
|
|
npdm::InstructionType mInstructionType;
|
|
|
|
npdm::ProcAddrSpaceType mProcAddressSpaceType;
|
2018-03-22 05:26:22 +00:00
|
|
|
byte_t mMainThreadPriority;
|
|
|
|
byte_t mMainThreadCpuId;
|
|
|
|
uint32_t mVersion;
|
|
|
|
uint32_t mMainThreadStackSize;
|
2017-07-07 00:18:33 +00:00
|
|
|
std::string mName;
|
|
|
|
std::string mProductCode;
|
|
|
|
sSection mAciPos;
|
|
|
|
sSection mAcidPos;
|
|
|
|
|
|
|
|
void calculateOffsets();
|
|
|
|
bool isEqual(const NpdmHeader& other) const;
|
|
|
|
void copyFrom(const NpdmHeader& other);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|