[nx] Added nx namespace.

This commit is contained in:
jakcron 2017-07-06 21:17:21 +10:00
parent 01162b8187
commit 7b34bd404d
14 changed files with 450 additions and 420 deletions

View file

@ -1,5 +1,7 @@
#include "AciHeader.h" #include "AciHeader.h"
using namespace nx;
void AciHeader::clearVariables() void AciHeader::clearVariables()
{ {
mType = TYPE_ACI0; mType = TYPE_ACI0;

View file

@ -4,9 +4,11 @@
#include <fnd/memory_blob.h> #include <fnd/memory_blob.h>
#include <nx/ISerialiseableBinary.h> #include <nx/ISerialiseableBinary.h>
class AciHeader : public ISerialiseableBinary namespace nx
{ {
public: class AciHeader : public ISerialiseableBinary
{
public:
enum AciType enum AciType
{ {
TYPE_ACI0, // for Access Control Info TYPE_ACI0, // for Access Control Info
@ -48,7 +50,7 @@ public:
const sSection& getKernelCapabilities() const; const sSection& getKernelCapabilities() const;
void setKernelCapabilities(u32 size); void setKernelCapabilities(u32 size);
private: private:
const std::string kModuleName = "ACI_HEADER"; const std::string kModuleName = "ACI_HEADER";
const std::string kAciStructSig = "ACI0"; const std::string kAciStructSig = "ACI0";
const std::string kAciDescStructSig = "ACID"; const std::string kAciDescStructSig = "ACID";
@ -105,5 +107,6 @@ private:
void calculateSectionOffsets(); void calculateSectionOffsets();
bool isEqual(const AciHeader& other) const; bool isEqual(const AciHeader& other) const;
void copyFrom(const AciHeader& other); void copyFrom(const AciHeader& other);
}; };
}

View file

@ -1,6 +1,6 @@
#include "FacBinary.h" #include "FacBinary.h"
using namespace nx;
FacBinary::FacBinary() : FacBinary::FacBinary() :
mHeader() mHeader()

View file

@ -5,10 +5,12 @@
#include <nx/ISerialiseableBinary.h> #include <nx/ISerialiseableBinary.h>
#include <nx/FacHeader.h> #include <nx/FacHeader.h>
class FacBinary : namespace nx
public ISerialiseableBinary
{ {
public: class FacBinary :
public ISerialiseableBinary
{
public:
enum FsAccessFlag enum FsAccessFlag
{ {
FSA_APPLICATION_INFO = BIT(0), FSA_APPLICATION_INFO = BIT(0),
@ -62,7 +64,7 @@ public:
const fnd::List<u32>& getSaveDataOwnerIds() const; const fnd::List<u32>& getSaveDataOwnerIds() const;
void addSaveDataOwnerId(u32 id); void addSaveDataOwnerId(u32 id);
private: private:
const std::string kModuleName = "FAC_BINARY"; const std::string kModuleName = "FAC_BINARY";
// raw binary // raw binary
@ -77,5 +79,6 @@ private:
void clearVariables(); void clearVariables();
bool isEqual(const FacBinary& other) const; bool isEqual(const FacBinary& other) const;
void copyFrom(const FacBinary& other); void copyFrom(const FacBinary& other);
}; };
}

View file

@ -1,6 +1,6 @@
#include "FacHeader.h" #include "FacHeader.h"
using namespace nx;
FacHeader::FacHeader() FacHeader::FacHeader()
{ {

View file

@ -3,10 +3,12 @@
#include <fnd/memory_blob.h> #include <fnd/memory_blob.h>
#include <nx/ISerialiseableBinary.h> #include <nx/ISerialiseableBinary.h>
class FacHeader : namespace nx
public ISerialiseableBinary
{ {
public: class FacHeader :
public ISerialiseableBinary
{
public:
FacHeader(); FacHeader();
FacHeader(const FacHeader& other); FacHeader(const FacHeader& other);
FacHeader(const u8* bytes); FacHeader(const u8* bytes);
@ -38,7 +40,7 @@ public:
size_t getSaveDataOwnerIdSize() const; size_t getSaveDataOwnerIdSize() const;
void setSaveDataOwnerIdSize(size_t size); void setSaveDataOwnerIdSize(size_t size);
private: private:
const std::string kModuleName = "FAC_HEADER"; const std::string kModuleName = "FAC_HEADER";
static const u32 kFacFormatVersion = 1; static const u32 kFacFormatVersion = 1;
@ -80,7 +82,8 @@ private:
// variables // variables
u64 mFsaRights; u64 mFsaRights;
struct sSection { struct sSection
{
size_t offset; size_t offset;
size_t size; size_t size;
} mContentOwnerIdPos, mSaveDataOwnerIdPos; } mContentOwnerIdPos, mSaveDataOwnerIdPos;
@ -89,5 +92,6 @@ private:
void calculateOffsets(); void calculateOffsets();
bool isEqual(const FacHeader& other) const; bool isEqual(const FacHeader& other) const;
void copyFrom(const FacHeader& other); void copyFrom(const FacHeader& other);
}; };
}

View file

@ -1,9 +1,11 @@
#pragma once #pragma once
#include <fnd/types.h> #include <fnd/types.h>
class ISerialiseableBinary namespace nx
{ {
public: class ISerialiseableBinary
{
public:
//virtual bool operator==(const ISerialiseableBinary& other) = 0; //virtual bool operator==(const ISerialiseableBinary& other) = 0;
//virtual void operator=(const ISerialiseableBinary& other) = 0; //virtual void operator=(const ISerialiseableBinary& other) = 0;
@ -13,5 +15,6 @@ public:
virtual void exportBinary() = 0; virtual void exportBinary() = 0;
virtual void importBinary(const u8* bytes) = 0; virtual void importBinary(const u8* bytes) = 0;
virtual void importBinary(const u8* bytes, size_t len) = 0; virtual void importBinary(const u8* bytes, size_t len) = 0;
}; };
}

View file

@ -1,6 +1,9 @@
#include "NcaHeader.h" #include "NcaHeader.h"
#include <fnd/exception.h> #include <fnd/exception.h>
using namespace nx;
void NcaHeader::exportBinary() void NcaHeader::exportBinary()
{ {
mBinaryBlob.alloc(sizeof(sNcaHeader)); mBinaryBlob.alloc(sizeof(sNcaHeader));

View file

@ -7,9 +7,11 @@
#include <crypto/sha.h> #include <crypto/sha.h>
#include <nx/ISerialiseableBinary.h> #include <nx/ISerialiseableBinary.h>
class NcaHeader : public ISerialiseableBinary namespace nx
{ {
public: class NcaHeader : public ISerialiseableBinary
{
public:
struct sSection struct sSection
{ {
u64 offset; u64 offset;
@ -71,7 +73,7 @@ public:
const fnd::List<crypto::aes::sAes128Key>& getAesKeys() const; const fnd::List<crypto::aes::sAes128Key>& getAesKeys() const;
void addKey(const crypto::aes::sAes128Key& key); void addKey(const crypto::aes::sAes128Key& key);
private: private:
const std::string kModuleName = "NCA_HEADER"; const std::string kModuleName = "NCA_HEADER";
const std::string kNcaSig = "NCA2"; const std::string kNcaSig = "NCA2";
static const size_t kSectionNum = 4; static const size_t kSectionNum = 4;
@ -152,4 +154,6 @@ private:
u32 sizeToBlockNum(u64 real_size) const; u32 sizeToBlockNum(u64 real_size) const;
bool isEqual(const NcaHeader& other) const; bool isEqual(const NcaHeader& other) const;
void copyFrom(const NcaHeader& other); void copyFrom(const NcaHeader& other);
}; };
}

View file

@ -1,6 +1,6 @@
#include "SacBinary.h" #include "SacBinary.h"
using namespace nx;
SacBinary::SacBinary() SacBinary::SacBinary()
{ {

View file

@ -6,10 +6,12 @@
#include <nx/ISerialiseableBinary.h> #include <nx/ISerialiseableBinary.h>
#include <nx/SacEntry.h> #include <nx/SacEntry.h>
class SacBinary : namespace nx
public ISerialiseableBinary
{ {
public: class SacBinary :
public ISerialiseableBinary
{
public:
SacBinary(); SacBinary();
SacBinary(const SacBinary& other); SacBinary(const SacBinary& other);
SacBinary(const u8* bytes, size_t len); SacBinary(const u8* bytes, size_t len);
@ -30,7 +32,7 @@ public:
// variables // variables
const fnd::List<SacEntry>& getServiceList() const; const fnd::List<SacEntry>& getServiceList() const;
void addService(const SacEntry& service); void addService(const SacEntry& service);
private: private:
const std::string kModuleName = "SAC_BINARY"; const std::string kModuleName = "SAC_BINARY";
// raw binary // raw binary
@ -42,5 +44,6 @@ private:
void clearVariables(); void clearVariables();
bool isEqual(const SacBinary& other) const; bool isEqual(const SacBinary& other) const;
void copyFrom(const SacBinary& other); void copyFrom(const SacBinary& other);
}; };
}

View file

@ -1,5 +1,7 @@
#include "SacEntry.h" #include "SacEntry.h"
using namespace nx;
SacEntry::SacEntry() : SacEntry::SacEntry() :
mIsServer(false), mIsServer(false),
mName("") mName("")

View file

@ -4,9 +4,11 @@
#include <fnd/memory_blob.h> #include <fnd/memory_blob.h>
#include <nx/ISerialiseableBinary.h> #include <nx/ISerialiseableBinary.h>
class SacEntry : public ISerialiseableBinary namespace nx
{ {
public: class SacEntry : public ISerialiseableBinary
{
public:
SacEntry(); SacEntry();
SacEntry(const std::string& name, bool isServer); SacEntry(const std::string& name, bool isServer);
SacEntry(const SacEntry& other); SacEntry(const SacEntry& other);
@ -29,14 +31,14 @@ public:
void setIsServer(bool isServer); void setIsServer(bool isServer);
const std::string& getName() const; const std::string& getName() const;
void setName(const std::string& name); void setName(const std::string& name);
private: private:
const std::string kModuleName = "SAC_ENTRY"; const std::string kModuleName = "SAC_ENTRY";
static const size_t kMaxServiceNameLen = 8; static const size_t kMaxServiceNameLen = 8;
enum SacEntryFlag enum SacEntryFlag
{ {
SAC_IS_SERVER = BIT(7), SAC_IS_SERVER = BIT(7),
SAC_NAME_LEN_MASK = BIT(7)-1 SAC_NAME_LEN_MASK = BIT(7) - 1
}; };
// raw binary // raw binary
@ -48,4 +50,5 @@ private:
bool isEqual(const SacEntry& other) const; bool isEqual(const SacEntry& other) const;
void copyFrom(const SacEntry& other); void copyFrom(const SacEntry& other);
}; };
}

View file

@ -6,7 +6,7 @@
#include <nx/NcaHeader.h> #include <nx/NcaHeader.h>
#include <inttypes.h> #include <inttypes.h>
const size_t kNcaSectorSize = NcaHeader::kDefaultBlockSize; const size_t kNcaSectorSize = nx::NcaHeader::kDefaultBlockSize;
void initNcaCtr(u8 ctr[crypto::aes::kAesBlockSize], u32 generation) void initNcaCtr(u8 ctr[crypto::aes::kAesBlockSize], u32 generation)
{ {
@ -69,7 +69,7 @@ int main(int argc, char** argv)
{ {
decryptNcaSectorXts(nca, sector, 1, nx::crypto::aes::nca_header_key[0], nx::crypto::aes::nca_header_key[1]); decryptNcaSectorXts(nca, sector, 1, nx::crypto::aes::nca_header_key[0], nx::crypto::aes::nca_header_key[1]);
NcaHeader hdr; nx::NcaHeader hdr;
hdr.importBinary(sector); hdr.importBinary(sector);
printf("[NCA Header]\n"); printf("[NCA Header]\n");
@ -79,7 +79,7 @@ int main(int argc, char** argv)
printf(" Sections:\n"); printf(" Sections:\n");
for (size_t i = 0; i < hdr.getSections().getSize(); i++) for (size_t i = 0; i < hdr.getSections().getSize(); i++)
{ {
const NcaHeader::sSection& section = hdr.getSections()[i]; const nx::NcaHeader::sSection& section = hdr.getSections()[i];
printf(" %lu:\n", i); printf(" %lu:\n", i);
//printf(" Start Blk: %" PRId32 "\n", section.start_blk); //printf(" Start Blk: %" PRId32 "\n", section.start_blk);
//printf(" End Blk: %" PRId32 "\n", section.end_blk); //printf(" End Blk: %" PRId32 "\n", section.end_blk);