Skip to content

Commit 36bf2a5

Browse files
committed
feat: make it go a lot faster
1 parent fec2555 commit 36bf2a5

File tree

1 file changed

+78
-30
lines changed

1 file changed

+78
-30
lines changed

script.js

+78-30
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,10 @@ function extract(conn, xpc_object, dict) {
161161
}
162162
}
163163

164-
function parseAndSendDictData(fnName, conn, dict) {
164+
var ps = new NativeCallback((fnName, conn, dict) => {
165165
var ret = {};
166-
ret["name"] = fnName;
166+
var fname = rcstr(fnName);
167+
ret["name"] = fname;
167168
ret["connName"] = "UNKNOWN";
168169
ret["pid"] = xpc_connection_get_pid(conn);
169170
if (conn != null) {
@@ -172,52 +173,99 @@ function parseAndSendDictData(fnName, conn, dict) {
172173
ret["connName"] = rcstr(connName);
173174
}
174175
}
175-
if (fnName == "xpc_connection_set_event_handler") {
176+
if (fname == "xpc_connection_set_event_handler") {
176177
var data = {"blockImplementation": dict.toString()};
177178
ret["dictionary"] = data;
178179
} else {
179180
ret["dictionary"] = extract(conn, dict, dict);
180181
}
181182
send(JSON.stringify(ret));
182-
}
183+
}, "void", ["pointer", "pointer", "pointer"]);
183184

184-
Interceptor.attach(xpc_connection_send_notification, {
185-
onEnter(args) {
186-
parseAndSendDictData("xpc_connection_send_notification", args[0], args[1]);
185+
var cm_notification = new CModule(`
186+
#include <gum/guminterceptor.h>
187+
extern void ps(void*,void*,void*);
188+
189+
void onEnter(GumInvocationContext * ic)
190+
{
191+
void * conn = gum_invocation_context_get_nth_argument(ic,0);
192+
void * obj = gum_invocation_context_get_nth_argument(ic,1);
193+
ps("xpc_connection_send_notification", conn, obj);
187194
}
188-
});
195+
`, {ps});
189196

190-
Interceptor.attach(xpc_connection_send_message, {
191-
onEnter(args) {
192-
parseAndSendDictData("xpc_connection_send_message", args[0], args[1]);
197+
var cm_send_message = new CModule(`
198+
#include <gum/guminterceptor.h>
199+
extern void ps(void*,void*,void*);
200+
201+
void onEnter(GumInvocationContext * ic)
202+
{
203+
void * conn = gum_invocation_context_get_nth_argument(ic,0);
204+
void * obj = gum_invocation_context_get_nth_argument(ic,1);
205+
ps("xpc_connection_send_message", conn, obj);
193206
}
194-
});
207+
`, {ps});
195208

196-
Interceptor.attach(xpc_connection_send_message_with_reply, {
197-
onEnter(args) {
198-
parseAndSendDictData("xpc_connection_send_message_with_reply", args[0], args[1]);
209+
var cm_send_message_with_reply = new CModule(`
210+
#include <gum/guminterceptor.h>
211+
extern void ps(void*,void*,void*);
212+
213+
void onEnter(GumInvocationContext * ic)
214+
{
215+
void * conn = gum_invocation_context_get_nth_argument(ic,0);
216+
void * obj = gum_invocation_context_get_nth_argument(ic,1);
217+
ps("xpc_connection_send_message_with_reply", conn, obj);
199218
}
200-
})
219+
`, {ps});
201220

202-
Interceptor.attach(xpc_connection_send_message_with_reply_sync, {
203-
onEnter(args) {
204-
parseAndSendDictData("xpc_connection_send_message_with_reply_sync", args[0], args[1]);
221+
var cm_send_message_with_reply_sync = new CModule(`
222+
#include <gum/guminterceptor.h>
223+
extern void ps(void*,void*,void*);
224+
225+
void onEnter(GumInvocationContext * ic)
226+
{
227+
void * conn = gum_invocation_context_get_nth_argument(ic,0);
228+
void * obj = gum_invocation_context_get_nth_argument(ic,1);
229+
ps("xpc_connection_send_message_with_reply_sync", conn, obj);
205230
}
206-
})
231+
`, {ps});
207232

208-
Interceptor.attach(xpc_connection_call_event_handler, {
209-
onEnter(args) {
210-
parseAndSendDictData("xpc_connection_call_event_handler", args[0], args[1]);
233+
var cm_call_event_handler = new CModule(`
234+
#include <gum/guminterceptor.h>
235+
extern void ps(void*,void*,void*);
236+
237+
void onEnter(GumInvocationContext * ic)
238+
{
239+
void * conn = gum_invocation_context_get_nth_argument(ic,0);
240+
void * obj = gum_invocation_context_get_nth_argument(ic,1);
241+
ps("xpc_connection_call_event_handler", conn, obj);
211242
}
212-
});
243+
`, {ps});
213244

214-
Interceptor.attach(xpc_connection_set_event_handler, {
215-
onEnter(args) {
216-
const implementationAddr = args[1].add(Process.pointerSize * 2);
217-
const implementation = Memory.readPointer(implementationAddr);
218-
parseAndSendDictData("xpc_connection_set_event_handler", args[0], implementation);
245+
var psize = Memory.alloc(Process.pointerSize);
246+
Memory.writeInt(psize, Process.pointerSize * 2);
247+
248+
var cm_set_event_handler = new CModule(`
249+
#include <gum/guminterceptor.h>
250+
extern int pointerSize;
251+
extern void ps(void*,void*,void*);
252+
253+
void onEnter(GumInvocationContext * ic)
254+
{
255+
void * conn = gum_invocation_context_get_nth_argument(ic,0);
256+
void * obj = gum_invocation_context_get_nth_argument(ic,1);
257+
void * impl = obj + (pointerSize*2);
258+
ps("xpc_connection_set_event_handler", conn, impl);
219259
}
220-
})
260+
`, {pointerSize: psize, ps});
261+
262+
Interceptor.attach(xpc_connection_send_notification, cm_notification);
263+
Interceptor.attach(xpc_connection_send_message, cm_send_message);
264+
Interceptor.attach(xpc_connection_send_message_with_reply, cm_send_message_with_reply);
265+
Interceptor.attach(xpc_connection_send_message_with_reply_sync, cm_send_message_with_reply_sync);
266+
Interceptor.attach(xpc_connection_call_event_handler, cm_call_event_handler);
267+
268+
Interceptor.attach(xpc_connection_set_event_handler, cm_set_event_handler);
221269

222270
Interceptor.attach(xpc_connection_create_mach_service, {
223271
onEnter(args) {

0 commit comments

Comments
 (0)