Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion StikJIT/JSSupport/IDeviceJSBridgeDebugProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
11 changes: 8 additions & 3 deletions StikJIT/JSSupport/RunJSView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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) ?? ""
Expand Down
1 change: 1 addition & 0 deletions StikJIT/Views/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ struct HomeView: View {
}
.onChange(of: scriptViewShow) { oldValue, newValue in
if !newValue, let jsModel {
jsModel.executionInterrupted = true
jsModel.semaphore?.signal()
}
}
Expand Down
27 changes: 10 additions & 17 deletions StikJIT/idevice/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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];
Expand All @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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");

Expand Down
1 change: 0 additions & 1 deletion StikJIT/idevice/jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Binary file modified StikJIT/idevice/libidevice_ffi.a
Binary file not shown.