Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdarg.h>
- #include <assert.h>
- #include <string.h>
- #include <string>
- #include <dirent.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <time.h>
- #include <math.h>
- #include <stddef.h>
- #include <sys/process.h>
- #include <cell/cell_fs.h>
- #include <sys/ss_get_open_psid.h>
- #include <sys/spu_initialize.h>
- #include <cell/dbgfont.h>
- #include <cell/sysmodule.h>
- #include <cell/pad/libpad.h>
- #include <sysutil/sysutil_sysparam.h>
- #include <PSGL/psglu.h>
- #include "../common/gfxCommon.h"
- #include "../common/gfxObject.h"
- #define BUTTON_SELECT (1<<0)
- #define BUTTON_L3 (1<<1)
- #define BUTTON_R3 (1<<2)
- #define BUTTON_START (1<<3)
- #define BUTTON_UP (1<<4)
- #define BUTTON_RIGHT (1<<5)
- #define BUTTON_DOWN (1<<6)
- #define BUTTON_LEFT (1<<7)
- #define BUTTON_L2 (1<<8)
- #define BUTTON_R2 (1<<9)
- #define BUTTON_L1 (1<<10)
- #define BUTTON_R1 (1<<11)
- #define BUTTON_TRIANGLE (1<<12)
- #define BUTTON_CIRCLE (1<<13)
- #define BUTTON_CROSS (1<<14)
- #define BUTTON_SQUARE (1<<15)
- SYS_PROCESS_PARAM(1001, 0x10000)
- uint32_t new_pad;
- uint32_t old_pad;
- uint64_t psidoffset = 0x800000000045218CULL;
- uint64_t conidoffset = 0x80000000003C2EF0ULL;
- uint64_t conidoffset2 = 0x8000000000452174ULL;
- void systemCallbackCheck(const uint64_t status, const uint64_t param, void *userdata)
- {
- (void)userdata;
- (void)param;
- switch (status)
- {
- case CELL_SYSUTIL_REQUEST_EXITGAME:
- sys_process_exit(0);
- break;
- default:
- break;
- }
- }
- int readPad( void )
- {
- int ret;
- uint32_t padd;
- CellPadData databuf;
- CellPadInfo2 infobuf;
- static uint32_t old_info = 0;
- ret = cellPadGetInfo2( &infobuf );
- if ( ret != 0 )
- {
- old_pad=new_pad = 0;
- return 1;
- }
- if ( infobuf.port_status[0] == CELL_PAD_STATUS_DISCONNECTED )
- {
- old_pad=new_pad = 0;
- return 1;
- }
- if((infobuf.system_info & CELL_PAD_INFO_INTERCEPTED) && (!(old_info & CELL_PAD_INFO_INTERCEPTED)))
- {
- old_info = infobuf.system_info;
- }
- else
- if((!(infobuf.system_info & CELL_PAD_INFO_INTERCEPTED)) && (old_info & CELL_PAD_INFO_INTERCEPTED))
- {
- old_info = infobuf.system_info;
- old_pad=new_pad = 0;
- return 1;
- }
- ret = cellPadGetData( 0, &databuf );
- if (ret != CELL_OK)
- {
- old_pad=new_pad = 0;
- return 1;
- }
- if (databuf.len == 0)
- {
- new_pad = 0;
- return 1;
- }
- padd = ( databuf.button[2] | ( databuf.button[3] << 8 ) );
- new_pad=padd & (~old_pad);
- old_pad= padd;
- return 1;
- }
- void clear()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
- }
- static inline void poke( uint64_t addr, uint64_t val)
- {
- system_call_2(7, addr, val);
- }
- static inline uint64_t peek(uint64_t address)
- {
- system_call_1(6, address);
- return_to_user_prog(uint64_t);
- }
- int mount(char *srcpath, char *dstpath)
- {
- system_call_2(35, (uint64_t) srcpath, (uint64_t) dstpath);
- return_to_user_prog(int);
- }
- void dumpLV2(const char *path)
- {
- FILE *output;
- uint64_t temp;
- uint64_t startpos;
- uint64_t endpos;
- startpos = 0x8000000000000000ULL;
- endpos = 0x80000000007FFFFFULL;
- output = fopen (path, "wb");
- for (uint64_t i = startpos; i < endpos; i = i + sizeof(uint64_t))
- {
- temp = peek (i);
- fwrite (&temp, sizeof(uint64_t), 1, output);
- }
- fclose (output);
- }
- uint64_t hexToULong(const char *chars)
- {
- return strtoull (chars,NULL,16);
- }
- int strLen(char *str)
- {
- int count = 0;
- while (*str++) count++;
- return count;
- }
- char *strToHexStr(char *str)
- {
- char *newstr = new char[16];
- memset(newstr, 0, 16);
- int len = strLen(str);
- for(int i = 0; i < len; i++)
- {
- char *chrs = new char[2];
- sprintf(chrs, "%02X", (char)str[i]);
- strcat(newstr, chrs);
- }
- for(int i = len; i < 8; i++)
- strcat(newstr, "00");
- return(newstr);
- }
- uint64_t strToULong(char *str)
- {
- char *chars = strToHexStr(str);
- return hexToULong(chars);
- }
- char* currentPSID = new char[32];
- char* currentCONID = new char[32];
- void refreshCONID()
- {
- uint64_t part1 = peek(conidoffset);
- uint64_t part2 = peek(conidoffset + 0x8);
- uint64_t part3 = peek(conidoffset + 0x10);
- uint64_t part4 = peek(conidoffset + 0x18);
- currentCONID = new char[36];
- sprintf(currentCONID, "%016llx\n%016llx\n%016llx\n%016llx", part1, part2, part3, part4);
- }
- void refreshPSID()
- {
- CellSsOpenPSID psid;
- sys_ss_get_open_psid(&psid);
- char* charshigh = new char[16];
- sprintf(charshigh, "%016llx", psid.high);
- char* charslow = new char[16];
- sprintf(charslow, "%016llx", psid.low);
- currentPSID = new char[32];
- sprintf(currentPSID, "%s%s", charshigh, charslow);
- refreshCONID();
- }
- int isMounted(const char *path)
- {
- int i, err;
- CellFsStat status;
- for (i = 0; i < 2; i++) {
- err = cellFsStat(path, &status);
- if (err == CELL_FS_SUCCEEDED) {
- return 1;
- }
- // sys_timer_sleep(1);
- }
- return 0;
- }
- int usb = 0;
- int main()
- {
- // Initialize 6 SPUs but reserve 1 SPU as a raw SPU for PSGL
- sys_spu_initialize(6, 1);
- cellSysutilRegisterCallback(0, systemCallbackCheck, NULL);
- cellSysmoduleLoadModule(CELL_SYSMODULE_IO);
- cellSysmoduleLoadModule(CELL_SYSMODULE_FS);
- cellPadInit(1);
- srand(time(0));
- // init PSGL and get the current system width and height
- gfxInitGraphics();
- // initalize the dbgFonts
- dbgFontInit();
- refreshPSID();
- while(1)
- {
- // check for exit
- cellSysutilCheckCallback();
- clear();
- // read pad
- readPad();
- // check if syscall works
- if(peek(0x80000000003EE470ULL) == 0xffffffff80010003ULL)
- break; // quit the loop
- if(new_pad & BUTTON_UP)
- if(usb < 127)
- usb++;
- if(new_pad & BUTTON_DOWN)
- if(usb > 0)
- usb--;
- if(new_pad & BUTTON_SELECT)
- {
- char device[12];
- sprintf(device, "/dev_usb%03d", usb);
- if(isMounted(device))
- {
- char path[21];
- sprintf(path, "%s/Lv-2.bin", device);
- dumpLV2(path);
- cellDbgFontPrintf( 0.06f, 0.1f, 1.15f, 0xff606060, "Lv-2 memory dumped to %s\nPress Start to continue.", path);
- cellDbgFontDraw();
- psglSwap();
- while(1)
- {
- readPad();
- if(old_pad & BUTTON_START)
- break;
- }
- }
- else
- {
- cellDbgFontPrintf( 0.06f, 0.1f, 1.15f, 0xff606060, "%s isn't mounted\nPress Start to continue.", device);
- cellDbgFontDraw();
- psglSwap();
- while(1)
- {
- readPad();
- if(old_pad & BUTTON_START)
- break;
- }
- }
- }
- if(new_pad & BUTTON_L1)
- {
- int fd;
- char part1[17];
- char part2[17];
- char part3[17];
- char part4[17];
- uint64_t nrw;
- char device[12];
- sprintf(device, "/dev_usb%03d", usb);
- if(isMounted(device))
- {
- char path[26];
- sprintf(path, "%s/consoleid.txt", device);
- CellFsErrno err = cellFsOpen(path,
- CELL_FS_O_RDONLY, &fd, NULL, 0);
- if(err == CELL_FS_SUCCEEDED)
- {
- //yay
- err = cellFsRead(fd, (void *)part1, (uint64_t)16, &nrw);
- if(err == CELL_FS_SUCCEEDED && nrw >= 16)
- {
- part1[16] = '\0';
- err = cellFsRead(fd, (void *)part2, (uint64_t)16, &nrw);
- if(err == CELL_FS_SUCCEEDED && nrw >= 16)
- {
- part2[16] = '\0';
- err = cellFsRead(fd, (void *)part3, (uint64_t)16, &nrw);
- if(err == CELL_FS_SUCCEEDED && nrw >= 16)
- {
- part3[16] = '\0';
- err = cellFsRead(fd, (void *)part4, (uint64_t)16, &nrw);
- if(err == CELL_FS_SUCCEEDED && nrw >= 16)
- {
- part4[16] = '\0';
- // write out the consoleid now
- uint64_t part1u = hexToULong(part1);
- uint64_t part2u = hexToULong(part2);
- uint64_t part3u = hexToULong(part3);
- uint64_t part4u = hexToULong(part4);
- poke(conidoffset, part1u);
- poke(conidoffset + 0x8, part2u); // 4 64-bit integers
- poke(conidoffset + 0x10, part3u);
- poke(conidoffset + 0x18, part4u);
- poke(conidoffset2, part1u);
- poke(conidoffset2 + 0x8, part2u);
- }
- else
- {
- cellDbgFontPrintf( 0.06f, 0.1f, 1.15f, 0xff606060, "Unable to read consoleid part 4\nPress Start to continue.");
- cellDbgFontDraw();
- psglSwap();
- while(1)
- {
- readPad();
- if(old_pad & BUTTON_START)
- break;
- }
- }
- }
- else
- {
- cellDbgFontPrintf( 0.06f, 0.1f, 1.15f, 0xff606060, "Unable to read consoleid part 3\nPress Start to continue.");
- cellDbgFontDraw();
- psglSwap();
- while(1)
- {
- readPad();
- if(old_pad & BUTTON_START)
- break;
- }
- }
- }
- else
- {
- cellDbgFontPrintf( 0.06f, 0.1f, 1.15f, 0xff606060, "Unable to read consoleid part 2\nPress Start to continue.");
- cellDbgFontDraw();
- psglSwap();
- while(1)
- {
- readPad();
- if(old_pad & BUTTON_START)
- break;
- }
- }
- }
- else
- {
- cellDbgFontPrintf( 0.06f, 0.1f, 1.15f, 0xff606060, "Unable to read consoleid part 1\nPress Start to continue.");
- cellDbgFontDraw();
- psglSwap();
- while(1)
- {
- readPad();
- if(old_pad & BUTTON_START)
- break;
- }
- }
- err = cellFsClose(fd);
- }
- else
- {
- cellDbgFontPrintf( 0.06f, 0.1f, 1.15f, 0xff606060, "Unable to read consoleid.txt\nPress Start to continue.");
- cellDbgFontDraw();
- psglSwap();
- while(1)
- {
- readPad();
- if(old_pad & BUTTON_START)
- break;
- }
- }
- }
- else
- {
- cellDbgFontPrintf( 0.06f, 0.1f, 1.15f, 0xff606060, "%s isn't mounted\nPress Start to continue.", device);
- cellDbgFontDraw();
- psglSwap();
- while(1)
- {
- readPad();
- if(old_pad & BUTTON_START)
- break;
- }
- }
- refreshPSID();
- }
- if(new_pad & BUTTON_R1)
- {
- int fd;
- char part1[17];
- char part2[17];
- uint64_t nrw;
- char device[12];
- sprintf(device, "/dev_usb%03d", usb);
- if(isMounted(device))
- {
- char path[21];
- sprintf(path, "%s/psid.txt", device);
- CellFsErrno err = cellFsOpen(path,
- CELL_FS_O_RDONLY, &fd, NULL, 0);
- if(err == CELL_FS_SUCCEEDED)
- {
- //yay
- err = cellFsRead(fd, (void *)part1, (uint64_t)16, &nrw);
- if(err == CELL_FS_SUCCEEDED && nrw >= 16)
- {
- part1[16] = '\0';
- err = cellFsRead(fd, (void *)part2, (uint64_t)16, &nrw);
- if(err == CELL_FS_SUCCEEDED && nrw >= 16)
- {
- part2[16] = '\0';
- // write out the PSID now
- uint64_t part1u = hexToULong(part1);
- uint64_t part2u = hexToULong(part2);
- poke(psidoffset, part1u); // PSID starts at 0x800000000044A18C
- poke(psidoffset + 0x8ULL, part2u); // 2 64-bit integers
- }
- else
- {
- cellDbgFontPrintf( 0.06f, 0.1f, 1.15f, 0xff606060, "Unable to read PSID part 2\nPress Start to continue.");
- cellDbgFontDraw();
- psglSwap();
- while(1)
- {
- readPad();
- if(old_pad & BUTTON_START)
- break;
- }
- }
- }
- else
- {
- cellDbgFontPrintf( 0.06f, 0.1f, 1.15f, 0xff606060, "Unable to read PSID part 1\nPress Start to continue.");
- cellDbgFontDraw();
- psglSwap();
- while(1)
- {
- readPad();
- if(old_pad & BUTTON_START)
- break;
- }
- }
- err = cellFsClose(fd);
- }
- else
- {
- cellDbgFontPrintf( 0.06f, 0.1f, 1.15f, 0xff606060, "Unable to read psid.txt\nPress Start to continue.");
- cellDbgFontDraw();
- psglSwap();
- while(1)
- {
- readPad();
- if(old_pad & BUTTON_START)
- break;
- }
- }
- }
- else
- {
- cellDbgFontPrintf( 0.06f, 0.1f, 1.15f, 0xff606060, "%s isn't mounted\nPress Start to continue.", device);
- cellDbgFontDraw();
- psglSwap();
- while(1)
- {
- readPad();
- if(old_pad & BUTTON_START)
- break;
- }
- }
- refreshPSID();
- }
- if(new_pad & BUTTON_CROSS)
- {
- char *part1 = new char[17];
- char *part2 = new char[17];
- sprintf(part1,"%08x%08x",rand(),rand());
- sprintf(part2,"%08x%08x",rand(),rand());
- uint64_t part1u = hexToULong(part1);
- uint64_t part2u = hexToULong(part2);
- poke(psidoffset, part1u); // PSID starts at 0x800000000044A18C
- poke(psidoffset + 0x8ULL, part2u); // 2 64-bit integers
- refreshPSID();
- }
- if(new_pad & BUTTON_SQUARE)
- {
- char *part1 = new char[17];
- sprintf(part1,"%08x%08x",rand(),rand());
- uint64_t part1u = hexToULong(part1);
- poke(conidoffset + 0x8, part1u);
- poke(conidoffset2 + 0x8, part1u);
- refreshPSID();
- }
- if(new_pad & BUTTON_TRIANGLE)
- break;
- // print help stuff
- cellDbgFontPrintf( 0.06f, 0.1f, 1.15f, 0xff606060, "PSIDPatch 1.5 - by stoker25\nCurrent PSID: %s\n\nCross - Randomise PSID\nSquare - Randomise ConsoleID\nR1 - Change PSID to /dev_usb%03d/psid.txt\nL1 - Change ConsoleID to /consoleid.txt\nUp/Down - Change USB", currentPSID, usb);
- cellDbgFontPrintf( 0.06f, 0.4f, 1.15f, 0xff606060, "Select - Dump Lv-2\nTriangle - Quit PSIDPatch");
- cellDbgFontPrintf( 0.06f, 0.55f, 1.15f, 0xff606060, "Current Console ID:\n%s", currentCONID);
- cellDbgFontDraw();
- // swap PSGL buffers
- psglSwap();
- sys_timer_usleep(200000);
- }
- sys_process_exit(0);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement