mirror of
https://github.com/StikDebug/StikDebug.git
synced 2026-10-15 20:10:30 +00:00
* Heartbeat rework * remove some debug loggings * stik mini tool poc * Saperate JITEnableContext into extensions and put each feature into their own files. Fix local pairing file is removed after switched to external device by directly loading the remote device's pairing file in place. * custom origin & xmlhttprequest * Fix some memory leak * allow background script access idevice (codes are from the old JSSupport branch) Tests are not carried out but most of the js api should work. Do we need to obfuscate some functions' name? * Fix JITEnableContext singleton initializer race condition * Fix instprox callback --------- Co-authored-by: Stephen B <158498287+StephenDev0@users.noreply.github.com>
67 lines
2.2 KiB
Objective-C
67 lines
2.2 KiB
Objective-C
//
|
|
// IDeviceJSBridgeSBServices.m
|
|
// StikJIT
|
|
//
|
|
// Created by s s on 2025/4/25.
|
|
//
|
|
|
|
@import Foundation;
|
|
#import "JSSupport.h"
|
|
|
|
@implementation IDeviceJSBridge (SBServices)
|
|
|
|
- (void)springboard_services_connectWithBody:(NSDictionary *)body replyHandler:(nonnull void (^)(id _Nullable, NSString * _Nullable))replyHandler {
|
|
NSError* heartbeatErr = nil;
|
|
[JITEnableContext.shared ensureHeartbeatWithError:&heartbeatErr];
|
|
if(heartbeatErr) {
|
|
replyHandler(nil, heartbeatErr.localizedDescription);
|
|
return;
|
|
}
|
|
|
|
IdeviceProviderHandle* provider = [JITEnableContext.shared getTcpProviderHandle];
|
|
|
|
SpringBoardServicesClientHandle *sb_services = NULL;
|
|
IdeviceFfiError* err = springboard_services_connect(provider, &sb_services);
|
|
if (err) {
|
|
replyHandler(nil, [self errFreeFromIdeviceFfiError:err]);
|
|
return;
|
|
}
|
|
int handleId = [self registerIdeviceHandle:sb_services freeFunc:(void*)springboard_services_free];
|
|
replyHandler(@(handleId), nil);
|
|
}
|
|
|
|
|
|
- (void)springboard_services_get_iconWithBody:(NSDictionary *)body replyHandler:(nonnull void (^)(id _Nullable, NSString * _Nullable))replyHandler {
|
|
|
|
int clientId = [body[@"client"] intValue];
|
|
if(!handles[@(clientId)] || handles[@(clientId)].freeFunc != springboard_services_free) {
|
|
replyHandler(nil, @"Invalid springboard services client handle");
|
|
return;
|
|
}
|
|
IDeviceHandle* clientHandleObj = handles[@(clientId)];
|
|
SpringBoardServicesClientHandle* client = clientHandleObj.handle;
|
|
NSString* bundleID = body[@"bundle_id"];
|
|
if(![bundleID isKindOfClass:NSString.class]) {
|
|
replyHandler(nil, @"Invalid bundle id");
|
|
return;
|
|
}
|
|
|
|
void *pngData = NULL;
|
|
size_t data_len = 0;
|
|
IdeviceFfiError* err = springboard_services_get_icon(client, [bundleID UTF8String], &pngData, &data_len);
|
|
if (err) {
|
|
replyHandler(nil, [self errFreeFromIdeviceFfiError:err]);
|
|
return;
|
|
}
|
|
|
|
if(data_len == 0) {
|
|
replyHandler(@(-1), nil);
|
|
}
|
|
|
|
NSData* data = [NSData dataWithBytes:pngData length:data_len];
|
|
free(pngData);
|
|
int handleId = [self registerNSData:data];
|
|
replyHandler(@(handleId), nil);
|
|
}
|
|
|
|
@end
|