unpack-pbp.h
Code: Select all
// Dan Peori (peori@oopo.net)
// modded by Ruggero Russo (ruj89@crazynet.org)
// 0: no errors
//-1: infile errors
//-2: wrong infile format
//-3: memory allocation errors
//-4: outfile errors
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <string.h>
#include <stdlib.h>
#define printf pspDebugScreenPrintf
typedef struct { char signature[4]; int version; int offset[8]; } HEADER;
int extract_elf(char file_path[256]) {
HEADER header;
int total_size, size, infile, outfile;
void *buffer;
// Check the argument count.
if(file_path == "") { printf("USAGE: %s <filename>\n", file_path); return -1; }
// Open the input file.
if(!(infile = sceIoOpen(file_path, PSP_O_RDONLY, 0777))) { printf("ERROR: Could not open the input file. (%s)\n", file_path); return -1; }
// Get the input file size.
total_size = sceIoLseek(infile, 0, PSP_SEEK_END);
sceIoLseek(infile, 0, PSP_SEEK_SET);
if (total_size < 0) { printf("ERROR: Could not get the input file size.\n"); return -1; }
// Read in the input file header.
if (sceIoRead(infile, &header, sizeof(HEADER)) < 0) { printf("ERROR: Could not read the input file header.\n"); return -1; }
// Check the input file signature.
if (header.signature[0] != 0x00) { printf("ERROR: Input file is not a PBP file or it is kxploited.\n"); return -2; } else
if (header.signature[1] != 0x50) { printf("ERROR: Input file is not a PBP file or it is kxploited.\n"); return -2; } else
if (header.signature[2] != 0x42) { printf("ERROR: Input file is not a PBP file or it is kxploited.\n"); return -2; } else
if (header.signature[3] != 0x50) { printf("ERROR: Input file is not a PBP file or it is kxploited.\n"); return -2; }
// For data.psp section...
// Get the size of the section data.
size = header.offset[7] - header.offset[6];
// Allocate the section data buffer.
buffer = malloc(size);
if (buffer == NULL) { printf("ERROR: Could not allocate the section data buffer. (%d)\n", size); return -3; }
// Read in the section data.
if (sceIoRead(infile, buffer, size) < 0) { printf("ERROR: Could not read in the section data.\n"); return -1; }
// Open the output file.
if(!(outfile = sceIoOpen("ms0:/eboot.elf", PSP_O_WRONLY|PSP_O_CREAT, 0777))) { printf("ERROR: Could not open the output file. (eboot.elf)\n"); return -4; }
// Write out the section data.
if (sceIoWrite(outfile, buffer, size) < 0) { printf("ERROR: Could not write out the section data.\n"); return -4; }
// Close the output file.
if (sceIoClose(outfile) < 0) { printf("ERROR: Could not close the output file.\n"); return -4; }
// Free the section data buffer.
free(buffer);
// Output the section information.
printf("%8d bytes | eboot.elf\n", size);
// Close the input file.
if (sceIoClose(infile) < 0) { printf("ERROR: Could not close the input file.\n"); return -1; }
return 0;
}
Code: Select all
#include <pspdebug.h>
#include <pspuser.h>
#include <string.h>
#include <pspsdk.h>
#include "unpack-pbp.h"
PSP_MODULE_INFO("ssaver",0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
#define printf pspDebugScreenPrintf
int extract_elf(char file_path[256]);
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
int thid = 0;
/* Note the use of THREAD_ATTR_USER to ensure the callback thread is in user mode */
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, PSP_THREAD_ATTR_USER, NULL);
if(thid >= 0)
{
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int main(int argc, char **argv)
{
SceKernelLMOption option;
int status;
SceUID ssaver;
pspDebugScreenInit();
SetupCallbacks();
extract_elf("ms0:/eboot_mod.pbp");
memset(&option, 0, sizeof(option));
option.size = sizeof(option);
option.mpidtext = 2;
option.mpiddata = 2;
option.position = 0;
option.access = 1;
ssaver = sceKernelLoadModule("ms0:/eboot.elf",0,&option);
if(ssaver < 0) printf("Can't load the elf file");
else sceKernelStartModule(ssaver,0,NULL,&status,NULL);
sceKernelSleepThread();
return 0;
}
Why does it show the error message "Can't load the elf file"? I tried to extract the elf using PSPBrew and to comment the extract_elf function, but it was the same...