Skip to content

Commit 0bde0f5

Browse files
committed
fix: support ios13 on Windows
1 parent 0d465c7 commit 0bde0f5

File tree

4 files changed

+123
-91
lines changed

4 files changed

+123
-91
lines changed

IOSDeviceLib/Declarations.h

+24-2
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,27 @@ struct FileUploadData {
134134

135135
#pragma region Dll_Type_Definitions
136136

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

139138
#ifdef _WIN32
139+
typedef unsigned(__cdecl *device_notification_subscribe_ptr)(void(*f)(const DevicePointer*), long, long, long, HANDLE*);
140140
typedef void(__cdecl *run_loop_ptr)();
141+
typedef void* CFArrayRef;
141142
typedef void* CFStringRef;
142-
typedef void* CFURLRef;
143143
typedef void* CFDictionaryRef;
144+
typedef void* CFURLRef;
145+
typedef void* CFPropertyListFormat;
146+
extern CFPropertyListFormat kCFPropertyListXMLFormat_v1_0;
147+
typedef void* CFSocketNativeHandle;
148+
typedef unsigned(__cdecl *device_secure_start_service_ptr)(AMDeviceRef device, CFStringRef service_name, unsigned int *unknown, ServiceConnRef * handle);
149+
typedef CFSocketNativeHandle(__cdecl *service_connection_get_socket_ptr)(ServiceConnRef con);
150+
typedef long(__cdecl *service_connection_receive_ptr)(ServiceConnRef, void *, long);
151+
typedef long(__cdecl *service_connection_send_message_ptr)(ServiceConnRef serviceConnection, CFDictionaryRef message, CFPropertyListFormat format);
152+
153+
extern service_connection_send_message_ptr __AMDServiceConnectionSendMessage;
154+
extern service_connection_receive_ptr __AMDServiceConnectionReceive;
155+
156+
typedef unsigned(__cdecl *device_create_house_arrest_service_ptr)(const DeviceInfo*, CFStringRef identifier, void * unknown, AFCConnectionRef * handle);
157+
144158
typedef void*(__cdecl *device_copy_device_identifier)(const DeviceInfo*);
145159
typedef void*(__cdecl *device_copy_value)(const DeviceInfo*, CFStringRef, CFStringRef);
146160
typedef unsigned(__cdecl *device_uninstall_application)(HANDLE, CFStringRef, void*, void(*f)(), void*);
@@ -153,6 +167,7 @@ typedef unsigned long(__cdecl *cf_get_concrete_type_id)();
153167
typedef unsigned(__cdecl *cfdictionary_get_count)(CFDictionaryRef);
154168
typedef void(__cdecl *cfdictionary_get_keys_and_values)(CFDictionaryRef, const void**, const void**);
155169
typedef CFStringRef(__cdecl *cfstring_create_with_cstring)(void*, const char*, unsigned);
170+
typedef CFArrayRef(__cdecl *cfarray_create)(void*, const void**, long, void**);
156171
typedef unsigned(__cdecl *device_secure_operation_with_path)(int, const DeviceInfo*, CFURLRef, CFDictionaryRef, void(*f)(), int);
157172
typedef unsigned(__cdecl *device_secure_operation_with_bundle_id)(int, const DeviceInfo*, CFStringRef, int, void(*f)(), int);
158173
typedef void(__cdecl *cfrelease)(CFStringRef);
@@ -183,8 +198,14 @@ typedef int(__cdecl *usb_mux_connect_by_port)(int, int, long long*);
183198
#pragma region Dll_Method_Definitions
184199

185200
#ifdef _WIN32
201+
extern HINSTANCE mobile_device_dll;
186202
#define GET_IF_EXISTS(variable, type, dll, method_name) (variable ? variable : variable = (type)GetProcAddress(dll, method_name))
187203

204+
#define AMDeviceSecureStartService GET_IF_EXISTS(__AMDeviceSecureStartService, device_secure_start_service_ptr, mobile_device_dll, "AMDeviceSecureStartService")
205+
#define AMDServiceConnectionGetSocket GET_IF_EXISTS(__AMDServiceConnectionGetSocket, service_connection_get_socket_ptr, mobile_device_dll, "AMDServiceConnectionGetSocket")
206+
#define AMDServiceConnectionReceive GET_IF_EXISTS(__AMDServiceConnectionReceive, service_connection_receive_ptr, mobile_device_dll, "AMDServiceConnectionReceive")
207+
#define AMDServiceConnectionSendMessage GET_IF_EXISTS(__AMDServiceConnectionSendMessage, service_connection_send_message_ptr, mobile_device_dll, "AMDServiceConnectionSendMessage")
208+
#define AMDeviceCreateHouseArrestService GET_IF_EXISTS(__AMDeviceCreateHouseArrestService, device_create_house_arrest_service_ptr, mobile_device_dll, "AMDeviceCreateHouseArrestService")
188209
#define AMDeviceNotificationSubscribe GET_IF_EXISTS(__AMDeviceNotificationSubscribe, device_notification_subscribe_ptr, mobile_device_dll, "AMDeviceNotificationSubscribe")
189210
#define AMDeviceCopyDeviceIdentifier GET_IF_EXISTS(__AMDeviceCopyDeviceIdentifier, device_copy_device_identifier, mobile_device_dll, "AMDeviceCopyDeviceIdentifier")
190211
#define AMDeviceCopyValue GET_IF_EXISTS(__AMDeviceCopyValue, device_copy_value, mobile_device_dll, "AMDeviceCopyValue")
@@ -215,6 +236,7 @@ typedef int(__cdecl *usb_mux_connect_by_port)(int, int, long long*);
215236
#define CFDictionaryGetCount GET_IF_EXISTS(__CFDictionaryGetCount, cfdictionary_get_count, core_foundation_dll, "CFDictionaryGetCount")
216237
#define CFDictionaryGetKeysAndValues GET_IF_EXISTS(__CFDictionaryGetKeysAndValues, cfdictionary_get_keys_and_values, core_foundation_dll, "CFDictionaryGetKeysAndValues")
217238
#define CFStringCreateWithCString GET_IF_EXISTS(__CFStringCreateWithCString, cfstring_create_with_cstring, core_foundation_dll, "CFStringCreateWithCString")
239+
#define CFArrayCreate GET_IF_EXISTS(__CFArrayCreate, cfarray_create, core_foundation_dll, "CFArrayCreate")
218240
#define CFURLCreateWithString GET_IF_EXISTS(__CFURLCreateWithString, cfurl_create_with_string, core_foundation_dll, "CFURLCreateWithString")
219241
#define CFDictionaryCreate GET_IF_EXISTS(__CFDictionaryCreate, cfdictionary_create, core_foundation_dll, "CFDictionaryCreate")
220242
#define CFRelease GET_IF_EXISTS(__CFRelease, cfrelease, core_foundation_dll, "CFRelease")

IOSDeviceLib/IOSDeviceLib.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#ifdef _WIN32
2626
#pragma region Dll_Variable_Definitions
2727

28+
CFPropertyListFormat kCFPropertyListXMLFormat_v1_0 = (CFPropertyListFormat)100;
2829
device_notification_subscribe_ptr __AMDeviceNotificationSubscribe;
2930
HINSTANCE mobile_device_dll;
3031
HINSTANCE core_foundation_dll;
@@ -34,6 +35,11 @@ device_copy_value __AMDeviceCopyValue;
3435
device_start_service __AMDeviceStartService;
3536
device_uninstall_application __AMDeviceUninstallApplication;
3637
device_secure_operation_with_bundle_id __AMDeviceSecureUninstallApplication;
38+
device_secure_start_service_ptr __AMDeviceSecureStartService;
39+
service_connection_get_socket_ptr __AMDServiceConnectionGetSocket;
40+
service_connection_receive_ptr __AMDServiceConnectionReceive;
41+
service_connection_send_message_ptr __AMDServiceConnectionSendMessage;
42+
device_create_house_arrest_service_ptr __AMDeviceCreateHouseArrestService;
3743
device_connection_operation __AMDeviceStartSession;
3844
device_connection_operation __AMDeviceStopSession;
3945
device_connection_operation __AMDeviceConnect;
@@ -57,6 +63,7 @@ cf_get_concrete_type_id __CFDictionaryGetTypeID;
5763
cfdictionary_get_count __CFDictionaryGetCount;
5864
cfdictionary_get_keys_and_values __CFDictionaryGetKeysAndValues;
5965
cfstring_create_with_cstring __CFStringCreateWithCString;
66+
cfarray_create __CFArrayCreate;
6067
cfurl_create_with_string __CFURLCreateWithString;
6168
cfdictionary_create __CFDictionaryCreate;
6269
cfrelease __CFRelease;
@@ -365,7 +372,7 @@ std::mutex start_service_mutex;
365372
ServiceInfo start_secure_service(std::string device_identifier, const char* service_name, std::string method_id, bool should_log_error, bool skip_cache)
366373
{
367374
start_service_mutex.lock();
368-
ServiceInfo serviceInfoResult;
375+
ServiceInfo serviceInfoResult = {};
369376
if (!devices.count(device_identifier))
370377
{
371378
if (should_log_error)
@@ -454,10 +461,13 @@ AFCConnectionRef start_house_arrest(std::string device_identifier, const char* a
454461
HANDLE start_debug_server(std::string device_identifier, std::string ddi, std::string method_id)
455462
{
456463
ServiceInfo info = start_secure_service(device_identifier, kDebugServer, method_id, false, false);
464+
// mount_image is not available on Windows
465+
#ifndef _WIN32
457466
if (!info.socket && mount_image(device_identifier, ddi, method_id))
458467
{
459468
info = start_secure_service(device_identifier, kDebugServer, method_id, true, false);
460469
}
470+
#endif
461471

462472
return info.socket;
463473
}

IOSDeviceLib/SocketHelper.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <io.h>
55
#include <fcntl.h>
66
#include <ws2tcpip.h>
7+
typedef void* CFDictionaryRef;
78

89
#pragma comment(lib, "Ws2_32.lib")
910
#else
@@ -22,7 +23,6 @@ typedef unsigned long long SOCKET;
2223
#include <string>
2324
#include <functional>
2425
#include "PlistCpp/include/boost/any.hpp"
25-
2626
struct LengthEncodedMessage {
2727
char *message;
2828
size_t length;

IOSDeviceLib/windows_impl.cpp

+87-87
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,87 @@
1-
#ifdef _WIN32
2-
#include "Declarations.h"
3-
#include "Constants.h"
4-
#include "FileHelper.h"
5-
#include "Printing.h"
6-
#include "SocketHelper.h"
7-
#include "CommonFunctions.h"
8-
9-
#include <map>
10-
#include <sstream>
11-
extern int __result;
12-
13-
std::string get_signature_base64(std::string image_signature_path)
14-
{
15-
FileInfo signature_file_info = get_file_info(image_signature_path, true);
16-
return base64_encode(&signature_file_info.contents[0], signature_file_info.size);
17-
}
18-
19-
bool mount_image(std::string& device_identifier, std::string& image_path, std::string& method_id)
20-
{
21-
PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(!exists(image_path), "Could not find developer disk image", device_identifier, method_id, false);
22-
std::string image_signature_path = image_path + ".signature";
23-
PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(!exists(image_signature_path), "Could not find developer disk image signature", device_identifier, method_id, false);
24-
25-
HANDLE mountFd = start_secure_service(device_identifier, kMobileImageMounter, method_id);
26-
if (!mountFd)
27-
{
28-
return false;
29-
}
30-
31-
FileInfo image_file_info = get_file_info(image_path, false);
32-
std::string signature_base64 = get_signature_base64(image_signature_path);
33-
34-
std::stringstream xml_command;
35-
int bytes_sent;
36-
std::map<std::string, boost::any> dict;
37-
xml_command << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
38-
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
39-
"<plist version=\"1.0\">"
40-
"<dict>"
41-
"<key>Command</key>"
42-
"<string>ReceiveBytes</string>"
43-
"<key>ImageSize</key>"
44-
"<integer>" + std::to_string(image_file_info.size) + "</integer>"
45-
"<key>ImageType</key>"
46-
"<string>Developer</string>"
47-
"<key>ImageSignature</key>"
48-
"<data>" + signature_base64 + "</data>"
49-
"</dict>"
50-
"</plist>";
51-
52-
bytes_sent = send_message(xml_command.str().c_str(), (SOCKET)mountFd);
53-
dict = receive_message((SOCKET)mountFd);
54-
PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(dict.count(kErrorKey), boost::any_cast<std::string>(dict[kErrorKey]).c_str(), device_identifier, method_id, false);
55-
if (boost::any_cast<std::string>(dict[kStatusKey]) == "ReceiveBytesAck")
56-
{
57-
image_file_info = get_file_info(image_path, true);
58-
bytes_sent = send((SOCKET)mountFd, &image_file_info.contents[0], image_file_info.size, 0);
59-
dict = receive_message((SOCKET)mountFd);
60-
xml_command.str("");
61-
xml_command << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
62-
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
63-
"<plist version=\"1.0\">"
64-
"<dict>"
65-
"<key>Command</key>"
66-
"<string>MountImage</string>"
67-
"<key>ImageType</key>"
68-
"<string>Developer</string>"
69-
"<key>ImageSignature</key>"
70-
"<data>" + signature_base64 + "</data>"
71-
"<key>ImagePath</key>"
72-
"<string>/var/mobile/Media/PublicStaging/staging.dimage</string>"
73-
"</dict>"
74-
"</plist>";
75-
bytes_sent = send_message(xml_command.str().c_str(), (SOCKET)mountFd);
76-
dict = receive_message((SOCKET)mountFd);
77-
PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(dict.count(kErrorKey), boost::any_cast<std::string>(dict[kErrorKey]).c_str(), device_identifier, method_id, false);
78-
return dict.count(kStatusKey) && has_complete_status(dict);
79-
}
80-
else
81-
{
82-
print_error("Could not transfer disk image", device_identifier, method_id, kUnexpectedError);
83-
return false;
84-
}
85-
}
86-
87-
#endif // _WIN32
1+
//#ifdef _WIN32
2+
//#include "Declarations.h"
3+
//#include "Constants.h"
4+
//#include "FileHelper.h"
5+
//#include "Printing.h"
6+
//#include "SocketHelper.h"
7+
//#include "CommonFunctions.h"
8+
//
9+
//#include <map>
10+
//#include <sstream>
11+
//extern int __result;
12+
//
13+
//std::string get_signature_base64(std::string image_signature_path)
14+
//{
15+
// FileInfo signature_file_info = get_file_info(image_signature_path, true);
16+
// return base64_encode(&signature_file_info.contents[0], signature_file_info.size);
17+
//}
18+
//
19+
//bool mount_image(std::string& device_identifier, std::string& image_path, std::string& method_id)
20+
//{
21+
// PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(!exists(image_path), "Could not find developer disk image", device_identifier, method_id, false);
22+
// std::string image_signature_path = image_path + ".signature";
23+
// PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(!exists(image_signature_path), "Could not find developer disk image signature", device_identifier, method_id, false);
24+
//
25+
// ServiceInfo serviceInfo = start_secure_service(device_identifier, kMobileImageMounter, method_id);
26+
// if (!serviceInfo.socket)
27+
// {
28+
// return false;
29+
// }
30+
//
31+
// FileInfo image_file_info = get_file_info(image_path, false);
32+
// std::string signature_base64 = get_signature_base64(image_signature_path);
33+
//
34+
// std::stringstream xml_command;
35+
// int bytes_sent;
36+
// std::map<std::string, boost::any> dict;
37+
// xml_command << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
38+
// "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
39+
// "<plist version=\"1.0\">"
40+
// "<dict>"
41+
// "<key>Command</key>"
42+
// "<string>ReceiveBytes</string>"
43+
// "<key>ImageSize</key>"
44+
// "<integer>" + std::to_string(image_file_info.size) + "</integer>"
45+
// "<key>ImageType</key>"
46+
// "<string>Developer</string>"
47+
// "<key>ImageSignature</key>"
48+
// "<data>" + signature_base64 + "</data>"
49+
// "</dict>"
50+
// "</plist>";
51+
//
52+
// bytes_sent = send_message(xml_command.str().c_str(), (SOCKET)mountFd);
53+
// dict = receive_message((SOCKET)mountFd);
54+
// PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(dict.count(kErrorKey), boost::any_cast<std::string>(dict[kErrorKey]).c_str(), device_identifier, method_id, false);
55+
// if (boost::any_cast<std::string>(dict[kStatusKey]) == "ReceiveBytesAck")
56+
// {
57+
// image_file_info = get_file_info(image_path, true);
58+
// bytes_sent = send((SOCKET)mountFd, &image_file_info.contents[0], image_file_info.size, 0);
59+
// dict = receive_message((SOCKET)mountFd);
60+
// xml_command.str("");
61+
// xml_command << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
62+
// "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"
63+
// "<plist version=\"1.0\">"
64+
// "<dict>"
65+
// "<key>Command</key>"
66+
// "<string>MountImage</string>"
67+
// "<key>ImageType</key>"
68+
// "<string>Developer</string>"
69+
// "<key>ImageSignature</key>"
70+
// "<data>" + signature_base64 + "</data>"
71+
// "<key>ImagePath</key>"
72+
// "<string>/var/mobile/Media/PublicStaging/staging.dimage</string>"
73+
// "</dict>"
74+
// "</plist>";
75+
// bytes_sent = send_message(xml_command.str().c_str(), (SOCKET)mountFd);
76+
// dict = receive_message((SOCKET)mountFd);
77+
// PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(dict.count(kErrorKey), boost::any_cast<std::string>(dict[kErrorKey]).c_str(), device_identifier, method_id, false);
78+
// return dict.count(kStatusKey) && has_complete_status(dict);
79+
// }
80+
// else
81+
// {
82+
// print_error("Could not transfer disk image", device_identifier, method_id, kUnexpectedError);
83+
// return false;
84+
// }
85+
//}
86+
//
87+
//#endif // _WIN32

0 commit comments

Comments
 (0)