@@ -78,6 +78,8 @@ struct afc_connection {
78
78
unsigned int context; /* 40 */
79
79
};
80
80
81
+ typedef struct afc_connection * AFCConnectionRef;
82
+
81
83
struct afc_dictionary {
82
84
unsigned char unknown[0 ]; /* size unknown */
83
85
};
@@ -88,18 +90,27 @@ struct afc_directory {
88
90
89
91
struct afc_file {
90
92
afc_file_ref file_ref;
91
- afc_connection* afc_conn_p;
93
+ AFCConnectionRef afc_conn_p;
92
94
};
93
95
94
96
struct ApplicationCache {
95
- afc_connection* afc_connection;
97
+ AFCConnectionRef afc_connection;
96
98
bool has_initialized_gdb;
97
99
};
98
100
101
+ typedef HANDLE service_conn_t ;
102
+ typedef service_conn_t * ServiceConnRef;
103
+ typedef struct DeviceInfo * AMDeviceRef;
104
+ struct ServiceInfo {
105
+ HANDLE socket;
106
+ ServiceConnRef connection;
107
+ int connection_id;
108
+ };
109
+
99
110
struct DeviceData {
100
111
DeviceInfo* device_info;
101
112
struct DeviceServerData * device_server_data;
102
- std::map<const char *, HANDLE > services;
113
+ std::map<const char *, ServiceInfo > services;
103
114
int sessions;
104
115
std::map<std::string, ApplicationCache> apps_cache;
105
116
@@ -122,13 +133,27 @@ struct FileUploadData {
122
133
123
134
#pragma region Dll_Type_Definitions
124
135
125
- typedef unsigned (__cdecl *device_notification_subscribe_ptr)(void (*f)(const DevicePointer*), long, long, long, HANDLE*);
126
136
127
137
#ifdef _WIN32
138
+ typedef unsigned (__cdecl *device_notification_subscribe_ptr)(void (*f)(const DevicePointer*), long, long, long, HANDLE*);
128
139
typedef void (__cdecl *run_loop_ptr)();
140
+ typedef void * CFArrayRef ;
129
141
typedef void * CFStringRef ;
130
- typedef void * CFURLRef ;
131
142
typedef void * CFDictionaryRef ;
143
+ typedef void * CFURLRef ;
144
+ typedef void * CFPropertyListFormat ;
145
+ extern CFPropertyListFormat kCFPropertyListXMLFormat_v1_0 ;
146
+ typedef void * CFSocketNativeHandle ;
147
+ typedef unsigned (__cdecl *device_secure_start_service_ptr)(AMDeviceRef device, CFStringRef service_name, unsigned int *unknown, ServiceConnRef * handle);
148
+ typedef CFSocketNativeHandle (__cdecl *service_connection_get_socket_ptr)(ServiceConnRef con);
149
+ typedef long (__cdecl *service_connection_receive_ptr)(ServiceConnRef, void *, long );
150
+ typedef long (__cdecl *service_connection_send_message_ptr)(ServiceConnRef serviceConnection, CFDictionaryRef message, CFPropertyListFormat format);
151
+
152
+ extern service_connection_send_message_ptr __AMDServiceConnectionSendMessage;
153
+ extern service_connection_receive_ptr __AMDServiceConnectionReceive;
154
+
155
+ typedef unsigned (__cdecl *device_create_house_arrest_service_ptr)(const DeviceInfo*, CFStringRef identifier, void * unknown, AFCConnectionRef * handle);
156
+
132
157
typedef void *(__cdecl *device_copy_device_identifier)(const DeviceInfo*);
133
158
typedef void *(__cdecl *device_copy_value)(const DeviceInfo*, CFStringRef , CFStringRef );
134
159
typedef unsigned (__cdecl *device_uninstall_application)(HANDLE, CFStringRef , void *, void (*f)(), void*);
@@ -141,6 +166,7 @@ typedef unsigned long(__cdecl *cf_get_concrete_type_id)();
141
166
typedef unsigned (__cdecl *cfdictionary_get_count)(CFDictionaryRef );
142
167
typedef void (__cdecl *cfdictionary_get_keys_and_values)(CFDictionaryRef , const void **, const void **);
143
168
typedef CFStringRef (__cdecl *cfstring_create_with_cstring)(void *, const char *, unsigned );
169
+ typedef CFArrayRef (__cdecl *cfarray_create)(void *, const void **, long , void **);
144
170
typedef unsigned (__cdecl *device_secure_operation_with_path)(int , const DeviceInfo*, CFURLRef , CFDictionaryRef , void (*f)(), int);
145
171
typedef unsigned (__cdecl *device_secure_operation_with_bundle_id)(int , const DeviceInfo*, CFStringRef , int , void (*f)(), int);
146
172
typedef void (__cdecl *cfrelease)(CFStringRef );
@@ -149,18 +175,18 @@ typedef CFDictionaryRef(__cdecl *cfdictionary_create)(void *, void*, void*, int,
149
175
typedef void *(__cdecl *cfurl_create_with_string)(void *, CFStringRef , void *);
150
176
151
177
typedef unsigned (__cdecl *afc_connection_open)(HANDLE, const char *, void *);
152
- typedef unsigned (__cdecl *afc_connection_close)(afc_connection* );
153
- typedef unsigned (__cdecl *afc_file_info_open)(afc_connection* , const char *, afc_dictionary**);
154
- typedef unsigned (__cdecl *afc_directory_read)(afc_connection* , afc_directory*, char **);
155
- typedef unsigned (__cdecl *afc_directory_open)(afc_connection* , const char *, afc_directory**);
156
- typedef unsigned (__cdecl *afc_directory_close)(afc_connection* , afc_directory*);
157
- typedef unsigned (__cdecl *afc_directory_create)(afc_connection* , const char *);
158
- typedef unsigned (__cdecl *afc_remove_path)(afc_connection* , const char *);
159
- typedef unsigned (__cdecl *afc_fileref_open)(afc_connection* , const char *, unsigned long long , afc_file_ref*);
160
- typedef unsigned (__cdecl *afc_fileref_read)(afc_connection* , afc_file_ref, void *, size_t *);
161
- typedef unsigned (__cdecl *afc_get_device_info_key)(afc_connection* , const char *, char **);
162
- typedef unsigned (__cdecl *afc_fileref_write)(afc_connection* , afc_file_ref, const void *, size_t );
163
- typedef unsigned (__cdecl *afc_fileref_close)(afc_connection* , afc_file_ref);
178
+ typedef unsigned (__cdecl *afc_connection_close)(AFCConnectionRef );
179
+ typedef unsigned (__cdecl *afc_file_info_open)(AFCConnectionRef , const char *, afc_dictionary**);
180
+ typedef unsigned (__cdecl *afc_directory_read)(AFCConnectionRef , afc_directory*, char **);
181
+ typedef unsigned (__cdecl *afc_directory_open)(AFCConnectionRef , const char *, afc_directory**);
182
+ typedef unsigned (__cdecl *afc_directory_close)(AFCConnectionRef , afc_directory*);
183
+ typedef unsigned (__cdecl *afc_directory_create)(AFCConnectionRef , const char *);
184
+ typedef unsigned (__cdecl *afc_remove_path)(AFCConnectionRef , const char *);
185
+ typedef unsigned (__cdecl *afc_fileref_open)(AFCConnectionRef , const char *, unsigned long long , afc_file_ref*);
186
+ typedef unsigned (__cdecl *afc_fileref_read)(AFCConnectionRef , afc_file_ref, void *, size_t *);
187
+ typedef unsigned (__cdecl *afc_get_device_info_key)(AFCConnectionRef , const char *, char **);
188
+ typedef unsigned (__cdecl *afc_fileref_write)(AFCConnectionRef , afc_file_ref, const void *, size_t );
189
+ typedef unsigned (__cdecl *afc_fileref_close)(AFCConnectionRef , afc_file_ref);
164
190
typedef unsigned (__cdecl *device_start_house_arrest)(const DeviceInfo*, CFStringRef , void *, HANDLE*, unsigned int *);
165
191
typedef unsigned (__cdecl *device_lookup_applications)(const DeviceInfo*, CFDictionaryRef , CFDictionaryRef *);
166
192
typedef int (__cdecl *usb_mux_connect_by_port)(int , int , long long *);
@@ -171,8 +197,14 @@ typedef int(__cdecl *usb_mux_connect_by_port)(int, int, long long*);
171
197
#pragma region Dll_Method_Definitions
172
198
173
199
#ifdef _WIN32
200
+ extern HINSTANCE mobile_device_dll;
174
201
#define GET_IF_EXISTS (variable, type, dll, method_name ) (variable ? variable : variable = (type)GetProcAddress(dll, method_name))
175
202
203
+ #define AMDeviceSecureStartService GET_IF_EXISTS (__AMDeviceSecureStartService, device_secure_start_service_ptr, mobile_device_dll, " AMDeviceSecureStartService" )
204
+ #define AMDServiceConnectionGetSocket GET_IF_EXISTS (__AMDServiceConnectionGetSocket, service_connection_get_socket_ptr, mobile_device_dll, " AMDServiceConnectionGetSocket" )
205
+ #define AMDServiceConnectionReceive GET_IF_EXISTS (__AMDServiceConnectionReceive, service_connection_receive_ptr, mobile_device_dll, " AMDServiceConnectionReceive" )
206
+ #define AMDServiceConnectionSendMessage GET_IF_EXISTS (__AMDServiceConnectionSendMessage, service_connection_send_message_ptr, mobile_device_dll, " AMDServiceConnectionSendMessage" )
207
+ #define AMDeviceCreateHouseArrestService GET_IF_EXISTS (__AMDeviceCreateHouseArrestService, device_create_house_arrest_service_ptr, mobile_device_dll, " AMDeviceCreateHouseArrestService" )
176
208
#define AMDeviceNotificationSubscribe GET_IF_EXISTS (__AMDeviceNotificationSubscribe, device_notification_subscribe_ptr, mobile_device_dll, " AMDeviceNotificationSubscribe" )
177
209
#define AMDeviceCopyDeviceIdentifier GET_IF_EXISTS (__AMDeviceCopyDeviceIdentifier, device_copy_device_identifier, mobile_device_dll, " AMDeviceCopyDeviceIdentifier" )
178
210
#define AMDeviceCopyValue GET_IF_EXISTS (__AMDeviceCopyValue, device_copy_value, mobile_device_dll, " AMDeviceCopyValue" )
@@ -203,6 +235,7 @@ typedef int(__cdecl *usb_mux_connect_by_port)(int, int, long long*);
203
235
#define CFDictionaryGetCount GET_IF_EXISTS (__CFDictionaryGetCount, cfdictionary_get_count, core_foundation_dll, " CFDictionaryGetCount" )
204
236
#define CFDictionaryGetKeysAndValues GET_IF_EXISTS (__CFDictionaryGetKeysAndValues, cfdictionary_get_keys_and_values, core_foundation_dll, " CFDictionaryGetKeysAndValues" )
205
237
#define CFStringCreateWithCString GET_IF_EXISTS (__CFStringCreateWithCString, cfstring_create_with_cstring, core_foundation_dll, " CFStringCreateWithCString" )
238
+ #define CFArrayCreate GET_IF_EXISTS (__CFArrayCreate, cfarray_create, core_foundation_dll, " CFArrayCreate" )
206
239
#define CFURLCreateWithString GET_IF_EXISTS (__CFURLCreateWithString, cfurl_create_with_string, core_foundation_dll, " CFURLCreateWithString" )
207
240
#define CFDictionaryCreate GET_IF_EXISTS (__CFDictionaryCreate, cfdictionary_create, core_foundation_dll, " CFDictionaryCreate" )
208
241
#define CFRelease GET_IF_EXISTS (__CFRelease, cfrelease, core_foundation_dll, " CFRelease" )
@@ -230,12 +263,17 @@ typedef int(__cdecl *usb_mux_connect_by_port)(int, int, long long*);
230
263
231
264
extern " C"
232
265
{
266
+ CFSocketNativeHandle AMDServiceConnectionGetSocket (ServiceConnRef con);
267
+ long AMDServiceConnectionReceive (ServiceConnRef, void *, long );
268
+ long AMDServiceConnectionSendMessage (ServiceConnRef serviceConnection, CFDictionaryRef message, CFPropertyListFormat format);
269
+ unsigned AMDeviceSecureStartService (AMDeviceRef device, CFStringRef service_name, unsigned int *unknown, ServiceConnRef * handle);
233
270
unsigned AMDeviceNotificationSubscribe (void (*f)(const DevicePointer*), long, long, long, HANDLE*);
234
271
CFStringRef AMDeviceCopyDeviceIdentifier (const DeviceInfo*);
235
272
CFStringRef AMDeviceCopyValue (const DeviceInfo*, CFStringRef , CFStringRef );
236
273
unsigned AMDeviceMountImage (const DeviceInfo*, CFStringRef , CFDictionaryRef , void (*f)(void *, int ), void*);
237
274
unsigned AMDeviceStartService (const DeviceInfo*, CFStringRef , HANDLE*, void *);
238
275
unsigned AMDeviceLookupApplications (const DeviceInfo*, CFDictionaryRef , CFDictionaryRef *);
276
+ unsigned AMDeviceCreateHouseArrestService (const DeviceInfo*, CFStringRef identifier, void * unknown, AFCConnectionRef * handle);
239
277
int AMDeviceGetConnectionID (const DeviceInfo*);
240
278
int AMDeviceGetInterfaceType (const DeviceInfo*);
241
279
unsigned AMDeviceUninstallApplication (HANDLE, CFStringRef , void *, void (*f)(), void*);
@@ -251,17 +289,17 @@ extern "C"
251
289
unsigned AMDeviceSecureInstallApplication (int , const DeviceInfo*, CFURLRef , CFDictionaryRef , void (*f)(), int);
252
290
unsigned AMDeviceStartHouseArrestService (const DeviceInfo*, CFStringRef , void *, HANDLE*, unsigned int *);
253
291
unsigned AFCConnectionOpen (HANDLE, const char *, void *);
254
- unsigned AFCConnectionClose (afc_connection* );
255
- unsigned AFCRemovePath (afc_connection* , const char *);
256
- unsigned AFCFileInfoOpen (afc_connection* , const char *, afc_dictionary**);
257
- unsigned AFCDirectoryRead (afc_connection* , afc_directory*, char **);
258
- unsigned AFCDirectoryOpen (afc_connection* , const char *, afc_directory**);
259
- unsigned AFCDirectoryClose (afc_connection* , afc_directory*);
260
- unsigned AFCDirectoryCreate (afc_connection* , const char *);
261
- unsigned AFCFileRefOpen (afc_connection* , const char *, unsigned long long , afc_file_ref*);
262
- unsigned AFCFileRefRead (afc_connection* , afc_file_ref, void *, size_t *);
263
- unsigned AFCFileRefWrite (afc_connection* , afc_file_ref, const void *, size_t );
264
- unsigned AFCFileRefClose (afc_connection* , afc_file_ref);
292
+ unsigned AFCConnectionClose (AFCConnectionRef );
293
+ unsigned AFCRemovePath (AFCConnectionRef , const char *);
294
+ unsigned AFCFileInfoOpen (AFCConnectionRef , const char *, afc_dictionary**);
295
+ unsigned AFCDirectoryRead (AFCConnectionRef , afc_directory*, char **);
296
+ unsigned AFCDirectoryOpen (AFCConnectionRef , const char *, afc_directory**);
297
+ unsigned AFCDirectoryClose (AFCConnectionRef , afc_directory*);
298
+ unsigned AFCDirectoryCreate (AFCConnectionRef , const char *);
299
+ unsigned AFCFileRefOpen (AFCConnectionRef , const char *, unsigned long long , afc_file_ref*);
300
+ unsigned AFCFileRefRead (AFCConnectionRef , afc_file_ref, void *, size_t *);
301
+ unsigned AFCFileRefWrite (AFCConnectionRef , afc_file_ref, const void *, size_t );
302
+ unsigned AFCFileRefClose (AFCConnectionRef , afc_file_ref);
265
303
unsigned USBMuxConnectByPort (int , int , long long *);
266
304
}
267
305
0 commit comments