From f734f8b4c64ea7d42be6b1ec8591bb664cee4875 Mon Sep 17 00:00:00 2001 From: jakcron Date: Sun, 3 Oct 2021 10:47:54 +0800 Subject: [PATCH] Move old RomfsProcess header to not_ported. --- src/not_ported/RomfsProcess.h | 136 ++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 src/not_ported/RomfsProcess.h diff --git a/src/not_ported/RomfsProcess.h b/src/not_ported/RomfsProcess.h new file mode 100644 index 0000000..35575c4 --- /dev/null +++ b/src/not_ported/RomfsProcess.h @@ -0,0 +1,136 @@ +#pragma once +#include "types.h" + +#include + +namespace nstool { + +class RomfsProcess +{ +public: + struct sDirectory; + struct sFile; + + struct sDirectory + { + std::string name; + std::vector dir_list; + std::vector file_list; + + void operator=(const sDirectory& other) + { + name = other.name; + dir_list = other.dir_list; + file_list = other.file_list; + } + + bool operator==(const sDirectory& other) const + { + return (name == other.name) \ + && (dir_list == other.dir_list) \ + && (file_list == other.file_list); + } + + bool operator!=(const sDirectory& other) const + { + return !operator==(other); + } + + bool operator==(const std::string& other) const + { + return (name == other); + } + }; + + struct sFile + { + std::string name; + int64_t offset; + int64_t size; + + void operator=(const sFile& other) + { + name = other.name; + offset = other.offset; + size = other.size; + } + + bool operator==(const sFile& other) const + { + return (name == other.name) \ + && (offset == other.offset) \ + && (size == other.size); + } + + bool operator!=(const sFile& other) const + { + return !operator==(other); + } + + bool operator==(const std::string& other) const + { + return (name == other); + } + }; + + RomfsProcess(); + + void process(); + + // generic + void setInputFile(const std::shared_ptr& file); + void setCliOutputMode(CliOutputMode type); + void setVerifyMode(bool verify); + + // romfs specific + void setMountPointName(const std::string& mount_name); + void setExtractPath(const tc::io::Path& path); + void setListFs(bool list_fs); + + const sDirectory& getRootDir() const; +private: + const std::string kModuleName = "RomfsProcess"; + static const size_t kCacheSize = 0x10000; + + std::shared_ptr mFile; + CliOutputMode mCliOutputMode; + bool mShowBasicInfo; + bool mShowExtendedInfo; + bool mShowLayoutInfo; + bool mShowKeydata; + bool mVerbose; + bool mVerify; + + tc::Optional mExtractPath; + std::string mMountName; + bool mListFs; + + tc::ByteData mCache; + + size_t mDirNum; + size_t mFileNum; + nn::hac::sRomfsHeader mHdr; + tc::ByteData mDirNodes; + tc::ByteData mFileNodes; + sDirectory mRootDir; + + inline nn::hac::sRomfsDirEntry* get_dir_node(uint32_t offset) { return (nn::hac::sRomfsDirEntry*)(mDirNodes.data() + offset); } + inline nn::hac::sRomfsFileEntry* get_file_node(uint32_t offset) { return (nn::hac::sRomfsFileEntry*)(mFileNodes.data() + offset); } + + + void printTab(size_t tab) const; + void displayFile(const sFile& file, size_t tab) const; + void displayDir(const sDirectory& dir, size_t tab) const; + + void displayHeader(); + void displayFs(); + + void extractDir(const std::string& path, const sDirectory& dir); + void extractFs(); + + bool validateHeaderLayout(const nn::hac::sRomfsHeader* hdr) const; + void importDirectory(uint32_t dir_offset, sDirectory& dir); + void resolveRomfs(); +}; + +} \ No newline at end of file