-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathether-enabler.c
78 lines (63 loc) · 2.47 KB
/
ether-enabler.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <psp2kern/kernel/debug.h>
#include <psp2kern/kernel/modulemgr.h>
#include <psp2kern/kernel/suspend.h>
#include <taihen.h>
#include <string.h>
int ksceKernelSysrootCheckModelCapability(int cap);
int module_get_export_func(SceUID pid, const char *modname, uint32_t libnid, uint32_t funcnid, uintptr_t *func);
static SceUID g_hook = 0;
static tai_hook_ref_t g_ksceKernelSysrootCheckModelCapability_hook;
int (*sceUsbServMacSelectForDriver)(SceUInt32 usbPort, SceBool clientMode);
SceBool (*sceUsbServMacGetForDriver)(SceUInt32 usbPort);
#if !defined(LITE_MODE)
static int eth_sysevent_handler(int resume, int eventid, void *args, void *opt) {
if (resume)
{
sceUsbServPortModeSetForDriver(2, 0); // re-set host mode
}
return 0;
}
#endif
static int ksceKernelSysrootCheckModelCapability_patched(int cap) {
int ret = TAI_CONTINUE(int, g_ksceKernelSysrootCheckModelCapability_hook, cap);
// TODO: check set caps on devkit/testkit. force only 5 for now
if (cap == 5)// || cap == 6)
{
ret = 1;
}
return ret;
}
int module_start(int args, void *argv) {
(void)args;
(void)argv;
int ret;
module_get_export_func(KERNEL_PID, "SceUsbServ", 0xA75BBDF2, 0x7AD36284, (uintptr_t *)&sceUsbServMacSelectForDriver);
module_get_export_func(KERNEL_PID, "SceUsbServ", 0xA75BBDF2, 0xF0553A69, (uintptr_t *)&sceUsbServMacGetForDriver);
#if !defined(LITE_MODE)
// enable host mode (0) on multicn (port 2)
ret = sceUsbServPortModeSetForDriver(2, 0);
ksceDebugPrintf("Port: 2, result: %x \n", ret);
#endif
// settings check paf::system::SupportsWiredEthernet(), which check capability 5 and 6, so fake one
int cap = 0;
cap = (ksceKernelSysrootCheckModelCapability(5) || ksceKernelSysrootCheckModelCapability(6));
if (!cap)
{
g_hook = taiHookFunctionExportForKernel(KERNEL_PID, &g_ksceKernelSysrootCheckModelCapability_hook, "SceSysmem", 0x2ED7F97A, 0x8AA268D6, ksceKernelSysrootCheckModelCapability_patched);
ksceDebugPrintf("taiHookFunctionExportForKernel: 0x%08X\n", g_hook);
}
#if !defined(LITE_MODE)
// to restore host on resume
ksceKernelRegisterSysEventHandler("zeth_sysevent", eth_sysevent_handler, NULL);
#endif
return SCE_KERNEL_START_SUCCESS;
}
void _start() __attribute__ ((weak, alias ("module_start")));
int module_stop()
{
if (g_hook > 0)
{
taiHookReleaseForKernel(g_hook, g_ksceKernelSysrootCheckModelCapability_hook);
}
return SCE_KERNEL_STOP_SUCCESS;
}