Skip to content

Commit

Permalink
Minor formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tambry authored and Nekotekina committed Jul 26, 2015
1 parent 6ef4cec commit 14897b2
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 33 deletions.
3 changes: 2 additions & 1 deletion Utilities/AutoPause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 14 additions & 7 deletions rpcs3/Crypto/key_vault.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
6 changes: 4 additions & 2 deletions rpcs3/Crypto/unedat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
15 changes: 8 additions & 7 deletions rpcs3/Crypto/unpkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,29 +110,29 @@ 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; i<parts; i++)
for (u32 i = 0; i < parts; i++)
{
memset(buf, 0, sizeof(buf));
u32 length = pkg_f.read(buf, BUF_SIZE);
u32 bits = (length + HASH_LEN - 1) / HASH_LEN;

if (m_header->pkg_type == PKG_RELEASE_TYPE_DEBUG)
{
for (u32 j=0; j<bits; j++)
for (u32 j = 0; j < bits; j++)
{
u8 hash[0x14];
sha1(key, 0x40, hash);
*(u64*)&buf[j*HASH_LEN + 0] ^= *(u64*)&hash[0];
*(u64*)&buf[j*HASH_LEN + 8] ^= *(u64*)&hash[8];
*(u64*)&buf[j * HASH_LEN + 0] ^= *(u64*)&hash[0];
*(u64*)&buf[j * HASH_LEN + 8] ^= *(u64*)&hash[8];
*(be_t<u64>*)&key[0x38] += 1;
}
}

if (m_header->pkg_type == PKG_RELEASE_TYPE_RELEASE)
{
for (u32 j=0; j<bits; j++)
for (u32 j = 0; j < bits; j++)
{
aes_crypt_ecb(&c, AES_ENCRYPT, iv, ctr+j*HASH_LEN);
aes_crypt_ecb(&c, AES_ENCRYPT, iv, ctr + j * HASH_LEN);

be_t<u64> hi = *(be_t<u64>*)&iv[0];
be_t<u64> lo = *(be_t<u64>*)&iv[8];
Expand All @@ -145,7 +145,8 @@ int Decrypt(const fs::file& pkg_f, const fs::file& dec_pkg_f, PKGHeader* m_heade
*(be_t<u64>*)&iv[8] = lo;
}

for (u32 j=0; j<length; j++) {
for (u32 j = 0; j < length; j++)
{
buf[j] ^= ctr[j];
}
}
Expand Down
13 changes: 10 additions & 3 deletions rpcs3/Ini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,26 @@ static std::pair<int, int> StringToSize(const std::string& str)
{
std::size_t start = 0, found;
std::vector<int> 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]);
}
Expand Down
57 changes: 49 additions & 8 deletions rpcs3/Loader/TROPUSR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
{
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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<rXmlNode> n = doc.GetRoot()->GetChildren(); n; n = n->GetNext())
{
if (n->GetName() == "trophy")
Expand Down Expand Up @@ -164,6 +196,7 @@ bool TROPUSRLoader::Generate(const std::string& filepath, const std::string& con
m_header.unk2 = 0;

Save(filepath);

return true;
}

Expand All @@ -174,29 +207,36 @@ 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
}

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
}

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;
}

Expand All @@ -208,5 +248,6 @@ bool TROPUSRLoader::Close()
m_file = nullptr;
return true;
}

return false;
}
Loading

0 comments on commit 14897b2

Please sign in to comment.