Skip to content

Commit

Permalink
Add wifi-always-on patch
Browse files Browse the repository at this point in the history
  • Loading branch information
isage committed Jun 11, 2024
1 parent 1db5069 commit 13c4be0
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions include/catlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
57 changes: 52 additions & 5 deletions kernel_module/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -180,7 +192,6 @@ static int net_thread(SceSize args, void *argp)
return 0;
}

CatLogConfig_t Config;

int SaveConfig(void)
{
Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
6 changes: 6 additions & 0 deletions user_module/network_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
<list_item id="id_catlog_level_debug" title="Debug" value="1"/>
<list_item id="id_catlog_level_trace" title="Trace" value="2"/>
</list>

<toggle_switch id="enable_net"
key="/CONFIG/CATLOG/net"
title="Keep Wi-Fi ON"
description="Always keep wifi on" />

</setting_list>

</setting_list>
Expand Down
16 changes: 13 additions & 3 deletions user_module/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 13c4be0

Please sign in to comment.