Skip to content
Permalink
Browse files

PRX Decryption: add pauth decryption

  • Loading branch information
DaveeFTW committed Jan 11, 2020
1 parent e7ec568 commit 4c9e7b742471e1614c9670c0a35023da2320f94e
Showing with 29 additions and 88 deletions.
  1. +9 −5 Core/ELF/PrxDecrypter.cpp
  2. +20 −83 Core/HLE/scePauth.cpp
@@ -122,8 +122,6 @@ static const u8 key_2E5E10F0[] = {0x9D, 0x5C, 0x5B, 0xAF, 0x8C, 0xD8, 0x69, 0x7E
static const u8 key_2E5E12F0[] = {0x8A, 0x7B, 0xC9, 0xD6, 0x52, 0x58, 0x88, 0xEA, 0x51, 0x83, 0x60, 0xCA, 0x16, 0x79, 0xE2, 0x07};
static const u8 key_2E5E13F0[] = {0xFF, 0xA4, 0x68, 0xC3, 0x31, 0xCA, 0xB7, 0x4C, 0xF1, 0x23, 0xFF, 0x01, 0x65, 0x3D, 0x26, 0x36};
static const u8 key_2FD30BF0[] = {0xD8, 0x58, 0x79, 0xF9, 0xA4, 0x22, 0xAF, 0x86, 0x90, 0xAC, 0xDA, 0x45, 0xCE, 0x60, 0x40, 0x3F};
static const u8 key_2FD311F0[] = {0x3A, 0x6B, 0x48, 0x96, 0x86, 0xA5, 0xC8, 0x80, 0x69, 0x6C, 0xE6, 0x4B, 0xF6, 0x04, 0x17, 0x44};
static const u8 key_2FD312F0[] = {0xC5, 0xFB, 0x69, 0x03, 0x20, 0x7A, 0xCF, 0xBA, 0x2C, 0x90, 0xF8, 0xB8, 0x4D, 0xD2, 0xF1, 0xDE};
static const u8 keys02G_E[] = {0x9D, 0x09, 0xFD, 0x20, 0xF3, 0x8F, 0x10, 0x69, 0x0D, 0xB2, 0x6F, 0x00, 0xCC, 0xC5, 0x51, 0x2E};
static const u8 keys03G_E[] = {0x4F, 0x44, 0x5C, 0x62, 0xB3, 0x53, 0xC4, 0x30, 0xFC, 0x3A, 0xA4, 0x5B, 0xEC, 0xFE, 0x51, 0xEA};
static const u8 keys05G_E[] = {0x5D, 0xAA, 0x72, 0xF2, 0x26, 0x60, 0x4D, 0x1C, 0xE7, 0x2D, 0xC8, 0xA3, 0x2F, 0x79, 0xC5, 0x54};
@@ -147,6 +145,11 @@ static const u8 key_380283F0[] = {0x34, 0x20, 0x0C, 0x8E, 0xA1, 0x86, 0x79, 0x84
static const u8 key_407810F0[] = {0xAF, 0xAD, 0xCA, 0xF1, 0x95, 0x59, 0x91, 0xEC, 0x1B, 0x27, 0xD0, 0x4E, 0x8A, 0xF3, 0x3D, 0xE7};
static const u8 drmkeys_6XX_1[] = {0x36, 0xEF, 0x82, 0x4E, 0x74, 0xFB, 0x17, 0x5B, 0x14, 0x14, 0x05, 0xF3, 0xB3, 0x8A, 0x76, 0x18};
static const u8 drmkeys_6XX_2[] = {0x21, 0x52, 0x5D, 0x76, 0xF6, 0x81, 0x0F, 0x15, 0x2F, 0x4A, 0x40, 0x89, 0x63, 0xA0, 0x10, 0x55};
static const u8 pauth_98b83b5d_1[] = {0xB0, 0x24, 0xC8, 0x16, 0x43, 0xE8, 0xF0, 0x1C, 0x8C, 0x30, 0x67, 0x73, 0x3E, 0x96, 0x35, 0xEF};
static const u8 pauth_98b83b5d_xor[] = {0xA9, 0x1E, 0xDD, 0x7B, 0x09, 0xBB, 0x22, 0xB5, 0x9D, 0xA3, 0x30, 0x69, 0x13, 0x6E, 0x0E, 0xD8};
static const u8 pauth_f7aa47f6_1[] = {0xC5, 0xFB, 0x69, 0x03, 0x20, 0x7A, 0xCF, 0xBA, 0x2C, 0x90, 0xF8, 0xB8, 0x4D, 0xD2, 0xF1, 0xDE};
static const u8 pauth_f7aa47f6_2[] = {0x3A, 0x6B, 0x48, 0x96, 0x86, 0xA5, 0xC8, 0x80, 0x69, 0x6C, 0xE6, 0x4B, 0xF6, 0x04, 0x17, 0x44};
static const u8 pauth_f7aa47f6_xor[] = {0xA9, 0x1E, 0xDD, 0x7B, 0x09, 0xBB, 0x22, 0xB5, 0x9D, 0xA3, 0x30, 0x69, 0x13, 0x6E, 0x0E, 0xD8};

// PRXDecrypter 144-byte tag keys.
static const u32 g_key0[] = {
@@ -398,8 +401,6 @@ static const TAG_INFO2 g_tagInfo2[] =
{ 0x2E5E12F0, key_2E5E12F0, 0x48 },
{ 0x2E5E13F0, key_2E5E13F0, 0x48 },
{ 0x2FD30BF0, key_2FD30BF0, 0x47 },
{ 0x2FD311F0, key_2FD311F0, 0x47 },
{ 0x2FD312F0, key_2FD312F0, 0x47 },
{ 0xD91605F0, key_D91605F0, 0x5D, 2},
{ 0xD91606F0, key_D91606F0, 0x5D, 2},
{ 0xD91608F0, key_D91608F0, 0x5D, 2},
@@ -446,7 +447,10 @@ static const TAG_INFO2 g_tagInfo2[] =
{ 0x380283F0, key_380283F0, 0x5A },
{ 0x407810F0, key_407810F0, 0x6A },
{ 0xE92410F0, drmkeys_6XX_1, 0x40 },
{ 0x692810F0, drmkeys_6XX_2, 0x40 }
{ 0x692810F0, drmkeys_6XX_2, 0x40 },
{ 0x2FD313F0, pauth_98b83b5d_1, 0x47, 5, pauth_98b83b5d_xor },
{ 0x2FD312F0, pauth_f7aa47f6_1, 0x47, 5, pauth_f7aa47f6_xor },
{ 0x2FD311F0, pauth_f7aa47f6_2, 0x47, 5, pauth_f7aa47f6_xor },
};

static const TAG_INFO2 *GetTagInfo2(u32 tagFind)
@@ -20,6 +20,7 @@

#include "Core/MemMap.h"
#include "Core/System.h"
#include "Core/ELF/PrxDecrypter.h"
#include "Core/FileSystems/MetaFileSystem.h"
#include "Core/HLE/scePauth.h"
#include "Core/HLE/HLE.h"
@@ -28,100 +29,36 @@

static int scePauth_F7AA47F6(u32 srcPtr, int srcLength, u32 destLengthPtr, u32 workArea)
{
u8 *src, *key;
u32 crc;
char name[256];
std::string hostPath;
FILE *fp;
int size;

INFO_LOG(HLE, "scePauth_F7AA47F6(%08x, %08x, %08x, %08x)", srcPtr, srcLength, destLengthPtr, workArea);

sprintf(name, "ms0:/PAUTH");
pspFileSystem.GetHostPath(std::string(name), hostPath);

src = (u8*)Memory::GetPointer(srcPtr);
key = (u8*)Memory::GetPointer(workArea);
crc = crc32(0, src, srcLength);

sprintf(name, "%s/pauth_%08x.bin.decrypt", hostPath.c_str(), crc);
fp = File::OpenCFile(name, "rb");
if (fp){
fseek(fp, 0, SEEK_END);
size = ftell(fp);
fseek(fp, 0, SEEK_SET);
fread(src, 1, size, fp);
fclose(fp);
Memory::Write_U32(size, destLengthPtr);
INFO_LOG(HLE, "Read from decrypted file %s", name);
return 0;
}

pspFileSystem.MkDir("ms0:/PAUTH");

sprintf(name, "%s/pauth_%08x.bin", hostPath.c_str(), crc);
ERROR_LOG(HLE, "No decrypted file found! save as %s", name);
auto src = Memory::GetPointer(srcPtr);
auto key = Memory::GetPointer(workArea);

fp = File::OpenCFile(name, "wb");
fwrite(src, 1, srcLength, fp);
fclose(fp);
const auto decryptResult = pspDecryptPRX(src, src, srcLength, key);

sprintf(name, "%s/pauth_%08x.key", hostPath.c_str(), crc);
fp = File::OpenCFile(name, "wb");
fwrite(key, 1, 16, fp);
fclose(fp);
if (decryptResult < 0)
{
ERROR_LOG(HLE, "Pauth decryption failed 0x%08X", decryptResult);
return decryptResult;
}

// We failed decrypting and dumped encrypted files, some games like Idolmaster
// use this to check for firmware version, so let's still return no problem.
Memory::Write_U32(decryptResult, destLengthPtr);
return 0;
}

static int scePauth_98B83B5D(u32 srcPtr, int srcLength, u32 destLengthPtr, u32 workArea)
{
u8 *src, *key;
u32 crc;
char name[256];
std::string hostPath;
FILE *fp;
int size;

INFO_LOG(HLE, "scePauth_98B83B5D(%08x, %08x, %08x, %08x)", srcPtr, srcLength, destLengthPtr, workArea);

sprintf(name, "ms0:/PAUTH");
pspFileSystem.GetHostPath(std::string(name), hostPath);

src = (u8*)Memory::GetPointer(srcPtr);
key = (u8*)Memory::GetPointer(workArea);
crc = crc32(0, src, srcLength);

sprintf(name, "%s/pauth_%08x.bin.decrypt", hostPath.c_str(), crc);
fp = File::OpenCFile(name, "rb");
if (fp){
fseek(fp, 0, SEEK_END);
size = ftell(fp);
fseek(fp, 0, SEEK_SET);
fread(src, 1, size, fp);
fclose(fp);
Memory::Write_U32(size, destLengthPtr);
INFO_LOG(HLE, "Read from decrypted file %s", name);
return 0;
}
auto src = Memory::GetPointer(srcPtr);
auto key = Memory::GetPointer(workArea);

pspFileSystem.MkDir("ms0:/PAUTH");
const auto decryptResult = pspDecryptPRX(src, src, srcLength, key);

sprintf(name, "%s/pauth_%08x.bin", hostPath.c_str(), crc);
ERROR_LOG(HLE, "No decrypted file found! save as %s", name);

fp = File::OpenCFile(name, "wb");
fwrite(src, 1, srcLength, fp);
fclose(fp);

sprintf(name, "%s/pauth_%08x.key", hostPath.c_str(), crc);
fp = File::OpenCFile(name, "wb");
fwrite(key, 1, 16, fp);
fclose(fp);
if (decryptResult < 0)
{
ERROR_LOG(HLE, "Pauth decryption failed 0x%08X", decryptResult);
return decryptResult;
}

return -1;
Memory::Write_U32(decryptResult, destLengthPtr);
return 0;
}

const HLEFunction scePauth[] = {

0 comments on commit 4c9e7b7

Please sign in to comment.
You can’t perform that action at this time.