yifanlu / taiHEN

CFW framework for PS Vita
MIT License
307 stars 46 forks source link

Hooking a weak import crashes the application #9

Closed TheOfficialFloW closed 7 years ago

TheOfficialFloW commented 7 years ago

This one crashes because the screenshot module isn't loaded yet. taiHookFunctionImport(&sceScreenShotDisableRef, "ScePspemu", 0xF26FC97D, 0x50AE9FF9, sceScreenShotDisablePatched);

Error code is: C1-2719-9

yifanlu commented 7 years ago

Can you try adding a hook to the sceSysmoduleLoadModule import? Then in your hook you can add code to add hooks for each module after it's loaded.

yifanlu commented 7 years ago

The error, btw is SCE_KERNEL_ERROR_MODULEMGR_INVALID_STUB 0x8002D00A Invalid stub

It's caused by taiHEN hooking an unresolved stub.

yifanlu commented 7 years ago

e5b376155e25aa4ed1183424f7c3a4a4e48d5a25 should stop the crash, but you still have to deal with the new error return. My suggestion is to add a hook to sceSysmoduleLoadModule with something like

ret = TAI_CONTINUE(int, load_module_uid, id);
ss_uid = -1;
if (ret >= 0 && id == SCE_SYSMODULE_SCREEN_SHOT) {
  ss_uid = taiHookFunctionImport(&sceScreenShotDisableRef, "ScePspemu", 0xF26FC97D, 0x50AE9FF9, sceScreenShotDisablePatched);
}
return ret;

then add a hook to sceSysmoduleUnloadModule with something like

ret = TAI_CONTINUE(int, unload_module_uid, id);
if (ret >= 0 && ss_uid >= 0 && id == SCE_SYSMODULE_SCREEN_SHOT) {
  ss_uid = taiHookRelease(ss_uid, sceScreenShotDisableRef);
}
return ret;

This way, you can take care of both hooking, cleanup, and multiple loads/unloads. Because many apps dynamically load sysmodules on demand (load-call-unload) and this would be a better solution than adding a ton of code in taiHEN to take account of all the edge cases.

yifanlu commented 7 years ago

Let me know if that works for you, if it does you can go ahead and close the ticket :)

TheOfficialFloW commented 7 years ago

Works great, thanks. I'll close the issue then.