Skip to content

Commit 0b545cc

Browse files
authored
Merge pull request #4 from illusion0001/plugin-loader
Load PRX into `ScePartyDaemon`
2 parents 23baa50 + 32c808b commit 0b545cc

File tree

6 files changed

+157
-65
lines changed

6 files changed

+157
-65
lines changed

.github/workflows/build.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ name: PS4 HEN Payload
22

33
on:
44
push:
5-
branches:
6-
- Multi-HEN
75
pull_request:
86
workflow_dispatch:
97

@@ -15,14 +13,15 @@ jobs:
1513
runs-on: ubuntu-latest
1614
env:
1715
zip: ps4-hen-vtx
16+
zip_glob: ps4-hen-*.bin
1817
steps:
1918
- name: Checkout repository
2019
uses: actions/checkout@main
2120
with:
2221
submodules: recursive # Ensure submodules are checked out
2322

2423
- name: Set execute permissions for scripts
25-
run: chmod +x build.sh
24+
run: chmod +x build.sh download_prx.sh
2625

2726
- name: Install dependencies
2827
run: sudo apt-get update && sudo apt-get install -y make gcc zip
@@ -34,18 +33,18 @@ jobs:
3433
3534
- name: Build and package binaries
3635
run: |
36+
./download_prx.sh
3737
VERSIONS="505 672 700 701 702 750 751 755 800 801 803 850 852 900 903 904 950 951 960 1000 1001 1050 1070 1071 1100 1102 1150 1152 1200 1202"
3838
for VERSION in $VERSIONS; do
3939
./build.sh $VERSION
4040
done
41-
zip ${{ env.zip }}.zip ps4-hen-*.bin
41+
zip ${{ env.zip }}.zip ${{ env.zip_glob }}
4242
4343
- name: Upload payload
44-
if: github.event_name != 'push' && github.ref != 'refs/heads/Multi-HEN'
4544
uses: actions/upload-artifact@main
4645
with:
4746
name: ${{ env.zip }}
48-
path: ps4-hen-*.bin
47+
path: ${{ env.zip_glob }}
4948

