Skip to content

Commit 5011616

Browse files
Merge pull request #55 from telerik/feature/xcode11
feat: migrate to Secure Connections in order to support iOS13, Xcode11 and eventually WIFI sync
2 parents db3c0db + 71e6b60 commit 5011616

File tree

9 files changed

+356
-281
lines changed

9 files changed

+356
-281
lines changed

IOSDeviceLib.xcodeproj/project.pbxproj

+1
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,7 @@
11431143
developmentRegion = English;
11441144
hasScannedForEncodings = 0;
11451145
knownRegions = (
1146+
English,
11461147
en,
11471148
);
11481149
mainGroup = 70F6ADA21DEEB71300DD4722;

IOSDeviceLib/CommonFunctions.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
#include "PlistCpp/include/boost/any.hpp"
77
#include "Declarations.h"
88

9+
AFCConnectionRef start_house_arrest(std::string device_identifier, const char* application_identifier, std::string method_id);
910
inline bool has_complete_status(std::map<std::string, boost::any>& dict);
10-
HANDLE start_service(std::string device_identifier, const char* service_name, std::string method_id, bool should_log_error = true, bool skip_cache = false);
11+
ServiceInfo start_secure_service(std::string device_identifier, const char* service_name, std::string method_id, bool should_log_error = true, bool skip_cache = false);
1112
bool mount_image(std::string& device_identifier, std::string& image_path, std::string& method_id);
1213
std::string get_device_property_value(std::string& device_identifier, const char* property_name);
1314
int start_session(std::string& device_identifier);
1415
void stop_session(std::string& device_identifier);
15-
CFStringRef create_CFString(const char* str);
16+
CFStringRef create_CFString(const char* str);

IOSDeviceLib/Declarations.h

+66-28
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ struct afc_connection {
7878
unsigned int context; /* 40 */
7979
};
8080

