#pragma once #include "types.h" #include #include #include #include #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 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 extract_path; } fs; // XCI options struct XciOptions { tc::Optional update_extract_path; tc::Optional logo_extract_path; tc::Optional normal_extract_path; tc::Optional secure_extract_path; } xci; // NCA options struct NcaOptions { tc::Optional part0_extract_path; tc::Optional part1_extract_path; tc::Optional part2_extract_path; tc::Optional part3_extract_path; } nca; // KIP options struct KipOptions { tc::Optional extract_path; } kip; // ASET Options struct AsetOptions { tc::Optional icon_extract_path; tc::Optional nacp_extract_path; } aset; Settings() { infile.filetype = FILE_TYPE_ERROR; infile.path = tc::Optional(); 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(); xci.logo_extract_path = tc::Optional(); xci.normal_extract_path = tc::Optional(); xci.secure_extract_path = tc::Optional(); fs.show_fs_tree = false; fs.extract_path = tc::Optional(); nca.part0_extract_path = tc::Optional(); nca.part1_extract_path = tc::Optional(); nca.part2_extract_path = tc::Optional(); nca.part3_extract_path = tc::Optional(); kip.extract_path = tc::Optional(); aset.icon_extract_path = tc::Optional(); aset.nacp_extract_path = tc::Optional(); } }; class SettingsInitializer : public Settings { public: SettingsInitializer(const std::vector& args); private: void parse_args(const std::vector& args); void determine_filetype(); void usage_text() const; void dump_keys() const; void dump_rsa_key(const KeyBag::rsa_key_t& key, const std::string& label, size_t indent, bool expanded_key_data) const; std::string mModuleLabel; bool mShowLayout; bool mShowKeydata; bool mVerbose; tc::Optional mKeysetPath; tc::Optional mTitleKey; tc::Optional mBodyKey; tc::Optional mTikPath; tc::Optional 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; }; }