nstool/lib/libnx/include/nx/PfsHeader.h

103 lines
2.1 KiB
C
Raw Normal View History

2017-07-18 14:17:32 +00:00
#pragma once
#include <string>
#include <fnd/types.h>
2018-06-24 08:18:54 +00:00
#include <fnd/ISerialisable.h>
2017-07-18 14:17:32 +00:00
#include <fnd/List.h>
#include <nx/pfs.h>
2017-07-18 14:17:32 +00:00
namespace nx
{
class PfsHeader :
2018-06-24 08:18:54 +00:00
public fnd::ISerialisable
2017-07-18 14:17:32 +00:00
{
public:
enum FsType
{
TYPE_PFS0,
TYPE_HFS0
};
2017-07-18 14:17:32 +00:00
struct sFile
{
std::string name;
size_t offset;
size_t size;
size_t hash_protected_size;
crypto::sha::sSha256Hash hash;
2017-07-18 14:17:32 +00:00
sFile& operator=(const sFile& other)
{
name = other.name;
offset = other.offset;
size = other.size;
hash_protected_size = other.hash_protected_size;
hash = other.hash;
2017-07-18 14:17:32 +00:00
return *this;
}
bool operator==(const sFile& other) const
{
return (name == other.name) \
&& (offset == other.offset) \
&& (size == other.size) \
&& (hash_protected_size == other.hash_protected_size) \
&& (hash == other.hash);
2017-07-18 14:17:32 +00:00
}
bool operator!=(const sFile& other) const
{
return !operator==(other);
}
bool operator==(const std::string& other) const
{
return (name == other);
}
bool operator!=(const std::string& other) const
{
return !operator==(other);
}
};
PfsHeader();
PfsHeader(const PfsHeader& other);
2018-06-24 08:18:54 +00:00
void operator=(const PfsHeader& other);
2017-07-18 14:17:32 +00:00
bool operator==(const PfsHeader& other) const;
bool operator!=(const PfsHeader& other) const;
// to be used after export
size_t getSize() 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;
2017-07-18 14:17:32 +00:00
// variables
void clear();
FsType getFsType() const;
void setFsType(FsType type);
2017-07-18 14:17:32 +00:00
const fnd::List<sFile>& getFileList() const;
void addFile(const std::string& name, size_t size);
void addFile(const std::string& name, size_t size, size_t hash_protected_size, const crypto::sha::sSha256Hash& hash);
2017-07-18 14:17:32 +00:00
private:
const std::string kModuleName = "PFS_HEADER";
// binary blob
2018-06-24 08:18:54 +00:00
fnd::Vec<byte_t> mRawBinary;
2017-07-18 14:17:32 +00:00
// variables
FsType mFsType;
2017-07-18 14:17:32 +00:00
fnd::List<sFile> mFileList;
size_t getFileEntrySize(FsType fs_type);
2017-07-18 14:17:32 +00:00
void calculateOffsets(size_t data_offset);
};
}