Skip to content

Commit 939e313

Browse files
committed
a little bit of hooking, io redirect and cleanup
1 parent 5677d51 commit 939e313

File tree

2 files changed

+41
-21
lines changed
  • kern
    • file_hello_world/source
    • server_hello_world/source

2 files changed

+41
-21
lines changed
Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
1-
#define _XOPEN_SOURCE 700
2-
#define __BSD_VISIBLE 1
3-
#define _KERNEL
4-
#define _STANDALONE
5-
#define _WANT_UCRED
6-
#include <sys/cdefs.h>
7-
#include <sys/types.h>
8-
#include <sys/limits.h>
9-
#include <sys/param.h>
10-
#include <sys/kernel.h>
11-
//#include <sys/libkern.h>
12-
#include <sys/systm.h>
13-
14-
#include <sys/sysproto.h>
15-
//#include <sys/unistd.h>
16-
#include <sys/syscallsubr.h>
17-
181
#include <ps4/kern.h>
192

20-
#define STDIN_FILENO 0
3+
#ifndef STDOUT_FILENO
4+
#define STDOUT_FILENO 1
5+
#endif
216

227
int main(int argc, char **argv)
238
{
@@ -27,7 +12,7 @@ int main(int argc, char **argv)
2712
int r;
2813

2914
td = ps4KernThreadCurrent();
30-
r = ps4KernUtilFilePrint(td, STDIN_FILENO, "Hello world from your ps4 kernel, ps4sdk and hito <3\n{main:%p, argc:%i, argv[0]:%s}\n", main, argc, argv[0]);
15+
r = ps4KernUtilFilePrint(td, STDOUT_FILENO, "Hello world from your ps4 kernel, ps4sdk.\nKind regards hito <3\n\n{main:%p, argc:%i, argv[0]:%s}\n", main, argc, argv[0]);
3116

3217
return r;
3318
}

kern/server_hello_world/source/main.c

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,34 @@
55
#define _WANT_UCRED
66
#include <sys/cdefs.h>
77
#include <sys/types.h>
8+
#include <sys/limits.h>
89
#include <sys/param.h>
910
#include <sys/kernel.h>
1011
//#include <sys/libkern.h>
1112
#include <sys/systm.h>
13+
14+
#include <sys/sysproto.h>
15+
//#include <sys/unistd.h>
1216
#include <sys/syscallsubr.h>
1317

1418
#include <ps4/kern.h>
1519

1620
#define SERVER_PORT 5057
1721

22+
#ifndef STDOUT_FILENO
23+
#define STDOUT_FILENO 1
24+
#endif
25+
26+
static int c;
27+
28+
//int printf(const char *fmt, ...)
29+
int printf_hook(void *td, Ps4KernFunctionHookArgument *uap)
30+
{
31+
// fully variadic maybe on the next season of ps4sdk
32+
ps4KernUtilSocketPrint(td, c, (const char *)uap->arguments->general[1]);
33+
return PS4_KERN_FUNCTION_HOOK_CONTINUE;
34+
}
35+
1836
int main(int argc, char **argv)
1937
{
2038
// send this elf to 5054, connect, see connection get closed
@@ -23,8 +41,25 @@ int main(int argc, char **argv)
2341
int client;
2442

2543
td = ps4KernThreadCurrent();
26-
client = ps4KernUtilServerCreateSingleAccept(td, SERVER_PORT);
27-
ps4KernUtilSocketPrint(td, client, "Hello world from your ps4 kernel, ps4sdk and hito <3\n{main:%p, argc:%i, argv[0]:%s}\n", main, argc, argv[0]);
44+
client = ps4KernUtilServerCreateSingleAccept(td, SERVER_PORT); // see kern/util for more
45+
46+
ps4KernUtilSocketPrint(td, client, "Hello world from your ps4 kernel and ps4sdk.\n{main:%p, argc:%i, argv[0]:%s}\n\n", main, argc, argv[0]);
47+
48+
//(you will need to (re)connect 5052 if you send this to 5054)
49+
//(without messing with the redirected, the rest works as intended)
50+
//(basically you hijack the user fd and the userland starts interfering)
51+
//ps4KernUtilStandardIoRedirectPlain(td, client);
52+
//ps4KernUtilFilePrint(td, STDOUT_FILENO, "Somebody is watching over us... controlling us. It's true, I tell you. It's true! We are merely sprites that dance at the beck and call of our button-pressing overlord. This is a video game. Don't you see? We are characters in a video game!\n\n");
53+
54+
c = client;
55+
printf("S.T.A.R.S ... !\n"); // the kernel printf does not go to an fd
56+
ps4KernFunctionHookSized((void *)ps4KernDlSym("printf"), (void *)printf_hook, 16); // 16 is a valid instruction offset in printf !!!
57+
printf("It's a weapon. It's really powerful, especially against living things.\n\n");
58+
ps4KernFunctionUnhook((void *)ps4KernDlSym("printf"));
59+
printf("S.T.A.R.S ... !\n");
60+
61+
ps4KernUtilSocketPrint(td, client, "Kind regards and greetings to all who read this <3,\nhito\n");
62+
2863
ps4KernUtilSocketClose(td, client);
2964

3065
return 0;

0 commit comments

Comments
 (0)