mirror of
https://github.com/StikDebug/StikDebug.git
synced 2026-10-16 20:30:30 +00:00
url scheme & tcp provider caching
This commit is contained in:
parent
85e16fb724
commit
33fc8b4db7
9 changed files with 70 additions and 69 deletions
19
StikJIT/Info.plist
Normal file
19
StikJIT/Info.plist
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleURLTypes</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CFBundleTypeRole</key>
|
||||
<string>Editor</string>
|
||||
<key>CFBundleURLName</key>
|
||||
<string>com.stik.StikJIT.enableJIT</string>
|
||||
<key>CFBundleURLSchemes</key>
|
||||
<array>
|
||||
<string>stikjit</string>
|
||||
</array>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
|
@ -23,6 +23,9 @@ struct HomeView: View {
|
|||
@State private var isProcessing = false
|
||||
@State private var isShowingInstalledApps = false
|
||||
@State private var isShowingPairingFilePicker = false
|
||||
|
||||
@State private var viewDidAppeared = false
|
||||
@State private var pendingBundleIdToEnableJIT : String? = nil
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
|
|
@ -108,6 +111,29 @@ struct HomeView: View {
|
|||
startJITInBackground(with: selectedBundle)
|
||||
}
|
||||
}
|
||||
.onOpenURL { url in
|
||||
print(url.path())
|
||||
if url.host() != "enable-jit" {
|
||||
return
|
||||
}
|
||||
|
||||
let components = URLComponents(url: url, resolvingAgainstBaseURL: false)
|
||||
if let bundleId = components?.queryItems?.first(where: { $0.name == "bundle-id" })?.value {
|
||||
if viewDidAppeared {
|
||||
startJITInBackground(with: bundleId)
|
||||
} else {
|
||||
pendingBundleIdToEnableJIT = bundleId
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
.onAppear() {
|
||||
viewDidAppeared = true
|
||||
if let pendingBundleIdToEnableJIT {
|
||||
startJITInBackground(with: pendingBundleIdToEnableJIT)
|
||||
self.pendingBundleIdToEnableJIT = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func refreshBackground() {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ JITEnableContext* sharedJITContext = nil;
|
|||
|
||||
@implementation JITEnableContext {
|
||||
int heartbeatSessionId;
|
||||
TcpProviderHandle* provider;
|
||||
}
|
||||
|
||||
+ (instancetype)shared {
|
||||
|
|
@ -79,33 +80,33 @@ JITEnableContext* sharedJITContext = nil;
|
|||
return;
|
||||
}
|
||||
self->heartbeatSessionId = arc4random();
|
||||
startHeartbeat(pairingFile, &(self->heartbeatSessionId), ^(int result, const char *message) {
|
||||
startHeartbeat(pairingFile, &(self->provider), &(self->heartbeatSessionId), ^(int result, const char *message) {
|
||||
completionHandler(result,[NSString stringWithCString:message encoding:NSASCIIStringEncoding]);
|
||||
}, [self createCLogger:logger]);
|
||||
}
|
||||
- (void)debugAppWithBundleID:(NSString*)bundleID logger:(LogFunc)logger {
|
||||
NSError* err = nil;
|
||||
IdevicePairingFile* pairingFile = [self getPairingFileWithError:&err];
|
||||
if(err) {
|
||||
if(!provider) {
|
||||
if(logger) {
|
||||
logger(err.localizedDescription);
|
||||
logger(@"Provider not initialized!");
|
||||
}
|
||||
NSLog(@"Provider not initialized!");
|
||||
return;
|
||||
}
|
||||
|
||||
debug_app(pairingFile, [bundleID UTF8String], [self createCLogger:logger]);
|
||||
debug_app(provider, [bundleID UTF8String], [self createCLogger:logger]);
|
||||
}
|
||||
|
||||
|
||||
// bundleId:name
|
||||
- (NSDictionary<NSString*, NSString*>*)getAppListWithError:(NSError**)error {
|
||||
IdevicePairingFile* pairingFile = [self getPairingFileWithError:error];
|
||||
if(*error) {
|
||||
if(!provider) {
|
||||
NSLog(@"Provider not initialized!");
|
||||
*error = [self errorWithStr:@"Provider not initialized!" code:-1];
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString* errorStr = nil;
|
||||
NSDictionary<NSString*, NSString*>* ans = list_installed_apps(pairingFile, &errorStr);
|
||||
NSDictionary<NSString*, NSString*>* ans = list_installed_apps(provider, &errorStr);
|
||||
if(errorStr){
|
||||
*error = [self errorWithStr:errorStr code:-17];
|
||||
return nil;
|
||||
|
|
@ -114,4 +115,11 @@ JITEnableContext* sharedJITContext = nil;
|
|||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
self->heartbeatSessionId = arc4random();
|
||||
if(provider) {
|
||||
tcp_provider_free(provider);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -9,6 +9,6 @@
|
|||
#define APPLIST_H
|
||||
@import Foundation;
|
||||
|
||||
NSDictionary<NSString*, NSString*>* list_installed_apps(IdevicePairingFile* pairing_file, NSString** error);
|
||||
NSDictionary<NSString*, NSString*>* list_installed_apps(TcpProviderHandle* provider, NSString** error);
|
||||
|
||||
#endif /* APPLIST_H */
|
||||
|
|
|
|||
|
|
@ -14,30 +14,12 @@
|
|||
|
||||
#include "applist.h"
|
||||
|
||||
NSDictionary<NSString*, NSString*>* list_installed_apps(IdevicePairingFile* pairing_file, NSString** error) {
|
||||
struct sockaddr_in addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(LOCKDOWN_PORT);
|
||||
if (inet_pton(AF_INET, "10.7.0.1", &addr.sin_addr) <= 0) {
|
||||
*error = @"Invalid IP address";
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSDictionary<NSString*, NSString*>* list_installed_apps(TcpProviderHandle* provider, NSString** error) {
|
||||
IdeviceErrorCode err = IdeviceSuccess;
|
||||
// IdeviceErrorCode err = IdeviceSuccess;
|
||||
|
||||
TcpProviderHandle *provider = NULL;
|
||||
err = idevice_tcp_provider_new((struct sockaddr *)&addr, pairing_file, "ExampleProvider", &provider);
|
||||
if (err != IdeviceSuccess) {
|
||||
*error = @"Failed to create TCP provider";
|
||||
return nil;
|
||||
}
|
||||
|
||||
InstallationProxyClientHandle *client = NULL;
|
||||
err = installation_proxy_connect_tcp(provider, &client);
|
||||
if (err != IdeviceSuccess) {
|
||||
tcp_provider_free(provider);
|
||||
*error = @"Failed to connect to installation proxy";
|
||||
return nil;
|
||||
}
|
||||
|
|
@ -47,7 +29,6 @@ NSDictionary<NSString*, NSString*>* list_installed_apps(IdevicePairingFile* pair
|
|||
err = installation_proxy_get_apps(client, NULL, NULL, 0, &apps, &apps_len);
|
||||
if (err != IdeviceSuccess) {
|
||||
installation_proxy_client_free(client);
|
||||
tcp_provider_free(provider);
|
||||
*error = @"Failed to get apps";
|
||||
return nil;
|
||||
}
|
||||
|
|
@ -100,7 +81,6 @@ NSDictionary<NSString*, NSString*>* list_installed_apps(IdevicePairingFile* pair
|
|||
|
||||
|
||||
installation_proxy_client_free(client);
|
||||
tcp_provider_free(provider);
|
||||
|
||||
return ans;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
#include <limits.h>
|
||||
#include "heartbeat.h"
|
||||
|
||||
void startHeartbeat(IdevicePairingFile* pairing_file, int* heartbeatSessionId, HeartbeatCompletionHandlerC completion, LogFuncC logger) {
|
||||
void startHeartbeat(IdevicePairingFile* pairing_file, TcpProviderHandle** provider, int* heartbeatSessionId, HeartbeatCompletionHandlerC completion, LogFuncC logger) {
|
||||
int currentSessionId = *heartbeatSessionId;
|
||||
logger("DEBUG: Initializing logger...");
|
||||
idevice_init_logger(Debug, Disabled, NULL);
|
||||
|
|
@ -29,9 +29,8 @@ void startHeartbeat(IdevicePairingFile* pairing_file, int* heartbeatSessionId, H
|
|||
IdeviceErrorCode err = IdeviceSuccess;
|
||||
|
||||
logger("DEBUG: Creating TCP provider...");
|
||||
TcpProviderHandle *provider = NULL;
|
||||
err = idevice_tcp_provider_new((struct sockaddr *)&addr, pairing_file,
|
||||
"ExampleProvider", &provider);
|
||||
"ExampleProvider", provider);
|
||||
if (err != IdeviceSuccess) {
|
||||
logger("DEBUG: Failed to create TCP provider: %d", err);
|
||||
completion(err, "Failed to create TCP provider");
|
||||
|
|
@ -41,13 +40,12 @@ void startHeartbeat(IdevicePairingFile* pairing_file, int* heartbeatSessionId, H
|
|||
|
||||
logger("DEBUG: Connecting to installation proxy...");
|
||||
HeartbeatClientHandle *client = NULL;
|
||||
err = heartbeat_connect_tcp(provider, &client);
|
||||
err = heartbeat_connect_tcp(*provider, &client);
|
||||
if (err != IdeviceSuccess) {
|
||||
completion(err, "Failed to connect to Heartbeat");
|
||||
logger("DEBUG: Failed to connect to installation proxy: %d", err);
|
||||
return;
|
||||
}
|
||||
tcp_provider_free(provider);
|
||||
logger("DEBUG: Connected to installation proxy successfully.");
|
||||
|
||||
completion(0, "Heartbeat Completed");
|
||||
|
|
|
|||
|
|
@ -13,6 +13,6 @@
|
|||
typedef void (^HeartbeatCompletionHandlerC)(int result, const char *message);
|
||||
typedef void (^LogFuncC)(const char* message, ...);
|
||||
|
||||
void startHeartbeat(IdevicePairingFile* pairintFile, int* heartbeatSessionId, HeartbeatCompletionHandlerC completion, LogFuncC logger);
|
||||
void startHeartbeat(IdevicePairingFile* pairintFile, TcpProviderHandle** provider, int* heartbeatSessionId, HeartbeatCompletionHandlerC completion, LogFuncC logger);
|
||||
|
||||
#endif /* HEARTBEAT_H */
|
||||
|
|
|
|||
|
|
@ -19,48 +19,18 @@
|
|||
|
||||
#include "jit.h"
|
||||
|
||||
int debug_app(IdevicePairingFile* pairing, const char *bundle_id, LogFuncC logger) {
|
||||
int debug_app(TcpProviderHandle* tcp_provider, const char *bundle_id, LogFuncC logger) {
|
||||
// Initialize logger
|
||||
idevice_init_logger(Debug, Disabled, NULL);
|
||||
|
||||
// Hardcode device IP
|
||||
const char *device_ip = "10.7.0.1";
|
||||
|
||||
/*****************************************************************
|
||||
* CoreDeviceProxy Setup
|
||||
*****************************************************************/
|
||||
logger("=== Setting up CoreDeviceProxy ===");
|
||||
|
||||
// Create socket address
|
||||
struct sockaddr_in addr;
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(LOCKDOWN_PORT);
|
||||
if (inet_pton(AF_INET, device_ip, &addr.sin_addr) != 1) {
|
||||
logger("Invalid IP address");
|
||||
return 1;
|
||||
}
|
||||
|
||||
IdeviceErrorCode err = IdeviceSuccess;
|
||||
|
||||
// Create TCP provider
|
||||
TcpProviderHandle *tcp_provider = NULL;
|
||||
err = idevice_tcp_provider_new((struct sockaddr *)&addr, pairing,
|
||||
"ProcessDebugTest", &tcp_provider);
|
||||
if (err != IdeviceSuccess) {
|
||||
logger("Failed to create TCP provider: %d", err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Connect to CoreDeviceProxy
|
||||
CoreDeviceProxyHandle *core_device = NULL;
|
||||
err = core_device_proxy_connect_tcp(tcp_provider, &core_device);
|
||||
if (err != IdeviceSuccess) {
|
||||
logger("Failed to connect to CoreDeviceProxy: %d", err);
|
||||
tcp_provider_free(tcp_provider);
|
||||
return 1;
|
||||
}
|
||||
tcp_provider_free(tcp_provider);
|
||||
|
||||
// Get server RSD port
|
||||
uint16_t rsd_port;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,6 @@
|
|||
#include "idevice.h"
|
||||
|
||||
typedef void (^LogFuncC)(const char* message, ...);
|
||||
int debug_app(IdevicePairingFile* pairintFile, const char *bundle_id, LogFuncC logger);
|
||||
int debug_app(TcpProviderHandle* provider, const char *bundle_id, LogFuncC logger);
|
||||
|
||||
#endif /* JIT_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue