Minor formatting

This commit is contained in:
Raul Tambre 2015-07-26 11:14:56 +03:00 committed by Nekotekina
parent 6ef4cecf57
commit 14897b23b7
7 changed files with 120 additions and 33 deletions

View file

@ -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.

View file

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

View file

@ -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.

View file

@ -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; i<parts; i++)
for (u32 i = 0; i < parts; i++)
{
memset(buf, 0, sizeof(buf));
u32 length = pkg_f.read(buf, BUF_SIZE);
@ -118,21 +118,21 @@ int Decrypt(const fs::file& pkg_f, const fs::file& dec_pkg_f, PKGHeader* m_heade
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];
@ -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];
}
}

View file

@ -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]);
}

View file

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

View file

@ -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<m_header.trp_files_count; i++)
for (u32 i = 0; i < m_header.trp_files_count; i++)
{
if (trp_f.Read(&m_entries[i], sizeof(TRPEntry)) != sizeof(TRPEntry))
{
return false;
}
if (show)
{
LOG_NOTICE(LOADER, "TRP entry #%d: %s", m_entries[i].name);
}
}
return true;
@ -71,9 +88,12 @@ bool TRPLoader::LoadHeader(bool show)
bool TRPLoader::ContainsEntry(const char *filename)
{
for (const TRPEntry& entry : m_entries) {
for (const TRPEntry& entry : m_entries)
{
if (!strcmp(entry.name, filename))
{
return true;
}
}
return false;
}
@ -81,19 +101,27 @@ bool TRPLoader::ContainsEntry(const char *filename)
void TRPLoader::RemoveEntry(const char *filename)
{
std::vector<TRPEntry>::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);
}
}
}