StikDebug/StikJIT/idevice/mount.m
Stephen f3d2dec2e5
Semi-Rewrite – Major Refactor & Codebase Cleanup (#328)
* 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
2026-02-25 13:44:00 -05:00

128 lines
3.9 KiB
Objective-C

//
// mount1.m
// StikDebug
//
// Created by s s on 2025/12/6.
//
#include "mount.h"
#import "JITEnableContext.h"
#import "JITEnableContextInternal.h"
@import Foundation;
NSError* makeError(int code, NSString* msg);
size_t getMountedDeviceCount(IdeviceProviderHandle* provider, NSError** error) {
ImageMounterHandle *client = NULL;
IdeviceFfiError *err = image_mounter_connect(provider, &client);
if (err) {
*error = makeError(err->code, @(err->message));
idevice_error_free(err);
return 0;
}
plist_t *devices = NULL;
size_t deviceLength = 0;
err = image_mounter_copy_devices(client, &devices, &deviceLength);
image_mounter_free(client);
if (err) {
*error = makeError(err->code, @(err->message));
idevice_error_free(err);
return 0;
}
for (int i = 0; i < (int)deviceLength; i++) {
plist_free(devices[i]);
}
idevice_data_free((uint8_t *)devices, deviceLength * sizeof(plist_t));
return deviceLength;
}
int mountPersonalDDI(IdeviceProviderHandle* provider, IdevicePairingFile* pairingFile2, NSString* imagePath, NSString* trustcachePath, NSString* manifestPath, NSError** error) {
NSData *image = [NSData dataWithContentsOfFile:imagePath];
NSData *trustcache = [NSData dataWithContentsOfFile:trustcachePath];
NSData *buildManifest = [NSData dataWithContentsOfFile:manifestPath];
if (!image || !trustcache || !buildManifest) {
idevice_pairing_file_free(pairingFile2);
*error = makeError(1, @"Failed to read one or more files");
return 1;
}
LockdowndClientHandle *lockdownClient = NULL;
IdeviceFfiError *err = lockdownd_connect(provider, &lockdownClient);
if (err) {
*error = makeError(6, @(err->message));
idevice_pairing_file_free(pairingFile2);
idevice_error_free(err);
return 6;
}
err = lockdownd_start_session(lockdownClient, pairingFile2);
idevice_pairing_file_free(pairingFile2);
if (err) {
*error = makeError(7, @(err->message));
idevice_error_free(err);
lockdownd_client_free(lockdownClient);
return 7;
}
plist_t uniqueChipIDPlist = NULL;
err = lockdownd_get_value(lockdownClient, "UniqueChipID", NULL, &uniqueChipIDPlist);
lockdownd_client_free(lockdownClient);
if (err) {
*error = makeError(8, @(err->message));
idevice_error_free(err);
return 8;
}
uint64_t uniqueChipID = 0;
plist_get_uint_val(uniqueChipIDPlist, &uniqueChipID);
plist_free(uniqueChipIDPlist);
ImageMounterHandle *mounterClient = NULL;
err = image_mounter_connect(provider, &mounterClient);
if (err) {
*error = makeError(9, @(err->message));
idevice_error_free(err);
return 9;
}
err = image_mounter_mount_personalized(
mounterClient,
provider,
[image bytes],
[image length],
[trustcache bytes],
[trustcache length],
[buildManifest bytes],
[buildManifest length],
NULL,
uniqueChipID
);
image_mounter_free(mounterClient);
if (err) {
*error = makeError(10, @(err->message));
idevice_error_free(err);
return 10;
}
return 0;
}
@implementation JITEnableContext(DDI)
- (NSUInteger)getMountedDeviceCount:(NSError**)error {
[self ensureHeartbeatWithError:error];
if (*error) { return 0; }
return getMountedDeviceCount(provider, error);
}
- (NSInteger)mountPersonalDDIWithImagePath:(NSString*)imagePath trustcachePath:(NSString*)trustcachePath manifestPath:(NSString*)manifestPath error:(NSError**)error {
[self ensureHeartbeatWithError:error];
if (*error) { return 0; }
IdevicePairingFile *pairing = [self getPairingFileWithError:error];
if (*error) { return 0; }
return mountPersonalDDI(provider, pairing, imagePath, trustcachePath, manifestPath, error);
}
@end