 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
darkness
Joined: 15 Jun 2008 Posts: 121
|
Posted: Thu Jun 19, 2008 4:06 am Post subject: 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) |
|
| Back to top |
|
 |
Cpasjuste
Joined: 29 May 2005 Posts: 214
|
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Thu Jun 19, 2008 9:10 pm Post subject: |
|
|
cpajuste, I pm'd you in case you didn't notice >.< _________________
Upgrade your PSP |
|
| Back to top |
|
 |
darkness
Joined: 15 Jun 2008 Posts: 121
|
Posted: Thu Jun 19, 2008 9:30 pm Post subject: |
|
|
? It works? It's very good and simple!
Congraturations, but how to start it after a launched eboot?
I think is not possible to launch it with a simple thread! |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Thu Jun 19, 2008 9:34 pm Post subject: |
|
|
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:
| Quote: | | 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. |
and what he is saying is to put my function to load iso's or homebrew before the code part which patches sceKernelExitGame.
this is what I don't understand because if I don't use the function from the module the patch does not affect anything _________________
Upgrade your PSP |
|
| Back to top |
|
 |
darkness
Joined: 15 Jun 2008 Posts: 121
|
Posted: Thu Jun 19, 2008 9:42 pm Post subject: |
|
|
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! |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Thu Jun 19, 2008 9:57 pm Post subject: |
|
|
You must load the prx with pspSdkLoadStartModule.
try loading to User partition, I only tried to Kernel. _________________
Upgrade your PSP |
|
| Back to top |
|
 |
darkness
Joined: 15 Jun 2008 Posts: 121
|
Posted: Thu Jun 19, 2008 10:04 pm Post subject: |
|
|
| Thanks Pirata Nervo! |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Thu Jun 19, 2008 11:05 pm Post subject: |
|
|
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? _________________
Upgrade your PSP |
|
| Back to top |
|
 |
Cpasjuste
Joined: 29 May 2005 Posts: 214
|
Posted: Thu Jun 19, 2008 11:31 pm Post subject: |
|
|
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 :
| Code: |
#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 |
|
| Back to top |
|
 |
