Skip to content

Commit

Permalink
added patch for sceIoOpenForDriver to be able to redirect eboot.bin
Browse files Browse the repository at this point in the history
  • Loading branch information
GabyPCgeeK authored Mar 14, 2018
1 parent 26a9330 commit 8d16ff3
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions repatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,35 @@
#include <vitasdkkern.h>
#include <taihen.h>


#define printf ksceDebugPrintf

static int hooks_uid[2];
static tai_hook_ref_t ref_hooks[2];
static int hooks_uid[3];
static tai_hook_ref_t ref_hooks[3];

static int ksceIoOpen_patched(const char *filename, int flag, SceIoMode mode) {
int ret = -1, state;
ENTER_SYSCALL(state);
SceUID pid = ksceKernelGetProcessId();
char titleid[32];
ksceKernelGetProcessTitleId(pid, titleid, sizeof(titleid));

if (memcmp("main", titleid, sizeof("main") - 1)==0) {
if (memcmp("ux0:/rePatch", filename, sizeof("ux0:/rePatch") - 1)!=0) {
if (strstr(filename, "eboot.bin") != NULL) {
char new_path[128];
char *old_path = strchr(strchr(filename, '/') + 1, '/') + 1;
if(old_path[0] == '/')
old_path++;
snprintf(new_path, sizeof(new_path), "ux0:/rePatch/%s",old_path);
ret = ksceIoOpen(new_path, flag, mode);
}
}
}

if(ret < 0) ret = TAI_CONTINUE(int, ref_hooks[2], filename, flag, mode);
EXIT_SYSCALL(state);
return ret;
}

static int ksceIoOpenForPid_patched(SceUID pid, const char *filename, int flag, SceIoMode mode) {
int ret = -1, state;
Expand All @@ -36,6 +59,7 @@ static int ksceIoOpenForPid_patched(SceUID pid, const char *filename, int flag,
EXIT_SYSCALL(state);
return ret;
}

static int _sceIoGetstat_patched(const char *file, SceIoStat *stat, int r2) {
int ret = -1, state;
SceIoStat k_stat;
Expand Down Expand Up @@ -67,11 +91,13 @@ void _start() __attribute__ ((weak, alias ("module_start")));
int module_start(SceSize argc, const void *args) {
hooks_uid[0] = taiHookFunctionExportForKernel(KERNEL_PID, &ref_hooks[0], "SceIofilemgr", TAI_ANY_LIBRARY, 0xC3D34965, ksceIoOpenForPid_patched);
hooks_uid[1] = taiHookFunctionExportForKernel(KERNEL_PID, &ref_hooks[1], "SceIofilemgr", TAI_ANY_LIBRARY, 0x8E7E11F2, _sceIoGetstat_patched);
hooks_uid[2] = taiHookFunctionExportForKernel(KERNEL_PID, &ref_hooks[2], "SceIofilemgr", TAI_ANY_LIBRARY, 0x75192972, ksceIoOpen_patched);
return SCE_KERNEL_START_SUCCESS;
}

int module_stop(SceSize argc, const void *args) {
if (hooks_uid[0] >= 0) taiHookReleaseForKernel(hooks_uid[0], ref_hooks[0]);
if (hooks_uid[1] >= 0) taiHookReleaseForKernel(hooks_uid[1], ref_hooks[1]);
if (hooks_uid[2] >= 0) taiHookReleaseForKernel(hooks_uid[2], ref_hooks[2]);
return SCE_KERNEL_STOP_SUCCESS;
}
}

0 comments on commit 8d16ff3

Please sign in to comment.