81+
typedef struct afc_connection * AFCConnectionRef;
82+
8183
struct afc_dictionary {
8284
unsigned char unknown[0]; /* size unknown */
8385
};
@@ -88,18 +90,27 @@ struct afc_directory {
8890

8991
struct afc_file {
9092
afc_file_ref file_ref;
91-
afc_connection* afc_conn_p;
93+
AFCConnectionRef afc_conn_p;
9294
};
9395

9496
struct ApplicationCache {
95-
afc_connection* afc_connection;
97+
AFCConnectionRef afc_connection;
9698
bool has_initialized_gdb;
9799
};
98100

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+
99110
struct DeviceData {
100111
DeviceInfo* device_info;
101112
struct DeviceServerData* device_server_data;
102-
std::map<const char*, HANDLE> services;
113+
std::map<const char*, ServiceInfo> services;
103114
int sessions;
104115
std::map<std::string, ApplicationCache> apps_cache;
105116

@@ -122,13 +133,27 @@ struct FileUploadData {
122133

123134
#pragma region Dll_Type_Definitions
124135

125-
typedef unsigned(__cdecl *device_notification_subscribe_ptr)(void(*f)(const DevicePointer*), long, long, long, HANDLE*);
126136

127137
#ifdef _WIN32
138+
typedef unsigned(__cdecl *device_notification_subscribe_ptr)(void(*f)(const DevicePointer*), long, long, long, HANDLE*);
128139
typedef void(__cdecl *run_loop_ptr)();
140+
typedef void* CFArrayRef;
129141
typedef void* CFStringRef;
130-
typedef void* CFURLRef;
131142
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+
132157
typedef void*(__cdecl *device_copy_device_identifier)(const DeviceInfo*);
133158
typedef void*(__cdecl *device_copy_value)(const DeviceInfo*, CFStringRef, CFStringRef);
134159
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)();
141166
typedef unsigned(__cdecl *cfdictionary_get_count)(CFDictionaryRef);
142167
typedef void(__cdecl *cfdictionary_get_keys_and_values)(CFDictionaryRef, const void**, const void**);
143168
typedef CFStringRef(__cdecl *cfstring_create_with_cstring)(void*, const char*, unsigned);
169+
typedef CFArrayRef(__cdecl *cfarray_create)(void*, const void**, long, void**);
144170
typedef unsigned(__cdecl *device_secure_operation_with_path)(int, const DeviceInfo*, CFURLRef, CFDictionaryRef, void(*f)(), int);
145171
typedef unsigned(__cdecl *device_secure_operation_with_bundle_id)(int, const DeviceInfo*, CFStringRef, int, void(*f)(), int);
146172
typedef void(__cdecl *cfrelease)(CFStringRef);
@@ -149,18 +175,18 @@ typedef CFDictionaryRef(__cdecl *cfdictionary_create)(void *, void*, void*, int,
149175
typedef void*(__cdecl *cfurl_create_with_string)(void *, CFStringRef, void*);
150176

151177
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);
164190
typedef unsigned(__cdecl *device_start_house_arrest)(const DeviceInfo*, CFStringRef, void*, HANDLE*, unsigned int*);
165191
typedef unsigned(__cdecl *device_lookup_applications)(const DeviceInfo*, CFDictionaryRef, CFDictionaryRef*);
166192
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*);
171197
#pragma region Dll_Method_Definitions
172198

173199
#ifdef _WIN32
200+
extern HINSTANCE mobile_device_dll;
174201
#define GET_IF_EXISTS(variable, type, dll, method_name) (variable ? variable : variable = (type)GetProcAddress(dll, method_name))
175202

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")
176208
#define AMDeviceNotificationSubscribe GET_IF_EXISTS(__AMDeviceNotificationSubscribe, device_notification_subscribe_ptr, mobile_device_dll, "AMDeviceNotificationSubscribe")
177209
#define AMDeviceCopyDeviceIdentifier GET_IF_EXISTS(__AMDeviceCopyDeviceIdentifier, device_copy_device_identifier, mobile_device_dll, "AMDeviceCopyDeviceIdentifier")
178210
#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*);
203235
#define CFDictionaryGetCount GET_IF_EXISTS(__CFDictionaryGetCount, cfdictionary_get_count, core_foundation_dll, "CFDictionaryGetCount")
204236
#define CFDictionaryGetKeysAndValues GET_IF_EXISTS(__CFDictionaryGetKeysAndValues, cfdictionary_get_keys_and_values, core_foundation_dll, "CFDictionaryGetKeysAndValues")
205237
#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")
206239
#define CFURLCreateWithString GET_IF_EXISTS(__CFURLCreateWithString, cfurl_create_with_string, core_foundation_dll, "CFURLCreateWithString")
207240
#define CFDictionaryCreate GET_IF_EXISTS(__CFDictionaryCreate, cfdictionary_create, core_foundation_dll, "CFDictionaryCreate")
208241
#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*);
230263

231264
extern "C"
232265
{
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);
233270
unsigned AMDeviceNotificationSubscribe(void(*f)(const DevicePointer*), long, long, long, HANDLE*);
234271
CFStringRef AMDeviceCopyDeviceIdentifier(const DeviceInfo*);
235272
CFStringRef AMDeviceCopyValue(const DeviceInfo*, CFStringRef, CFStringRef);
236273
unsigned AMDeviceMountImage(const DeviceInfo*, CFStringRef, CFDictionaryRef, void(*f)(void*, int), void*);
237274
unsigned AMDeviceStartService(const DeviceInfo*, CFStringRef, HANDLE*, void*);
238275
unsigned AMDeviceLookupApplications(const DeviceInfo*, CFDictionaryRef, CFDictionaryRef*);
276+
unsigned AMDeviceCreateHouseArrestService(const DeviceInfo*, CFStringRef identifier, void * unknown, AFCConnectionRef * handle);
239277
int AMDeviceGetConnectionID(const DeviceInfo*);
240278
int AMDeviceGetInterfaceType(const DeviceInfo*);
241279
unsigned AMDeviceUninstallApplication(HANDLE, CFStringRef, void*, void(*f)(), void*);
@@ -251,17 +289,17 @@ extern "C"
251289
unsigned AMDeviceSecureInstallApplication(int, const DeviceInfo*, CFURLRef, CFDictionaryRef, void(*f)(), int);
252290
unsigned AMDeviceStartHouseArrestService(const DeviceInfo*, CFStringRef, void*, HANDLE*, unsigned int*);
253291
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);
265303
unsigned USBMuxConnectByPort(int, int, long long*);
266304
}
267305

IOSDeviceLib/FileHelper.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ FileInfo get_file_info(std::string& path, bool get_contents)
2929

3030
std::vector<char> buffer(size);
3131
file.read(buffer.data(), size);
32-
if (buffer.size() == 0 && size == 0)
33-
{
34-
// We will get here if the file exists and it is empty.
35-
buffer.push_back(""[0]);
36-
}
32+
if (buffer.size() == 0 && size == 0)
33+
{
34+
// We will get here if the file exists and it is empty.
35+
buffer.push_back(""[0]);
36+
}
3737

38-
result.contents = buffer;
38+
result.contents = buffer;
3939
}
4040
}
41-
else
42-
{
43-
return {-1};
44-
}
41+
else
42+
{
43+
return {-1};
44+
}
4545

4646
return result;
4747
}

0 commit comments

Comments
 (0)