darkness
Joined: 15 Jun 2008 Posts: 121
|
Posted: Thu Jun 19, 2008 11:32 pm Post subject: |
|
|
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:
| Code: |
/* 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");
|
And in the prx:
| Code: |
int module_start(SceSize args, void *argp)
{
char* mystring=(char*)malloc(strlen(argp));
argp=mystring;
printf("%s", mystring);
...
...
}
|
This is that I want to do, but is fill of errors!
Can you give me a little help? |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Thu Jun 19, 2008 11:47 pm Post subject: |
|
|
darkness:
what do you mean by "I've started it in Kernel memory partition and it works perfectly! "
started the pbp or the prx?
because I tried the prx and does not.
@cpasjute, thanks.
I will take a look at the code and see if I understand _________________
Upgrade your PSP |
|
| Back to top |
|
 |
darkness
Joined: 15 Jun 2008 Posts: 121
|
Posted: Fri Jun 20, 2008 12:05 am Post subject: |
|
|
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!
| Code: |
pspSdkLoadStartModule("ms0:/PSP/GAME/Explorer/apihook.prx", PSP_MEMORY_PARTITION_KERNEL);
execEboot("ms0:/PSP/GAME/AdhocFileTransfer/EBOOT.PBP");
|
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! |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Fri Jun 20, 2008 12:08 am Post subject: |
|
|
I am trying something, should work.
I will let you know and post there if it works. _________________
Upgrade your PSP |
|
| Back to top |
|
 |
darkness
Joined: 15 Jun 2008 Posts: 121
|
Posted: Fri Jun 20, 2008 12:19 am Post subject: |
|
|
I've try to start the prx as a plugin, (I've put in in game.txt file), and It works perfectly!!!
But how to start it as a plugin from a application? |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Fri Jun 20, 2008 12:27 am Post subject: |
|
|
that's what I am trying to do lol. _________________
Upgrade your PSP |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Fri Jun 20, 2008 1:26 am Post subject: |
|
|
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:
| Code: |
#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;
}
|
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) _________________
Upgrade your PSP |
|
| Back to top |
|
 |
Cpasjuste
Joined: 29 May 2005 Posts: 214
|
Posted: Fri Jun 20, 2008 5:32 pm Post subject: |
|
|
| With your "execEboot(path); " function, it won't work of course since you loadexec an eboot. When you loadexec something, the hook is lost ...you need to use the load/start module function to load your .pbp for the hook to be active. |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Fri Jun 20, 2008 8:29 pm Post subject: |
|
|
I used it first but then it didn't work so I tired with the loadexec :P _________________
Upgrade your PSP |
|
| Back to top |
|
 |
darkness
Joined: 15 Jun 2008 Posts: 121
|
Posted: Sat Jun 21, 2008 3:29 am Post subject: |
|
|
Pirata Nervo, have you resolved?
I have a bad idea:
can we patch the loadexec fuct to don't stop the loaded prxs?
I think it's possible...or I haven't understand very well what do the psp when start a new executables |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Sat Jun 21, 2008 4:10 am Post subject: |
|
|
Nop I did not try anymore since I made my post with the code. I have been working on other things.
And yes you can patch the function but re-write a loadexec function is not easy, I saw one before made/reversed (probably reversed) by dark alex and of course it's in MIPS and C. _________________
Upgrade your PSP |
|
| Back to top |
|
 |
Cpasjuste
Joined: 29 May 2005 Posts: 214
|
Posted: Sat Jun 21, 2008 4:50 am Post subject: |
|
|
| The code i posted works out of the box, i don't understand what is the problem. If i have the time i will write and post a sample that load a hard coded eboot with the sceKernelExitGame hooked. |
|
| Back to top |
|
 |
darkness
Joined: 15 Jun 2008 Posts: 121
|
Posted: Sat Jun 21, 2008 10:15 pm Post subject: |
|
|
| Yes, please... |
|
| Back to top |
|
 |
psp.padawan
Joined: 12 Nov 2007 Posts: 10
|
Posted: Sun Jun 22, 2008 11:45 pm Post subject: |
|
|
Hi All,
I use Cpasjuste's api hook sample and it works fine. try calling the apihook first before calling loadStartModule()
| Code: |
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);
}
|
|
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Mon Jun 23, 2008 7:31 am Post subject: |
|
|
Yeh I did.
My prx crashes :(
Would you mind to post your prx source code?
I have tried a lot of different ways and nothing.
I am still trying. _________________
Upgrade your PSP |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Mon Jun 23, 2008 6:11 pm Post subject: |
|
|
Ok this is my prx now:
| Code: |
#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;
}
|
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 _________________
Upgrade your PSP |
|
| Back to top |
|
 |
psp.padawan
Joined: 12 Nov 2007 Posts: 10
|
Posted: Mon Jun 23, 2008 10:05 pm Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Pirata Nervo
Joined: 09 Oct 2007 Posts: 409
|
Posted: Mon Jun 23, 2008 10:27 pm Post subject: |
|
|
What moonlight samples?
Edit:
Seems to be returning "partition mismatch" when loading the module (homebrew), I am loading it to kernel partition as in the sample. If I change to user partition, I get a failed to allocate the memory block error _________________
Upgrade your PSP |
|
| Back to top |
|
 |
psp.padawan
Joined: 12 Nov 2007 Posts: 10
|
Posted: Mon Jun 23, 2008 11:19 pm Post subject: |
|
|
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:
| Code: |
#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;
}
|
Makefile:
| Code: |
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
|
|
|
| Back to top |
|
 |
darkness
Joined: 15 Jun 2008 Posts: 121
|
Posted: Mon Jun 23, 2008 11:27 pm Post subject: |
|
|
Why have you patch the exit game api befor launch the new module?
It's patch the current loaded api( I think), and when launch the new executables the exit game function is not patched!
It's true? |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|