From 14897b23b7705473d799814c09194de74d6c94b3 Mon Sep 17 00:00:00 2001 From: Raul Tambre Date: Sun, 26 Jul 2015 11:14:56 +0300 Subject: [PATCH] Minor formatting --- Utilities/AutoPause.cpp | 3 +- rpcs3/Crypto/key_vault.cpp | 21 +++++++++----- rpcs3/Crypto/unedat.cpp | 6 ++-- rpcs3/Crypto/unpkg.cpp | 15 +++++----- rpcs3/Ini.cpp | 13 +++++++-- rpcs3/Loader/TROPUSR.cpp | 57 ++++++++++++++++++++++++++++++++------ rpcs3/Loader/TRP.cpp | 38 +++++++++++++++++++++---- 7 files changed, 120 insertions(+), 33 deletions(-) diff --git a/Utilities/AutoPause.cpp b/Utilities/AutoPause.cpp index a6c1cabfc6f9..4f7cadcabb98 100644 --- a/Utilities/AutoPause.cpp +++ b/Utilities/AutoPause.cpp @@ -82,7 +82,8 @@ void AutoPause::Reload(void) initialized = true; } -void AutoPause::TryPause(u32 code) { +void AutoPause::TryPause(u32 code) +{ if (code < 1024) { //Would first check Enable setting. Then the list length. diff --git a/rpcs3/Crypto/key_vault.cpp b/rpcs3/Crypto/key_vault.cpp index 04a949c1beb3..615fcdcc5d31 100644 --- a/rpcs3/Crypto/key_vault.cpp +++ b/rpcs3/Crypto/key_vault.cpp @@ -773,27 +773,34 @@ void rap_to_rif(unsigned char* rap, unsigned char* rif) aes_crypt_cbc(&aes, AES_DECRYPT, 0x10, iv, rap, key); // rap2rifkey round. - for (round = 0; round < 5; ++round) { - for (i = 0; i < 16; ++i) { + for (round = 0; round < 5; ++round) + { + for (i = 0; i < 16; ++i) + { int p = RAP_PBOX[i]; key[p] ^= RAP_E1[p]; } - for (i = 15; i >= 1; --i) { + for (i = 15; i >= 1; --i) + { int p = RAP_PBOX[i]; int pp = RAP_PBOX[i - 1]; key[p] ^= key[pp]; } int o = 0; - for (i = 0; i < 16; ++i) { + for (i = 0; i < 16; ++i) + { int p = RAP_PBOX[i]; unsigned char kc = key[p] - o; unsigned char ec2 = RAP_E2[p]; - if (o != 1 || kc != 0xFF) { + if (o != 1 || kc != 0xFF) + { o = kc < ec2 ? 1 : 0; key[p] = kc - ec2; - } else if (kc == 0xFF) { + } else if (kc == 0xFF) + { key[p] = kc - ec2; - } else { + } else + { key[p] = kc; } } diff --git a/rpcs3/Crypto/unedat.cpp b/rpcs3/Crypto/unedat.cpp index 9bfaa000e702..cbada68e5086 100644 --- a/rpcs3/Crypto/unedat.cpp +++ b/rpcs3/Crypto/unedat.cpp @@ -7,7 +7,8 @@ void generate_key(int crypto_mode, int version, unsigned char *key_final, unsigned char *iv_final, unsigned char *key, unsigned char *iv) { int mode = (int)(crypto_mode & 0xF0000000); - switch (mode) { + switch (mode) + { case 0x10000000: // Encrypted ERK. // Decrypt the key with EDAT_KEY + EDAT_IV and copy the original IV. @@ -32,7 +33,8 @@ void generate_key(int crypto_mode, int version, unsigned char *key_final, unsign void generate_hash(int hash_mode, int version, unsigned char *hash_final, unsigned char *hash) { int mode = (int)(hash_mode & 0xF0000000); - switch (mode) { + switch (mode) + { case 0x10000000: // Encrypted HASH. // Decrypt the hash with EDAT_KEY + EDAT_IV. diff --git a/rpcs3/Crypto/unpkg.cpp b/rpcs3/Crypto/unpkg.cpp index b76f75fecf7e..4c196a9cd6c8 100644 --- a/rpcs3/Crypto/unpkg.cpp +++ b/rpcs3/Crypto/unpkg.cpp @@ -110,7 +110,7 @@ int Decrypt(const fs::file& pkg_f, const fs::file& dec_pkg_f, PKGHeader* m_heade memcpy(iv, m_header->klicensee, sizeof(iv)); aes_setkey_enc(&c, PKG_AES_KEY, 128); - for (u32 i=0; ipkg_type == PKG_RELEASE_TYPE_DEBUG) { - for (u32 j=0; j*)&key[0x38] += 1; } } if (m_header->pkg_type == PKG_RELEASE_TYPE_RELEASE) { - for (u32 j=0; j hi = *(be_t*)&iv[0]; be_t lo = *(be_t*)&iv[8]; @@ -145,7 +145,8 @@ int Decrypt(const fs::file& pkg_f, const fs::file& dec_pkg_f, PKGHeader* m_heade *(be_t*)&iv[8] = lo; } - for (u32 j=0; j StringToSize(const std::string& str) { std::size_t start = 0, found; std::vector vec; - for (int i = 0; i < 2 && (found = str.find_first_of('x', start)); i++) { - try { + + for (int i = 0; i < 2 && (found = str.find_first_of('x', start)); i++) + { + try + { vec.push_back(std::stoi(str.substr(start, found == std::string::npos ? found : found - start))); } - catch (const std::invalid_argument& e) { + catch (const std::invalid_argument& e) + { return std::make_pair(-1, -1); } if (found == std::string::npos) break; start = found + 1; } + if (vec.size() < 2 || vec[0] < 0 || vec[1] < 0) + { return std::make_pair(-1, -1); + } return std::make_pair(vec[0], vec[1]); } diff --git a/rpcs3/Loader/TROPUSR.cpp b/rpcs3/Loader/TROPUSR.cpp index 76e343f24de8..6c357f5a515a 100644 --- a/rpcs3/Loader/TROPUSR.cpp +++ b/rpcs3/Loader/TROPUSR.cpp @@ -20,10 +20,14 @@ TROPUSRLoader::~TROPUSRLoader() bool TROPUSRLoader::Load(const std::string& filepath, const std::string& configpath) { if (m_file) + { Close(); + } if (!Emu.GetVFS().ExistsFile(filepath)) + { Generate(filepath, configpath); + } m_file = Emu.GetVFS().OpenFile(filepath, vfsRead); LoadHeader(); @@ -36,34 +40,47 @@ bool TROPUSRLoader::Load(const std::string& filepath, const std::string& configp bool TROPUSRLoader::LoadHeader() { - if(!m_file->IsOpened()) + if (!m_file->IsOpened()) + { return false; + } m_file->Seek(0); + if (m_file->Read(&m_header, sizeof(TROPUSRHeader)) != sizeof(TROPUSRHeader)) + { return false; + } + return true; } bool TROPUSRLoader::LoadTableHeaders() { - if(!m_file->IsOpened()) + if (!m_file->IsOpened()) + { return false; + } m_file->Seek(0x30); m_tableHeaders.clear(); m_tableHeaders.resize(m_header.tables_count); - for (TROPUSRTableHeader& tableHeader : m_tableHeaders) { + + for (TROPUSRTableHeader& tableHeader : m_tableHeaders) + { if (m_file->Read(&tableHeader, sizeof(TROPUSRTableHeader)) != sizeof(TROPUSRTableHeader)) return false; } + return true; } bool TROPUSRLoader::LoadTables() { - if(!m_file->IsOpened()) + if (!m_file->IsOpened()) + { return false; + } for (const TROPUSRTableHeader& tableHeader : m_tableHeaders) { @@ -73,7 +90,9 @@ bool TROPUSRLoader::LoadTables() { m_table4.clear(); m_table4.resize(tableHeader.entries_count); - for (auto& entry : m_table4) { + + for (auto& entry : m_table4) + { if (m_file->Read(&entry, sizeof(TROPUSREntry4)) != sizeof(TROPUSREntry4)) return false; } @@ -83,7 +102,9 @@ bool TROPUSRLoader::LoadTables() { m_table6.clear(); m_table6.resize(tableHeader.entries_count); - for (auto& entry : m_table6) { + + for (auto& entry : m_table6) + { if (m_file->Read(&entry, sizeof(TROPUSREntry6)) != sizeof(TROPUSREntry6)) return false; } @@ -99,20 +120,30 @@ bool TROPUSRLoader::LoadTables() bool TROPUSRLoader::Save(const std::string& filepath) { if (m_file) + { Close(); + } m_file = Emu.GetVFS().OpenFile(filepath, vfsWriteNew); m_file->Write(&m_header, sizeof(TROPUSRHeader)); for (const TROPUSRTableHeader& tableHeader : m_tableHeaders) + { m_file->Write(&tableHeader, sizeof(TROPUSRTableHeader)); + } for (const auto& entry : m_table4) + { m_file->Write(&entry, sizeof(TROPUSREntry4)); + } + for (const auto& entry : m_table6) + { m_file->Write(&entry, sizeof(TROPUSREntry6)); + } m_file->Close(); + return true; } @@ -125,6 +156,7 @@ bool TROPUSRLoader::Generate(const std::string& filepath, const std::string& con m_table4.clear(); m_table6.clear(); + for (std::shared_ptr n = doc.GetRoot()->GetChildren(); n; n = n->GetNext()) { if (n->GetName() == "trophy") @@ -164,6 +196,7 @@ bool TROPUSRLoader::Generate(const std::string& filepath, const std::string& con m_header.unk2 = 0; Save(filepath); + return true; } @@ -174,8 +207,10 @@ u32 TROPUSRLoader::GetTrophiesCount() u32 TROPUSRLoader::GetTrophyUnlockState(u32 id) { - if (id >= m_table6.size()) + if (id >= m_table6.size()) + { LOG_WARNING(LOADER, "TROPUSRLoader::GetUnlockState: Invalid id=%d", id); + } return m_table6[id].trophy_state; // Let's assume the trophies are stored ordered } @@ -183,7 +218,9 @@ u32 TROPUSRLoader::GetTrophyUnlockState(u32 id) u64 TROPUSRLoader::GetTrophyTimestamp(u32 id) { if (id >= m_table6.size()) + { LOG_WARNING(LOADER, "TROPUSRLoader::GetTrophyTimestamp: Invalid id=%d", id); + } // TODO: What timestamp does sceNpTrophyGetTrophyInfo want, timestamp1 or timestamp2? return m_table6[id].timestamp2; // Let's assume the trophies are stored ordered @@ -191,12 +228,15 @@ u64 TROPUSRLoader::GetTrophyTimestamp(u32 id) bool TROPUSRLoader::UnlockTrophy(u32 id, u64 timestamp1, u64 timestamp2) { - if (id >= m_table6.size()) + if (id >= m_table6.size()) + { return false; + } m_table6[id].trophy_state = 1; m_table6[id].timestamp1 = timestamp1; m_table6[id].timestamp2 = timestamp2; + return true; } @@ -208,5 +248,6 @@ bool TROPUSRLoader::Close() m_file = nullptr; return true; } + return false; } diff --git a/rpcs3/Loader/TRP.cpp b/rpcs3/Loader/TRP.cpp index b4ca2131d900..d68228784afc 100644 --- a/rpcs3/Loader/TRP.cpp +++ b/rpcs3/Loader/TRP.cpp @@ -17,10 +17,14 @@ TRPLoader::~TRPLoader() bool TRPLoader::Install(std::string dest, bool show) { if (!trp_f.IsOpened()) + { return false; + } if (!dest.empty() && dest.back() != '/') + { dest += '/'; + } if (!Emu.GetVFS().ExistsDir(dest)) { @@ -41,29 +45,42 @@ bool TRPLoader::Install(std::string dest, bool show) bool TRPLoader::LoadHeader(bool show) { - if(!trp_f.IsOpened()) + if (!trp_f.IsOpened()) + { return false; + } trp_f.Seek(0); + if (trp_f.Read(&m_header, sizeof(TRPHeader)) != sizeof(TRPHeader)) + { return false; + } if (m_header.trp_magic != 0xDCA24D00) + { return false; + } if (show) + { LOG_NOTICE(LOADER, "TRP version: 0x%x", m_header.trp_version); + } m_entries.clear(); m_entries.resize(m_header.trp_files_count); - for(u32 i=0; i::iterator i = m_entries.begin(); - while (i != m_entries.end()) { + while (i != m_entries.end()) + { if (!strcmp(i->name, filename)) + { i = m_entries.erase(i); + } else + { i++; + } } } void TRPLoader::RenameEntry(const char *oldname, const char *newname) { - for (const TRPEntry& entry : m_entries) { + for (const TRPEntry& entry : m_entries) + { if (!strcmp(entry.name, oldname)) + { memcpy((void*)entry.name, newname, 32); + } } }