99extern char kpayload [];
1010extern 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
289287static 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
304342int _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