From 13c4be0a97c3b9a5ea6dda80d388ab338c03a5fe Mon Sep 17 00:00:00 2001 From: Ivan Epifanov Date: Tue, 11 Jun 2024 19:52:57 +0300 Subject: [PATCH] Add wifi-always-on patch --- README.md | 1 + include/catlog.h | 5 +-- kernel_module/src/main.c | 57 +++++++++++++++++++++++++++++--- user_module/network_settings.xml | 6 ++++ user_module/user.c | 16 +++++++-- 5 files changed, 75 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 353a255..4a67682 100644 --- a/README.md +++ b/README.md @@ -20,4 +20,5 @@ PlayStation® Vita™ network logging plugin ## Credits * [Princess-of-Sleeping](https://github.com/Princess-of-Sleeping), [cuevavirus](https://git.shotatoshounenwachigau.moe/) - PrincessLog * [SKGleba](https://github.com/SKGleba) - settings menu idea and injection code +* [Electry](https://github.com/Electry) - wifi patch * CBPS \ No newline at end of file diff --git a/include/catlog.h b/include/catlog.h index 50e3439..64038ab 100644 --- a/include/catlog.h +++ b/include/catlog.h @@ -7,9 +7,10 @@ typedef struct { uint32_t host; uint16_t port; uint16_t loglevel; + uint8_t net; } CatLogConfig_t; -int CatLogReadConfig(uint32_t* host, uint16_t* port, uint16_t* level); -int CatLogUpdateConfig(uint32_t host, uint16_t port, uint16_t level); +int CatLogReadConfig(uint32_t* host, uint16_t* port, uint16_t* level, uint8_t* net); +int CatLogUpdateConfig(uint32_t host, uint16_t port, uint16_t level, uint8_t net); #endif // CATLOG_H \ No newline at end of file diff --git a/kernel_module/src/main.c b/kernel_module/src/main.c index 5eff301..d3b3f47 100644 --- a/kernel_module/src/main.c +++ b/kernel_module/src/main.c @@ -49,11 +49,16 @@ int module_get_export_func(SceUID pid, const char *modname, uint32_t libnid, uin name##HookUid = taiHookFunctionExportForKernel(KERNEL_PID, &name##HookRef, (module), (lib_nid), (func_nid), \ (const void *)name##HookFunc) +#define BIND_FUNC_OFFSET_HOOK(name, modid, segidx, offset, thumb) \ + name##HookUid = taiHookFunctionOffsetForKernel(KERNEL_PID, &name##HookRef, \ + (modid), (segidx), (offset), thumb, (const void*)name##HookFunc) #define GetExport(modname, lib_nid, func_nid, func) \ module_get_export_func(KERNEL_PID, modname, lib_nid, func_nid, (uintptr_t *)func) +CatLogConfig_t Config; + static int net_thread_run = 0; static SceUID net_thread_uid = 0; @@ -95,6 +100,13 @@ DECL_FUNC_HOOK(sceSblQafMgrIsAllowSystemAppDebugForDriver_patched) return 1; } +DECL_FUNC_HOOK(ScePower_3e10_patched, int pid, int flags, unsigned int set) +{ + if (flags == 3 && Config.net) // WLAN/COM + set = 1; + return TAI_CONTINUE(int, ScePower_3e10_patchedHookRef, pid, flags, set); +} + /* flags for sceNetShutdown */ #define SCE_NET_SHUT_RD 0 #define SCE_NET_SHUT_WR 1 @@ -180,7 +192,6 @@ static int net_thread(SceSize args, void *argp) return 0; } -CatLogConfig_t Config; int SaveConfig(void) { @@ -198,6 +209,7 @@ int CreateConfig(void) Config.host = 0x0100007f; // 127.0.0.1 Config.port = DEFAULT_PORT; Config.loglevel = 2; + Config.net = 0; SceUID fd = ksceIoOpen(CFG_PATH, SCE_O_WRONLY | SCE_O_CREAT | SCE_O_TRUNC, 0666); if (fd < 0) return fd; @@ -210,8 +222,25 @@ int CreateConfig(void) int CheckConfig(void) { - SceIoStat buf; - return ksceIoGetstat(CFG_PATH, &buf); + SceUID fd = ksceIoOpen(CFG_PATH, SCE_O_RDONLY, 0); + if (fd < 0) + { + return fd; + } + + CatLogConfig_t tmp; + + int res = ksceIoRead(fd, &tmp, sizeof(CatLogConfig_t)); + + if (res != sizeof(CatLogConfig_t)) + { + ksceIoClose(fd); + return -1; + } + + ksceIoClose(fd); + + return 0; } int LoadConfig(void) @@ -252,7 +281,7 @@ int LoadConfig(void) } -int CatLogUpdateConfig(uint32_t host, uint16_t port, uint16_t level) +int CatLogUpdateConfig(uint32_t host, uint16_t port, uint16_t level, uint8_t net) { uint32_t state; @@ -261,6 +290,7 @@ int CatLogUpdateConfig(uint32_t host, uint16_t port, uint16_t level) Config.host = host; Config.port = port; Config.loglevel = level; + Config.net = net; sceKernelSetAssertLevelForKernel(Config.loglevel); server.sin_addr.s_addr = host; @@ -273,7 +303,7 @@ int CatLogUpdateConfig(uint32_t host, uint16_t port, uint16_t level) return 0; } -int CatLogReadConfig(uint32_t* host, uint16_t* port, uint16_t* level) +int CatLogReadConfig(uint32_t* host, uint16_t* port, uint16_t* level, uint8_t* net) { int res; uint32_t state; @@ -298,6 +328,12 @@ int CatLogReadConfig(uint32_t* host, uint16_t* port, uint16_t* level) goto end; } + res = ksceKernelMemcpyKernelToUser((void *)net, &Config.net, 1); + if (res < 0) + { + goto end; + } + end: EXIT_SYSCALL(state); @@ -328,6 +364,15 @@ int CatLogInit(void) goto end; } + tai_module_info_t modInfo; + modInfo.size = sizeof(tai_module_info_t); + + if (taiGetModuleInfoForKernel(KERNEL_PID, "ScePower", &modInfo) < 0) + { + ret = -1; + goto end; + } + if (GetExport("SceSysmem", 0x88C17370, 0xCE9060F1, &sceKernelSetAssertLevelForKernel) < 0) if (GetExport("SceSysmem", 0x13D793B7, 0xC5889385, &sceKernelSetAssertLevelForKernel) < 0) { @@ -359,6 +404,8 @@ int CatLogInit(void) BIND_FUNC_EXPORT_HOOK(sceSblQafMgrIsAllowKernelDebugForDriver_patched, "SceSysmem", 0xFFFFFFFF, 0x382C71E8); BIND_FUNC_EXPORT_HOOK(sceSblQafMgrIsAllowSystemAppDebugForDriver_patched, "SceSysmem", 0xFFFFFFFF, 0xCAD47130); + BIND_FUNC_OFFSET_HOOK(ScePower_3e10_patched, modInfo.modid, 0, 0x3E10, 1); + ret = sceDebugDisableInfoDumpForKernel(0); if (ret < 0) { diff --git a/user_module/network_settings.xml b/user_module/network_settings.xml index 6d73c2e..1dd7144 100644 --- a/user_module/network_settings.xml +++ b/user_module/network_settings.xml @@ -68,6 +68,12 @@ + + + diff --git a/user_module/user.c b/user_module/user.c index 0bb6657..400a2ab 100644 --- a/user_module/user.c +++ b/user_module/user.c @@ -63,6 +63,11 @@ DECL_FUNC_HOOK(sceRegMgrGetKeyInt, const char *category, const char *name, int * { *value = cfg.port; } + + if (sceClibStrncmp(name, "net", 3) == 0) + { + *value = cfg.net; + } } return 0; } @@ -100,7 +105,12 @@ DECL_FUNC_HOOK(sceRegMgrSetKeyInt, const char *category, const char *name, int v cfg.port = value; } - CatLogUpdateConfig(cfg.host, cfg.port, cfg.loglevel); + if (sceClibStrncmp(name, "net", 3) == 0) + { + cfg.net = value; + } + + CatLogUpdateConfig(cfg.host, cfg.port, cfg.loglevel, cfg.net); return 0; } @@ -116,7 +126,7 @@ DECL_FUNC_HOOK(sceRegMgrSetKeyStr, const char *category, const char *name, char sceNetInetPton(SCE_NET_AF_INET, value, &cfg.host); } - CatLogUpdateConfig(cfg.host, cfg.port, cfg.loglevel); + CatLogUpdateConfig(cfg.host, cfg.port, cfg.loglevel, cfg.net); return 0; } return TAI_CONTINUE(int, sceRegMgrSetKeyStrHookRef, category, name, value, len); @@ -199,7 +209,7 @@ int module_start(SceSize argc, const void *args) return SCE_KERNEL_START_SUCCESS; } - CatLogReadConfig(&cfg.host, &cfg.port, &cfg.loglevel); + CatLogReadConfig(&cfg.host, &cfg.port, &cfg.loglevel, &cfg.net); BIND_FUNC_IMPORT_HOOK(sceKernelLoadStartModule, "SceSettings", 0xCAE9ACE6, 0x2DCC4AFA); BIND_FUNC_IMPORT_HOOK(sceKernelStopUnloadModule, "SceSettings", 0xCAE9ACE6, 0x2415F8A4);