summaryrefslogtreecommitdiff
path: root/data/uikittools/ldrestart-jbd.diff
blob: 49b86d4b8eb3536687c33f0f55522f0f4b795bc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
diff --git a/ldrestart.cpp b/ldrestart.cpp
index a6d6cb6..c9a3b33 100644
--- a/ldrestart.cpp
+++ b/ldrestart.cpp
@@ -34,6 +34,28 @@
 #define FLAG_PLATFORMIZE (1 << 1)
 #include <dlfcn.h>
 
+#include <os/log.h>
+
+const char *first[] = {
+    NULL
+};
+
+const char *last[] = {
+    "com.apple.assertiond",
+    "com.apple.backboardd",
+    NULL
+};
+
+const char *skip[] = {
+    "jailbreakd",
+    "com.apple.MobileFileIntegrity",
+    "com.openssh.sshd.",
+    "com.apple.SpringBoard",
+   // "com.apple.logd",
+    "com.apple.diagnosticd",
+    NULL
+};
+
 void platformizeme() {
 	void* handle = dlopen("/usr/lib/libjailbreak.dylib", RTLD_LAZY);
 	if (!handle) return;
@@ -51,6 +72,70 @@ void platformizeme() {
 	ptr(getpid(), FLAG_PLATFORMIZE);
 }
 
+bool launch_stop(const char * job)
+{
+    launch_data_t resp;
+    launch_data_t msg;
+
+    msg = launch_data_alloc(LAUNCH_DATA_DICTIONARY);
+    if (msg == NULL) {
+        fprintf(stderr, "out of memory");
+        exit(-1);
+    }
+
+    launch_data_dict_insert(msg, launch_data_new_string(job),
+            LAUNCH_KEY_STOPJOB);
+
+    resp = launch_msg(msg);
+    launch_data_free(msg);
+
+    if (resp == NULL) {
+        return false;
+    }
+
+    switch (launch_data_get_type(resp)) {
+        case LAUNCH_DATA_ERRNO:
+            errno = launch_data_get_errno(resp);
+            launch_data_free(resp);
+            if (errno != 0) {
+                return false;
+            }
+
+            return true;
+
+        default:
+            launch_data_free(resp);
+            return false;
+    }
+}
+
+long long launch_pid(const char * job)
+{
+    launch_data_t msg = launch_data_alloc(LAUNCH_DATA_DICTIONARY);
+    if (msg == NULL) {
+        fprintf(stderr, "out of memory");
+        exit(-1);
+    }
+    launch_data_dict_insert(msg, launch_data_new_string(job), LAUNCH_KEY_GETJOB);
+
+    launch_data_t resp = launch_msg(msg);
+    launch_data_free(msg);
+
+    if (resp == NULL) {
+        return 0;
+    }
+    auto integer(launch_data_dict_lookup(resp, LAUNCH_JOBKEY_PID));
+    if (integer == NULL)
+       return 0;
+    if (launch_data_get_type(integer) != LAUNCH_DATA_INTEGER) {
+        launch_data_free(resp);
+        return 0;
+    }
+    long long pid = launch_data_get_integer(integer);
+    launch_data_free(resp);
+    return pid;
+}
+
 void process(launch_data_t value, const char *name, void *baton) {
     if (launch_data_get_type(value) != LAUNCH_DATA_DICTIONARY)
         return;
@@ -68,6 +153,19 @@ void process(launch_data_t value, const char *name, void *baton) {
         return;
     auto label(launch_data_get_string(string));
 
+    for (const char **skipped = first; *skipped != NULL; skipped++) {
+        if (strcmp(label, *skipped) == 0)
+            return;
+    }
+    for (const char **skipped = skip; *skipped != NULL; skipped++) {
+        if (strncmp(label, *skipped, strlen(*skipped)) == 0)
+            return;
+    }
+    for (const char **skipped = last; *skipped != NULL; skipped++) {
+        if (strcmp(label, *skipped) == 0)
+            return;
+    }
+
     auto stop(launch_data_alloc(LAUNCH_DATA_DICTIONARY));
     launch_data_dict_insert(stop, string, LAUNCH_KEY_STOPJOB);
 
@@ -86,6 +184,23 @@ void process(launch_data_t value, const char *name, void *baton) {
 
 int main(int argc, char *argv[]) {
     platformizeme();
+    for (const char **service = first; *service != NULL; service++) {
+        launch_stop(*service);
+    }
+  //  long long origPid = launch_pid("com.apple.logd");
+  //  if (origPid > 0) {
+  //      launch_stop("com.apple.logd");
+  //      for (int tries=0; tries<10; tries++) {
+  //          long long newPid=launch_pid("com.apple.logd");
+  //          if (newPid > 0 && newPid != origPid)
+  //              break;
+  //          sleep(1);
+  //      }
+  //      // Ensure logd has finished restarting
+  //      os_log(OS_LOG_DEFAULT, "ldrestart: waiting for logd to be ready to process messages");
+  //  } else {
+  //      fprintf(stderr, "no logd running??\n");
+  //  }
     auto request(launch_data_new_string(LAUNCH_KEY_GETJOBS));
     auto response(launch_msg(request));
     launch_data_free(request);
@@ -96,5 +212,8 @@ int main(int argc, char *argv[]) {
         return EX_SOFTWARE;
 
     launch_data_dict_iterate(response, &process, NULL);
+    for (const char **service = last; *service != NULL; service++) {
+        launch_stop(*service);
+    }
     return EX_OK;
 }