mirror of
https://github.com/jakcron/nstool
synced 2024-11-23 05:59:29 +00:00
155 lines
3.5 KiB
C
155 lines
3.5 KiB
C
|
#pragma once
|
||
|
#include "types.h"
|
||
|
#include <string>
|
||
|
#include <vector>
|
||
|
#include <tc/Optional.h>
|
||
|
#include <tc/io.h>
|
||
|
|
||
|
#include "KeyBag.h"
|
||
|
|
||
|
namespace nstool {
|
||
|
|
||
|
struct Settings
|
||
|
{
|
||
|
enum FileType
|
||
|
{
|
||
|
FILE_TYPE_ERROR,
|
||
|
FILE_TYPE_GAMECARD,
|
||
|
FILE_TYPE_NSP,
|
||
|
FILE_TYPE_PARTITIONFS,
|
||
|
FILE_TYPE_ROMFS,
|
||
|
FILE_TYPE_NCA,
|
||
|
FILE_TYPE_META,
|
||
|
FILE_TYPE_CNMT,
|
||
|
FILE_TYPE_NSO,
|
||
|
FILE_TYPE_NRO,
|
||
|
FILE_TYPE_NACP,
|
||
|
FILE_TYPE_INI,
|
||
|
FILE_TYPE_KIP,
|
||
|
FILE_TYPE_PKI_CERT,
|
||
|
FILE_TYPE_ES_TIK,
|
||
|
FILE_TYPE_HB_ASSET,
|
||
|
};
|
||
|
|
||
|
struct InputFileOptions
|
||
|
{
|
||
|
FileType filetype;
|
||
|
tc::Optional<tc::io::Path> path;
|
||
|
} infile;
|
||
|
|
||
|
struct Options
|
||
|
{
|
||
|
CliOutputMode cli_output_mode;
|
||
|
bool verify;
|
||
|
bool is_dev;
|
||
|
KeyBag keybag;
|
||
|
} opt;
|
||
|
|
||
|
// code options
|
||
|
struct CodeOptions
|
||
|
{
|
||
|
bool list_api;
|
||
|
bool list_symbols;
|
||
|
bool is_64bit_instruction; // true=64bit, false=32bit
|
||
|
} code;
|
||
|
|
||
|
// Generic FS options
|
||
|
struct FsOptions
|
||
|
{
|
||
|
bool show_fs_tree;
|
||
|
tc::Optional<tc::io::Path> extract_path;
|
||
|
} fs;
|
||
|
|
||
|
// XCI options
|
||
|
struct XciOptions
|
||
|
{
|
||
|
tc::Optional<tc::io::Path> update_extract_path;
|
||
|
tc::Optional<tc::io::Path> logo_extract_path;
|
||
|
tc::Optional<tc::io::Path> normal_extract_path;
|
||
|
tc::Optional<tc::io::Path> secure_extract_path;
|
||
|
} xci;
|
||
|
|
||
|
// NCA options
|
||
|
struct NcaOptions
|
||
|
{
|
||
|
tc::Optional<tc::io::Path> part0_extract_path;
|
||
|
tc::Optional<tc::io::Path> part1_extract_path;
|
||
|
tc::Optional<tc::io::Path> part2_extract_path;
|
||
|
tc::Optional<tc::io::Path> part3_extract_path;
|
||
|
} nca;
|
||
|
|
||
|
// KIP options
|
||
|
struct KipOptions
|
||
|
{
|
||
|
tc::Optional<tc::io::Path> extract_path;
|
||
|
} kip;
|
||
|
|
||
|
// ASET Options
|
||
|
struct AsetOptions
|
||
|
{
|
||
|
tc::Optional<tc::io::Path> icon_extract_path;
|
||
|
tc::Optional<tc::io::Path> nacp_extract_path;
|
||
|
} aset;
|
||
|
|
||
|
Settings()
|
||
|
{
|
||
|
infile.filetype = FILE_TYPE_ERROR;
|
||
|
infile.path = tc::Optional<tc::io::Path>();
|
||
|
|
||
|
opt.cli_output_mode = CliOutputMode();
|
||
|
opt.verify = false;
|
||
|
opt.is_dev = false;
|
||
|
opt.keybag = KeyBag();
|
||
|
|
||
|
code.list_api = false;
|
||
|
code.list_symbols = false;
|
||
|
code.is_64bit_instruction = true;
|
||
|
|
||
|
xci.update_extract_path = tc::Optional<tc::io::Path>();
|
||
|
xci.logo_extract_path = tc::Optional<tc::io::Path>();
|
||
|
xci.normal_extract_path = tc::Optional<tc::io::Path>();
|
||
|
xci.secure_extract_path = tc::Optional<tc::io::Path>();
|
||
|
|
||
|
fs.show_fs_tree = false;
|
||
|
fs.extract_path = tc::Optional<tc::io::Path>();
|
||
|
|
||
|
nca.part0_extract_path = tc::Optional<tc::io::Path>();
|
||
|
nca.part1_extract_path = tc::Optional<tc::io::Path>();
|
||
|
nca.part2_extract_path = tc::Optional<tc::io::Path>();
|
||
|
nca.part3_extract_path = tc::Optional<tc::io::Path>();
|
||
|
|
||
|
kip.extract_path = tc::Optional<tc::io::Path>();
|
||
|
|
||
|
aset.icon_extract_path = tc::Optional<tc::io::Path>();
|
||
|
aset.nacp_extract_path = tc::Optional<tc::io::Path>();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
class SettingsInitializer : public Settings
|
||
|
{
|
||
|
public:
|
||
|
SettingsInitializer(const std::vector<std::string>& args);
|
||
|
private:
|
||
|
void parse_args(const std::vector<std::string>& args);
|
||
|
void determine_filetype();
|
||
|
void usage_text();
|
||
|
|
||
|
std::string mModuleLabel;
|
||
|
|
||
|
bool mShowLayout;
|
||
|
bool mShowKeydata;
|
||
|
|
||
|
tc::Optional<tc::io::Path> mKeysetPath;
|
||
|
tc::Optional<KeyBag::aes128_key_t> mTitleKey;
|
||
|
tc::Optional<KeyBag::aes128_key_t> mBodyKey;
|
||
|
tc::Optional<tc::io::Path> mTikPath;
|
||
|
tc::Optional<tc::io::Path> mCertPath;
|
||
|
|
||
|
bool determineValidNcaFromSample(const tc::ByteData& raw_data) const;
|
||
|
bool determineValidEsCertFromSample(const tc::ByteData& raw_data) const;
|
||
|
bool determineValidEsTikFromSample(const tc::ByteData& raw_data) const;
|
||
|
bool determineValidCnmtFromSample(const tc::ByteData& raw_data) const;
|
||
|
bool determineValidNacpFromSample(const tc::ByteData& raw_data) const;
|
||
|
};
|
||
|
|
||
|
}
|