5049
- name: Release for branch Multi-HEN
5150
if: github.event_name == 'push' && github.ref == 'refs/heads/Multi-HEN'

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
**/*.o
22
**/*.bin
33
**/*.map
4+
**/*.inc
5+
**/*.prx
6+
**/*.zip

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
## Features
44
- Current Supports 5.05 - 12.02
55
- Homebrew Enabler
6+
- [Plugins System](https://github.com/illusion0001/ps4-hen-plugins)
7+
- Load PRX into `ScePartyDaemon` (Starts klog server on port 3232, based on [klogsrv](https://github.com/ps5-payload-dev/klogsrv))
8+
- [Source](https://github.com/illusion0001/ps4-hen-plugins/tree/main/plugin_server)
9+
- Load PRX into retail apps (on startup in CRT `_init_env`) (Shows only notification for now)
10+
- [Source](https://github.com/illusion0001/ps4-hen-plugins/tree/main/plugin_loader)
611
- Jailbreak
712
- Sandbox Escape
813
- Debug Settings

download_prx.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
c=$PWD
4+
cd installer/build
5+
f=plugins.zip
6+
curl -fLJO https://github.com/illusion0001/ps4-hen-plugins/releases/latest/download/$f
7+
unzip $f
8+
cd bin/plugins/prx_final
9+
for file in *.prx; do xxd -i "$file" > "$c/installer/include/${file}.inc"; done
10+
cd $c

installer/source/main.c

Lines changed: 99 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@
99
extern char kpayload[];
1010
extern unsigned kpayload_size;
1111

12-
int install_payload(struct thread *td, struct install_payload_args* args)
12+
int install_payload(struct thread *td, struct install_payload_args *args)
1313
{
14-
struct ucred* cred;
15-
struct filedesc* fd;
14+
struct ucred *cred;
15+
struct filedesc *fd;
1616

1717
fd = td->td_proc->p_fd;
1818
cred = td->td_proc->p_ucred;
1919

20-
uint8_t* kernel_base = (uint8_t*)(__readmsr(0xC0000082) - XFAST_SYSCALL_addr);
21-
uint8_t* kernel_ptr = (uint8_t*)kernel_base;
22-
void** got_prison0 = (void**)&kernel_ptr[PRISON0_addr];
23-
void** got_rootvnode = (void**)&kernel_ptr[ROOTVNODE_addr];
20+
uint8_t *kernel_base = (uint8_t *)(__readmsr(0xC0000082) - XFAST_SYSCALL_addr);
21+
uint8_t *kernel_ptr = (uint8_t *)kernel_base;
22+
void **got_prison0 = (void **)&kernel_ptr[PRISON0_addr];
23+
void **got_rootvnode = (void **)&kernel_ptr[ROOTVNODE_addr];
2424

25-
void (*pmap_protect)(void * pmap, uint64_t sva, uint64_t eva, uint8_t pr) = (void *)(kernel_base + pmap_protect_addr);
25+
void (*pmap_protect)(void *pmap, uint64_t sva, uint64_t eva, uint8_t pr) = (void *)(kernel_base + pmap_protect_addr);
2626
void *kernel_pmap_store = (void *)(kernel_base + PMAP_STORE_addr);
2727

28-
uint8_t* payload_data = args->payload_info->buffer;
28+
uint8_t *payload_data = args->payload_info->buffer;
2929
size_t payload_size = args->payload_info->size;
30-
struct payload_header* payload_header = (struct payload_header*)payload_data;
31-
uint8_t* payload_buffer = (uint8_t*)&kernel_base[DT_HASH_SEGMENT_addr];
30+
struct payload_header *payload_header = (struct payload_header *)payload_data;
31+
uint8_t *payload_buffer = (uint8_t *)&kernel_base[DT_HASH_SEGMENT_addr];
3232

3333
if (!payload_data || payload_size < sizeof(payload_header) || payload_header->signature != 0x5041594C4F414458ull)
3434
return -1;
@@ -57,7 +57,7 @@ int install_payload(struct thread *td, struct install_payload_args* args)
5757
*sceProcCap = 0xffffffffffffffff; // Sce Process
5858

5959
// Use "kmem" for all patches
60-
uint8_t *kmem;
60+
uint8_t *kmem;
6161

6262
// Disable write protection
6363
uint64_t cr0 = readCr0();
@@ -70,7 +70,7 @@ int install_payload(struct thread *td, struct install_payload_args* args)
7070
kmem[2] = 0x00;
7171
kmem[3] = 0x00;
7272

73-
//flatz Patch sys_dynlib_dlsym: Allow from anywhere
73+
// flatz Patch sys_dynlib_dlsym: Allow from anywhere
7474
kmem = (uint8_t *)&kernel_base[sys_dynlib_dlsym_patch1];
7575
kmem[0] = 0xEB;
7676
kmem[1] = 0x4C;
@@ -105,13 +105,13 @@ int install_payload(struct thread *td, struct install_payload_args* args)
105105
kmem = (uint8_t *)&kernel_base[enable_copyin_patch1];
106106
kmem[0] = 0x90;
107107
kmem[1] = 0x90;
108-
108+
109109
if (FW != 505)
110110
{
111-
kmem = (uint8_t *)&kernel_base[enable_copyin_patch2];
112-
kmem[0] = 0x90;
113-
kmem[1] = 0x90;
114-
kmem[2] = 0x90;
111+
kmem = (uint8_t *)&kernel_base[enable_copyin_patch2];
112+
kmem[0] = 0x90;
113+
kmem[1] = 0x90;
114+
kmem[2] = 0x90;
115115
}
116116
// copyout
117117
kmem = (uint8_t *)&kernel_base[enable_copyout_patch1];
@@ -120,25 +120,25 @@ int install_payload(struct thread *td, struct install_payload_args* args)
120120

121121
if (FW != 505)
122122
{
123-
kmem = (uint8_t *)&kernel_base[enable_copyout_patch2];
124-
kmem[0] = 0x90;
125-
kmem[1] = 0x90;
126-
kmem[2] = 0x90;
123+
kmem = (uint8_t *)&kernel_base[enable_copyout_patch2];
124+
kmem[0] = 0x90;
125+
kmem[1] = 0x90;
126+
kmem[2] = 0x90;
127127
}
128-
128+
129129
// Patch copyinstr
130130
kmem = (uint8_t *)&kernel_base[enable_copyinstr_patch1];
131131
kmem[0] = 0x90;
132132
kmem[1] = 0x90;
133-
133+
134134
if (FW != 505)
135135
{
136-
kmem = (uint8_t *)&kernel_base[enable_copyinstr_patch2];
137-
kmem[0] = 0x90;
138-
kmem[1] = 0x90;
139-
kmem[2] = 0x90;
136+
kmem = (uint8_t *)&kernel_base[enable_copyinstr_patch2];
137+
kmem[0] = 0x90;
138+
kmem[1] = 0x90;
139+
kmem[2] = 0x90;
140140
}
141-
141+
142142
kmem = (uint8_t *)&kernel_base[enable_copyinstr_patch3];
143143
kmem[0] = 0x90;
144144
kmem[1] = 0x90;
@@ -148,7 +148,7 @@ int install_payload(struct thread *td, struct install_payload_args* args)
148148
kmem[0] = 0xEB;
149149

150150
// ptrace patches
151-
kmem = (uint8_t*)&kernel_base[enable_ptrace_patch1];
151+
kmem = (uint8_t *)&kernel_base[enable_ptrace_patch1];
152152
kmem[0] = 0x90;
153153
kmem[1] = 0x90;
154154
kmem[2] = 0x90;
@@ -165,15 +165,15 @@ int install_payload(struct thread *td, struct install_payload_args* args)
165165
kmem[3] = 0x00;
166166
kmem[4] = 0x00;
167167

168-
// patch ASLR, thanks 2much4u
169-
kmem = (uint8_t *)&kernel_base[disable_aslr_patch];
170-
kmem[0] = 0x90;
171-
kmem[1] = 0x90;
168+
// patch ASLR, thanks 2much4u
169+
kmem = (uint8_t *)&kernel_base[disable_aslr_patch];
170+
kmem[0] = 0x90;
171+
kmem[1] = 0x90;
172172

173-
// Change directory depth limit from 9 to 64
173+
// Change directory depth limit from 9 to 64
174174
kmem = (uint8_t *)&kernel_base[depth_limit_patch];
175175
kmem[0] = 0x40;
176-
176+
177177
// setlogin patch (for autolaunch check)
178178
kmem = (uint8_t *)&kernel_base[enable_setlogin_patch];
179179
kmem[0] = 0x48;
@@ -232,7 +232,6 @@ int install_payload(struct thread *td, struct install_payload_args* args)
232232
kmem[4] = 0x90;
233233
kmem[5] = 0x90;
234234

235-
236235
// Enable mount for unprivileged user
237236
kmem = (uint8_t *)&kernel_base[enable_mount_patch];
238237
kmem[0] = 0x90;
@@ -253,7 +252,6 @@ int install_payload(struct thread *td, struct install_payload_args* args)
253252
kmem[0] = 0x90;
254253
kmem[1] = 0x90;
255254

256-
257255
// Patch debug setting errors
258256
kmem = (uint8_t *)&kernel_base[debug_menu_error_patch1];
259257
kmem[0] = 0x00;
@@ -271,8 +269,8 @@ int install_payload(struct thread *td, struct install_payload_args* args)
271269
memset(payload_buffer, 0, PAGE_SIZE);
272270
memcpy(payload_buffer, payload_data, payload_size);
273271

274-
uint64_t sss = ((uint64_t)payload_buffer) & ~(uint64_t)(PAGE_SIZE-1);
275-
uint64_t eee = ((uint64_t)payload_buffer + payload_size + PAGE_SIZE - 1) & ~(uint64_t)(PAGE_SIZE-1);
272+
uint64_t sss = ((uint64_t)payload_buffer) & ~(uint64_t)(PAGE_SIZE - 1);
273+
uint64_t eee = ((uint64_t)payload_buffer + payload_size + PAGE_SIZE - 1) & ~(uint64_t)(PAGE_SIZE - 1);
276274
kernel_base[pmap_protect_p_addr] = 0xEB;
277275
pmap_protect(kernel_pmap_store, sss, eee, 7);
278276
kernel_base[pmap_protect_p_addr] = 0x75;
@@ -281,35 +279,75 @@ int install_payload(struct thread *td, struct install_payload_args* args)
281279
writeCr0(cr0);
282280

283281
int (*payload_entrypoint)();
284-
*((void**)&payload_entrypoint) = (void*)(&payload_buffer[payload_header->entrypoint_offset]);
282+
*((void **)&payload_entrypoint) = (void *)(&payload_buffer[payload_header->entrypoint_offset]);
285283

286284
return payload_entrypoint();
287285
}
288286

289287
static inline void patch_update(void)
290288
{
291-
unlink(PS4_UPDATE_FULL_PATH);
292-
rmdir(PS4_UPDATE_FULL_PATH);
293-
if (mkdir(PS4_UPDATE_FULL_PATH, 0777) != 0) {
294-
printf_debug("Failed to create /update/PS4UPDATE.PUP.");
295-
}
296-
297-
unlink(PS4_UPDATE_TEMP_PATH);
298-
rmdir(PS4_UPDATE_TEMP_PATH);
299-
if (mkdir(PS4_UPDATE_TEMP_PATH, 0777) != 0) {
300-
printf_debug("Failed to create /update/PS4UPDATE.PUP.net.temp.");
301-
}
289+
unlink(PS4_UPDATE_FULL_PATH);
290+
rmdir(PS4_UPDATE_FULL_PATH);
291+
if (mkdir(PS4_UPDATE_FULL_PATH, 0777) != 0)
292+
{
293+
printf_debug("Failed to create /update/PS4UPDATE.PUP.");
294+
}
295+
296+
unlink(PS4_UPDATE_TEMP_PATH);
297+
rmdir(PS4_UPDATE_TEMP_PATH);
298+
if (mkdir(PS4_UPDATE_TEMP_PATH, 0777) != 0)
299+
{
300+
printf_debug("Failed to create /update/PS4UPDATE.PUP.net.temp.");
301+
}
302+
}
303+
304+
// clang-format off
305+
static const
306+
#include "plugin_bootloader.prx.inc"
307+
static const
308+
#include "plugin_loader.prx.inc"
309+
static const
310+
#include "plugin_server.prx.inc"
311+
312+
static void write_blob(const char* path, const void* blob, const size_t blobsz)
313+
{
314+
int fd = open(path, O_CREAT | O_RDWR, 0777);
315+
printf_debug("fd %s %d\n", path, fd);
316+
if (fd > 0)
317+
{
318+
write(fd, blob,blobsz);
319+
close(fd);
320+
}
321+
}
322+
323+
static void upload_prx_to_disk(void)
324+
{
325+
write_blob("/user/data/plugin_bootloader.prx", plugin_bootloader_prx, sizeof(plugin_bootloader_prx));
326+
write_blob("/user/data/plugin_loader.prx", plugin_loader_prx, sizeof(plugin_loader_prx));
327+
write_blob("/user/data/plugin_server.prx", plugin_server_prx, sizeof(plugin_server_prx));
328+
}
329+
// clang-format on
330+
331+
static void kill_party(void)
332+
{
333+
static char proc[] = "ScePartyDaemon";
334+
int party = findProcess(proc);
335+
printf_debug("%s %d\n", proc, party);
336+
if (party > 0)
337+
{
338+
kill(party, SIGKILL);
339+
}
302340
}
303341

304342
int _main(struct thread *td)
305-
{
343+
{
306344

307345
int result;
308346

309347
initKernel();
310348
initLibc();
311349

312-
printf_debug("Starting...\n");
350+
printf_debug("Starting...\n");
313351

314352
struct payload_info payload_info;
315353
payload_info.buffer = (uint8_t *)kpayload;
@@ -324,9 +362,13 @@ int _main(struct thread *td)
324362
patch_update();
325363
initSysUtil();
326364

327-
char fw_version[6] = {0};
328-
get_firmware_string(fw_version);
329-
printf_notification("Welcome To PS4HEN v"VERSION"\nPS4 Firmware %s", fw_version);
365+
jailbreak();
366+
upload_prx_to_disk();
367+
kill_party();
368+
369+
char fw_version[6] = {0};
370+
get_firmware_string(fw_version);
371+
printf_notification("Welcome To PS4HEN v" VERSION "\nPS4 Firmware %s", fw_version);
330372

331373
printf_debug("Done.\n");
332374

0 commit comments

Comments
 (0)