/** * Remember you have to export the hooker function if using syscall hook */ int hook_import_bynid(SceModule *pMod, char *library, unsigned int nid, void *func, int syscall) { PspModuleImport *pImp; void *stubTab; int stubLen; int i = 0; if(pMod == NULL) return -1; stubTab = pMod->stub_top; stubLen = pMod->stub_size; while(i<stubLen) { pImp = (PspModuleImport*)(stubTab+i); if((pImp->name) && (strcmp(pImp->name, library) == 0)) { int j; for(j=0; j<pImp->funcCount; j++) { if(pImp->fnids[j] == nid) { void *addr = (void*)(&pImp->funcs[j*2]); if(syscall) { u32 syscall_num; syscall_num = sctrlKernelQuerySystemCall(func); if(syscall_num == (u32)-1) { printk("%s: cannot find syscall in %s_%08X\n", __func__, library, nid); return -1; } _sw(0x03E00008, (u32)addr); _sw(MAKE_SYSCALL(syscall_num), (u32)(addr + 4)); } else { _sw(MAKE_JUMP(func), (u32)addr); _sw(NOP, (u32)(addr + 4)); } sceKernelDcacheWritebackInvalidateRange(addr, 8); sceKernelIcacheInvalidateRange(addr, 8); } } } i += (pImp->entLen * 4); } return 0; }
/** * Remember you have to export the hooker function if using syscall hook */ int hook_import_bynid(SceModule *pMod, char *library, unsigned int nid, void *func) { PspModuleImport *pImp; void *stubTab; int stubLen; int i = 0; if(pMod == NULL) return -1; stubTab = pMod->stub_top; stubLen = pMod->stub_size; while(i<stubLen) { pImp = (PspModuleImport*)(stubTab+i); if((pImp->name) && (strcmp(pImp->name, library) == 0)) { int j; for(j=0; j<pImp->funcCount; j++) { if(pImp->fnids[j] == nid) { void *addr = (void*)(&pImp->funcs[j*2]); if(func == NULL) { _sw(0x03E00008, (u32)addr); _sw(NOP, (u32)(addr + 4)); } else { // Partition Check SceModule2 * mod = (SceModule2 *)pMod; if(((mod->text_addr & 0x80000000) && (((uint32_t)func) & 0x80000000)) || ((mod->text_addr & 0x80000000) == 0 && (((uint32_t)func) & 0x80000000) == 0)) { REDIRECT_FUNCTION(func, addr); } else { _sw(0x03E00008, (u32)addr); _sw(MAKE_SYSCALL(sctrlKernelQuerySystemCall(func)), (u32)(addr + 4)); } } sceKernelDcacheWritebackInvalidateRange(addr, 8); sceKernelIcacheInvalidateRange(addr, 8); } } } i += (pImp->entLen * 4); } return 0; }