Skip to content

Commit ba27961

Browse files
committed
extended example in kernel-run to include some more fn
1 parent ad0c276 commit ba27961

File tree

5 files changed

+106
-7
lines changed

5 files changed

+106
-7
lines changed

kernel/kernel-run/include/kmain.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#ifndef KMainH
22
#define KMainH
33

4+
typedef int (*RunnableInt)();
5+
46
int kmain(int argc, char **argv);
7+
int kmain2(int argc, char **argv);
8+
int kmain3(int argc, char **argv);
59

610
#endif

kernel/kernel-run/source/kmain.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,7 @@ int kmain(int argc, char **argv)
3737

3838
free(kmoo, mt);
3939

40-
return 42; // important notice from kernel!
40+
RunnableInt sceSblACMgrIsVideoplayerProcess = (RunnableInt)ps4KernelDlSym("sceSblACMgrIsVideoplayerProcess");
41+
42+
return sceSblACMgrIsVideoplayerProcess(); //see kmain2's content & return
4143
}

kernel/kernel-run/source/kmain2.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#undef _SYS_CDEFS_H_
2+
#undef _SYS_TYPES_H_
3+
#undef _SYS_PARAM_H_
4+
#undef _SYS_MALLOC_H_
5+
6+
#define _XOPEN_SOURCE 700
7+
#define __BSD_VISIBLE 1
8+
#define _KERNEL
9+
#define _WANT_UCRED
10+
#include <sys/cdefs.h>
11+
#include <sys/types.h>
12+
#include <sys/param.h>
13+
#include <sys/kernel.h>
14+
#include <sys/systm.h>
15+
#include <sys/malloc.h>
16+
17+
#undef offsetof
18+
#include <kernel.h>
19+
#include <ps4/kernel.h>
20+
#include <ps4/internal/kernelexploit.h>
21+
22+
#include "kmain.h"
23+
24+
// kernel functions called, in user-land function ... yay for evil voodoo Oo?!
25+
int kmain2(int argc, char **argv)
26+
{
27+
RunnableInt sceSblACMgrIsVideoplayerProcess = (RunnableInt)ps4KernelDlSym("sceSblACMgrIsVideoplayerProcess");
28+
ps4KernelPatchToTruthFunction((void *)sceSblACMgrIsVideoplayerProcess);
29+
30+
return sceSblACMgrIsVideoplayerProcess(); // important notice from kernel!
31+
}

kernel/kernel-run/source/kmain3.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#undef _SYS_CDEFS_H_
2+
#undef _SYS_TYPES_H_
3+
#undef _SYS_PARAM_H_
4+
#undef _SYS_MALLOC_H_
5+
6+
#define _XOPEN_SOURCE 700
7+
#define __BSD_VISIBLE 1
8+
#define _KERNEL
9+
#define _WANT_UCRED
10+
#include <sys/cdefs.h>
11+
#include <sys/types.h>
12+
#include <sys/param.h>
13+
#include <sys/kernel.h>
14+
#include <sys/systm.h>
15+
#include <sys/malloc.h>
16+
17+
#undef offsetof
18+
#include <kernel.h>
19+
#include <ps4/kernel.h>
20+
#include <ps4/internal/kernelexploit.h>
21+
22+
#include "kmain.h"
23+
24+
// kernel functions called, in user-land function ... yay for evil voodoo Oo?!
25+
int kmain3(int argc, char **argv)
26+
{
27+
RunnableInt sceSblACMgrIsVideoplayerProcess = (RunnableInt)ps4KernelDlSym("sceSblACMgrIsVideoplayerProcess");
28+
void *sceSblACMgrIsShellcoreProcess = ps4KernelDlSym("sceSblACMgrIsShellcoreProcess");
29+
ps4KernelHookFunction((void *)sceSblACMgrIsVideoplayerProcess, sceSblACMgrIsShellcoreProcess);
30+
31+
return sceSblACMgrIsVideoplayerProcess();
32+
}

kernel/kernel-run/source/main.c

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <sys/syscall.h>
1010

1111
#include <ps4/kernel.h>
12+
#include <ps4/internal/asmpayload.h>
1213

1314
#include "kmain.h"
1415

@@ -17,23 +18,24 @@ int main(int argc, char **argv)
1718
int kargc = 1;
1819
char *kargv[2];
1920
char *moo = malloc(32); // A moo!! :D
21+
int i;
2022

2123
kargv[0] = moo;
2224
kargv[1] = NULL;
2325

2426
printf("uid: %zu\n", getuid());
25-
// this syscall turns to return 0 after the first ps4KernelExecute
26-
// do not call it directly - use the patching ps4KernelExecute
27-
printf("sys: %i\n", syscall(SYS_ps4_kernel_execute, NULL));
27+
// this syscall returns 0 after the first ps4KernelRun (see in a rerun process)
28+
// do not use this directly (just for show and tell here)
29+
// use the self-patching ps4KernelRun wrapper instead
30+
printf("sys: %i\n", syscall(SYS_ps4_kernel_run, NULL));
2831

2932
strcpy(moo, "Hmm ... ? *yum, grass*");
3033
int r = ps4KernelRun(kmain, kargc, kargv);
31-
printf("return: %i\n", r);
34+
printf("return (sceSblACMgrIsVideoplayerProcess): %i\n", r);
3235
printf("moo: %s\n", moo);
33-
free(moo); //Bye moo :(
3436

3537
printf("uid: %zu\n", getuid());
36-
printf("sys: %i\n", syscall(SYS_ps4_kernel_execute, NULL));
38+
printf("sys: %i\n", syscall(SYS_ps4_kernel_run, NULL));
3739

3840
printf("ps4KernelIsInKernel(): %i\n", ps4KernelIsInKernel());
3941
printf("ps4KernelDlSym(kernel_map): %p\n", ps4KernelDlSym("kernel_map"));
@@ -42,5 +44,33 @@ int main(int argc, char **argv)
4244
ps4KernelEscalatePrivileges();
4345
printf("uid: %zu\n", getuid());
4446

47+
//ps4KernelUARTEnable();
48+
49+
// and some patching
50+
memset(moo, '\0', 32);
51+
void *sceSblACMgrIsVideoplayerProcess = ps4KernelDlSym("sceSblACMgrIsVideoplayerProcess");
52+
ps4KernelMemcpy(moo, sceSblACMgrIsVideoplayerProcess, 32);
53+
for(i = 0; i < 32; ++i)
54+
printf("%02X", ((unsigned char *)moo)[i]);
55+
printf("\n");
56+
57+
r = ps4KernelRun(kmain2, kargc, kargv);
58+
printf("return2 (sceSblACMgrIsVideoplayerProcess): %i\n", r);
59+
60+
ps4KernelMemcpy(moo, sceSblACMgrIsVideoplayerProcess, 32);
61+
for(i = 0; i < 32; ++i)
62+
printf("%02X", ((unsigned char *)moo)[i]);
63+
printf("\n");
64+
65+
r = ps4KernelRun(kmain3, kargc, kargv);
66+
printf("return3 (sceSblACMgrIsVideoplayerProcess): %i\n", r);
67+
68+
ps4KernelMemcpy(moo, sceSblACMgrIsVideoplayerProcess, 32);
69+
for(i = 0; i < 32; ++i)
70+
printf("%02X", ((unsigned char *)moo)[i]);
71+
printf("\n");
72+
73+
free(moo); //Bye moo, you did real good :(~
74+
4575
return EXIT_SUCCESS;
4676
}

0 commit comments

Comments
 (0)