mirror of
https://github.com/StikDebug/StikDebug.git
synced 2026-10-15 20:10:30 +00:00
* Change default UPLOAD_IPA value to 'false' * Part 1 of the great debloat * Remove Mini Tools, adopt native alerts in StikJITApp, and update HomeView UI * Refactor views to use native SwiftUI alerts instead of CustomErrorView * Update ProfileView to use minimal List UI style with native alerts * Fix up homeview * Squash: Redesign HomeView, remove Feature Flags, enable all tabs, refactor alerts, and updates - Redesign HomeView to a simpler style with 'Enable JIT' action. - Remove 'Help & Info' and 'Quick Launch' from Home. - Fix DDI false positive by starting heartbeat on HomeView appear. - Restore robust DDI checks and update app name to 'StikDebug'. - Remove FeatureFlags and Beta tags; enable 'profiles', 'processes', 'location' tabs by default. - Remove 'Devices' tab; add 'Target Device IP' field in Settings. - Hardcode 'Settings' tab to 4th position. - Refactor 'SettingsView' tab customization to be reorder-only. - Remove 'Appearance' theme section from Settings. - Refactor custom error cards to use native SwiftUI/UIKit alerts across the app (HomeView, ConsoleLogsView, ProfileView, etc). - Restore JS callback support and script execution logic in HomeView. - Add necessary Color extensions. - Update project version to 3.0.0. * Clean up: Remove In-App Purchases, update checker, and unused IPA installer code * delete more bloat * fix build issue * Remove widget to save on App IDs * Attempt heartbeat restart when Enable JIT button is pressed * Get rid of PIP * Update Tab Naming * remove more bloat * final changes for today * Remove unused packages * UX Improvements * revert bundle id * Update README.md * remove old idevice * add updated idevice * Fix ddi false positive errors and add templates for GitHub stuff * Remove more unused stuff. * Fix links and update README content * Update compatibility table in README.md * Improve performance of console logs * Remove old code * Change default UPLOAD_IPA value to 'true' * remove the welcome sheet * import support for .mobiledevicepair * Add back LC JIT stuff * Fix heartbeat issues with LC JIT * update the build yml for nightly stuff * Update README.md * Update README.md * Update GitHub Actions workflow for IPA build * Update GitHub Actions workflow for nightly builds * Add URL scheme to kill tasks stikjit://kill-process?pid=1234 * fix build issues * Added App Intents * Unify the error handling style across the app
361 lines
11 KiB
Objective-C
361 lines
11 KiB
Objective-C
//
|
|
// applist.c
|
|
// StikJIT
|
|
//
|
|
// Created by Stephen on 3/27/25.
|
|
//
|
|
|
|
#import "idevice.h"
|
|
#include <arpa/inet.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#import "applist.h"
|
|
#import "JITEnableContext.h"
|
|
#import "JITEnableContextInternal.h"
|
|
|
|
NSError* makeError(int code, NSString* msg);
|
|
static NSString *extractAppName(plist_t app)
|
|
{
|
|
plist_t displayNameNode = plist_dict_get_item(app, "CFBundleDisplayName");
|
|
if (displayNameNode) {
|
|
char *displayNameC = NULL;
|
|
plist_get_string_val(displayNameNode, &displayNameC);
|
|
if (displayNameC && displayNameC[0] != '\0') {
|
|
NSString *displayName = [NSString stringWithUTF8String:displayNameC];
|
|
plist_mem_free(displayNameC);
|
|
return displayName;
|
|
}
|
|
plist_mem_free(displayNameC);
|
|
}
|
|
|
|
plist_t nameNode = plist_dict_get_item(app, "CFBundleName");
|
|
if (nameNode) {
|
|
char *nameC = NULL;
|
|
plist_get_string_val(nameNode, &nameC);
|
|
if (nameC && nameC[0] != '\0') {
|
|
NSString *name = [NSString stringWithUTF8String:nameC];
|
|
plist_mem_free(nameC);
|
|
return name;
|
|
}
|
|
plist_mem_free(nameC);
|
|
}
|
|
|
|
return @"Unknown";
|
|
}
|
|
|
|
static BOOL nodeContainsHiddenTag(plist_t tagsNode)
|
|
{
|
|
if (!tagsNode || plist_get_node_type(tagsNode) != PLIST_ARRAY) {
|
|
return NO;
|
|
}
|
|
|
|
uint32_t tagsCount = plist_array_get_size(tagsNode);
|
|
for (uint32_t i = 0; i < tagsCount; i++) {
|
|
plist_t tagNode = plist_array_get_item(tagsNode, i);
|
|
if (!tagNode || plist_get_node_type(tagNode) != PLIST_STRING) {
|
|
continue;
|
|
}
|
|
char *tagC = NULL;
|
|
plist_get_string_val(tagNode, &tagC);
|
|
if (!tagC) {
|
|
continue;
|
|
}
|
|
BOOL isHidden = (strcmp(tagC, "hidden") == 0 || strcmp(tagC, "hidden-system-app") == 0);
|
|
free(tagC);
|
|
if (isHidden) {
|
|
return YES;
|
|
}
|
|
}
|
|
return NO;
|
|
}
|
|
|
|
static BOOL isHiddenSystemApp(plist_t app)
|
|
{
|
|
plist_t typeNode = plist_dict_get_item(app, "ApplicationType");
|
|
BOOL isSystemType = NO;
|
|
if (typeNode && plist_get_node_type(typeNode) == PLIST_STRING) {
|
|
char *typeC = NULL;
|
|
plist_get_string_val(typeNode, &typeC);
|
|
if (typeC) {
|
|
if (strcmp(typeC, "System") == 0 || strcmp(typeC, "HiddenSystemApp") == 0) {
|
|
isSystemType = YES;
|
|
}
|
|
free(typeC);
|
|
}
|
|
}
|
|
|
|
if (!isSystemType) {
|
|
return NO;
|
|
}
|
|
|
|
plist_t hiddenNode = plist_dict_get_item(app, "IsHidden");
|
|
if (hiddenNode && plist_get_node_type(hiddenNode) == PLIST_BOOLEAN) {
|
|
uint8_t hidden = 0;
|
|
plist_get_bool_val(hiddenNode, &hidden);
|
|
if (hidden) {
|
|
return YES;
|
|
}
|
|
}
|
|
|
|
plist_t tagsNode = plist_dict_get_item(app, "SBAppTags");
|
|
if (nodeContainsHiddenTag(tagsNode)) {
|
|
return YES;
|
|
}
|
|
|
|
return NO;
|
|
}
|
|
|
|
static NSDictionary<NSString*, NSString*> *buildAppDictionary(void *apps,
|
|
size_t count,
|
|
BOOL requireGetTaskAllow,
|
|
BOOL (^filter)(plist_t app))
|
|
{
|
|
NSMutableDictionary<NSString*, NSString*> *result = [NSMutableDictionary dictionaryWithCapacity:count];
|
|
|
|
for (size_t i = 0; i < count; i++) {
|
|
plist_t app = ((plist_t *)apps)[i];
|
|
plist_t ent = plist_dict_get_item(app, "Entitlements");
|
|
|
|
if (requireGetTaskAllow) {
|
|
if (!ent) continue;
|
|
plist_t tnode = plist_dict_get_item(ent, "get-task-allow");
|
|
if (!tnode) continue;
|
|
|
|
uint8_t isAllowed = 0;
|
|
plist_get_bool_val(tnode, &isAllowed);
|
|
if (!isAllowed) continue;
|
|
}
|
|
|
|
if (filter && !filter(app)) {
|
|
continue;
|
|
}
|
|
|
|
plist_t bidNode = plist_dict_get_item(app, "CFBundleIdentifier");
|
|
if (!bidNode) continue;
|
|
|
|
char *bidC = NULL;
|
|
plist_get_string_val(bidNode, &bidC);
|
|
if (!bidC || bidC[0] == '\0') {
|
|
plist_mem_free(bidC);
|
|
continue;
|
|
}
|
|
|
|
NSString *bundleID = [NSString stringWithUTF8String:bidC];
|
|
plist_mem_free(bidC);
|
|
|
|
result[bundleID] = extractAppName(app);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
static NSArray<NSDictionary*>* getSideloadedApps(IdeviceProviderHandle *provider,
|
|
NSString **error) {
|
|
InstallationProxyClientHandle *client = NULL;
|
|
IdeviceFfiError* err = installation_proxy_connect(provider, &client);
|
|
if (err) {
|
|
*error = [NSString stringWithFormat:@"Failed to connect to installation proxy: %s", err->message];
|
|
idevice_error_free(err);
|
|
return nil;
|
|
}
|
|
|
|
plist_t *apps = NULL;
|
|
size_t count = 0;
|
|
err = installation_proxy_get_apps(client, NULL, NULL, 0, (void*)&apps, &count);
|
|
if (err) {
|
|
*error = [NSString stringWithFormat:@"Failed to get apps: %s", err->message];
|
|
idevice_error_free(err);
|
|
installation_proxy_client_free(client);
|
|
return nil;
|
|
}
|
|
|
|
NSMutableArray<NSDictionary*>* result = [NSMutableArray new];
|
|
|
|
for (size_t i = 0; i < count; i++) {
|
|
plist_t app = ((plist_t *)apps)[i];
|
|
|
|
plist_t profileValidatedNode = 0;
|
|
if(!(profileValidatedNode = plist_dict_get_item(app, "ProfileValidated"))) {
|
|
continue;
|
|
}
|
|
|
|
char* bin = 0;
|
|
uint32_t size = 0;
|
|
plist_to_bin(app, &bin, &size);
|
|
if(!bin || size == 0) {
|
|
continue;
|
|
}
|
|
|
|
NSData* d = [NSData dataWithBytes:bin length:size];
|
|
NSError* err;
|
|
NSDictionary* dict = [NSPropertyListSerialization propertyListWithData:d options:0 format:nil error:&err];
|
|
plist_mem_free(bin);
|
|
|
|
if(err) {
|
|
continue;
|
|
}
|
|
|
|
[result addObject:dict];
|
|
|
|
}
|
|
|
|
installation_proxy_client_free(client);
|
|
for(int i = 0; i < count; ++i) {
|
|
plist_free(apps[i]);
|
|
}
|
|
idevice_data_free((uint8_t *)apps, sizeof(plist_t)*count);
|
|
|
|
return result;
|
|
}
|
|
|
|
static NSDictionary<NSString*, NSString*> *performAppQuery(IdeviceProviderHandle *provider,
|
|
BOOL requireGetTaskAllow,
|
|
NSString **error,
|
|
BOOL (^filter)(plist_t app))
|
|
{
|
|
InstallationProxyClientHandle *client = NULL;
|
|
IdeviceFfiError* err = installation_proxy_connect(provider, &client);
|
|
if (err) {
|
|
*error = [NSString stringWithFormat:@"Failed to connect to installation proxy: %s", err->message];
|
|
idevice_error_free(err);
|
|
return nil;
|
|
}
|
|
|
|
plist_t *apps = NULL;
|
|
size_t count = 0;
|
|
err = installation_proxy_get_apps(client, NULL, NULL, 0, (void*)&apps, &count);
|
|
if (err) {
|
|
*error = [NSString stringWithFormat:@"Failed to get apps: %s", err->message];
|
|
idevice_error_free(err);
|
|
installation_proxy_client_free(client);
|
|
return nil;
|
|
}
|
|
|
|
NSDictionary<NSString*, NSString*> *result = buildAppDictionary(apps, count, requireGetTaskAllow, filter);
|
|
installation_proxy_client_free(client);
|
|
for(int i = 0; i < count; ++i) {
|
|
plist_free(apps[i]);
|
|
}
|
|
idevice_data_free((uint8_t *)apps, sizeof(plist_t)*count);
|
|
return result;
|
|
}
|
|
|
|
NSDictionary<NSString*, NSString*>* list_installed_apps(IdeviceProviderHandle* provider, NSString** error) {
|
|
return performAppQuery(provider, YES, error, nil);
|
|
}
|
|
|
|
NSDictionary<NSString*, NSString*>* list_all_apps(IdeviceProviderHandle* provider, NSString** error) {
|
|
return performAppQuery(provider, NO, error, nil);
|
|
}
|
|
|
|
NSDictionary<NSString*, NSString*>* list_hidden_system_apps(IdeviceProviderHandle* provider, NSString** error) {
|
|
return performAppQuery(provider, NO, error, ^BOOL(plist_t app) {
|
|
return isHiddenSystemApp(app);
|
|
});
|
|
}
|
|
|
|
UIImage* getAppIcon(IdeviceProviderHandle* provider, NSString* bundleID, NSString** error) {
|
|
SpringBoardServicesClientHandle *client = NULL;
|
|
IdeviceFfiError *err = springboard_services_connect(provider, &client);
|
|
if (err) {
|
|
*error = [NSString stringWithUTF8String:err->message ?: "Failed to connect to SpringBoard Services"];
|
|
idevice_error_free(err);
|
|
return nil;
|
|
}
|
|
|
|
void *pngData = NULL;
|
|
size_t dataLen = 0;
|
|
err = springboard_services_get_icon(client, [bundleID UTF8String], &pngData, &dataLen);
|
|
if (err) {
|
|
*error = [NSString stringWithUTF8String:err->message ?: "Failed to get app icon"];
|
|
idevice_error_free(err);
|
|
springboard_services_free(client);
|
|
return nil;
|
|
}
|
|
|
|
NSData *data = [NSData dataWithBytes:pngData length:dataLen];
|
|
free(pngData);
|
|
UIImage *icon = [UIImage imageWithData:data];
|
|
|
|
springboard_services_free(client);
|
|
return icon;
|
|
}
|
|
|
|
@implementation JITEnableContext(App)
|
|
|
|
- (NSDictionary<NSString*, NSString*>*)getAppListWithError:(NSError**)error {
|
|
[self ensureHeartbeatWithError:error];
|
|
if(*error) {
|
|
return nil;
|
|
}
|
|
|
|
NSString* errorStr = nil;
|
|
NSDictionary<NSString*, NSString*>* apps = list_installed_apps(provider, &errorStr);
|
|
if (errorStr) {
|
|
*error = [self errorWithStr:errorStr code:-17];
|
|
return nil;
|
|
}
|
|
return apps;
|
|
}
|
|
|
|
- (NSDictionary<NSString*, NSString*>*)getAllAppsWithError:(NSError**)error {
|
|
[self ensureHeartbeatWithError:error];
|
|
if(*error) {
|
|
return nil;
|
|
}
|
|
|
|
NSString* errorStr = nil;
|
|
NSDictionary<NSString*, NSString*>* apps = list_all_apps(provider, &errorStr);
|
|
if (errorStr) {
|
|
*error = [self errorWithStr:errorStr code:-17];
|
|
return nil;
|
|
}
|
|
return apps;
|
|
}
|
|
|
|
- (NSDictionary<NSString*, NSString*>*)getHiddenSystemAppsWithError:(NSError**)error {
|
|
[self ensureHeartbeatWithError:error];
|
|
if(*error) {
|
|
return nil;
|
|
}
|
|
|
|
NSString* errorStr = nil;
|
|
NSDictionary<NSString*, NSString*>* apps = list_hidden_system_apps(provider, &errorStr);
|
|
if (errorStr) {
|
|
*error = [self errorWithStr:errorStr code:-17];
|
|
return nil;
|
|
}
|
|
return apps;
|
|
}
|
|
|
|
- (NSArray<NSDictionary*>*)getSideloadedAppsWithError:(NSError**)error {
|
|
[self ensureHeartbeatWithError:error];
|
|
if(*error) {
|
|
return nil;
|
|
}
|
|
|
|
NSString* errorStr = nil;
|
|
NSArray<NSDictionary*>* apps = getSideloadedApps(provider, &errorStr);
|
|
if (errorStr) {
|
|
*error = [self errorWithStr:errorStr code:-17];
|
|
return nil;
|
|
}
|
|
return apps;
|
|
}
|
|
|
|
- (UIImage*)getAppIconWithBundleId:(NSString*)bundleId error:(NSError**)error {
|
|
[self ensureHeartbeatWithError:error];
|
|
if(*error) {
|
|
return nil;
|
|
}
|
|
|
|
NSString* errorStr = nil;
|
|
UIImage* icon = getAppIcon(provider, bundleId, &errorStr);
|
|
if (errorStr) {
|
|
*error = [self errorWithStr:errorStr code:-17];
|
|
return nil;
|
|
}
|
|
return icon;
|
|
}
|
|
|
|
@end
|