#include #include #include #include #include #include #include #include #include /* http://psp.jim.sh/pspsdk-doc/group__Utils.html include SHA-1 checks on dump/restore */ void ReadKey(u16 key, void *buffer) { sceIdStorageReadLeaf(key, buffer); return; } void WriteKey(u16 key, void *buffer) { sceIdStorageWriteLeaf(key, buffer); sceIdStorageFlush(); return; } int CheckDummy(int key) { char buffdummy[512]; char buffdcmp[512]; int resdummy; memset(buffdummy, 0, 512); memset(buffdcmp, 0, 512); sceIdStorageReadLeaf(key, buffdummy); resdummy = memcmp(buffdummy, buffdcmp, 512); if (resdummy == 0) return 0; else return -1; } int CheckHW(void) { char chwbuff[512]; sceIdStorageReadLeaf(0x0050, chwbuff); if (chwbuff[33] == 0x02) return -1; else if (chwbuff[33] == 0x01) return 0; else return -2; } int BackupKeyToFile(u16 key, char filepath[50]) { char dumpbuff[512]; memset(dumpbuff, 0, 512); int f = sceIoOpen(filepath, PSP_O_WRONLY | PSP_O_CREAT, 0777); if (f < 0) return -1; sceIdStorageReadLeaf(key, dumpbuff); sceIoWrite(f, dumpbuff, 0x200); sceIoClose(f); return 0; } int BrickPSP(void) { char brickbuff[512]; if (sceIdStorageIsReadOnly()) return -1; memset(brickbuff, 0, 512); sceIdStorageWriteLeaf(0x0005, brickbuff); sceIdStorageWriteLeaf(0x0006, brickbuff); return 0; } int chkDowngrade(void) { char dgbuff[512]; sceIdStorageReadLeaf(0x0005, dgbuff); if (dgbuff[0] == 0x6E) { if (dgbuff[13] == 0x01) return 0; } else { return -1; } } int chkByte(u16 key, u32 offset, char val) { char buffbyte[512]; buffval[offset] == val memset(buffbyte, 0, 512); sceIdStorageLookup(key, offset, &buffbyte, 1); if((memcmp(buffbyte, buffval, 2)) == 0) { return 0; } else { return -1; } } int chkRegion(void) { int reg; sceIdStorageLookup(0x100, 61, ®, 1); if (reg == 0x00) return -1; else if (reg == 0x03) return 3; else if (reg == 0x04) return 4; else if (reg == 0x05) return 5; else if (reg == 0x06) return 6; else if (reg == 0x0A) return 7; else if (reg == 0x0B) return 8; else if (reg == 0x09) return 9; else if (reg == 0x0C) return 10; else if (reg == 0x0D) return 11; else return reg; } int dgTA082(void) { u8 leaf[512]; memset(leaf, 0, 512); if (chkDowngrade() < 0) return -1; if (scePowerGetBatteryLifePercent() < 75) return -2; if (sceIdStorageIsReadOnly()) return -4; if (CheckHW() == -1) { sceIdStorageReadLeaf(0x0006, leaf); sceIdStorageWriteLeaf(0x0042, leaf); sceIdStorageReadLeaf(0x0005, leaf); sceIdStorageWriteLeaf(0x0046, leaf); sceIdStorageReadLeaf(0x0005, leaf); sceIdStorageWriteLeaf(0x0006, leaf); sceIdStorageReadLeaf(0x0004, leaf); sceIdStorageWriteLeaf(0x0005, leaf); return 0; } else return -3; } int RestoreKeyFromFile(u16 key, char filepath[50]) { char buffer[512]; int f; memset(buffer, 0, 512); if (sceIdStorageIsReadOnly()) return -2; f = sceIoOpen(filepath, PSP_O_RDONLY, 0777); if(f <= 0) { return -1; } sceIoRead(f, buffer, 512); sceIdStorageWriteLeaf(key, buffer); sceIoClose(f); return 0; } int compareKeyBuffer(u16 key, void *buffer) { char buff[512]; int x; sceIdStorageReadKey(key, buff); x = memcmp(buff, buffer, 512); if (x == 0) return 0; else return -1; } int getMAC(void *buffer) { sceIdStorageLookup(0x044, 0, buffer, 6); return 0; } int getSerial(void *buffer) { sceIdStorageLookup(0x050, 0, buffer, 30); return 0; } int BackupIdStorageKeys(char folderpath[70]) { char KeyNum[56] char dump[512]; int f; u16 key; sceIoMkdir(folderpath , 0777); for(key=0x004;key<0x127;key++) { sprintf(KeyNum,"%s0x%03X.bin", folderpath, key); f = sceIoOpen(KeyNum, PSP_O_CREAT | PSP_O_TRUNC | PSP_O_WRONLY, 0777); if(f < 0) { return -1; } sceIdStorageReadLeaf(key, dump); sceIoWrite(f, dump, 512); sceIoClose(f); } return 0; } int RestoreIdStorageKeys(char folderpath[70]) { char KeyNum[56]; char dump[512]; int f; int chkTest; u16 key; int Failed = 0; sceKernelDelayThread(4*1000*1000); for(key=0x004;key<0x127;key++) { sprintf(KeyNum,"%s0x%03X.bin", folderpath, key); f = sceIoOpen(KeyNum, PSP_O_RDONLY, 0777); if(f < 0) { Failed = 1; return -1; } sceIoClose(f); } if(!Failed) { for(key=0x004;key<0x127;key++) { sprintf(KeyNum,"%s0x%03X.bin", folderpath, key); f = sceIoOpen(KeyNum, PSP_O_RDONLY, 0777); if(f < 0) { return -1; } Test = sceIoRead(f, dump, 512); if(Test<0) { return -1; }else{ sceIdStorageWriteLeaf(key, dump); sceIoClose(f); } } }else{ return -1; } return 0; }