5
5
#include <signal.h>
6
6
#include <dlfcn.h>
7
7
#include <os/log.h>
8
+ #include <util.h>
8
9
#include "syscall.h"
9
10
#include "litehook.h"
10
11
#include <libjailbreak/jbclient_xpc.h>
@@ -92,13 +93,63 @@ __attribute__((visibility ("default"))) pid_t forkfix___fork(void)
92
93
return pid ;
93
94
}
94
95
96
+ void apply_fork_hook (void )
97
+ {
98
+ static dispatch_once_t onceToken ;
99
+ dispatch_once (& onceToken , ^{
100
+ void * systemhookHandle = dlopen ("systemhook.dylib" , RTLD_NOLOAD );
101
+ if (systemhookHandle ) {
102
+ kern_return_t (* litehook_hook_function )(void * source , void * target ) = dlsym (systemhookHandle , "litehook_hook_function" );
103
+ if (litehook_hook_function ) {
104
+ litehook_hook_function ((void * )__fork , (void * )forkfix___fork );
105
+ }
106
+ }
107
+ });
108
+ }
109
+
110
+ // iOS 15 arm64e wrappers
111
+ // Only apply fork hook when something actually calls it
112
+ int fork_hook (void )
113
+ {
114
+ apply_fork_hook ();
115
+ return fork ();
116
+ }
117
+ int vfork_hook (void )
118
+ {
119
+ apply_fork_hook ();
120
+ return vfork ();
121
+ }
122
+ pid_t forkpty_hook (int * amaster , char * name , struct termios * termp , struct winsize * winp )
123
+ {
124
+ apply_fork_hook ();
125
+ return forkpty (amaster , name , termp , winp );
126
+ }
127
+ int daemon_hook (int __nochdir , int __noclose )
128
+ {
129
+ apply_fork_hook ();
130
+ return daemon (__nochdir , __noclose );
131
+ }
132
+
95
133
__attribute__((constructor )) static void initializer (void )
96
134
{
97
- void * systemhookHandle = dlopen ("systemhook.dylib" , RTLD_NOLOAD );
98
- if (systemhookHandle ) {
99
- kern_return_t (* litehook_hook_function )(void * source , void * target ) = dlsym (systemhookHandle , "litehook_hook_function" );
100
- if (litehook_hook_function ) {
101
- litehook_hook_function ((void * )& __fork , (void * )& forkfix___fork );
135
+ #ifdef __arm64e__
136
+ if (__builtin_available (iOS 16.0 , * )) { /* fall through */ }
137
+ else {
138
+ void * systemhookHandle = dlopen ("systemhook.dylib" , RTLD_NOLOAD );
139
+ if (systemhookHandle ) {
140
+ // On iOS 15 arm64e, instead of using instruction replacements, rebind __fork instead
141
+ // Less instruction replacements = Less spinlock panics
142
+ kern_return_t (* litehook_rebind_symbol_globally )(void * source , void * target ) = dlsym (systemhookHandle , "litehook_rebind_symbol_globally" );
143
+ if (litehook_rebind_symbol_globally ) {
144
+ litehook_rebind_symbol_globally ((void * )fork , (void * )fork_hook );
145
+ litehook_rebind_symbol_globally ((void * )vfork , (void * )vfork_hook );
146
+ litehook_rebind_symbol_globally ((void * )forkpty , (void * )forkpty_hook );
147
+ litehook_rebind_symbol_globally ((void * )daemon , (void * )daemon_hook );
148
+ }
102
149
}
150
+ return ;
103
151
}
152
+ #endif
153
+
154
+ apply_fork_hook ();
104
155
}
0 commit comments