From 55701cf670d9a27d136eb9e3cd55699d2ffb9859 Mon Sep 17 00:00:00 2001 From: Ivan Hernandez Date: Mon, 27 Jun 2022 14:50:59 -0400 Subject: [PATCH 1/7] Add a command to check whether a device has enabled developer mode. Developer mode was introduced in iOS 16. When checking devices on older versions the command will print an unsupported error. --- src/ios-deploy/ios-deploy.m | 39 +++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/ios-deploy/ios-deploy.m b/src/ios-deploy/ios-deploy.m index 7c281ee7..ea1ddcab 100644 --- a/src/ios-deploy/ios-deploy.m +++ b/src/ios-deploy/ios-deploy.m @@ -91,6 +91,7 @@ mach_error_t AMDeviceLookupApplications(AMDeviceRef device, CFDictionaryRef options, CFDictionaryRef *result); int AMDeviceGetInterfaceType(AMDeviceRef device); AMDeviceRef AMDeviceCopyPairedCompanion(AMDeviceRef device); +bool AMDeviceCopyDeveloperModeStatus(AMDeviceRef device, unsigned int *arg1); int AMDServiceConnectionSend(ServiceConnRef con, const void * data, size_t size); int AMDServiceConnectionReceive(ServiceConnRef con, void * data, size_t size); @@ -2289,6 +2290,32 @@ void uninstall_app(AMDeviceRef device) { } } +void check_developer_mode(AMDeviceRef device) { + unsigned int error_code = 0; + bool is_enabled = AMDeviceCopyDeveloperModeStatus(device, &error_code); + + if (error_code) { + const char *mobdev_error = get_error_message(error_code); + NSString *error_description = mobdev_error ? [NSString stringWithUTF8String:mobdev_error] : @"unknown."; + if (_json_output) { + NSLogJSON(@{ + @"Event": @"DeveloperMode", + @"IsEnabled": @(is_enabled), + @"Code": @(error_code), + @"Status": error_description, + }); + } else { + on_error(@"Encountered error checking developer mode status: %@", error_description); + } + } else { + if (_json_output) { + NSLogJSON(@{@"Event": @"DeveloperMode", @"IsEnabled": @(is_enabled)}); + } else { + on_error(@"Developer mode is%s enabled.", is_enabled ? "" : " not"); + } + } +} + void start_symbols_service_with_command(AMDeviceRef device, uint32_t command) { connect_and_start_session(device); check_error(AMDeviceSecureStartService(device, symbols_service_name, @@ -2608,7 +2635,9 @@ void handle_device(AMDeviceRef device) { uninstall_provisioning_profile(device); } else if (strcmp("download_profile", command) == 0) { download_provisioning_profile(device); - } + } else if (strcmp("check_developer_mode", command) == 0) { + check_developer_mode(device); + } exit(0); } @@ -2874,7 +2903,8 @@ void usage(const char* app) { @" --profile-uuid the UUID of the provisioning profile to target, use with other profile commands\n" @" --profile-download download a provisioning profile (requires --profile-uuid)\n" @" --profile-install install a provisioning profile\n" - @" --profile-uninstall uninstall a provisioning profile (requires --profile-uuid )\n", + @" --profile-uninstall uninstall a provisioning profile (requires --profile-uuid )\n" + @" --check-developer-mode checks whether the given device has developer mode enabled\n", [NSString stringWithUTF8String:app]); } @@ -2940,6 +2970,7 @@ int main(int argc, char *argv[]) { { "profile-uninstall", no_argument, NULL, 1005}, { "profile-download", required_argument, NULL, 1006}, { "profile-uuid", required_argument, NULL, 1007}, + { "check-developer-mode", no_argument, NULL, 1008}, { NULL, 0, NULL, 0 }, }; int ch; @@ -3115,6 +3146,10 @@ int main(int argc, char *argv[]) { case 1007: profile_uuid = optarg; break; + case 1008: + command_only = true; + command = "check_developer_mode"; + break; case 'P': command_only = true; command = "list_profiles"; From b1ef4050d416f58979b269695c18e3132d250d64 Mon Sep 17 00:00:00 2001 From: Ivan Hernandez Date: Tue, 28 Jun 2022 11:32:40 -0400 Subject: [PATCH 2/7] Update README.md usage to current usage and correct some on_error statements to NSLogOut statements. --- README.md | 24 +++++++++++++++++------- src/ios-deploy/ios-deploy.m | 4 ++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 592d6b04..730ec6c0 100644 --- a/README.md +++ b/README.md @@ -66,8 +66,8 @@ python -m py_compile src/scripts/*.py && xcodebuild -target ios-deploy && xcodeb -m, --noinstall directly start debugging without app install (-d not required) -A, --app_deltas incremental install. must specify a directory to store app deltas to determine what needs to be installed -p, --port port used for device, default: dynamic - -r, --uninstall uninstall the app before install (do not use with -m; app cache and data are cleared) - -9, --uninstall_only uninstall the app ONLY. Use only with -1 + -r, --uninstall uninstall the app before install (do not use with -m; app cache and data are cleared) + -9, --uninstall_only uninstall the app ONLY. Use only with -1 -1, --bundle_id specify bundle id for list and upload -l, --list[=] list all app files or the specified directory -o, --upload upload file @@ -76,18 +76,28 @@ python -m py_compile src/scripts/*.py && xcodebuild -target ios-deploy && xcodeb -D, --mkdir make directory on device -R, --rm remove file or directory on device (directories must be empty) -X, --rmtree remove directory and all contained files recursively on device - -V, --version print the executable version - -e, --exists check if the app with given bundle_id is installed or not - -B, --list_bundle_id list bundle_id + -V, --version print the executable version + -e, --exists check if the app with given bundle_id is installed or not + -B, --list_bundle_id list bundle_id -W, --no-wifi ignore wifi devices - -C, --get_battery_level get battery current capacity + -C, --get_battery_level get battery current capacity -O, --output write stdout to this file -E, --error_output write stderr to this file --detect_deadlocks start printing backtraces for all threads periodically after specific amount of seconds -f, --file_system specify file system for mkdir / list / upload / download / rm - -k, --key keys for the properties of the bundle. Joined by ',' and used only with -B and -j -F, --non-recursively specify non-recursively walk directory + -S, --symbols download OS symbols. must specify a directory to store the downloaded symbols -j, --json format output as JSON + -k, --key keys for the properties of the bundle. Joined by ',' and used only with -B and -j + --custom-script