Install a bootstrap and return to application... how?
Install a bootstrap and return to application... how?
Hi,
I'm trying to code a bootstrap to return to my programm when exit.
But how? I'm been able to patch the sceKernelExitGame function, but I'm not been able to return to my programm!
I've never coded a bootstrap or a patch on the fly for a module, so where I can find a example or a src?
Thanks in advance!
(I've searched for it, but in all the post there are no solution)
I'm trying to code a bootstrap to return to my programm when exit.
But how? I'm been able to patch the sceKernelExitGame function, but I'm not been able to return to my programm!
I've never coded a bootstrap or a patch on the fly for a module, so where I can find a example or a src?
Thanks in advance!
(I've searched for it, but in all the post there are no solution)
Hi, here is a sample i wrote for MyPspMenu : http://mydedibox.fr/downloads/PSP/apiHookSample.tar.gz
Hope it can help you.
Hope it can help you.
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
I couldn't understand what cpasjuste told me (how to use it.)
The prx patches the function sceKernelExitGame.
but if you load it from your app (at the beginning per example) the patch will work WHILE your app is running but after you exit it by running a game or any homebrew the patch is lost.
this is what he said:
this is what I don't understand because if I don't use the function from the module the patch does not affect anything
The prx patches the function sceKernelExitGame.
but if you load it from your app (at the beginning per example) the patch will work WHILE your app is running but after you exit it by running a game or any homebrew the patch is lost.
this is what he said:
and what he is saying is to put my function to load iso's or homebrew before the code part which patches sceKernelExitGame.In the "hook prx" i gave you, put your function to load your iso/eboot just before the sceKernelExitGame hook function. Since your module will be loaded before the hook function, it will be effective in this one.
this is what I don't understand because if I don't use the function from the module the patch does not affect anything
I've understand it, but I'm not been able to start the function for patch sceKernelExitGame!
I've understant that if I start i before launch a pbp or a prx, the function will patch the sceKernelExitGame of my programm and not of the lauched PBP\PRX!
I've an idea to load the function as a plugin, but I don't know how!
However thanks a lot!
I've understant that if I start i before launch a pbp or a prx, the function will patch the sceKernelExitGame of my programm and not of the lauched PBP\PRX!
I've an idea to load the function as a plugin, but I don't know how!
However thanks a lot!
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
I tried User partition and gives an error which means partition mismatch.
Probably because I am running user mode and trying to load a module to the same partition I am loading.
I will try loading a module to kernel mode partition and from that module load the prx to user partition.
as sceKernelLoadExec is from LoadExecForUser maybe it can only be hooked from user partition?
Probably because I am running user mode and trying to load a module to the same partition I am loading.
I will try loading a module to kernel mode partition and from that module load the prx to user partition.
as sceKernelLoadExec is from LoadExecForUser maybe it can only be hooked from user partition?
This code should help you both, it's the mypspmenu eboot/iso loader code, it's a bit crappy for now, i wanted to clean it before but anyway ...
The sceKernelExitGame hook is taken from the psplinkusb sources (thanks Tyranid).
From your application, loadexec an user mode .pbp that will load this kernel mode module.
The rest is easy to understand (i think) by reading the above code :
The sceKernelExitGame hook is taken from the psplinkusb sources (thanks Tyranid).
From your application, loadexec an user mode .pbp that will load this kernel mode module.
The rest is easy to understand (i think) by reading the above code :
Code: Select all
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/unistd.h>
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspiofilemgr.h>
#include <psptypes.h>
#include <pspsdk.h>
#include <stdlib.h>
#include <pspumd.h>
#include "../../include/systemctrl_se.h"
#include "../../include/pspmodulemgr_kernel.h"
#include "../../include/systemctrl.h"
#include "nethost.h"
#include "common.h"
#define HOSTFSDRIVER_NAME "USBHostFSDriver"
#define HOSTFSDRIVER_PID (0x1C9)
#define PSP_USBBUS_DRIVERNAME "USBBusDriver"
PSP_MODULE_INFO("mypspmenu_eboot_loader_main", 0x1000, 1, 1); // 0x1000 = Kernel MODE
PSP_MAIN_THREAD_ATTR(0);
int line = 1;
char buffer[5][128];
void doBlit(char *msg)
{
blit_string(1, line, msg,0xffffff,0x000000);
line++;
}
void remap(int usb)
{
SceModule *mod;
mod = sceKernelFindModuleByName("sceIOFileManager");
if(mod == NULL) printf("FAIL => sceIOFileManager module not found\n");
u32 * addr;
//addr = (u32 *)(mod->gp_value+0x2b30);
addr = (u32 *)(mod->gp_value+0x2AE0);
printf("addr : 0x%08X\n", mod->gp_value+0x2AE0);
memset(addr, 0, 64);
sceIoUnassign("ms0:");
if(usb) sceIoAssign("ms0:", "usbhost0:", NULL, IOASSIGN_RDWR, NULL, 0);
else sceIoAssign("ms0:", "nethost0:", NULL, IOASSIGN_RDWR, NULL, 0);
}
void execEboot(char *target)
{
struct SceKernelLoadExecVSHParam param;
memset(¶m, 0, sizeof(param));
param.key = "game";
param.size = sizeof(param);
param.args = strlen(target)+1;
param.argp = target;
sctrlKernelLoadExecVSHMs2(target, ¶m);
}
void exit_to_mypspmenu(void) {
execEboot("ms0:/PSP/GAME/mypspmenu/EBOOT.PBP");
}
int unload_loader(void)
{
sceKernelDelayThread(10*100000);
SceModule *mod;
SceUID modid;
int ret = 0;
int status;
mod = sceKernelFindModuleByName("MYPSPMENU_BOOTLOADER");
if(mod != NULL)
{
modid = mod->modid;
ret = sceKernelStopModule(modid, 0, NULL, &status, NULL);
if(ret >= 0)
{
ret = sceKernelUnloadModule(modid);
}
}
else
{
return 0;
}
return 0;
}
int build_args(char *args, const char *execfile, int argc, char **argv)
{
int loc = 0;
int i;
strcpy(args, execfile);
loc += strlen(execfile) + 1;
for(i = 0; i < argc; i++)
{
strcpy(&args[loc], argv[i]);
loc += strlen(argv[i]) + 1;
}
return loc;
}
int loadStartModuleWithArgs(const char *name, int argc, char **argv)
{
SceUID modid;
int status;
char args[128];
int len;
sprintf(tmp, "INFO => loading %s", name);
doBlit(tmp);
modid = sceKernelLoadModule(name, 0, NULL);
if(modid >= 0)
{
doBlit("SUCCESS => sceKernelStartModule");
len = build_args(args, name, argc, argv);
modid = sceKernelStartModule(modid, len, (void *) args, &status, NULL);
}
else
{
sprintf(tmp, "FAIL => error %x", modid);
doBlit(tmp);
doBlit("INFO => Exiting in a few seconds...");
sceKernelDelayThread(20*1000000);
exit_to_mypspmenu();
}
return modid;
}
int loadStartDiscModule(const char *name, int argc, char **argv)
{
SceUID modid;
int status;
char args[1024];
int len;
SceKernelLMOption option;
SceUID mpid = PSP_MEMORY_PARTITION_USER;
memset(&option, 0, sizeof(option));
option.size = sizeof(option);
option.mpidtext = mpid;
option.mpiddata = mpid;
option.position = 0;
option.access = 1;
modid = sceKernelLoadModuleDisc(name, 0, &option);
if(modid >= 0)
{
len = build_args(args, name, argc, argv);
modid = sceKernelStartModule(modid, len, (void *) args, &status, NULL);
}
else
{
sprintf(tmp, "FAIL => error %x", modid);
doBlit(tmp);
doBlit("INFO => Exiting in a few seconds...");
sceKernelDelayThread(20*1000000);
exit_to_mypspmenu();
}
return modid;
}
int loadStartModuleWithoutArgs(char *path)
{
u32 loadResult;
u32 startResult;
int status;
loadResult = kuKernelLoadModule(path, 0, NULL);
if (loadResult & 0x80000000){
return -1;
}
else
{
startResult = sceKernelStartModule(loadResult, 0, NULL, &status, NULL);
}
if (loadResult != startResult){
return -2;
}
return 0;
}
int loadStartModule(const char *name, int argc, char **argv, int mode)
{
SceUID modid;
int status;
char args[1024];
int len;
if(mode==2) name = "disc0:/PSP_GAME/SYSDIR/EBOOT.BIN";
SceKernelLMOption option;
SceUID mpid = PSP_MEMORY_PARTITION_USER;
memset(&option, 0, sizeof(option));
option.size = sizeof(option);
option.mpidtext = mpid;
option.mpiddata = mpid;
if(mode != 2) option.position = 1; else option.position = 0;
option.access = 1;
if(mode==0) // normal eboot
{
sprintf(tmp,"ld => %s", name);
doBlit(tmp);
modid = sceKernelLoadModuleMs2(name, 0, &option);
}
else if(mode==1) // psx eboot
{
//printf("loading module => %s\n", name);
sprintf(tmp,"ld => %s", name);
doBlit(tmp);
modid = sceKernelLoadModuleMs4(name, 0, NULL);
}
else if(mode==2) // umd eboot
{
sprintf(tmp,"ld => %s", name);
doBlit(tmp);
modid = ModuleMgrForKernel_A1A78C58(name, 0, &option);
}
if(modid >= 0)
{
len = build_args(args, name, argc, argv);
modid = sceKernelStartModule(modid, len, (void *) args, &status, NULL);
doBlit("SUCCESS => sceKernelStartModule()");
}
else
{
//printf("could not load module => %s || Error => %x\n", name, modid);
sprintf(tmp,"FAIL => error %x", modid);
doBlit(tmp);
doBlit("INFO => Exiting please wait...");
sceKernelDelayThread(20*1000000);
exit_to_mypspmenu();
//execEboot("ms0:/PSP/GAME/psplink/EBOOT.PBP");
//sceKernelSleepThread();
return 0;
}
return modid;
}
int loadNetHost()
{
strncpy(address, buffer[4], 16);
strncpy(port, "7513", 8);
strncpy(entry, "1", 9);
strncpy(adhocAddress, "0", 16);
startNetHost(address, port, entry, password, adhocAddress);
return 0;
}
int loadUsbHost()
{
loadStartModuleWithoutArgs("ms0:/PSP/GAME/mypspmenu/system/usbhostfs.prx");
int retVal = 0;
retVal = sceUsbStart(PSP_USBBUS_DRIVERNAME, 0, 0); //SceUsbStart
if (retVal != 0) {
printf("Error starting USB Bus driver\n");
return 0;
}
retVal = sceUsbStart(HOSTFSDRIVER_NAME, 0, 0);
if (retVal != 0) {
printf("Error starting USB Host driver\n");
return 0;
}
retVal = sceUsbActivate(HOSTFSDRIVER_PID); //SceUsbActivate
sceKernelDelayThread(30*100000);
return 0;
}
static int readLine(SceUID fd, char *Line, int MaxCharacters)
{
int i;
int Read;
char TempCharacter;
i = 0;
if (MaxCharacters == 0)
{
return 1;
}
do
{
Read = sceIoRead(fd, &TempCharacter, 1);
if (Read && TempCharacter != '\n' && TempCharacter != '\r')
{
Line[i++] = TempCharacter;
}
} while (TempCharacter != '\n' && Read == 1 && i < MaxCharacters);
Line[i] = 0;
return !Read;
}
int main_thread(SceSize args, void *argp)
{
int count = 0, eof = 0;
unload_loader();
sceKernelDelayThread(10*100000);
// Read and load the configuration line by line
SceUID fd = sceIoOpen("ms0:/PSP/GAME/mypspmenu/system/conf.log", PSP_O_RDONLY, 0777);
while (!eof)
{
eof = readLine(fd, buffer[count], 128);
//doBlit(buffer[count]);
count++;
}
sceIoClose(fd);
sceIoRemove("ms0:/PSP/GAME/mypspmenu/system/conf.log");
sceKernelDelayThread(10*100000);
strcpy(tmpPrx, buffer[0]);
strcat(tmpPrx, ".bin");
if(strcmp(buffer[1], "homebrew") == 0)
{
doBlit("INFO => homebrew mode enabled");
if(strcmp(buffer[3], "nethost") == 0)
{
doBlit("INFO => nethost mode enabled ...");
doBlit("INFO => please wait while initializing net driver ...");
loadNetHost();
remap(0);
loadStartModule(buffer[0], 0, NULL, 0);
}
else if(strcmp(buffer[3], "usbhost") == 0)
{
doBlit("INFO => usbhost mode enabled ...");
doBlit("INFO => please wait while initializing usb driver ...");
loadUsbHost();
remap(1);
loadStartModule(buffer[0], 0, NULL, 0);
}
else
{
loadStartModule(buffer[0], 0, NULL, 0);
}
}
else if(strcmp(buffer[1], "psx") == 0) {
doBlit("INFO => psx mode enabled");
loadStartModule(buffer[0], 0, NULL, 1);
}
else if(strcmp(buffer[1], "umd") == 0) {
doBlit("INFO => umd mode enabled");
int i = sceUmdCheckMedium();
if(!(i)) sceUmdWaitDriveStat(UMD_WAITFORDISC);
sceUmdActivate(1, "disc0:");
sceUmdWaitDriveStat(UMD_WAITFORINIT);
loadStartModule(buffer[0], 0, NULL, 2);
}
else if(strcmp(buffer[1], "iso") == 0)
{
doBlit("INFO => iso mode enabled");
if(strcmp(buffer[3], "nethost") == 0)
{
doBlit("INFO => nethost mode enabled ...");
doBlit("INFO => please wait while initializing net driver ...");
loadNetHost();
//sceKernelDelayThread(100*120000);
sctrlSEUmountUmd();
sctrlSEMountUmdFromFile(buffer[0], 0, 1);
}
else if(strcmp(buffer[3], "usbhost") == 0)
{
doBlit("INFO => usbhost mode enabled ...");
doBlit("INFO => please wait while initializing usb driver ...");
loadUsbHost();
sctrlSEUmountUmd();
sctrlSEMountUmdFromFile(buffer[0], 0, 1);
}
else
{
sctrlSEUmountUmd();
sctrlSEMountUmdFromFile(buffer[0], 0, 1);
}
doBlit("INFO => starting iso...");
int i = sceUmdCheckMedium();
if(!(i)) sceUmdWaitDriveStat(UMD_WAITFORDISC);
sceUmdActivate(1, "disc0:");
sceUmdWaitDriveStat(UMD_WAITFORINIT);
loadStartDiscModule("disc0:/PSP_GAME/SYSDIR/EBOOT.BIN", 0, NULL);
}
// Hook exit game function
if(atoi(buffer[2])==66) sctrlHENSetSpeed(66, 33);
else if(atoi(buffer[2])==111) sctrlHENSetSpeed(111, 55);
else if(atoi(buffer[2])==222) sctrlHENSetSpeed(222, 111);
else if(atoi(buffer[2])==266) sctrlHENSetSpeed(266, 133);
else if(atoi(buffer[2])==333) sctrlHENSetSpeed(333, 133);
SceModule *mod;
mod = sceKernelFindModuleByName("sceLoadExec");
if(mod) apiHookByName(mod->modid, "LoadExecForUser","sceKernelExitGame", exit_to_mypspmenu);
sceKernelExitDeleteThread(0);
return 0;
}
/* Entry point */
int module_start(SceSize args, void *argp)
{
int thid;
/* Create a high priority thread */
thid = sceKernelCreateThread("mypspmenu_eboot_loader_main_th", main_thread, 8, 0x1000, 0, NULL);
if(thid >= 0)
{
sceKernelStartThread(thid, args, argp);
}
return 0;
}
int module_stop()
{
sceKernelExitDeleteThread(0);
return 0;
}
Last edited by Cpasjuste on Thu Jun 19, 2008 11:33 pm, edited 2 times in total.
I've started it in Kernel memory partition and it works perfectly!
Excuse for my english but I've don't understand very well what you sayd!
I'm trying to start the prx with args, but I don't know how!
Is very simple I think but I don't know the structure of the args!
Example:
And in the prx:
This is that I want to do, but is fill of errors!
Can you give me a little help?
Excuse for my english but I've don't understand very well what you sayd!
I'm trying to start the prx with args, but I don't know how!
Is very simple I think but I don't know the structure of the args!
Example:
Code: Select all
/* I have to load the prx with a path
* so, i've try to start the prx with args:
*/
pspSdkLoadStartModule("ms0:/PSP/GAME/Explorer/krnlmod.prx", PSP_MEMORY_PARTITION_KERNEL, 14, "random string");
Code: Select all
int module_start(SceSize args, void *argp)
{
char* mystring=(char*)malloc(strlen(argp));
argp=mystring;
printf("%s", mystring);
...
...
}
Can you give me a little help?
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
cpasjute, I haven't understand very well your code!
This is the prx to load eboot etc.. and patch the exit game fuct?
I've writed this code, but the exit game funct is not be patched!
Why? The prx loaded is stopped when load the eboot?
The prx works, because if I don't start a eboot it patch the exit game funct of my programm, and return to my programm!
This is the prx to load eboot etc.. and patch the exit game fuct?
I've writed this code, but the exit game funct is not be patched!
Code: Select all
pspSdkLoadStartModule("ms0:/PSP/GAME/Explorer/apihook.prx", PSP_MEMORY_PARTITION_KERNEL);
execEboot("ms0:/PSP/GAME/AdhocFileTransfer/EBOOT.PBP");
The prx works, because if I don't start a eboot it patch the exit game funct of my programm, and return to my programm!
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
From what I can understand from Cpasjuste's code, it reads the file path from a file?
then loads and starts it with loadStartModule function.
right?
Well I tried this:
But crashes and shows a black screen only.
I also tried with the uncommented codeand with the loadStartModule uncommented and execEboot(path); commented and seems to load something but then crashes too.
Edit: Nvm, it was something in my PBP. It works and launches the correct file but does not patch anything >.< (I tried with loadstart module and without)
then loads and starts it with loadStartModule function.
right?
Well I tried this:
Code: Select all
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/unistd.h>
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspiofilemgr.h>
#include <psptypes.h>
#include <pspsdk.h>
#include <stdlib.h>
#include <pspumd.h>
#include "include/systemctrl_se.h"
#include "include/pspmodulemgr_kernel.h"
#include "include/systemctrl.h"
#include "apihook.h"
PSP_MODULE_INFO("hook sample", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
int execEboot(char *target)
{
int loadexec = 0;
struct SceKernelLoadExecVSHParam param;
char argp[256];
int args;
strcpy(argp, target);
args = strlen(target)+1;
memset(¶m, 0, sizeof(param));
param.size = sizeof(param);
param.args = args;
param.argp = argp;
param.key = NULL;
param.vshmain_args_size = 0;
param.vshmain_args = NULL;
//sceKernelSuspendAllUserThreads();
loadexec = sctrlKernelLoadExecVSHMs2(target, ¶m);
return loadexec;
}
void ExitNervOS(void) {
execEboot("ms0:/PSP/GAME/NervOS/EBOOT.PBP");
}
/*int build_args(char *args, const char *execfile, int argc, char **argv)
{
int loc = 0;
int i;
strcpy(args, execfile);
loc += strlen(execfile) + 1;
for(i = 0; i < argc; i++)
{
strcpy(&args[loc], argv[i]);
loc += strlen(argv[i]) + 1;
}
return loc;
}
int loadStartModule(const char *name, int argc, char **argv, int mode)
{
SceUID modid = 0;
int status;
char args[1024];
int len;
if(mode==2) name = "disc0:/PSP_GAME/SYSDIR/EBOOT.BIN";
SceKernelLMOption option;
SceUID mpid = PSP_MEMORY_PARTITION_USER;
memset(&option, 0, sizeof(option));
option.size = sizeof(option);
option.mpidtext = mpid;
option.mpiddata = mpid;
if(mode != 2) option.position = 1; else option.position = 0;
option.access = 1;
if(mode==0) // normal eboot
modid = sceKernelLoadModuleMs2(name, 0, &option);
else if(mode==1) // psx eboot
modid = sceKernelLoadModuleMs4(name, 0, NULL);
else if(mode==2) // umd eboot
modid = ModuleMgrForKernel_A1A78C58(name, 0, &option);
if(modid >= 0)
{
len = build_args(args, name, argc, argv);
modid = sceKernelStartModule(modid, len, (void *) args, &status, NULL);
}
else
{
sceKernelDelayThread(20*1000000);
ExitNervOS();
return 0;
}
return modid;
}*/
char filepath[255];
char * readPath(char * Filename)
{
char line[255];
FILE * File;
char path[255];
strcpy(path, "");
File = fopen(Filename, "r");
if(File == NULL) return NULL;
while(fgets(line, 255, File) != NULL)
{
strcpy(filepath, line);
}
fclose(File);
return filepath;
}
int main_thread(SceSize args, void *argp)
{
sceKernelDelayThread(10*100000);
char *path = "";;
strcpy(path, "");
path = readPath("ms0:/NervOS/documents/filepath.temp");
//loadStartModule(path, 0, NULL, 0);
execEboot(path);
// Hook exit game function
SceModule *mod;
mod = sceKernelFindModuleByName("sceLoadExec");
if(mod) apiHookByName(mod->modid, "LoadExecForUser","sceKernelExitGame", ExitNervOS);
sceKernelExitDeleteThread(0);
return 0;
}
/* Entry point */
int module_start(SceSize args, void *argp)
{
int thid;
/* Create a high priority thread */
thid = sceKernelCreateThread("hook_sample_thread", main_thread, 8, 64*1024, 0, NULL);
if(thid >= 0)
{
sceKernelStartThread(thid, args, argp);
}
return 0;
}
int module_stop()
{
sceKernelExitDeleteThread(0);
return 0;
}
I also tried with the uncommented codeand with the loadStartModule uncommented and execEboot(path); commented and seems to load something but then crashes too.
Edit: Nvm, it was something in my PBP. It works and launches the correct file but does not patch anything >.< (I tried with loadstart module and without)
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
-
- Posts: 10
- Joined: Mon Nov 12, 2007 7:48 pm
Hi All,
I use Cpasjuste's api hook sample and it works fine. try calling the apihook first before calling loadStartModule()
I use Cpasjuste's api hook sample and it works fine. try calling the apihook first before calling loadStartModule()
Code: Select all
int main_thread(SceSize args, void *argp)
{
sceKernelDelayThread(10*100000);
char *path = "";
strcpy(path, "");
path = readPath("ms0:/NervOS/documents/filepath.temp");
// Hook exit game function
SceModule *mod;
mod = sceKernelFindModuleByName("sceLoadExec");
if(mod) apiHookByName(mod->modid, "LoadExecForUser","sceKernelExitGame", ExitNervOS);
loadStartModule(path, 0, NULL, 0);
return sceKernelExitDeleteThread(0);
}
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
Ok this is my prx now:
the debug.txt file is written with this text inside:
Error executing module
so the problem is inside the loadStartModule function :/
It's not loading/starting it correctly
Code: Select all
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/unistd.h>
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspdisplay.h>
#include <pspiofilemgr.h>
#include <psptypes.h>
#include <pspsdk.h>
#include <stdlib.h>
#include <pspumd.h>
#include <pspmodulemgr_kernel.h>
#include <psploadexec_kernel.h>
#include <systemctrl.h>
#include <systemctrl_se.h>
#include "apihook.h"
PSP_MODULE_INFO("NervOS_PatchExit", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
int execEboot(char *target)
{
int loadexec = 0;
struct SceKernelLoadExecVSHParam param;
char argp[256];
int args;
strcpy(argp, target);
args = strlen(target)+1;
memset(¶m, 0, sizeof(param));
param.size = sizeof(param);
param.args = args;
param.argp = argp;
param.key = NULL;
param.vshmain_args_size = 0;
param.vshmain_args = NULL;
//sceKernelSuspendAllUserThreads();
loadexec = sctrlKernelLoadExecVSHMs2(target, ¶m);
return loadexec;
}
void ExitNervOS(void) {
execEboot("ms0:/PSP/GAME/NervOS/EBOOT.PBP");
}
int build_args(char *args, const char *execfile, int argc, char **argv)
{
int loc = 0;
int i;
strcpy(args, execfile);
loc += strlen(execfile) + 1;
for(i = 0; i < argc; i++)
{
strcpy(&args[loc], argv[i]);
loc += strlen(argv[i]) + 1;
}
return loc;
}
int writeDebug(char * debug)
{
int fd;
char buff[30];
strcpy(buff, debug);
fd = sceIoOpen("ms0:/debug.txt", PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777);
if(!fd) return -1;
sceIoWrite(fd, buff, sizeof(buff));
sceIoClose(fd);
return 0;
}
int loadStartModule(const char *name, int argc, char **argv, int mode)
{
SceUID modid = 0;
int status;
char args[1024];
int len;
if(mode==2) name = "disc0:/PSP_GAME/SYSDIR/EBOOT.BIN";
SceKernelLMOption option;
SceUID mpid = PSP_MEMORY_PARTITION_KERNEL;
memset(&option, 0, sizeof(option));
option.size = sizeof(option);
option.mpidtext = mpid;
option.mpiddata = mpid;
if(mode != 2) option.position = 1; else option.position = 0;
option.access = 1;
if(mode==0) // normal eboot
modid = sceKernelLoadModuleMs2(name, 0, &option);
else if(mode==1) // psx eboot
modid = sceKernelLoadModuleMs4(name, 0, NULL);
else if(mode==2) // umd eboot
modid = ModuleMgrForKernel_A1A78C58(name, 0, &option);
if(modid >= 0)
{
len = build_args(args, name, argc, argv);
modid = sceKernelStartModule(modid, len, (void *) args, &status, NULL);
}
else
{
writeDebug("Error executing module");
sceKernelDelayThread(20*1000000);
ExitNervOS();
return 0;
}
return modid;
}
char filepath[255];
char * readPath(char * Filename)
{
int fd = sceIoOpen(Filename, PSP_O_RDONLY, 0777);
if(!fd) return NULL;
sceIoRead(fd, filepath, sizeof(filepath));
sceIoClose(fd);
return filepath;
}
int main_thread(SceSize args, void *argp)
{
sceKernelDelayThread(1000000);
char *path = "";;
strcpy(path, "");
writeDebug("debug 1");
path = readPath("ms0:/NervOS/documents/filepath.temp");
writeDebug("debug 2");
// Hook exit game function
SceModule *mod;
mod = sceKernelFindModuleByName("sceLoadExec");
if(mod) apiHookByName(mod->modid, "LoadExecForUser","sceKernelExitGame", ExitNervOS);
else {
writeDebug("Error finding sceLoadExec");
}
loadStartModule(path, 0, NULL, 0);
sceKernelExitDeleteThread(0);
return 0;
}
/* Entry point */
int module_start(SceSize args, void *argp)
{
int thid;
/* Create a high priority thread */
thid = sceKernelCreateThread("hook_sample_thread", main_thread, 8, 64*1024, 0, NULL);
if(thid >= 0)
{
sceKernelStartThread(thid, args, argp);
}
return 0;
}
int module_stop()
{
sceKernelExitDeleteThread(0);
return 0;
}
Error executing module
so the problem is inside the loadStartModule function :/
It's not loading/starting it correctly
-
- Posts: 10
- Joined: Mon Nov 12, 2007 7:48 pm
Im creating a sample at the moment. I'll post it as soon as I finish it.
You can also have a look at the hense sdk samples from moonlight. Look at the loadmodule sample. That's basically what I use, Ive just added some stuff into it.
The Ebootloader calls loadprx.prx with the file you want to load as a parameter. Ive put the apihook call in the loadprx.prx kernel module.
You can also have a look at the hense sdk samples from moonlight. Look at the loadmodule sample. That's basically what I use, Ive just added some stuff into it.
The Ebootloader calls loadprx.prx with the file you want to load as a parameter. Ive put the apihook call in the loadprx.prx kernel module.
-
- Posts: 409
- Joined: Tue Oct 09, 2007 4:22 am
-
- Posts: 10
- Joined: Mon Nov 12, 2007 7:48 pm
moonlight released some sdk samples for HEN. You can find it in his website.
Anyway you can try this. I used the 3.71 M33 sdk with it:
Makefile:
Anyway you can try this. I used the 3.71 M33 sdk with it:
Code: Select all
#include <pspsdk.h>
#include <pspkernel.h>
#include <systemctrl.h>
#include <systemctrl_se.h>
#include <apihook.h>
#include <string.h>
#include <stdio.h>
PSP_MODULE_INFO("LoaderPRX", PSP_MODULE_KERNEL, 1, 0);
PSP_MAIN_THREAD_ATTR(0);
void executeEboot(char *target)
{
struct SceKernelLoadExecVSHParam param;
memset(¶m, 0, sizeof(param));
param.size = sizeof(param);
param.args = strlen(target)+1;
param.argp = target;
param.key = "game";
sctrlKernelLoadExecVSHMs2(target, ¶m);
}
void reloadMain()
{
executeEboot("ms0:/PSP/GAME/bootloader/EBOOT.PBP");
}
int main_thread(SceSize args, void *argp)
{
SceModule2 *mod;
SceUID uid = 0;
/* Unload the loader to free user memory */
while ((mod = sceKernelFindModuleByName("BootLoader")))
{
sceKernelStopModule(mod->modid, 0, NULL, NULL, NULL);
sceKernelUnloadModule(mod->modid);
}
// Hook exit game function
mod= sceKernelFindModuleByName("sceLoadExec");
if(mod) apiHookByName(mod->modid, "LoadExecForUser","sceKernelExitGame", reloadMain);
if (strstr((char *)argp, ".PBP"))
{
uid = sceKernelLoadModuleForLoadExecVSHMs2(argp, 0, NULL);
}
if (uid < 0)
{
Kprintf("Error %08X loading module", uid);
}
uid = sceKernelStartModule(uid, strlen(argp)+1, argp, NULL, NULL);
if (uid < 0)
{
Kprintf("Error %08X starting module", uid);
}
return sceKernelExitDeleteThread(0);
}
int module_start(SceSize args, void *argp)
{
SceUID th = sceKernelCreateThread("main_thread", main_thread, 8, 16*1024, 0, NULL);
if (th >= 0)
{
sceKernelStartThread(th, args, argp);
}
return 0;
}
int module_stop(SceSize args, void *argp)
{
return 0;
}
Code: Select all
TARGET = loadprx
OBJS = main.o apihook.o libs.o
INCDIR = ../../include
CFLAGS = -O2 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
BUILD_PRX = 1
PSP_FW_VERSION = 371
USE_KERNEL_LIBC = 1
USE_KERNEL_LIBS = 1
LIBDIR = ../../lib
LIBS = -lpspmodulemgr_kernel -lpspsystemctrl_kernel
LDFLAGS = -mno-crt0 -nostartfiles
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak