diff --git a/F00DFileKeyEncryptor.cpp b/F00DFileKeyEncryptor.cpp index 8f54833..1322a52 100644 --- a/F00DFileKeyEncryptor.cpp +++ b/F00DFileKeyEncryptor.cpp @@ -4,7 +4,7 @@ #include #include -F00DFileKeyEncryptor::F00DFileKeyEncryptor(psvpfs::path filePath) +F00DFileKeyEncryptor::F00DFileKeyEncryptor(const psvpfs::path& filePath) : m_filePath(filePath), m_isCacheLoaded(false) { } diff --git a/F00DFileKeyEncryptor.h b/F00DFileKeyEncryptor.h index f428fa1..c397f27 100644 --- a/F00DFileKeyEncryptor.h +++ b/F00DFileKeyEncryptor.h @@ -15,7 +15,7 @@ private: bool m_isCacheLoaded; public: - F00DFileKeyEncryptor(psvpfs::path filePath); + F00DFileKeyEncryptor(const psvpfs::path& filePath); private: int load_cache_flat_file(); diff --git a/FilesDbParser.cpp b/FilesDbParser.cpp index a908ef7..d91f924 100644 --- a/FilesDbParser.cpp +++ b/FilesDbParser.cpp @@ -168,13 +168,11 @@ bool FilesDbParser::verify_header_icv(std::ifstream& inputStream, const unsigned bool FilesDbParser::get_isUnicv(bool& isUnicv) { - psvpfs::path root(m_titleIdPath); - - psvpfs::path filepath = root / "sce_pfs" / "unicv.db"; + psvpfs::path filepath = m_titleIdPath / "sce_pfs" / "unicv.db"; if(!psvpfs::exists(filepath)) { - psvpfs::path filepath2 = root / "sce_pfs" / "icv.db"; + psvpfs::path filepath2 = m_titleIdPath / "sce_pfs" / "icv.db"; if(!psvpfs::exists(filepath2) || !psvpfs::is_directory(filepath2)) { m_output << "failed to find unicv.db file or icv.db folder" << std::endl; @@ -790,7 +788,7 @@ bool FilesDbParser::constructFilePaths(const std::map real_directories) +bool FilesDbParser::linkDirpaths(const std::set& real_directories) { m_output << "Linking dir paths..." << std::endl; @@ -826,7 +824,7 @@ bool FilesDbParser::linkDirpaths(const std::set real_directories) //checks that files exist //checks that file size is correct -bool FilesDbParser::linkFilepaths(const std::set real_files, std::uint32_t fileSectorSize) +bool FilesDbParser::linkFilepaths(const std::set& real_files, std::uint32_t fileSectorSize) { m_output << "Linking file paths..." << std::endl; diff --git a/FilesDbParser.h b/FilesDbParser.h index dfc0d91..0dc6933 100644 --- a/FilesDbParser.h +++ b/FilesDbParser.h @@ -245,9 +245,9 @@ private: bool constructFilePaths(const std::map& dirMatrix, const std::map& fileMatrix, const std::vector& flatBlocks); private: - bool linkDirpaths(const std::set real_directories); + bool linkDirpaths(const std::set& real_directories); - bool linkFilepaths(const std::set real_files, std::uint32_t fileSectorSize); + bool linkFilepaths(const std::set& real_files, std::uint32_t fileSectorSize); int matchFileLists(const std::set& files); diff --git a/LocalKeyGenerator.cpp b/LocalKeyGenerator.cpp index d93d2f5..eb32d7e 100644 --- a/LocalKeyGenerator.cpp +++ b/LocalKeyGenerator.cpp @@ -146,10 +146,9 @@ int check_keystone(std::shared_ptr cryptops, keystone_t& ks, //public functions -int get_sealedkey(std::shared_ptr cryptops, psvpfs::path titleIdPath, unsigned char* dec_key) +int get_sealedkey(std::shared_ptr cryptops, const psvpfs::path& titleIdPath, unsigned char* dec_key) { - psvpfs::path root(titleIdPath); - psvpfs::path filepath = root / "sce_sys" / "sealedkey"; + psvpfs::path filepath = titleIdPath / "sce_sys" / "sealedkey"; if(!psvpfs::exists(filepath)) { @@ -170,10 +169,9 @@ int get_sealedkey(std::shared_ptr cryptops, psvpfs::path titl return 0; } -int get_keystone(std::shared_ptr cryptops, psvpfs::path titleIdPath, char* passcode) +int get_keystone(std::shared_ptr cryptops, const psvpfs::path& titleIdPath, char* passcode) { - psvpfs::path root(titleIdPath); - psvpfs::path filepath = root / "sce_sys" / "keystone"; + psvpfs::path filepath = titleIdPath / "sce_sys" / "keystone"; if(!psvpfs::exists(filepath)) { diff --git a/LocalKeyGenerator.h b/LocalKeyGenerator.h index 2aefe86..5134b16 100644 --- a/LocalKeyGenerator.h +++ b/LocalKeyGenerator.h @@ -40,6 +40,6 @@ typedef struct keystone_t #pragma pack(pop) -int get_sealedkey(std::shared_ptr cryptops, psvpfs::path titleIdPath, unsigned char* dec_key); +int get_sealedkey(std::shared_ptr cryptops, const psvpfs::path& titleIdPath, unsigned char* dec_key); -int get_keystone(std::shared_ptr cryptops, psvpfs::path titleIdPath, char* passcode = 0); \ No newline at end of file +int get_keystone(std::shared_ptr cryptops, const psvpfs::path& titleIdPath, char* passcode = 0); \ No newline at end of file diff --git a/PfsFile.cpp b/PfsFile.cpp index bda02a6..c04c6c1 100644 --- a/PfsFile.cpp +++ b/PfsFile.cpp @@ -4,7 +4,7 @@ #include "PfsKeyGenerator.h" PfsFile::PfsFile(std::shared_ptr cryptops, std::shared_ptr iF00D, std::ostream& output, - const unsigned char* klicensee, psvpfs::path titleIdPath, + const unsigned char* klicensee, const psvpfs::path& titleIdPath, const sce_ng_pfs_file_t& file, const sce_junction& filepath, const sce_ng_pfs_header_t& ngpfs, std::shared_ptr table) : m_cryptops(cryptops), m_iF00D(iF00D), m_output(output), m_titleIdPath(titleIdPath), m_file(file), m_filepath(filepath), m_ngpfs(ngpfs), m_table(table) @@ -128,7 +128,7 @@ int PfsFile::init_crypt_ctx(CryptEngineWorkCtx* work_ctx, sig_tbl_t& block, std: return 0; } -int PfsFile::decrypt_icv_file(psvpfs::path destination_root) const +int PfsFile::decrypt_icv_file(const psvpfs::path& destination_root) const { //create new file @@ -201,7 +201,7 @@ int PfsFile::decrypt_icv_file(psvpfs::path destination_root) const return 0; } -int PfsFile::decrypt_unicv_file(psvpfs::path destination_root) const +int PfsFile::decrypt_unicv_file(const psvpfs::path& destination_root) const { //create new file @@ -363,7 +363,7 @@ int PfsFile::decrypt_unicv_file(psvpfs::path destination_root) const return 0; } -int PfsFile::decrypt_file(psvpfs::path destination_root) const +int PfsFile::decrypt_file(const psvpfs::path& destination_root) const { if(img_spec_to_is_unicv(m_ngpfs.image_spec)) return decrypt_unicv_file(destination_root); diff --git a/PfsFile.h b/PfsFile.h index 77bfda9..0c09537 100644 --- a/PfsFile.h +++ b/PfsFile.h @@ -19,7 +19,7 @@ private: std::shared_ptr m_iF00D; std::ostream& m_output; unsigned char m_klicensee[0x10]; - psvpfs::path m_titleIdPath; + const psvpfs::path& m_titleIdPath; private: const sce_ng_pfs_file_t& m_file; @@ -34,16 +34,16 @@ private: public: PfsFile(std::shared_ptr cryptops, std::shared_ptr iF00D, std::ostream& output, - const unsigned char* klicensee, psvpfs::path titleIdPath, + const unsigned char* klicensee, const psvpfs::path& titleIdPath, const sce_ng_pfs_file_t& file, const sce_junction& filepath, const sce_ng_pfs_header_t& ngpfs, std::shared_ptr table); private: int init_crypt_ctx(CryptEngineWorkCtx* work_ctx, sig_tbl_t& block, std::uint32_t sector_base, std::uint32_t tail_size, unsigned char* source) const; - int decrypt_icv_file(psvpfs::path destination_root) const; + int decrypt_icv_file(const psvpfs::path& destination_root) const; - int decrypt_unicv_file(psvpfs::path destination_root) const; + int decrypt_unicv_file(const psvpfs::path& destination_root) const; public: - int decrypt_file(psvpfs::path destination_root) const; + int decrypt_file(const psvpfs::path& destination_root) const; }; \ No newline at end of file diff --git a/PfsFilesystem.cpp b/PfsFilesystem.cpp index fe01aac..ea98cd9 100644 --- a/PfsFilesystem.cpp +++ b/PfsFilesystem.cpp @@ -5,7 +5,7 @@ #include PfsFilesystem::PfsFilesystem(std::shared_ptr cryptops, std::shared_ptr iF00D, std::ostream& output, - const unsigned char* klicensee, psvpfs::path titleIdPath) + const unsigned char* klicensee, const psvpfs::path& titleIdPath) : m_cryptops(cryptops), m_iF00D(iF00D), m_output(output), m_titleIdPath(titleIdPath) { memcpy(m_klicensee, klicensee, 0x10); @@ -35,7 +35,7 @@ static void to_uppercase(std::string &str) { std::transform(str.begin(), str.end(), str.begin(), static_cast(std::toupper)); } -int PfsFilesystem::decrypt_files(psvpfs::path destTitleIdPath) const +int PfsFilesystem::decrypt_files(const psvpfs::path& destTitleIdPath) const { const sce_ng_pfs_header_t& ngpfs = m_filesDbParser->get_header(); const std::vector& files = m_filesDbParser->get_files(); diff --git a/PfsFilesystem.h b/PfsFilesystem.h index fc3e002..12a04d6 100644 --- a/PfsFilesystem.h +++ b/PfsFilesystem.h @@ -16,7 +16,7 @@ private: std::shared_ptr m_iF00D; std::ostream& m_output; unsigned char m_klicensee[0x10]; - psvpfs::path m_titleIdPath; + const psvpfs::path& m_titleIdPath; private: std::unique_ptr m_filesDbParser; @@ -25,10 +25,10 @@ private: public: PfsFilesystem(std::shared_ptr cryptops, std::shared_ptr iF00D, std::ostream& output, - const unsigned char* klicensee, psvpfs::path titleIdPath); + const unsigned char* klicensee, const psvpfs::path& titleIdPath); public: int mount(); - int decrypt_files(psvpfs::path destTitleIdPath) const; + int decrypt_files(const psvpfs::path& destTitleIdPath) const; }; diff --git a/PfsPageMapper.cpp b/PfsPageMapper.cpp index 022bbe7..70b5a07 100644 --- a/PfsPageMapper.cpp +++ b/PfsPageMapper.cpp @@ -4,7 +4,7 @@ #include "UnicvDbParser.h" #include "FilesDbParser.h" -PfsPageMapper::PfsPageMapper(std::shared_ptr cryptops, std::shared_ptr iF00D, std::ostream& output, const unsigned char* klicensee, psvpfs::path titleIdPath) +PfsPageMapper::PfsPageMapper(std::shared_ptr cryptops, std::shared_ptr iF00D, std::ostream& output, const unsigned char* klicensee, const psvpfs::path& titleIdPath) : m_cryptops(cryptops), m_iF00D(iF00D), m_output(output), m_titleIdPath(titleIdPath) { memcpy(m_klicensee, klicensee, 0x10); @@ -395,9 +395,9 @@ int PfsPageMapper::bruteforce_map(const std::unique_ptr& filesDbP } //this is a test method that was supposed to be used for caching -int PfsPageMapper::load_page_map(psvpfs::path filepath, std::map& pageMap) const +int PfsPageMapper::load_page_map(const psvpfs::path& filepath, std::map& pageMap) const { - psvpfs::path fp(filepath); + const auto& fp = filepath; if(!psvpfs::exists(fp)) { diff --git a/PfsPageMapper.h b/PfsPageMapper.h index 3fca10a..8e3109a 100644 --- a/PfsPageMapper.h +++ b/PfsPageMapper.h @@ -30,10 +30,10 @@ private: std::shared_ptr m_iF00D; std::ostream& m_output; unsigned char m_klicensee[0x10]; - psvpfs::path m_titleIdPath; + const psvpfs::path& m_titleIdPath; public: - PfsPageMapper(std::shared_ptr cryptops, std::shared_ptr iF00D, std::ostream& output, const unsigned char* klicensee, psvpfs::path titleIdPath); + PfsPageMapper(std::shared_ptr cryptops, std::shared_ptr iF00D, std::ostream& output, const unsigned char* klicensee, const psvpfs::path& titleIdPath); private: std::shared_ptr brutforce_hashes(const std::unique_ptr& filesDbParser, std::map>& fileDatas, const unsigned char* secret, const unsigned char* signature) const; @@ -45,7 +45,7 @@ private: public: int bruteforce_map(const std::unique_ptr& filesDbParser, const std::unique_ptr& unicvDbParser); - int load_page_map(psvpfs::path filepath, std::map& pageMap) const; + int load_page_map(const psvpfs::path& filepath, std::map& pageMap) const; public: const std::map& get_pageMap() const; diff --git a/PsvPfsParserConfig.cpp b/PsvPfsParserConfig.cpp index 50844f4..04be65f 100644 --- a/PsvPfsParserConfig.cpp +++ b/PsvPfsParserConfig.cpp @@ -14,7 +14,7 @@ #include "PsvPfsParserConfig.h" #include "LocalKeyGenerator.h" -int execute(std::shared_ptr cryptops, std::shared_ptr iF00D, const unsigned char *klicensee, psvpfs::path titleIdPath, psvpfs::path destTitleIdPath) { +int execute(std::shared_ptr cryptops, std::shared_ptr iF00D, const unsigned char *klicensee, const psvpfs::path& titleIdPath, const psvpfs::path& destTitleIdPath) { PfsFilesystem pfs(cryptops, iF00D, std::cout, klicensee, titleIdPath); if (pfs.mount() < 0) diff --git a/UnicvDbParser.cpp b/UnicvDbParser.cpp index ac7e078..9dea2d6 100644 --- a/UnicvDbParser.cpp +++ b/UnicvDbParser.cpp @@ -8,7 +8,7 @@ #include "UnicvDbTypes.h" -UnicvDbParser::UnicvDbParser(psvpfs::path titleIdPath, std::ostream& output) +UnicvDbParser::UnicvDbParser(const psvpfs::path& titleIdPath, std::ostream& output) : m_titleIdPath(titleIdPath), m_output(output) { } @@ -21,13 +21,11 @@ int UnicvDbParser::parse() return -1; } - psvpfs::path root(m_titleIdPath); - - psvpfs::path filepath = root / "sce_pfs" / "unicv.db"; + psvpfs::path filepath = m_titleIdPath / "sce_pfs" / "unicv.db"; if(!psvpfs::exists(filepath)) { - psvpfs::path filepath2 = root / "sce_pfs" / "icv.db"; + psvpfs::path filepath2 = m_titleIdPath / "sce_pfs" / "icv.db"; if(!psvpfs::exists(filepath2) || !psvpfs::is_directory(filepath2)) { m_output << "failed to find unicv.db file or icv.db folder" << std::endl; diff --git a/UnicvDbParser.h b/UnicvDbParser.h index a1e529c..1785b5d 100644 --- a/UnicvDbParser.h +++ b/UnicvDbParser.h @@ -7,13 +7,13 @@ class UnicvDbParser { private: - psvpfs::path m_titleIdPath; + const psvpfs::path& m_titleIdPath; std::unique_ptr m_fdb; std::ostream& m_output; public: - UnicvDbParser(psvpfs::path titleIdPath, std::ostream& output); + UnicvDbParser(const psvpfs::path& titleIdPath, std::ostream& output); public: int parse(); diff --git a/Utils.cpp b/Utils.cpp index 8206175..223c32e 100644 --- a/Utils.cpp +++ b/Utils.cpp @@ -110,7 +110,7 @@ psvpfs::path source_path_to_dest_path(const psvpfs::path& source_root, const psv //=== -sce_junction::sce_junction(psvpfs::path value) +sce_junction::sce_junction(const psvpfs::path& value) : m_value(value), m_real(std::string()) { @@ -127,7 +127,7 @@ sce_junction::sce_junction(const sce_junction& other) //this is because virtual path in files.db may not exactly match to physical path //in real world - windows is case insensitive while linux is case sensitive //it seems that pfs assumes windows as its prior filesystem for tools -bool sce_junction::is_equal(psvpfs::path p) const +bool sce_junction::is_equal(const psvpfs::path& p) const { #ifdef PSVPFS_BOOST std::string left = m_value.generic_string(); @@ -187,7 +187,7 @@ bool sce_junction::open(std::ifstream& in) const } //create empty directory in destination root using path from this junction -bool sce_junction::create_empty_directory(psvpfs::path source_root, psvpfs::path destination_root) const +bool sce_junction::create_empty_directory(const psvpfs::path& source_root, const psvpfs::path& destination_root) const { //construct new path psvpfs::path new_path = source_path_to_dest_path(source_root, destination_root, m_real); @@ -201,7 +201,7 @@ bool sce_junction::create_empty_directory(psvpfs::path source_root, psvpfs::path //create empty file in destination root using path from this junction //leaves stream opened for other operations like write -bool sce_junction::create_empty_file(psvpfs::path source_root, psvpfs::path destination_root, std::ofstream& outputStream) const +bool sce_junction::create_empty_file(const psvpfs::path& source_root, const psvpfs::path& destination_root, std::ofstream& outputStream) const { //construct new path psvpfs::path new_path = source_path_to_dest_path(source_root, destination_root, m_real); @@ -225,7 +225,7 @@ bool sce_junction::create_empty_file(psvpfs::path source_root, psvpfs::path dest } //create empty file in destination root using path from this junction -bool sce_junction::create_empty_file(psvpfs::path source_root, psvpfs::path destination_root) const +bool sce_junction::create_empty_file(const psvpfs::path& source_root, const psvpfs::path& destination_root) const { std::ofstream outputStream; if(create_empty_file(source_root, destination_root, outputStream)) @@ -240,7 +240,7 @@ bool sce_junction::create_empty_file(psvpfs::path source_root, psvpfs::path dest } //copy file in destination root using path from this junction -bool sce_junction::copy_existing_file(psvpfs::path source_root, psvpfs::path destination_root) const +bool sce_junction::copy_existing_file(const psvpfs::path& source_root, const psvpfs::path& destination_root) const { //construct new path psvpfs::path new_path = source_path_to_dest_path(source_root, destination_root, m_real); @@ -268,7 +268,7 @@ bool sce_junction::copy_existing_file(psvpfs::path source_root, psvpfs::path des } -bool sce_junction::copy_existing_file(psvpfs::path source_root, psvpfs::path destination_root, std::uintmax_t size) const +bool sce_junction::copy_existing_file(const psvpfs::path& source_root, const psvpfs::path& destination_root, std::uintmax_t size) const { if (!copy_existing_file(source_root, destination_root)) return false; diff --git a/Utils.h b/Utils.h index 16f7e19..dfa1974 100644 --- a/Utils.h +++ b/Utils.h @@ -36,12 +36,12 @@ private: mutable psvpfs::path m_real; //real path in file system public: - sce_junction(psvpfs::path value); + sce_junction(const psvpfs::path& value); sce_junction(const sce_junction& other); public: - bool is_equal(psvpfs::path p) const; + bool is_equal(const psvpfs::path& p) const; bool is_equal(const sce_junction& other) const; @@ -61,20 +61,20 @@ public: bool open(std::ifstream& in) const; //create empty directory in destination root using path from this junction - bool create_empty_directory(psvpfs::path source_root, psvpfs::path destination_root) const; + bool create_empty_directory(const psvpfs::path& source_root, const psvpfs::path& destination_root) const; //create empty file in destination root using path from this junction //leaves stream opened for other operations like write - bool create_empty_file(psvpfs::path source_root, psvpfs::path destination_root, std::ofstream& outputStream) const; + bool create_empty_file(const psvpfs::path& source_root, const psvpfs::path& destination_root, std::ofstream& outputStream) const; //create empty file in destination root using path from this junction - bool create_empty_file(psvpfs::path source_root, psvpfs::path destination_root) const; + bool create_empty_file(const psvpfs::path& source_root, const psvpfs::path& destination_root) const; //copy file in destination root using path from this junction - bool copy_existing_file(psvpfs::path source_root, psvpfs::path destination_root) const; + bool copy_existing_file(const psvpfs::path& source_root, const psvpfs::path& destination_root) const; //copy file with specific size in destination root using path from this junction - bool copy_existing_file(psvpfs::path source_root, psvpfs::path destination_root, std::uintmax_t size) const; + bool copy_existing_file(const psvpfs::path& source_root, const psvpfs::path& destination_root, std::uintmax_t size) const; //return corresponding virtual path const psvpfs::path& get_value() const;