30
30
* log enable -v -f /Users/vargaz/gdb-remote.log gdb-remote all
31
31
*/
32
32
#define LLDB_PREP_CMDS CFSTR (" \
33
- platform select remote-ios --sysroot '{symbols_path}'\n \
33
+ platform select remote-'{platform}' --sysroot '{symbols_path}'\n \
34
34
target create \" {disk_app}\"\n \
35
35
script fruitstrap_device_app=\" {device_app}\"\n \
36
36
script fruitstrap_connect_url=\" connect://127.0.0.1:{device_port}\"\n \
88
88
int AMDeviceMountImage (AMDeviceRef device, CFStringRef image, CFDictionaryRef options, void *callback, int cbarg);
89
89
mach_error_t AMDeviceLookupApplications (AMDeviceRef device, CFDictionaryRef options, CFDictionaryRef *result);
90
90
int AMDeviceGetInterfaceType (AMDeviceRef device);
91
+ AMDeviceRef AMDeviceCopyPairedCompanion (AMDeviceRef device);
91
92
92
93
int AMDServiceConnectionSend (ServiceConnRef con, const void * data, size_t size);
93
94
int AMDServiceConnectionReceive (ServiceConnRef con, void * data, size_t size);
@@ -430,7 +431,7 @@ CFStringRef get_device_full_name(const AMDeviceRef device) {
430
431
CFRelease (device_name);
431
432
if (model != NULL )
432
433
CFRelease (model);
433
- if (model_name != NULL )
434
+ if (model_name != NULL && model_name != model )
434
435
CFRelease (model_name);
435
436
if (product_version)
436
437
CFRelease (product_version);
@@ -483,13 +484,33 @@ CFStringRef get_device_full_name(const AMDeviceRef device) {
483
484
return CFAutorelease (json_dict);
484
485
}
485
486
487
+ int get_companion_interface_type (AMDeviceRef device)
488
+ {
489
+ assert (AMDeviceGetInterfaceType (device) == 3 );
490
+ AMDeviceRef companion = AMDeviceCopyPairedCompanion (device);
491
+ int type = AMDeviceGetInterfaceType (companion);
492
+ AMDeviceRelease (companion);
493
+ return type;
494
+ }
495
+
486
496
CFStringRef get_device_interface_name (const AMDeviceRef device) {
487
- // AMDeviceGetInterfaceType(device) 0=Unknown, 1 = Direct/USB, 2 = Indirect/WIFI
497
+ // AMDeviceGetInterfaceType(device) 0=Unknown, 1 = Direct/USB, 2 = Indirect/WIFI, 3 = Companion proxy
488
498
switch (AMDeviceGetInterfaceType (device)) {
489
499
case 1 :
490
500
return CFSTR (" USB" );
491
501
case 2 :
492
502
return CFSTR (" WIFI" );
503
+ case 3 :
504
+ {
505
+ if (get_companion_interface_type (device) == 1 )
506
+ {
507
+ return CFSTR (" USB Companion proxy" );
508
+ }
509
+ else
510
+ {
511
+ return CFSTR (" WIFI Companion proxy" );
512
+ }
513
+ }
493
514
default :
494
515
return CFSTR (" Unknown Connection" );
495
516
}
@@ -512,6 +533,7 @@ CFStringRef copy_device_support_path(AMDeviceRef device, CFStringRef suffix) {
512
533
CFStringRef build = AMDeviceCopyValue (device, 0 , CFSTR (" BuildVersion" ));
513
534
CFStringRef deviceClass = AMDeviceCopyValue (device, 0 , CFSTR (" DeviceClass" ));
514
535
CFStringRef deviceModel = AMDeviceCopyValue (device, 0 , CFSTR (" HardwareModel" ));
536
+ CFStringRef productType = AMDeviceCopyValue (device, 0 , CFSTR (" ProductType" ));
515
537
CFStringRef deviceArch = NULL ;
516
538
CFStringRef path = NULL ;
517
539
@@ -531,7 +553,12 @@ CFStringRef copy_device_support_path(AMDeviceRef device, CFStringRef suffix) {
531
553
if (CFStringCompare (CFSTR (" AppleTV" ), deviceClass, 0 ) == kCFCompareEqualTo ) {
532
554
deviceClassPath[0 ] = CFSTR (" Platforms/AppleTVOS.platform/DeviceSupport" );
533
555
deviceClassPath[1 ] = CFSTR (" tvOS DeviceSupport" );
534
- } else {
556
+ }
557
+ else if (CFStringCompare (CFSTR (" Watch" ), deviceClass, 0 ) == kCFCompareEqualTo ) {
558
+ deviceClassPath[0 ] = CFSTR (" Platforms/WatchOS.platform/DeviceSupport" );
559
+ deviceClassPath[1 ] = CFSTR (" watchOS DeviceSupport" );
560
+ }
561
+ else {
535
562
deviceClassPath[0 ] = CFSTR (" Platforms/iPhoneOS.platform/DeviceSupport" );
536
563
deviceClassPath[1 ] = CFSTR (" iOS DeviceSupport" );
537
564
}
@@ -569,6 +596,11 @@ CFStringRef copy_device_support_path(AMDeviceRef device, CFStringRef suffix) {
569
596
path = copy_xcode_path_for (deviceClassPath[i], search);
570
597
CFRelease (search);
571
598
}
599
+ if (path == NULL ) {
600
+ CFStringRef search = CFStringCreateWithFormat (NULL , NULL , CFSTR (" %@ %@ (%@)/%@" ), productType, version, build, suffix);
601
+ path = copy_xcode_path_for (deviceClassPath[i], search);
602
+ CFRelease (search);
603
+ }
572
604
}
573
605
574
606
CFRelease (version);
@@ -589,6 +621,7 @@ CFStringRef copy_device_support_path(AMDeviceRef device, CFStringRef suffix) {
589
621
CFRelease (version_parts);
590
622
CFRelease (build);
591
623
CFRelease (deviceClass);
624
+ CFRelease (productType);
592
625
if (deviceModel != NULL ) {
593
626
CFRelease (deviceModel);
594
627
}
@@ -823,11 +856,31 @@ CFStringRef copy_modules_search_paths_pairs(CFStringRef symbols_path, CFStringRe
823
856
return res;
824
857
}
825
858
859
+ CFStringRef get_device_platform (AMDeviceRef device)
860
+ {
861
+ CFStringRef deviceClass = AMDeviceCopyValue (device, 0 , CFSTR (" DeviceClass" ));
862
+ CFStringRef platform;
863
+ if (CFStringCompare (CFSTR (" AppleTV" ), deviceClass, 0 ) == kCFCompareEqualTo ) {
864
+ platform = CFSTR (" tvos" );
865
+ }
866
+ else if (CFStringCompare (CFSTR (" Watch" ), deviceClass, 0 ) == kCFCompareEqualTo ) {
867
+ platform = CFSTR (" watchos" );
868
+ }
869
+ else {
870
+ platform = CFSTR (" ios" );
871
+ }
872
+ CFRelease (deviceClass);
873
+ return platform;
874
+ }
875
+
826
876
void write_lldb_prep_cmds (AMDeviceRef device, CFURLRef disk_app_url) {
827
877
CFStringRef symbols_path = copy_device_support_path (device, CFSTR (" Symbols" ));
828
878
CFMutableStringRef cmds = CFStringCreateMutableCopy (NULL , 0 , LLDB_PREP_CMDS);
829
879
CFRange range = { 0 , CFStringGetLength (cmds) };
830
880
881
+ CFStringFindAndReplace (cmds, CFSTR (" {platform}" ), get_device_platform (device), range, 0 );
882
+ range.length = CFStringGetLength (cmds);
883
+
831
884
CFStringFindAndReplace (cmds, CFSTR (" {symbols_path}" ), symbols_path, range, 0 );
832
885
range.length = CFStringGetLength (cmds);
833
886
@@ -1088,9 +1141,9 @@ void start_remote_debug_server(AMDeviceRef device) {
1088
1141
1089
1142
dbgServiceConnection = NULL ;
1090
1143
CFStringRef serviceName = CFSTR (" com.apple.debugserver" );
1091
- CFStringRef keys[] = { CFSTR (" MinIPhoneVersion" ), CFSTR (" MinAppleTVVersion" ) };
1092
- CFStringRef values[] = { CFSTR (" 14.0" ), CFSTR (" 14.0" )};
1093
- CFDictionaryRef version = CFDictionaryCreate (NULL , (const void **)&keys, (const void **)&values, 2 , &kCFTypeDictionaryKeyCallBacks , &kCFTypeDictionaryValueCallBacks );
1144
+ CFStringRef keys[] = { CFSTR (" MinIPhoneVersion" ), CFSTR (" MinAppleTVVersion" ), CFSTR ( " MinWatchVersion " ) };
1145
+ CFStringRef values[] = { CFSTR (" 14.0" ), CFSTR (" 14.0" ), CFSTR ( " 7.0 " ) }; // Not sure about older watchOS versions
1146
+ CFDictionaryRef version = CFDictionaryCreate (NULL , (const void **)&keys, (const void **)&values, 3 , &kCFTypeDictionaryKeyCallBacks , &kCFTypeDictionaryValueCallBacks );
1094
1147
1095
1148
bool useSecureProxy = AMDeviceIsAtLeastVersionOnPlatform (device, version);
1096
1149
if (useSecureProxy)
@@ -2003,6 +2056,11 @@ void handle_device(AMDeviceRef device) {
2003
2056
found_device = true ;
2004
2057
return ;
2005
2058
}
2059
+ if (found_device)
2060
+ {
2061
+ NSLogOut (@" Skipping %@ ." , device_full_name);
2062
+ return ;
2063
+ }
2006
2064
CFStringRef found_device_id = CFAutorelease (AMDeviceCopyDeviceIdentifier (device));
2007
2065
if (device_id != NULL ) {
2008
2066
CFStringRef deviceCFSTR = CFAutorelease (CFStringCreateWithCString (NULL , device_id, kCFStringEncodingUTF8 ));
@@ -2089,18 +2147,10 @@ void handle_device(AMDeviceRef device) {
2089
2147
2090
2148
CFDictionaryRef options;
2091
2149
if (app_deltas == NULL ) { // standard install
2092
- // NOTE: the secure version doesn't seem to require us to start the AFC service
2093
- ServiceConnRef afcFd;
2094
- connect_and_start_session (device);
2095
- check_error (AMDeviceSecureStartService (device, CFSTR (" com.apple.afc" ), NULL , &afcFd));
2096
- check_error (AMDeviceStopSession (device));
2097
- check_error (AMDeviceDisconnect (device));
2098
-
2099
2150
CFStringRef keys[] = { CFSTR (" PackageType" ) };
2100
2151
CFStringRef values[] = { CFSTR (" Developer" ) };
2101
2152
options = CFDictionaryCreate (NULL , (const void **)&keys, (const void **)&values, 1 , &kCFTypeDictionaryKeyCallBacks , &kCFTypeDictionaryValueCallBacks );
2102
2153
check_error (AMDeviceSecureTransferPath (0 , device, url, options, transfer_callback, 0 ));
2103
- AMDServiceConnectionInvalidate (afcFd);
2104
2154
2105
2155
connect_and_start_session (device);
2106
2156
check_error (AMDeviceSecureInstallApplication (0 , device, url, options, install_callback, 0 ));
@@ -2185,16 +2235,19 @@ void handle_device(AMDeviceRef device) {
2185
2235
void device_callback (struct am_device_notification_callback_info *info, void *arg) {
2186
2236
switch (info->msg ) {
2187
2237
case ADNCI_MSG_CONNECTED:
2188
- if (no_wifi && AMDeviceGetInterfaceType (info->dev ) == 2 )
2238
+ {
2239
+ int itype = AMDeviceGetInterfaceType (info->dev );
2240
+ if (no_wifi && (itype == 2 || ( itype == 3 && get_companion_interface_type (info->dev ) == 2 )))
2189
2241
{
2190
- NSLogVerbose (@" Skipping wifi device (type: %d )" , AMDeviceGetInterfaceType(info->dev) );
2242
+ NSLogVerbose (@" Skipping wifi device (type: %d )" , itype );
2191
2243
}
2192
2244
else
2193
2245
{
2194
- NSLogVerbose (@" Handling device type: %d " , AMDeviceGetInterfaceType(info->dev) );
2246
+ NSLogVerbose (@" Handling device type: %d " , itype );
2195
2247
handle_device (info->dev );
2196
2248
}
2197
2249
break ;
2250
+ }
2198
2251
case ADNCI_MSG_DISCONNECTED:
2199
2252
{
2200
2253
CFStringRef device_interface_name = get_device_interface_name (info->dev );
@@ -2540,6 +2593,15 @@ int main(int argc, char *argv[]) {
2540
2593
NSLogOut (@" [....] Waiting for iOS device to be connected" );
2541
2594
}
2542
2595
2543
- AMDeviceNotificationSubscribe (&device_callback, 0 , 0 , NULL , ¬ify);
2596
+
2597
+ CFStringRef keys[] = {
2598
+ CFSTR (" NotificationOptionSearchForPairedDevices" ),
2599
+ };
2600
+ const void * values[] = {
2601
+ kCFBooleanTrue ,
2602
+ };
2603
+ CFDictionaryRef options = CFDictionaryCreate (kCFAllocatorDefault , (const void **)keys, values, 1 , &kCFCopyStringDictionaryKeyCallBacks , &kCFTypeDictionaryValueCallBacks );
2604
+
2605
+ AMDeviceNotificationSubscribeWithOptions (&device_callback, 0 , 0 , NULL , ¬ify, options);
2544
2606
CFRunLoopRun ();
2545
2607
}
0 commit comments