Skip to content

Commit a865bd2

Browse files
committed
printf error and hidden argument in non generic hooks demonstrated
1 parent 496f421 commit a865bd2

File tree

2 files changed

+19
-6
lines changed
  • kernel

2 files changed

+19
-6
lines changed

kernel/function_hook/source/main.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ int snprintfHook(char *str, size_t size, const char *format, ...)
3939
va_list args;
4040

4141
ps4KernelThreadGetCurrent(&td);
42-
// !!! do not use format => strlen inf. loop => crash !!!
43-
ps4KernelSocketPrint(td, sock, "%p %zu ", str, size);
42+
//ps4KernelSocketPrint(td, sock, "%p %zu ", str, size);
4443
va_start(args, format);
4544
ps4KernelSocketPrintSizedWithArgumentList(td, sock, size, format, args);
4645
va_end(args);
@@ -75,7 +74,13 @@ int printfHook(const char *format, ...)
7574

7675
int kern_closeHook(struct thread *td, int fd)
7776
{
78-
ps4KernelSocketPrint(td, sock, "%p %i\n", td, fd);
77+
Ps4KernelFunctionHookArgument *arg;
78+
// hidden-argument-jutsu - do this as the first call thou!
79+
// also allows you to interrupt via return and set a return via arg
80+
// maybe that should switch around ... ? -> issue
81+
ps4KernelThreadGetSecondaryReturn(td, (register_t *)&arg);
82+
83+
ps4KernelSocketPrint(td, sock, "%p %p %i\n", td, arg->function, fd);
7984
return PS4_KERNEL_FUNCTION_HOOK_CONTROL_CONTINUE;
8085
}
8186

@@ -91,6 +96,8 @@ int indexHook(const char *s, int c)
9196

9297
int genericHook(struct thread *td, Ps4KernelFunctionHookArgument *arg)
9398
{
99+
// The current type returns 0,1 for now.
100+
// This will be changed to the same control values observed in function hooks (need to do it in asm ...)
94101
ps4KernelSocketPrint(td, sock, "Type %p:\n", arg->hookTypeCurrent);
95102

96103
ps4KernelSocketPrint(td, sock, "%p(%p, %p, %p, %p, %p, %p) %p\n\t => %p %p %p %p %p %p\n",
@@ -150,7 +157,7 @@ void socketPrintHook(struct thread *td, Ps4KernelSocket *s, Ps4KernelFunctionHoo
150157
"\tfree: %p\n"
151158
"\tmt: %p\n"
152159
"\tuserArgument: %p\n"
153-
"}\n",
160+
"}\n"
154161
"* = This is will not show per-hook runtime values due to the lock-less design.\n",
155162
arg,
156163
arg->function,

kernel/system_call_hook/source/main.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ static Ps4KernelSocket *sock;
2828

2929
int sysCloseHook(struct thread *td, struct close_args *uap)
3030
{
31-
ps4KernelSocketPrint(td, sock, "pre: %i\n", uap->fd);
31+
Ps4KernelSystemCallHookArgument *arg;
32+
// magic - do this in the first line thou!
33+
// also allows you to interrupt via return and set a return via arg
34+
// maybe that should be switch around ... ? -> issue
35+
ps4KernelThreadGetSecondaryReturn(td, (register_t *)&arg);
36+
37+
ps4KernelSocketPrint(td, sock, "pre: %p %p %i\n", arg->hookTypeCurrent, arg->number, uap->fd);
3238
return PS4_KERNEL_SYSTEM_CALL_HOOK_CONTROL_CONTINUE;
3339
}
3440

@@ -37,7 +43,7 @@ int sysCloseHookGeneric(struct thread *td, Ps4KernelSystemCallHookArgument *arg)
3743
struct close_args *uap;
3844
uap = (struct close_args *)arg->uap;
3945

40-
ps4KernelSocketPrint(td, sock, "generic: %i\n", uap->fd);
46+
ps4KernelSocketPrint(td, sock, "generic: %p %p %i\n", arg->hookTypeCurrent, arg->number, uap->fd);
4147
return PS4_KERNEL_SYSTEM_CALL_HOOK_CONTROL_CONTINUE;
4248
}
4349

0 commit comments

Comments
 (0)