12
12
#include < signal.h>
13
13
#include < getopt.h>
14
14
#include < pwd.h>
15
+ #include < dlfcn.h>
16
+
15
17
#include < netinet/in.h>
16
18
#include < netinet/tcp.h>
17
19
75
77
mach_error_t AMDeviceSecureStartService (AMDeviceRef device, CFStringRef service_name, unsigned int *unknown, ServiceConnRef * handle);
76
78
mach_error_t AMDeviceCreateHouseArrestService (AMDeviceRef device, CFStringRef identifier, CFDictionaryRef options, AFCConnectionRef * handle);
77
79
CFSocketNativeHandle AMDServiceConnectionGetSocket (ServiceConnRef con);
80
+ void AMDServiceConnectionInvalidate (ServiceConnRef con);
81
+
82
+ bool AMDeviceIsAtLeastVersionOnPlatform (AMDeviceRef device, CFDictionaryRef vers);
78
83
int AMDeviceSecureTransferPath (int zero, AMDeviceRef device, CFURLRef url, CFDictionaryRef options, void *callback, int cbarg);
79
84
int AMDeviceSecureInstallApplication (int zero, AMDeviceRef device, CFURLRef url, CFDictionaryRef options, void *callback, int cbarg);
80
85
int AMDeviceSecureInstallApplicationBundle (AMDeviceRef device, CFURLRef url, CFDictionaryRef options, void *callback, int cbarg);
81
86
int AMDeviceMountImage (AMDeviceRef device, CFStringRef image, CFDictionaryRef options, void *callback, int cbarg);
82
87
mach_error_t AMDeviceLookupApplications (AMDeviceRef device, CFDictionaryRef options, CFDictionaryRef *result);
83
88
int AMDeviceGetInterfaceType (AMDeviceRef device);
84
89
90
+ int AMDServiceConnectionSend (ServiceConnRef con, const void * data, size_t size);
91
+ int AMDServiceConnectionReceive (ServiceConnRef con, void * data, size_t size);
92
+
85
93
bool found_device = false , debug = false , verbose = false , unbuffered = false , nostart = false , debugserver_only = false , detect_only = false , install = true , uninstall = false , no_wifi = false ;
86
94
bool command_only = false ;
87
95
char *command = NULL ;
104
112
NSMutableArray *_file_meta_info = nil ;
105
113
int port = 0 ; // 0 means "dynamically assigned"
106
114
CFStringRef last_path = NULL ;
107
- service_conn_t gdbfd ;
115
+ ServiceConnRef dbgServiceConnection = NULL ;
108
116
pid_t parent = 0 ;
109
117
// PID of child process running lldb
110
118
pid_t child = 0 ;
135
143
} \
136
144
} while (false );
137
145
146
+
147
+ void disable_ssl (ServiceConnRef con)
148
+ {
149
+ // MobileDevice links with SSL, so function will be available;
150
+ typedef void (*SSL_free_t)(void *);
151
+ static SSL_free_t SSL_free = NULL ;
152
+ if (SSL_free == NULL )
153
+ {
154
+ SSL_free = (SSL_free_t)dlsym (RTLD_DEFAULT, " SSL_free" );
155
+ }
156
+
157
+ SSL_free (con->sslContext );
158
+ con->sslContext = NULL ;
159
+ }
160
+
161
+
138
162
void on_error (NSString * format, ...)
139
163
{
140
164
va_list valist;
@@ -959,13 +983,24 @@ void write_lldb_prep_cmds(AMDeviceRef device, CFURLRef disk_app_url) {
959
983
void
960
984
server_callback (CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef address, const void *data, void *info)
961
985
{
962
- if (CFDataGetLength (data) == 0 ) {
986
+ char buffer[0x1000 ];
987
+ int bytesRead = AMDServiceConnectionReceive (dbgServiceConnection, buffer, sizeof (buffer));
988
+ if (bytesRead == 0 )
989
+ {
963
990
// close the socket on which we've got end-of-file, the server_socket.
964
991
CFSocketInvalidate (s);
965
992
CFRelease (s);
966
993
return ;
967
994
}
968
- write (CFSocketGetNative (lldb_socket), CFDataGetBytePtr (data), CFDataGetLength (data));
995
+ write (CFSocketGetNative (lldb_socket), buffer, bytesRead);
996
+ while (bytesRead == sizeof (buffer))
997
+ {
998
+ bytesRead = AMDServiceConnectionReceive (dbgServiceConnection, buffer, sizeof (buffer));
999
+ if (bytesRead > 0 )
1000
+ {
1001
+ write (CFSocketGetNative (lldb_socket), buffer, bytesRead);
1002
+ }
1003
+ }
969
1004
}
970
1005
971
1006
void lldb_callback (CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef address, const void *data, void *info)
@@ -978,7 +1013,8 @@ void lldb_callback(CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef a
978
1013
CFRelease (s);
979
1014
return ;
980
1015
}
981
- write (gdbfd, CFDataGetBytePtr (data), CFDataGetLength (data));
1016
+ int sent = AMDServiceConnectionSend (dbgServiceConnection, CFDataGetBytePtr (data), CFDataGetLength (data));
1017
+ assert (CFDataGetLength (data) == sent);
982
1018
}
983
1019
984
1020
void fdvendor_callback (CFSocketRef s, CFSocketCallBackType callbackType, CFDataRef address, const void *data, void *info) {
@@ -1012,8 +1048,19 @@ void connect_and_start_session(AMDeviceRef device) {
1012
1048
1013
1049
void start_remote_debug_server (AMDeviceRef device) {
1014
1050
1015
- ServiceConnRef con = NULL ;
1016
- int start_err = AMDeviceSecureStartService (device, CFSTR (" com.apple.debugserver" ), NULL , &con);
1051
+ dbgServiceConnection = NULL ;
1052
+ CFStringRef serviceName = CFSTR (" com.apple.debugserver" );
1053
+ CFStringRef keys[] = { CFSTR (" MinIPhoneVersion" ), CFSTR (" MinAppleTVVersion" ) };
1054
+ CFStringRef values[] = { CFSTR (" 14.0" ), CFSTR (" 14.0" )};
1055
+ CFDictionaryRef version = CFDictionaryCreate (NULL , (const void **)&keys, (const void **)&values, 2 , &kCFTypeDictionaryKeyCallBacks , &kCFTypeDictionaryValueCallBacks );
1056
+
1057
+ bool useSecureProxy = AMDeviceIsAtLeastVersionOnPlatform (device, version);
1058
+ if (useSecureProxy)
1059
+ {
1060
+ serviceName = CFSTR (" com.apple.debugserver.DVTSecureSocketProxy" );
1061
+ }
1062
+
1063
+ int start_err = AMDeviceSecureStartService (device, serviceName, NULL , &dbgServiceConnection);
1017
1064
if (start_err != 0 )
1018
1065
{
1019
1066
// After we mount the image, iOS needs to scan the image to register new services.
@@ -1037,15 +1084,20 @@ void start_remote_debug_server(AMDeviceRef device) {
1037
1084
default :
1038
1085
check_error (start_err);
1039
1086
}
1040
- check_error (AMDeviceSecureStartService (device, CFSTR (" com.apple.debugserver" ), NULL , &con));
1087
+ check_error (AMDeviceSecureStartService (device, serviceName, NULL , &dbgServiceConnection));
1088
+ }
1089
+ assert (dbgServiceConnection != NULL );
1090
+
1091
+ if (!useSecureProxy)
1092
+ {
1093
+ disable_ssl (dbgServiceConnection);
1041
1094
}
1042
- assert (con != NULL );
1043
- gdbfd = AMDServiceConnectionGetSocket (con);
1095
+
1044
1096
/*
1045
1097
* The debugserver connection is through a fd handle, while lldb requires a host/port to connect, so create an intermediate
1046
1098
* socket to transfer data.
1047
1099
*/
1048
- server_socket = CFSocketCreateWithNative (NULL , gdbfd, kCFSocketDataCallBack , &server_callback, NULL );
1100
+ server_socket = CFSocketCreateWithNative (NULL , AMDServiceConnectionGetSocket (dbgServiceConnection), kCFSocketReadCallBack , &server_callback, NULL );
1049
1101
if (server_socket_runloop) {
1050
1102
CFRelease (server_socket_runloop);
1051
1103
}
@@ -2007,7 +2059,7 @@ void handle_device(AMDeviceRef device) {
2007
2059
CFStringRef values[] = { CFSTR (" Developer" ) };
2008
2060
options = CFDictionaryCreate (NULL , (const void **)&keys, (const void **)&values, 1 , &kCFTypeDictionaryKeyCallBacks , &kCFTypeDictionaryValueCallBacks );
2009
2061
check_error (AMDeviceSecureTransferPath (0 , device, url, options, transfer_callback, 0 ));
2010
- close (* afcFd);
2062
+ AMDServiceConnectionInvalidate ( afcFd);
2011
2063
2012
2064
connect_and_start_session (device);
2013
2065
check_error (AMDeviceSecureInstallApplication (0 , device, url, options, install_callback, 0 ));
0 commit comments