diff --git a/StikJIT/JSSupport/IDeviceJSBridgeDebugProxy.m b/StikJIT/JSSupport/IDeviceJSBridgeDebugProxy.m index 23ef5c7d..400d920a 100644 --- a/StikJIT/JSSupport/IDeviceJSBridgeDebugProxy.m +++ b/StikJIT/JSSupport/IDeviceJSBridgeDebugProxy.m @@ -17,7 +17,7 @@ command = debugserver_command_new([commandStr UTF8String], NULL, 0); char* attach_response = 0; - IdeviceFfiError* err = debug_proxy_send_command2(debugProxy, command, &attach_response); + IdeviceFfiError* err = debug_proxy_send_command(debugProxy, command, &attach_response); debugserver_command_free(command); if (err) { context.exception = [JSValue valueWithObject:[NSString stringWithFormat:@"error code %d, msg %s", err->code, err->message] inContext:context]; diff --git a/StikJIT/JSSupport/RunJSView.swift b/StikJIT/JSSupport/RunJSView.swift index 420cb041..46c6004a 100644 --- a/StikJIT/JSSupport/RunJSView.swift +++ b/StikJIT/JSSupport/RunJSView.swift @@ -12,7 +12,8 @@ import JavaScriptCore class RunJSViewModel : ObservableObject { var context: JSContext? @Published var logs: [String] = [] - @Published var scriptName : String = "Script" + @Published var scriptName: String = "Script" + @Published var executionInterrupted = false var pid: Int var debugProxy: OpaquePointer? var semaphore: dispatch_semaphore_t? @@ -33,8 +34,12 @@ class RunJSViewModel : ObservableObject { let sendCommandFunction: @convention(block) (String?) -> String? = { commandStr in guard let commandStr else { - self.context?.exception = JSValue(object: "command should not be nil", in: self.context!) - return nil + self.context?.exception = JSValue(object: "Command should not be nil.", in: self.context!) + return "" + } + if self.executionInterrupted { + self.context?.exception = JSValue(object: "Script execution is interrupted by StikDebug.", in: self.context!) + return "" } return handleJSContextSendDebugCommand(self.context, commandStr, self.debugProxy) ?? "" diff --git a/StikJIT/Views/HomeView.swift b/StikJIT/Views/HomeView.swift index 0aaab352..7aeceeca 100644 --- a/StikJIT/Views/HomeView.swift +++ b/StikJIT/Views/HomeView.swift @@ -321,6 +321,7 @@ struct HomeView: View { } .onChange(of: scriptViewShow) { oldValue, newValue in if !newValue, let jsModel { + jsModel.executionInterrupted = true jsModel.semaphore?.signal() } } diff --git a/StikJIT/idevice/jit.c b/StikJIT/idevice/jit.c index 643c2aff..808236ad 100644 --- a/StikJIT/idevice/jit.c +++ b/StikJIT/idevice/jit.c @@ -18,20 +18,6 @@ #include "jit.h" -IdeviceFfiError* debug_proxy_send_command2(struct DebugProxyHandle *handle, struct DebugserverCommandHandle *command, char **response) { - IdeviceFfiError* err = debug_proxy_send_command(handle, command, response); - if(err) { - return err; - } - for(int i = 0; i < 10; ++i) { - if(*response) { - return err; - } - debug_proxy_read_response(handle, response); - } - return err; -} - void runDebugServerCommand(int pid, DebugProxyHandle* debug_proxy, LogFuncC logger, DebugAppCallback callback) { // enable QStartNoAckMode char *disableResponse = NULL; @@ -49,6 +35,7 @@ void runDebugServerCommand(int pid, DebugProxyHandle* debug_proxy, LogFuncC logg callback(pid, debug_proxy, semaphore); dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); err = debug_proxy_send_raw(debug_proxy, "\x03", 1); + usleep(500); } else { // Send vAttach command with PID in hex char attach_command[64]; @@ -61,7 +48,7 @@ void runDebugServerCommand(int pid, DebugProxyHandle* debug_proxy, LogFuncC logg } char *attach_response = NULL; - err = debug_proxy_send_command2(debug_proxy, attach_cmd, &attach_response); + err = debug_proxy_send_command(debug_proxy, attach_cmd, &attach_response); debugserver_command_free(attach_cmd); if (err) { @@ -79,11 +66,12 @@ void runDebugServerCommand(int pid, DebugProxyHandle* debug_proxy, LogFuncC logg logger("Failed to create detach command"); } else { char *detach_response = NULL; - err = debug_proxy_send_command2(debug_proxy, detach_cmd, &detach_response); + err = debug_proxy_send_command(debug_proxy, detach_cmd, &detach_response); debugserver_command_free(detach_cmd); if (err) { - logger("Failed to detach from process: %d", err); + logger("Failed to detach from process: %d", err->code); + idevice_error_free(err); } else if (detach_response != NULL) { logger("Detach response: %s", detach_response); idevice_string_free(detach_response); @@ -188,6 +176,11 @@ int debug_app(IdeviceProviderHandle* tcp_provider, const char *bundle_id, LogFun return 1; } printf("Successfully launched app with PID: %llu\n", pid); + + char* path = malloc(2048); + snprintf(path, 2048, "%s/Documents/debugProxy.pcap", getenv("HOME")); + adapter_pcap(adapter, path); + free(path); printf("\n=== Setting up Debug Proxy ===\n"); diff --git a/StikJIT/idevice/jit.h b/StikJIT/idevice/jit.h index 88be3ff9..ee5b1958 100644 --- a/StikJIT/idevice/jit.h +++ b/StikJIT/idevice/jit.h @@ -13,7 +13,6 @@ typedef void (^LogFuncC)(const char* message, ...); typedef void (^DebugAppCallback)(int pid, struct DebugProxyHandle* debug_proxy, dispatch_semaphore_t semaphore); int debug_app(IdeviceProviderHandle* tcp_provider, const char *bundle_id, LogFuncC logger, DebugAppCallback callback); -IdeviceFfiError* debug_proxy_send_command2(struct DebugProxyHandle *handle, struct DebugserverCommandHandle *command, char **response); int debug_app_pid(IdeviceProviderHandle* tcp_provider, int pid, LogFuncC logger, DebugAppCallback callback); #endif /* JIT_H */ diff --git a/StikJIT/idevice/libidevice_ffi.a b/StikJIT/idevice/libidevice_ffi.a index 57bc7a31..4211de92 100644 Binary files a/StikJIT/idevice/libidevice_ffi.a and b/StikJIT/idevice/libidevice_ffi.a differ