From 0d465c7ba9e7e05bc405c1276a94bc932b22837f Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Fri, 9 Aug 2019 17:01:43 +0300 Subject: [PATCH 1/4] feat: migrate to Secure Connections in order to support iOS13, Xcode11 and maybe the WIFI sync --- IOSDeviceLib.xcodeproj/project.pbxproj | 1 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + IOSDeviceLib/CommonFunctions.h | 5 +- IOSDeviceLib/Declarations.h | 71 ++-- IOSDeviceLib/IOSDeviceLib.cpp | 318 +++++++++--------- IOSDeviceLib/SocketHelper.cpp | 31 +- IOSDeviceLib/SocketHelper.h | 4 + IOSDeviceLib/windows_impl.cpp | 4 +- 8 files changed, 249 insertions(+), 193 deletions(-) create mode 100644 IOSDeviceLib.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/IOSDeviceLib.xcodeproj/project.pbxproj b/IOSDeviceLib.xcodeproj/project.pbxproj index f89f77e..b2585ec 100644 --- a/IOSDeviceLib.xcodeproj/project.pbxproj +++ b/IOSDeviceLib.xcodeproj/project.pbxproj @@ -1143,6 +1143,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 70F6ADA21DEEB71300DD4722; diff --git a/IOSDeviceLib.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/IOSDeviceLib.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/IOSDeviceLib.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/IOSDeviceLib/CommonFunctions.h b/IOSDeviceLib/CommonFunctions.h index 1c94393..109d5c1 100644 --- a/IOSDeviceLib/CommonFunctions.h +++ b/IOSDeviceLib/CommonFunctions.h @@ -6,10 +6,11 @@ #include "PlistCpp/include/boost/any.hpp" #include "Declarations.h" +AFCConnectionRef start_house_arrest(std::string device_identifier, const char* application_identifier, std::string method_id); inline bool has_complete_status(std::map& dict); -HANDLE start_service(std::string device_identifier, const char* service_name, std::string method_id, bool should_log_error = true, bool skip_cache = false); +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); bool mount_image(std::string& device_identifier, std::string& image_path, std::string& method_id); std::string get_device_property_value(std::string& device_identifier, const char* property_name); int start_session(std::string& device_identifier); void stop_session(std::string& device_identifier); -CFStringRef create_CFString(const char* str); \ No newline at end of file +CFStringRef create_CFString(const char* str); diff --git a/IOSDeviceLib/Declarations.h b/IOSDeviceLib/Declarations.h index 85602bf..c137e48 100644 --- a/IOSDeviceLib/Declarations.h +++ b/IOSDeviceLib/Declarations.h @@ -63,6 +63,7 @@ struct LiveSyncApplicationInfo { typedef unsigned long long afc_file_ref; + struct afc_connection { unsigned int handle; /* 0 */ unsigned int unknown0; /* 4 */ @@ -78,6 +79,8 @@ struct afc_connection { unsigned int context; /* 40 */ }; +typedef struct afc_connection * AFCConnectionRef; + struct afc_dictionary { unsigned char unknown[0]; /* size unknown */ }; @@ -88,18 +91,27 @@ struct afc_directory { struct afc_file { afc_file_ref file_ref; - afc_connection* afc_conn_p; + AFCConnectionRef afc_conn_p; }; struct ApplicationCache { - afc_connection* afc_connection; + AFCConnectionRef afc_connection; bool has_initialized_gdb; }; +typedef HANDLE service_conn_t; +typedef service_conn_t * ServiceConnRef; +typedef struct DeviceInfo * AMDeviceRef; +struct ServiceInfo { + HANDLE socket; + ServiceConnRef connection; + int connection_id; +}; + struct DeviceData { DeviceInfo* device_info; struct DeviceServerData* device_server_data; - std::map services; + std::map services; int sessions; std::map apps_cache; @@ -149,18 +161,18 @@ typedef CFDictionaryRef(__cdecl *cfdictionary_create)(void *, void*, void*, int, typedef void*(__cdecl *cfurl_create_with_string)(void *, CFStringRef, void*); typedef unsigned(__cdecl *afc_connection_open)(HANDLE, const char*, void*); -typedef unsigned(__cdecl *afc_connection_close)(afc_connection*); -typedef unsigned(__cdecl *afc_file_info_open)(afc_connection*, const char*, afc_dictionary**); -typedef unsigned(__cdecl *afc_directory_read)(afc_connection*, afc_directory*, char**); -typedef unsigned(__cdecl *afc_directory_open)(afc_connection*, const char*, afc_directory**); -typedef unsigned(__cdecl *afc_directory_close)(afc_connection*, afc_directory*); -typedef unsigned(__cdecl *afc_directory_create)(afc_connection*, const char *); -typedef unsigned(__cdecl *afc_remove_path)(afc_connection*, const char *); -typedef unsigned(__cdecl *afc_fileref_open)(afc_connection*, const char *, unsigned long long, afc_file_ref*); -typedef unsigned(__cdecl *afc_fileref_read)(afc_connection*, afc_file_ref, void *, size_t*); -typedef unsigned(__cdecl *afc_get_device_info_key)(afc_connection*, const char *, char**); -typedef unsigned(__cdecl *afc_fileref_write)(afc_connection*, afc_file_ref, const void*, size_t); -typedef unsigned(__cdecl *afc_fileref_close)(afc_connection*, afc_file_ref); +typedef unsigned(__cdecl *afc_connection_close)(AFCConnectionRef); +typedef unsigned(__cdecl *afc_file_info_open)(AFCConnectionRef, const char*, afc_dictionary**); +typedef unsigned(__cdecl *afc_directory_read)(AFCConnectionRef, afc_directory*, char**); +typedef unsigned(__cdecl *afc_directory_open)(AFCConnectionRef, const char*, afc_directory**); +typedef unsigned(__cdecl *afc_directory_close)(AFCConnectionRef, afc_directory*); +typedef unsigned(__cdecl *afc_directory_create)(AFCConnectionRef, const char *); +typedef unsigned(__cdecl *afc_remove_path)(AFCConnectionRef, const char *); +typedef unsigned(__cdecl *afc_fileref_open)(AFCConnectionRef, const char *, unsigned long long, afc_file_ref*); +typedef unsigned(__cdecl *afc_fileref_read)(AFCConnectionRef, afc_file_ref, void *, size_t*); +typedef unsigned(__cdecl *afc_get_device_info_key)(AFCConnectionRef, const char *, char**); +typedef unsigned(__cdecl *afc_fileref_write)(AFCConnectionRef, afc_file_ref, const void*, size_t); +typedef unsigned(__cdecl *afc_fileref_close)(AFCConnectionRef, afc_file_ref); typedef unsigned(__cdecl *device_start_house_arrest)(const DeviceInfo*, CFStringRef, void*, HANDLE*, unsigned int*); typedef unsigned(__cdecl *device_lookup_applications)(const DeviceInfo*, CFDictionaryRef, CFDictionaryRef*); typedef int(__cdecl *usb_mux_connect_by_port)(int, int, long long*); @@ -228,14 +240,21 @@ typedef int(__cdecl *usb_mux_connect_by_port)(int, int, long long*); #include +// TODO: handle Windows + extern "C" { + CFSocketNativeHandle AMDServiceConnectionGetSocket(ServiceConnRef con); + long AMDServiceConnectionReceive(ServiceConnRef, void *, long); + long AMDServiceConnectionSendMessage(ServiceConnRef serviceConnection, CFDictionaryRef message, CFPropertyListFormat format); + unsigned AMDeviceSecureStartService(AMDeviceRef device, CFStringRef service_name, unsigned int *unknown, ServiceConnRef * handle); unsigned AMDeviceNotificationSubscribe(void(*f)(const DevicePointer*), long, long, long, HANDLE*); CFStringRef AMDeviceCopyDeviceIdentifier(const DeviceInfo*); CFStringRef AMDeviceCopyValue(const DeviceInfo*, CFStringRef, CFStringRef); unsigned AMDeviceMountImage(const DeviceInfo*, CFStringRef, CFDictionaryRef, void(*f)(void*, int), void*); unsigned AMDeviceStartService(const DeviceInfo*, CFStringRef, HANDLE*, void*); unsigned AMDeviceLookupApplications(const DeviceInfo*, CFDictionaryRef, CFDictionaryRef*); + unsigned AMDeviceCreateHouseArrestService(const DeviceInfo*, CFStringRef identifier, void * unknown, AFCConnectionRef * handle); int AMDeviceGetConnectionID(const DeviceInfo*); int AMDeviceGetInterfaceType(const DeviceInfo*); unsigned AMDeviceUninstallApplication(HANDLE, CFStringRef, void*, void(*f)(), void*); @@ -251,17 +270,17 @@ extern "C" unsigned AMDeviceSecureInstallApplication(int, const DeviceInfo*, CFURLRef, CFDictionaryRef, void(*f)(), int); unsigned AMDeviceStartHouseArrestService(const DeviceInfo*, CFStringRef, void*, HANDLE*, unsigned int*); unsigned AFCConnectionOpen(HANDLE, const char*, void*); - unsigned AFCConnectionClose(afc_connection*); - unsigned AFCRemovePath(afc_connection*, const char*); - unsigned AFCFileInfoOpen(afc_connection*, const char*, afc_dictionary**); - unsigned AFCDirectoryRead(afc_connection*, afc_directory*, char**); - unsigned AFCDirectoryOpen(afc_connection*, const char*, afc_directory**); - unsigned AFCDirectoryClose(afc_connection*, afc_directory*); - unsigned AFCDirectoryCreate(afc_connection*, const char*); - unsigned AFCFileRefOpen(afc_connection*, const char*, unsigned long long, afc_file_ref*); - unsigned AFCFileRefRead(afc_connection*, afc_file_ref, void*, size_t*); - unsigned AFCFileRefWrite(afc_connection*, afc_file_ref, const void*, size_t); - unsigned AFCFileRefClose(afc_connection*, afc_file_ref); + unsigned AFCConnectionClose(AFCConnectionRef); + unsigned AFCRemovePath(AFCConnectionRef, const char*); + unsigned AFCFileInfoOpen(AFCConnectionRef, const char*, afc_dictionary**); + unsigned AFCDirectoryRead(AFCConnectionRef, afc_directory*, char**); + unsigned AFCDirectoryOpen(AFCConnectionRef, const char*, afc_directory**); + unsigned AFCDirectoryClose(AFCConnectionRef, afc_directory*); + unsigned AFCDirectoryCreate(AFCConnectionRef, const char*); + unsigned AFCFileRefOpen(AFCConnectionRef, const char*, unsigned long long, afc_file_ref*); + unsigned AFCFileRefRead(AFCConnectionRef, afc_file_ref, void*, size_t*); + unsigned AFCFileRefWrite(AFCConnectionRef, afc_file_ref, const void*, size_t); + unsigned AFCFileRefClose(AFCConnectionRef, afc_file_ref); unsigned USBMuxConnectByPort(int, int, long long*); } diff --git a/IOSDeviceLib/IOSDeviceLib.cpp b/IOSDeviceLib/IOSDeviceLib.cpp index 32fc539..72611dd 100644 --- a/IOSDeviceLib/IOSDeviceLib.cpp +++ b/IOSDeviceLib/IOSDeviceLib.cpp @@ -81,7 +81,9 @@ afc_fileref_close __AFCFileRefClose; using json = nlohmann::json; int __result; +int nextServiceConnectionId = 1; std::map devices; +std::map serviceConnections; std::string get_dirname(std::string& path) { @@ -125,11 +127,7 @@ int start_session(std::string& device_identifier) { const DeviceInfo* device_info = devices[device_identifier].device_info; UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT(AMDeviceConnect(device_info), start_session_mutex); - if (!AMDeviceIsPaired(device_info)) - { - UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT(AMDevicePair(device_info), start_session_mutex); - } - + assert(AMDeviceIsPaired(device_info)); UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT(AMDeviceValidatePairing(device_info), start_session_mutex); UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT(AMDeviceStartSession(device_info), start_session_mutex); } @@ -201,7 +199,7 @@ void cleanup_file_resources(const std::string& device_identifier, const std::str if (devices[device_identifier].apps_cache[application_identifier].afc_connection) { - afc_connection* afc_connection_to_close = devices[device_identifier].apps_cache[application_identifier].afc_connection; + AFCConnectionRef afc_connection_to_close = devices[device_identifier].apps_cache[application_identifier].afc_connection; AFCConnectionClose(afc_connection_to_close); devices[device_identifier].apps_cache.erase(application_identifier); } @@ -363,54 +361,62 @@ void start_run_loop() } std::mutex start_service_mutex; -HANDLE start_service(std::string device_identifier, const char* service_name, std::string method_id, bool should_log_error, bool skip_cache) -{ - start_service_mutex.lock(); - if (!devices.count(device_identifier)) - { - if (should_log_error) - print_error("Device not found", device_identifier, method_id, kAMDNotFoundError); - - start_service_mutex.unlock(); - return NULL; - } - - if (devices[device_identifier].services.count(service_name)) - { - start_service_mutex.unlock(); - return devices[device_identifier].services[service_name]; - } - HANDLE socket = nullptr; - PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(start_session(device_identifier), "Could not start device session", device_identifier, method_id, NULL); - CFStringRef cf_service_name = create_CFString(service_name); - unsigned result = AMDeviceStartService(devices[device_identifier].device_info, cf_service_name, &socket, NULL); - stop_session(device_identifier); - CFRelease(cf_service_name); - if (result) - { - std::string message("Could not start service "); - message += service_name; - if (should_log_error) - print_error(message.c_str(), device_identifier, method_id, result); - - start_service_mutex.unlock(); - return NULL; - } - - if (!skip_cache) { - devices[device_identifier].services[service_name] = socket; - } - - start_service_mutex.unlock(); - return socket; +ServiceInfo start_secure_service(std::string device_identifier, const char* service_name, std::string method_id, bool should_log_error, bool skip_cache) +{ + start_service_mutex.lock(); + ServiceInfo serviceInfoResult; + if (!devices.count(device_identifier)) + { + if (should_log_error) + print_error("Device not found", device_identifier, method_id, kAMDNotFoundError); + + start_service_mutex.unlock(); + return serviceInfoResult; + } + + if (!skip_cache && devices[device_identifier].services.count(service_name)) + { + start_service_mutex.unlock(); + return devices[device_identifier].services[service_name]; + } + + PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(start_session(device_identifier), "Could not start device session", device_identifier, method_id, serviceInfoResult); + CFStringRef cf_service_name = create_CFString(service_name); + + ServiceConnRef connection; + unsigned result = AMDeviceSecureStartService(devices[device_identifier].device_info, cf_service_name, NULL, &connection); + service_conn_t socket = (void*)AMDServiceConnectionGetSocket(connection); + + stop_session(device_identifier); + CFRelease(cf_service_name); + if (result) + { + std::string message("Could not start service "); + message += service_name; + if (should_log_error) + print_error(message.c_str(), device_identifier, method_id, result); + + start_service_mutex.unlock(); + return serviceInfoResult; + } + + serviceInfoResult.socket = socket; + serviceInfoResult.connection = connection; + serviceInfoResult.connection_id = nextServiceConnectionId; + serviceConnections[nextServiceConnectionId] = connection; + nextServiceConnectionId++; + + if (!skip_cache) { + devices[device_identifier].services[service_name] = serviceInfoResult; + } + + start_service_mutex.unlock(); + return serviceInfoResult; } -// We do not use this method. -// When we used it to upload files to the live ION we had problems writing them on the root of the ION. -// The method is not deleted because it works for some applications and we can use it in the future for something. -#if 0 -HANDLE start_house_arrest(std::string device_identifier, const char* application_identifier, std::string method_id) + +AFCConnectionRef start_house_arrest(std::string device_identifier, const char* application_identifier, std::string method_id) { if (!devices.count(device_identifier)) { @@ -418,17 +424,19 @@ HANDLE start_house_arrest(std::string device_identifier, const char* application return NULL; } - if (devices[device_identifier].services.count(kHouseArrest)) + AFCConnectionRef persistedHouseArrestService = devices[device_identifier].apps_cache[application_identifier].afc_connection; + if (persistedHouseArrestService) { - return devices[device_identifier].services[kHouseArrest]; + return persistedHouseArrestService; } - HANDLE houseFd = nullptr; + AFCConnectionRef conn = NULL; start_session(device_identifier); CFStringRef cf_application_identifier = create_CFString(application_identifier); - unsigned result = AMDeviceStartHouseArrestService(devices[device_identifier].device_info, cf_application_identifier, 0, &houseFd, 0); - CFRelease(cf_application_identifier); + unsigned result = AMDeviceCreateHouseArrestService(devices[device_identifier].device_info, cf_application_identifier, 0, &conn); + stop_session(device_identifier); + CFRelease(cf_application_identifier); if (result) { @@ -438,67 +446,38 @@ HANDLE start_house_arrest(std::string device_identifier, const char* application return NULL; } - devices[device_identifier].services[kHouseArrest] = houseFd; - return houseFd; + devices[device_identifier].apps_cache[application_identifier].afc_connection = conn; + + return conn; } -#endif HANDLE start_debug_server(std::string device_identifier, std::string ddi, std::string method_id) { - HANDLE gdb = start_service(device_identifier, kDebugServer, method_id, false); - if (!gdb && mount_image(device_identifier, ddi, method_id)) - { - gdb = start_service(device_identifier, kDebugServer, method_id); - } - - return gdb; -} - -bool start_afc_client(std::string& device_identifier, std::string& destination, const char* application_identifier, HANDLE house_arrest_fd, std::string& method_id) -{ - std::string command_name = kVendDocumentsCommandName; - if (!contains(destination, kDocumentsFolder)) + ServiceInfo info = start_secure_service(device_identifier, kDebugServer, method_id, false, false); + if (!info.socket && mount_image(device_identifier, ddi, method_id)) { - command_name = kVendContainerCommandName; + info = start_secure_service(device_identifier, kDebugServer, method_id, true, false); } - std::stringstream xml_command; - xml_command << "" - "" - "" - "" - "Command" - "" + command_name + "" - "Identifier" - "" + std::string(application_identifier) + "" - "" - ""; - - int bytes_sent = send_message(xml_command.str().c_str(), (SOCKET)house_arrest_fd); - std::map dict = receive_message((SOCKET)house_arrest_fd); - - PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(dict.count(kErrorKey), boost::any_cast(dict[kErrorKey]).c_str(), device_identifier, method_id, false); - - return true; + return info.socket; } -afc_connection *get_afc_connection(std::string& device_identifier, const char* application_identifier, std::string& root_path, std::string& method_id) +AFCConnectionRef get_afc_connection(std::string& device_identifier, const char* application_identifier, std::string& root_path, std::string& method_id) { if (devices.count(device_identifier) && devices[device_identifier].apps_cache[application_identifier].afc_connection) { return devices[device_identifier].apps_cache[application_identifier].afc_connection; } - HANDLE house_fd = start_service(device_identifier, kHouseArrest, method_id); - if (!house_fd || !start_afc_client(device_identifier, root_path, application_identifier, house_fd, method_id)) + + AFCConnectionRef con_ref = start_house_arrest(device_identifier, application_identifier, method_id); + if (!con_ref) { return NULL; } - afc_connection* afc_conn_p = nullptr; - PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(AFCConnectionOpen(house_fd, 0, &afc_conn_p), "Could not open afc connection", device_identifier, method_id, NULL); - devices[device_identifier].apps_cache[application_identifier].afc_connection = afc_conn_p; - return afc_conn_p; + devices[device_identifier].apps_cache[application_identifier].afc_connection = con_ref; + return con_ref; } void uninstall_application(std::string application_identifier, std::string device_identifier, std::string method_id) @@ -509,7 +488,7 @@ void uninstall_application(std::string application_identifier, std::string devic return; } - HANDLE socket = start_service(device_identifier, kInstallationProxy, method_id); + HANDLE socket = start_secure_service(device_identifier, kInstallationProxy, method_id, true, false).socket; if (!socket) { return; @@ -616,7 +595,7 @@ void perform_detached_operation(void(*operation)(std::string, std::string, std:: std::thread([operation, first_arg, device_identifier, method_id]() { operation(first_arg, device_identifier, method_id); }).detach(); } -void read_dir(afc_connection* afc_conn_p, const char* dir, json &files, std::stringstream &errors, std::string method_id, std::string device_identifier) +void read_dir(AFCConnectionRef afc_conn_p, const char* dir, json &files, std::stringstream &errors, std::string method_id, std::string device_identifier) { char *dir_ent; files.push_back(dir); @@ -677,7 +656,7 @@ void list_files(std::string device_identifier, const char *application_identifie list_files_mutex.lock(); std::string device_root(device_path); - afc_connection* afc_conn_p = get_afc_connection(device_identifier, application_identifier, device_root, method_id); + AFCConnectionRef afc_conn_p = get_afc_connection(device_identifier, application_identifier, device_root, method_id); if (!afc_conn_p) { print_error("Could not establish AFC Connection", device_identifier, method_id); @@ -703,7 +682,7 @@ void list_files(std::string device_identifier, const char *application_identifie list_files_mutex.unlock(); } -bool ensure_device_path_exists(std::string &device_path, afc_connection *connection) +bool ensure_device_path_exists(std::string &device_path, AFCConnectionRef connection) { std::vector directories = split(device_path, kUnixPathSeparator); std::string curent_device_path(""); @@ -733,7 +712,7 @@ void upload_file(std::string device_identifier, const char *application_identifi upload_file_mutex.lock(); std::string afc_destination_str = windows_path_to_unix(files[0].destination); - afc_connection* afc_conn_p = get_afc_connection(device_identifier, application_identifier, afc_destination_str, method_id); + AFCConnectionRef afc_conn_p = get_afc_connection(device_identifier, application_identifier, afc_destination_str, method_id); if (!afc_conn_p) { upload_file_mutex.unlock(); @@ -843,7 +822,7 @@ void delete_file(std::string device_identifier, const char *application_identifi delete_file_mutex.lock(); std::string destination_str = windows_path_to_unix(destination); - afc_connection* afc_conn_p = get_afc_connection(device_identifier, application_identifier, destination_str, method_id); + AFCConnectionRef afc_conn_p = get_afc_connection(device_identifier, application_identifier, destination_str, method_id); if (!afc_conn_p) { delete_file_mutex.unlock(); @@ -867,7 +846,7 @@ void delete_file(std::string device_identifier, const char *application_identifi std::unique_ptr get_afc_file(std::string device_identifier, const char *application_identifier, const char *destination, std::string method_id){ afc_file_ref file_ref; std::string destination_str = windows_path_to_unix(destination); - afc_connection* afc_conn_p = get_afc_connection(device_identifier, application_identifier, destination_str, method_id); + AFCConnectionRef afc_conn_p = get_afc_connection(device_identifier, application_identifier, destination_str, method_id); if (!afc_conn_p) { return NULL; @@ -937,38 +916,50 @@ void read_file(std::string device_identifier, const char *application_identifier void get_application_infos(std::string device_identifier, std::string method_id) { - HANDLE socket = start_service(device_identifier, kInstallationProxy, method_id); - if (!socket) + ServiceInfo serviceInfo = start_secure_service(device_identifier, kInstallationProxy, method_id, true, false); + if (!serviceInfo.socket) { return; } - - const char *xml_command = "" - "" - "" - "" - "Command" - "Browse" - "ClientOptions" - "" - "ApplicationType" - "User" - "ReturnAttributes" - "" - "CFBundleIdentifier" - "IceniumLiveSyncEnabled" - "configuration" - "" - "" - "" - ""; - - int bytes_sent = send_message(xml_command, (SOCKET)socket); + + CFStringRef cf_bundle_id_key = create_CFString("CFBundleIdentifier"); + CFStringRef cf_config_key = create_CFString("configuration"); + const void* cf_return_attributes[] = { cf_bundle_id_key, cf_config_key }; + const CFArrayRef cf_return_attributes_array = CFArrayCreate(NULL, cf_return_attributes, 2, NULL); + + CFStringRef cf_app_type_key = create_CFString("ApplicationType"); + CFStringRef cf_return_attrs_key = create_CFString("ReturnAttributes"); + const void *client_opts_keys_arr[] = { cf_app_type_key, cf_return_attrs_key }; + + + CFStringRef cf_user_value = create_CFString("User"); + const void *client_opts_values_arr[] = { cf_user_value, cf_return_attributes_array }; + CFDictionaryRef clinet_opts_dict = CFDictionaryCreate(NULL, client_opts_keys_arr, client_opts_values_arr, 2, NULL, NULL); + + CFStringRef cf_command_key = create_CFString("Command"); + CFStringRef cf_client_options_key = create_CFString("ClientOptions"); + const void *keys_arr[] = { cf_command_key, cf_client_options_key }; + CFStringRef cf_browse_value = create_CFString("Browse"); + const void *values_arr[] = { cf_browse_value, clinet_opts_dict }; + CFDictionaryRef dict_command = CFDictionaryCreate(NULL, keys_arr, values_arr, 2, NULL, NULL); + + send_con_message(serviceInfo.connection, dict_command); + CFRelease(cf_bundle_id_key); + CFRelease(cf_config_key); + CFRelease(cf_return_attributes_array); + CFRelease(cf_app_type_key); + CFRelease(cf_return_attrs_key); + CFRelease(cf_user_value); + CFRelease(clinet_opts_dict); + CFRelease(cf_command_key); + CFRelease(cf_client_options_key); + CFRelease(cf_browse_value); + CFRelease(dict_command); std::vector livesync_app_infos; while (true) { - std::map dict = receive_message((SOCKET)socket); + std::map dict = receive_con_message(serviceInfo.connection); PRINT_ERROR_AND_RETURN_IF_FAILED_RESULT(dict.count(kErrorKey), boost::any_cast(dict[kErrorKey]).c_str(), device_identifier, method_id); if (dict.empty() || (dict.count(kStatusKey) && has_complete_status(dict))) { @@ -986,7 +977,6 @@ void get_application_infos(std::string device_identifier, std::string method_id) { std::map app_info = boost::any_cast>(list); json current_info = { - { "IceniumLiveSyncEnabled", app_info.count("IceniumLiveSyncEnabled") && boost::any_cast(app_info["IceniumLiveSyncEnabled"]) }, { "CFBundleIdentifier", app_info.count("CFBundleIdentifier") ? boost::any_cast(app_info["CFBundleIdentifier"]) : "" }, { "configuration", app_info.count("configuration") ? boost::any_cast(app_info["configuration"]) : ""}, }; @@ -1084,16 +1074,18 @@ void lookup_apps(std::string device_identifier, std::string method_id) void device_log(std::string device_identifier, std::string method_id) { - HANDLE socket = start_service(device_identifier, kSyslog, method_id); - if (!socket) + ServiceInfo serviceInfo = start_secure_service(device_identifier, kSyslog, method_id, true, false); + if (!serviceInfo.socket) { return; } char *buffer = new char[kDeviceLogBytesToRead]; int bytes_read; - while ((bytes_read = recv((SOCKET)socket, buffer, kDeviceLogBytesToRead, 0)) > 0) - { + + // inspired by: https://github.com/DerekSelander/mobdevim/blob/a457f119f1576b85e9f8f89be8713f018ee97f59/mobdevim/console.temp_caseinsensitive_rename.m#L27 + while ((bytes_read = AMDServiceConnectionReceive(serviceInfo.connection, buffer, kDeviceLogBytesToRead)) > 0) + { json message; message[kDeviceId] = device_identifier; message[kMessage] = std::string(buffer, bytes_read); @@ -1106,40 +1098,42 @@ void device_log(std::string device_identifier, std::string method_id) void post_notification(std::string device_identifier, PostNotificationInfo post_notification_info, std::string method_id) { - HANDLE handle = start_service(device_identifier, kNotificationProxy, method_id, true, true); - if (!handle) + ServiceInfo info = start_secure_service(device_identifier, kNotificationProxy, method_id, true, true); + if (!info.socket) { return; } - - if (!devices.count(device_identifier)) - { - print_error("Device not found", device_identifier, method_id, kAMDNotFoundError); - return; - } - - std::stringstream xml_command; - xml_command << "" - "" - "" - "" - "Command" - "" + post_notification_info.command_type + "" - "Name" - "" + post_notification_info.notification_name + "" - "ClientOptions" - "" - "" - ""; - - SOCKET socket = (SOCKET)handle; - send_message(xml_command.str().c_str(), socket); - print(json({ { kResponse, socket }, { kId, method_id }, { kDeviceId, device_identifier } })); + + CFStringRef cf_command_key = create_CFString("Command"); + CFStringRef cf_command_value = create_CFString(post_notification_info.command_type.c_str()); + CFStringRef cf_name_key = create_CFString("Name"); + CFStringRef cf_name_value = create_CFString(post_notification_info.notification_name.c_str()); + CFStringRef cf_client_options_key = create_CFString("ClientOptions"); + CFStringRef cf_client_options_value = create_CFString(""); + const void *keys_arr[] = { cf_command_key, cf_name_key, cf_client_options_key }; + const void *values_arr[] = { cf_command_value, cf_name_value, cf_client_options_value }; + CFDictionaryRef dict_command = CFDictionaryCreate(NULL, keys_arr, values_arr, 3, NULL, NULL); + + send_con_message(info.connection, dict_command); + CFRelease(cf_command_key); + CFRelease(cf_command_value); + CFRelease(cf_name_key); + CFRelease(cf_name_value); + CFRelease(cf_client_options_key); + CFRelease(cf_client_options_value); + CFRelease(dict_command); + + print(json({ { kResponse, info.connection_id }, { kId, method_id }, { kDeviceId, device_identifier } })); } void await_notification_response(std::string device_identifier, AwaitNotificationResponseInfo await_notification_response_info, std::string method_id) { - std::map response = receive_message(await_notification_response_info.socket, await_notification_response_info.timeout); + ServiceConnRef connection = serviceConnections[(int)await_notification_response_info.socket]; + std::string invalid_connection_error_message = "Invalid connectionId: " + std::to_string(await_notification_response_info.socket); + PRINT_ERROR_AND_RETURN_IF_FAILED_RESULT(connection == nullptr, invalid_connection_error_message.c_str(), device_identifier, method_id); + + ServiceInfo currentNotificationProxy = devices[device_identifier].services[kNotificationProxy]; + std::map response = receive_con_message(connection); if (response.size()) { PRINT_ERROR_AND_RETURN_IF_FAILED_RESULT(response.count(kErrorKey), boost::any_cast(response[kErrorKey]).c_str(), device_identifier, method_id); diff --git a/IOSDeviceLib/SocketHelper.cpp b/IOSDeviceLib/SocketHelper.cpp index 6c62454..b6995e9 100644 --- a/IOSDeviceLib/SocketHelper.cpp +++ b/IOSDeviceLib/SocketHelper.cpp @@ -3,10 +3,39 @@ #include "SocketHelper.h" #include "Constants.h" - +#include "Declarations.h" #include "PlistCpp/Plist.hpp" #include "PlistCpp/PlistDate.hpp" +std::mutex receive_con_message_mutex; +std::map receive_con_message(ServiceConnRef con) +{ + receive_con_message_mutex.lock(); + std::map dict; + char *buffer = new char[4]; + int bytes_read = AMDServiceConnectionReceive(con, buffer, 4); + if (bytes_read > 0) + { + unsigned long res = ntohl(*((unsigned long*)buffer)); + delete[] buffer; + buffer = new char[res]; + bytes_read = AMDServiceConnectionReceive(con, buffer, res); + if (bytes_read > 0) + { + Plist::readPlist(buffer, res, dict); + } + } + + delete[] buffer; + receive_con_message_mutex.unlock(); + return dict; +} + +long send_con_message(ServiceConnRef serviceConnection, CFDictionaryRef message) +{ + return AMDServiceConnectionSendMessage(serviceConnection, message, kCFPropertyListXMLFormat_v1_0); +} + int send_message(const char* message, SOCKET socket, long long length) { LengthEncodedMessage length_encoded_message = get_message_with_encoded_length(message, length); diff --git a/IOSDeviceLib/SocketHelper.h b/IOSDeviceLib/SocketHelper.h index 3927edd..93cc183 100644 --- a/IOSDeviceLib/SocketHelper.h +++ b/IOSDeviceLib/SocketHelper.h @@ -12,8 +12,10 @@ typedef unsigned long long SOCKET; #endif #ifndef _WIN32 + #include #include +#include #endif #include @@ -38,6 +40,8 @@ struct Utf16Message { LengthEncodedMessage get_message_with_encoded_length(const char* message, long long length = -1); int send_message(const char* message, SOCKET socket, long long length = -1); int send_message(std::string message, SOCKET socket, long long length = -1); +long send_con_message(HANDLE* serviceConnection, CFDictionaryRef message); +std::map receive_con_message(HANDLE* con); std::map receive_message(SOCKET socket, int timeout = 5); std::string receive_message_raw(SOCKET socket, int size = 1000); diff --git a/IOSDeviceLib/windows_impl.cpp b/IOSDeviceLib/windows_impl.cpp index 47d01b6..ead36c0 100644 --- a/IOSDeviceLib/windows_impl.cpp +++ b/IOSDeviceLib/windows_impl.cpp @@ -22,7 +22,7 @@ bool mount_image(std::string& device_identifier, std::string& image_path, std::s std::string image_signature_path = image_path + ".signature"; PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(!exists(image_signature_path), "Could not find developer disk image signature", device_identifier, method_id, false); - HANDLE mountFd = start_service(device_identifier, kMobileImageMounter, method_id); + HANDLE mountFd = start_secure_service(device_identifier, kMobileImageMounter, method_id); if (!mountFd) { return false; @@ -84,4 +84,4 @@ bool mount_image(std::string& device_identifier, std::string& image_path, std::s } } -#endif // _WIN32 \ No newline at end of file +#endif // _WIN32 From eea1931fa20713c2b2b877303fe8e62a1c83faba Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Thu, 15 Aug 2019 10:15:52 +0300 Subject: [PATCH 2/4] fix: support ios13 on Windows --- .../xcshareddata/IDEWorkspaceChecks.plist | 8 - IOSDeviceLib/Declarations.h | 26 ++- IOSDeviceLib/IOSDeviceLib.cpp | 12 +- IOSDeviceLib/SocketHelper.h | 2 +- IOSDeviceLib/windows_impl.cpp | 174 +++++++++--------- 5 files changed, 123 insertions(+), 99 deletions(-) delete mode 100644 IOSDeviceLib.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/IOSDeviceLib.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/IOSDeviceLib.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d9810..0000000 --- a/IOSDeviceLib.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEDidComputeMac32BitWarning - - - diff --git a/IOSDeviceLib/Declarations.h b/IOSDeviceLib/Declarations.h index c137e48..3a2054c 100644 --- a/IOSDeviceLib/Declarations.h +++ b/IOSDeviceLib/Declarations.h @@ -134,13 +134,27 @@ struct FileUploadData { #pragma region Dll_Type_Definitions -typedef unsigned(__cdecl *device_notification_subscribe_ptr)(void(*f)(const DevicePointer*), long, long, long, HANDLE*); #ifdef _WIN32 +typedef unsigned(__cdecl *device_notification_subscribe_ptr)(void(*f)(const DevicePointer*), long, long, long, HANDLE*); typedef void(__cdecl *run_loop_ptr)(); +typedef void* CFArrayRef; typedef void* CFStringRef; -typedef void* CFURLRef; typedef void* CFDictionaryRef; +typedef void* CFURLRef; +typedef void* CFPropertyListFormat; +extern CFPropertyListFormat kCFPropertyListXMLFormat_v1_0; +typedef void* CFSocketNativeHandle; +typedef unsigned(__cdecl *device_secure_start_service_ptr)(AMDeviceRef device, CFStringRef service_name, unsigned int *unknown, ServiceConnRef * handle); +typedef CFSocketNativeHandle(__cdecl *service_connection_get_socket_ptr)(ServiceConnRef con); +typedef long(__cdecl *service_connection_receive_ptr)(ServiceConnRef, void *, long); +typedef long(__cdecl *service_connection_send_message_ptr)(ServiceConnRef serviceConnection, CFDictionaryRef message, CFPropertyListFormat format); + +extern service_connection_send_message_ptr __AMDServiceConnectionSendMessage; +extern service_connection_receive_ptr __AMDServiceConnectionReceive; + +typedef unsigned(__cdecl *device_create_house_arrest_service_ptr)(const DeviceInfo*, CFStringRef identifier, void * unknown, AFCConnectionRef * handle); + typedef void*(__cdecl *device_copy_device_identifier)(const DeviceInfo*); typedef void*(__cdecl *device_copy_value)(const DeviceInfo*, CFStringRef, CFStringRef); 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)(); typedef unsigned(__cdecl *cfdictionary_get_count)(CFDictionaryRef); typedef void(__cdecl *cfdictionary_get_keys_and_values)(CFDictionaryRef, const void**, const void**); typedef CFStringRef(__cdecl *cfstring_create_with_cstring)(void*, const char*, unsigned); +typedef CFArrayRef(__cdecl *cfarray_create)(void*, const void**, long, void**); typedef unsigned(__cdecl *device_secure_operation_with_path)(int, const DeviceInfo*, CFURLRef, CFDictionaryRef, void(*f)(), int); typedef unsigned(__cdecl *device_secure_operation_with_bundle_id)(int, const DeviceInfo*, CFStringRef, int, void(*f)(), int); typedef void(__cdecl *cfrelease)(CFStringRef); @@ -183,8 +198,14 @@ typedef int(__cdecl *usb_mux_connect_by_port)(int, int, long long*); #pragma region Dll_Method_Definitions #ifdef _WIN32 +extern HINSTANCE mobile_device_dll; #define GET_IF_EXISTS(variable, type, dll, method_name) (variable ? variable : variable = (type)GetProcAddress(dll, method_name)) +#define AMDeviceSecureStartService GET_IF_EXISTS(__AMDeviceSecureStartService, device_secure_start_service_ptr, mobile_device_dll, "AMDeviceSecureStartService") +#define AMDServiceConnectionGetSocket GET_IF_EXISTS(__AMDServiceConnectionGetSocket, service_connection_get_socket_ptr, mobile_device_dll, "AMDServiceConnectionGetSocket") +#define AMDServiceConnectionReceive GET_IF_EXISTS(__AMDServiceConnectionReceive, service_connection_receive_ptr, mobile_device_dll, "AMDServiceConnectionReceive") +#define AMDServiceConnectionSendMessage GET_IF_EXISTS(__AMDServiceConnectionSendMessage, service_connection_send_message_ptr, mobile_device_dll, "AMDServiceConnectionSendMessage") +#define AMDeviceCreateHouseArrestService GET_IF_EXISTS(__AMDeviceCreateHouseArrestService, device_create_house_arrest_service_ptr, mobile_device_dll, "AMDeviceCreateHouseArrestService") #define AMDeviceNotificationSubscribe GET_IF_EXISTS(__AMDeviceNotificationSubscribe, device_notification_subscribe_ptr, mobile_device_dll, "AMDeviceNotificationSubscribe") #define AMDeviceCopyDeviceIdentifier GET_IF_EXISTS(__AMDeviceCopyDeviceIdentifier, device_copy_device_identifier, mobile_device_dll, "AMDeviceCopyDeviceIdentifier") #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*); #define CFDictionaryGetCount GET_IF_EXISTS(__CFDictionaryGetCount, cfdictionary_get_count, core_foundation_dll, "CFDictionaryGetCount") #define CFDictionaryGetKeysAndValues GET_IF_EXISTS(__CFDictionaryGetKeysAndValues, cfdictionary_get_keys_and_values, core_foundation_dll, "CFDictionaryGetKeysAndValues") #define CFStringCreateWithCString GET_IF_EXISTS(__CFStringCreateWithCString, cfstring_create_with_cstring, core_foundation_dll, "CFStringCreateWithCString") +#define CFArrayCreate GET_IF_EXISTS(__CFArrayCreate, cfarray_create, core_foundation_dll, "CFArrayCreate") #define CFURLCreateWithString GET_IF_EXISTS(__CFURLCreateWithString, cfurl_create_with_string, core_foundation_dll, "CFURLCreateWithString") #define CFDictionaryCreate GET_IF_EXISTS(__CFDictionaryCreate, cfdictionary_create, core_foundation_dll, "CFDictionaryCreate") #define CFRelease GET_IF_EXISTS(__CFRelease, cfrelease, core_foundation_dll, "CFRelease") diff --git a/IOSDeviceLib/IOSDeviceLib.cpp b/IOSDeviceLib/IOSDeviceLib.cpp index 72611dd..6d7c879 100644 --- a/IOSDeviceLib/IOSDeviceLib.cpp +++ b/IOSDeviceLib/IOSDeviceLib.cpp @@ -25,6 +25,7 @@ #ifdef _WIN32 #pragma region Dll_Variable_Definitions +CFPropertyListFormat kCFPropertyListXMLFormat_v1_0 = (CFPropertyListFormat)100; device_notification_subscribe_ptr __AMDeviceNotificationSubscribe; HINSTANCE mobile_device_dll; HINSTANCE core_foundation_dll; @@ -34,6 +35,11 @@ device_copy_value __AMDeviceCopyValue; device_start_service __AMDeviceStartService; device_uninstall_application __AMDeviceUninstallApplication; device_secure_operation_with_bundle_id __AMDeviceSecureUninstallApplication; +device_secure_start_service_ptr __AMDeviceSecureStartService; +service_connection_get_socket_ptr __AMDServiceConnectionGetSocket; +service_connection_receive_ptr __AMDServiceConnectionReceive; +service_connection_send_message_ptr __AMDServiceConnectionSendMessage; +device_create_house_arrest_service_ptr __AMDeviceCreateHouseArrestService; device_connection_operation __AMDeviceStartSession; device_connection_operation __AMDeviceStopSession; device_connection_operation __AMDeviceConnect; @@ -57,6 +63,7 @@ cf_get_concrete_type_id __CFDictionaryGetTypeID; cfdictionary_get_count __CFDictionaryGetCount; cfdictionary_get_keys_and_values __CFDictionaryGetKeysAndValues; cfstring_create_with_cstring __CFStringCreateWithCString; +cfarray_create __CFArrayCreate; cfurl_create_with_string __CFURLCreateWithString; cfdictionary_create __CFDictionaryCreate; cfrelease __CFRelease; @@ -365,7 +372,7 @@ std::mutex start_service_mutex; ServiceInfo start_secure_service(std::string device_identifier, const char* service_name, std::string method_id, bool should_log_error, bool skip_cache) { start_service_mutex.lock(); - ServiceInfo serviceInfoResult; + ServiceInfo serviceInfoResult = {}; if (!devices.count(device_identifier)) { if (should_log_error) @@ -454,10 +461,13 @@ AFCConnectionRef start_house_arrest(std::string device_identifier, const char* a HANDLE start_debug_server(std::string device_identifier, std::string ddi, std::string method_id) { ServiceInfo info = start_secure_service(device_identifier, kDebugServer, method_id, false, false); + // mount_image is not available on Windows +#ifndef _WIN32 if (!info.socket && mount_image(device_identifier, ddi, method_id)) { info = start_secure_service(device_identifier, kDebugServer, method_id, true, false); } +#endif return info.socket; } diff --git a/IOSDeviceLib/SocketHelper.h b/IOSDeviceLib/SocketHelper.h index 93cc183..1f4b2be 100644 --- a/IOSDeviceLib/SocketHelper.h +++ b/IOSDeviceLib/SocketHelper.h @@ -4,6 +4,7 @@ #include #include #include +typedef void* CFDictionaryRef; #pragma comment(lib, "Ws2_32.lib") #else @@ -22,7 +23,6 @@ typedef unsigned long long SOCKET; #include #include #include "PlistCpp/include/boost/any.hpp" - struct LengthEncodedMessage { char *message; size_t length; diff --git a/IOSDeviceLib/windows_impl.cpp b/IOSDeviceLib/windows_impl.cpp index ead36c0..b01418e 100644 --- a/IOSDeviceLib/windows_impl.cpp +++ b/IOSDeviceLib/windows_impl.cpp @@ -1,87 +1,87 @@ -#ifdef _WIN32 -#include "Declarations.h" -#include "Constants.h" -#include "FileHelper.h" -#include "Printing.h" -#include "SocketHelper.h" -#include "CommonFunctions.h" - -#include -#include -extern int __result; - -std::string get_signature_base64(std::string image_signature_path) -{ - FileInfo signature_file_info = get_file_info(image_signature_path, true); - return base64_encode(&signature_file_info.contents[0], signature_file_info.size); -} - -bool mount_image(std::string& device_identifier, std::string& image_path, std::string& method_id) -{ - PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(!exists(image_path), "Could not find developer disk image", device_identifier, method_id, false); - std::string image_signature_path = image_path + ".signature"; - PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(!exists(image_signature_path), "Could not find developer disk image signature", device_identifier, method_id, false); - - HANDLE mountFd = start_secure_service(device_identifier, kMobileImageMounter, method_id); - if (!mountFd) - { - return false; - } - - FileInfo image_file_info = get_file_info(image_path, false); - std::string signature_base64 = get_signature_base64(image_signature_path); - - std::stringstream xml_command; - int bytes_sent; - std::map dict; - xml_command << "" - "" - "" - "" - "Command" - "ReceiveBytes" - "ImageSize" - "" + std::to_string(image_file_info.size) + "" - "ImageType" - "Developer" - "ImageSignature" - "" + signature_base64 + "" - "" - ""; - - bytes_sent = send_message(xml_command.str().c_str(), (SOCKET)mountFd); - dict = receive_message((SOCKET)mountFd); - PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(dict.count(kErrorKey), boost::any_cast(dict[kErrorKey]).c_str(), device_identifier, method_id, false); - if (boost::any_cast(dict[kStatusKey]) == "ReceiveBytesAck") - { - image_file_info = get_file_info(image_path, true); - bytes_sent = send((SOCKET)mountFd, &image_file_info.contents[0], image_file_info.size, 0); - dict = receive_message((SOCKET)mountFd); - xml_command.str(""); - xml_command << "" - "" - "" - "" - "Command" - "MountImage" - "ImageType" - "Developer" - "ImageSignature" - "" + signature_base64 + "" - "ImagePath" - "/var/mobile/Media/PublicStaging/staging.dimage" - "" - ""; - bytes_sent = send_message(xml_command.str().c_str(), (SOCKET)mountFd); - dict = receive_message((SOCKET)mountFd); - PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(dict.count(kErrorKey), boost::any_cast(dict[kErrorKey]).c_str(), device_identifier, method_id, false); - return dict.count(kStatusKey) && has_complete_status(dict); - } - else - { - print_error("Could not transfer disk image", device_identifier, method_id, kUnexpectedError); - return false; - } -} - -#endif // _WIN32 +//#ifdef _WIN32 +//#include "Declarations.h" +//#include "Constants.h" +//#include "FileHelper.h" +//#include "Printing.h" +//#include "SocketHelper.h" +//#include "CommonFunctions.h" +// +//#include +//#include +//extern int __result; +// +//std::string get_signature_base64(std::string image_signature_path) +//{ +// FileInfo signature_file_info = get_file_info(image_signature_path, true); +// return base64_encode(&signature_file_info.contents[0], signature_file_info.size); +//} +// +//bool mount_image(std::string& device_identifier, std::string& image_path, std::string& method_id) +//{ +// PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(!exists(image_path), "Could not find developer disk image", device_identifier, method_id, false); +// std::string image_signature_path = image_path + ".signature"; +// PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(!exists(image_signature_path), "Could not find developer disk image signature", device_identifier, method_id, false); +// +// ServiceInfo serviceInfo = start_secure_service(device_identifier, kMobileImageMounter, method_id); +// if (!serviceInfo.socket) +// { +// return false; +// } +// +// FileInfo image_file_info = get_file_info(image_path, false); +// std::string signature_base64 = get_signature_base64(image_signature_path); +// +// std::stringstream xml_command; +// int bytes_sent; +// std::map dict; +// xml_command << "" +// "" +// "" +// "" +// "Command" +// "ReceiveBytes" +// "ImageSize" +// "" + std::to_string(image_file_info.size) + "" +// "ImageType" +// "Developer" +// "ImageSignature" +// "" + signature_base64 + "" +// "" +// ""; +// +// bytes_sent = send_message(xml_command.str().c_str(), (SOCKET)mountFd); +// dict = receive_message((SOCKET)mountFd); +// PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(dict.count(kErrorKey), boost::any_cast(dict[kErrorKey]).c_str(), device_identifier, method_id, false); +// if (boost::any_cast(dict[kStatusKey]) == "ReceiveBytesAck") +// { +// image_file_info = get_file_info(image_path, true); +// bytes_sent = send((SOCKET)mountFd, &image_file_info.contents[0], image_file_info.size, 0); +// dict = receive_message((SOCKET)mountFd); +// xml_command.str(""); +// xml_command << "" +// "" +// "" +// "" +// "Command" +// "MountImage" +// "ImageType" +// "Developer" +// "ImageSignature" +// "" + signature_base64 + "" +// "ImagePath" +// "/var/mobile/Media/PublicStaging/staging.dimage" +// "" +// ""; +// bytes_sent = send_message(xml_command.str().c_str(), (SOCKET)mountFd); +// dict = receive_message((SOCKET)mountFd); +// PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(dict.count(kErrorKey), boost::any_cast(dict[kErrorKey]).c_str(), device_identifier, method_id, false); +// return dict.count(kStatusKey) && has_complete_status(dict); +// } +// else +// { +// print_error("Could not transfer disk image", device_identifier, method_id, kUnexpectedError); +// return false; +// } +//} +// +//#endif // _WIN32 From 1959a1836dc740538ad9a9ba7dfea12494a78d7e Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Fri, 16 Aug 2019 08:43:00 +0300 Subject: [PATCH 3/4] chore: fix indentations --- IOSDeviceLib/Declarations.h | 19 ++- IOSDeviceLib/FileHelper.cpp | 20 +-- IOSDeviceLib/IOSDeviceLib.cpp | 234 +++++++++++++++++----------------- IOSDeviceLib/SocketHelper.h | 2 +- IOSDeviceLib/StringHelper.cpp | 42 +++--- 5 files changed, 157 insertions(+), 160 deletions(-) diff --git a/IOSDeviceLib/Declarations.h b/IOSDeviceLib/Declarations.h index 3a2054c..b6cf262 100644 --- a/IOSDeviceLib/Declarations.h +++ b/IOSDeviceLib/Declarations.h @@ -63,7 +63,6 @@ struct LiveSyncApplicationInfo { typedef unsigned long long afc_file_ref; - struct afc_connection { unsigned int handle; /* 0 */ unsigned int unknown0; /* 4 */ @@ -103,9 +102,9 @@ typedef HANDLE service_conn_t; typedef service_conn_t * ServiceConnRef; typedef struct DeviceInfo * AMDeviceRef; struct ServiceInfo { - HANDLE socket; - ServiceConnRef connection; - int connection_id; + HANDLE socket; + ServiceConnRef connection; + int connection_id; }; struct DeviceData { @@ -262,21 +261,19 @@ extern HINSTANCE mobile_device_dll; #include -// TODO: handle Windows - extern "C" { - CFSocketNativeHandle AMDServiceConnectionGetSocket(ServiceConnRef con); - long AMDServiceConnectionReceive(ServiceConnRef, void *, long); - long AMDServiceConnectionSendMessage(ServiceConnRef serviceConnection, CFDictionaryRef message, CFPropertyListFormat format); - unsigned AMDeviceSecureStartService(AMDeviceRef device, CFStringRef service_name, unsigned int *unknown, ServiceConnRef * handle); + CFSocketNativeHandle AMDServiceConnectionGetSocket(ServiceConnRef con); + long AMDServiceConnectionReceive(ServiceConnRef, void *, long); + long AMDServiceConnectionSendMessage(ServiceConnRef serviceConnection, CFDictionaryRef message, CFPropertyListFormat format); + unsigned AMDeviceSecureStartService(AMDeviceRef device, CFStringRef service_name, unsigned int *unknown, ServiceConnRef * handle); unsigned AMDeviceNotificationSubscribe(void(*f)(const DevicePointer*), long, long, long, HANDLE*); CFStringRef AMDeviceCopyDeviceIdentifier(const DeviceInfo*); CFStringRef AMDeviceCopyValue(const DeviceInfo*, CFStringRef, CFStringRef); unsigned AMDeviceMountImage(const DeviceInfo*, CFStringRef, CFDictionaryRef, void(*f)(void*, int), void*); unsigned AMDeviceStartService(const DeviceInfo*, CFStringRef, HANDLE*, void*); unsigned AMDeviceLookupApplications(const DeviceInfo*, CFDictionaryRef, CFDictionaryRef*); - unsigned AMDeviceCreateHouseArrestService(const DeviceInfo*, CFStringRef identifier, void * unknown, AFCConnectionRef * handle); + unsigned AMDeviceCreateHouseArrestService(const DeviceInfo*, CFStringRef identifier, void * unknown, AFCConnectionRef * handle); int AMDeviceGetConnectionID(const DeviceInfo*); int AMDeviceGetInterfaceType(const DeviceInfo*); unsigned AMDeviceUninstallApplication(HANDLE, CFStringRef, void*, void(*f)(), void*); diff --git a/IOSDeviceLib/FileHelper.cpp b/IOSDeviceLib/FileHelper.cpp index 8bad1d2..c0b5b51 100644 --- a/IOSDeviceLib/FileHelper.cpp +++ b/IOSDeviceLib/FileHelper.cpp @@ -29,19 +29,19 @@ FileInfo get_file_info(std::string& path, bool get_contents) std::vector buffer(size); file.read(buffer.data(), size); - if (buffer.size() == 0 && size == 0) - { - // We will get here if the file exists and it is empty. - buffer.push_back(""[0]); - } + if (buffer.size() == 0 && size == 0) + { + // We will get here if the file exists and it is empty. + buffer.push_back(""[0]); + } - result.contents = buffer; + result.contents = buffer; } } - else - { - return {-1}; - } + else + { + return {-1}; + } return result; } diff --git a/IOSDeviceLib/IOSDeviceLib.cpp b/IOSDeviceLib/IOSDeviceLib.cpp index 6d7c879..8d4fcef 100644 --- a/IOSDeviceLib/IOSDeviceLib.cpp +++ b/IOSDeviceLib/IOSDeviceLib.cpp @@ -134,7 +134,7 @@ int start_session(std::string& device_identifier) { const DeviceInfo* device_info = devices[device_identifier].device_info; UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT(AMDeviceConnect(device_info), start_session_mutex); - assert(AMDeviceIsPaired(device_info)); + assert(AMDeviceIsPaired(device_info)); UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT(AMDeviceValidatePairing(device_info), start_session_mutex); UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT(AMDeviceStartSession(device_info), start_session_mutex); } @@ -371,55 +371,55 @@ std::mutex start_service_mutex; ServiceInfo start_secure_service(std::string device_identifier, const char* service_name, std::string method_id, bool should_log_error, bool skip_cache) { - start_service_mutex.lock(); + start_service_mutex.lock(); ServiceInfo serviceInfoResult = {}; - if (!devices.count(device_identifier)) - { - if (should_log_error) - print_error("Device not found", device_identifier, method_id, kAMDNotFoundError); - - start_service_mutex.unlock(); - return serviceInfoResult; - } - - if (!skip_cache && devices[device_identifier].services.count(service_name)) - { - start_service_mutex.unlock(); - return devices[device_identifier].services[service_name]; - } - - PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(start_session(device_identifier), "Could not start device session", device_identifier, method_id, serviceInfoResult); - CFStringRef cf_service_name = create_CFString(service_name); - - ServiceConnRef connection; - unsigned result = AMDeviceSecureStartService(devices[device_identifier].device_info, cf_service_name, NULL, &connection); - service_conn_t socket = (void*)AMDServiceConnectionGetSocket(connection); - - stop_session(device_identifier); - CFRelease(cf_service_name); - if (result) - { - std::string message("Could not start service "); - message += service_name; - if (should_log_error) - print_error(message.c_str(), device_identifier, method_id, result); - - start_service_mutex.unlock(); - return serviceInfoResult; - } - - serviceInfoResult.socket = socket; - serviceInfoResult.connection = connection; - serviceInfoResult.connection_id = nextServiceConnectionId; - serviceConnections[nextServiceConnectionId] = connection; - nextServiceConnectionId++; - - if (!skip_cache) { - devices[device_identifier].services[service_name] = serviceInfoResult; - } - - start_service_mutex.unlock(); - return serviceInfoResult; + if (!devices.count(device_identifier)) + { + if (should_log_error) + print_error("Device not found", device_identifier, method_id, kAMDNotFoundError); + + start_service_mutex.unlock(); + return serviceInfoResult; + } + + if (!skip_cache && devices[device_identifier].services.count(service_name)) + { + start_service_mutex.unlock(); + return devices[device_identifier].services[service_name]; + } + + PRINT_ERROR_AND_RETURN_VALUE_IF_FAILED_RESULT(start_session(device_identifier), "Could not start device session", device_identifier, method_id, serviceInfoResult); + CFStringRef cf_service_name = create_CFString(service_name); + + ServiceConnRef connection; + unsigned result = AMDeviceSecureStartService(devices[device_identifier].device_info, cf_service_name, NULL, &connection); + service_conn_t socket = (void*)AMDServiceConnectionGetSocket(connection); + + stop_session(device_identifier); + CFRelease(cf_service_name); + if (result) + { + std::string message("Could not start service "); + message += service_name; + if (should_log_error) + print_error(message.c_str(), device_identifier, method_id, result); + + start_service_mutex.unlock(); + return serviceInfoResult; + } + + serviceInfoResult.socket = socket; + serviceInfoResult.connection = connection; + serviceInfoResult.connection_id = nextServiceConnectionId; + serviceConnections[nextServiceConnectionId] = connection; + nextServiceConnectionId++; + + if (!skip_cache) { + devices[device_identifier].services[service_name] = serviceInfoResult; + } + + start_service_mutex.unlock(); + return serviceInfoResult; } @@ -431,19 +431,19 @@ AFCConnectionRef start_house_arrest(std::string device_identifier, const char* a return NULL; } - AFCConnectionRef persistedHouseArrestService = devices[device_identifier].apps_cache[application_identifier].afc_connection; + AFCConnectionRef persistedHouseArrestService = devices[device_identifier].apps_cache[application_identifier].afc_connection; if (persistedHouseArrestService) { - return persistedHouseArrestService; + return persistedHouseArrestService; } AFCConnectionRef conn = NULL; start_session(device_identifier); CFStringRef cf_application_identifier = create_CFString(application_identifier); - unsigned result = AMDeviceCreateHouseArrestService(devices[device_identifier].device_info, cf_application_identifier, 0, &conn); - + unsigned result = AMDeviceCreateHouseArrestService(devices[device_identifier].device_info, cf_application_identifier, 0, &conn); + stop_session(device_identifier); - CFRelease(cf_application_identifier); + CFRelease(cf_application_identifier); if (result) { @@ -454,7 +454,7 @@ AFCConnectionRef start_house_arrest(std::string device_identifier, const char* a } devices[device_identifier].apps_cache[application_identifier].afc_connection = conn; - + return conn; } @@ -479,7 +479,7 @@ AFCConnectionRef get_afc_connection(std::string& device_identifier, const char* return devices[device_identifier].apps_cache[application_identifier].afc_connection; } - + AFCConnectionRef con_ref = start_house_arrest(device_identifier, application_identifier, method_id); if (!con_ref) { @@ -931,40 +931,40 @@ void get_application_infos(std::string device_identifier, std::string method_id) { return; } - - CFStringRef cf_bundle_id_key = create_CFString("CFBundleIdentifier"); - CFStringRef cf_config_key = create_CFString("configuration"); - const void* cf_return_attributes[] = { cf_bundle_id_key, cf_config_key }; - const CFArrayRef cf_return_attributes_array = CFArrayCreate(NULL, cf_return_attributes, 2, NULL); - - CFStringRef cf_app_type_key = create_CFString("ApplicationType"); - CFStringRef cf_return_attrs_key = create_CFString("ReturnAttributes"); - const void *client_opts_keys_arr[] = { cf_app_type_key, cf_return_attrs_key }; - - - CFStringRef cf_user_value = create_CFString("User"); - const void *client_opts_values_arr[] = { cf_user_value, cf_return_attributes_array }; - CFDictionaryRef clinet_opts_dict = CFDictionaryCreate(NULL, client_opts_keys_arr, client_opts_values_arr, 2, NULL, NULL); - - CFStringRef cf_command_key = create_CFString("Command"); - CFStringRef cf_client_options_key = create_CFString("ClientOptions"); - const void *keys_arr[] = { cf_command_key, cf_client_options_key }; - CFStringRef cf_browse_value = create_CFString("Browse"); - const void *values_arr[] = { cf_browse_value, clinet_opts_dict }; - CFDictionaryRef dict_command = CFDictionaryCreate(NULL, keys_arr, values_arr, 2, NULL, NULL); + + CFStringRef cf_bundle_id_key = create_CFString("CFBundleIdentifier"); + CFStringRef cf_config_key = create_CFString("configuration"); + const void* cf_return_attributes[] = { cf_bundle_id_key, cf_config_key }; + const CFArrayRef cf_return_attributes_array = CFArrayCreate(NULL, cf_return_attributes, 2, NULL); + + CFStringRef cf_app_type_key = create_CFString("ApplicationType"); + CFStringRef cf_return_attrs_key = create_CFString("ReturnAttributes"); + const void *client_opts_keys_arr[] = { cf_app_type_key, cf_return_attrs_key }; + + + CFStringRef cf_user_value = create_CFString("User"); + const void *client_opts_values_arr[] = { cf_user_value, cf_return_attributes_array }; + CFDictionaryRef clinet_opts_dict = CFDictionaryCreate(NULL, client_opts_keys_arr, client_opts_values_arr, 2, NULL, NULL); + + CFStringRef cf_command_key = create_CFString("Command"); + CFStringRef cf_client_options_key = create_CFString("ClientOptions"); + const void *keys_arr[] = { cf_command_key, cf_client_options_key }; + CFStringRef cf_browse_value = create_CFString("Browse"); + const void *values_arr[] = { cf_browse_value, clinet_opts_dict }; + CFDictionaryRef dict_command = CFDictionaryCreate(NULL, keys_arr, values_arr, 2, NULL, NULL); send_con_message(serviceInfo.connection, dict_command); - CFRelease(cf_bundle_id_key); - CFRelease(cf_config_key); - CFRelease(cf_return_attributes_array); - CFRelease(cf_app_type_key); - CFRelease(cf_return_attrs_key); - CFRelease(cf_user_value); - CFRelease(clinet_opts_dict); - CFRelease(cf_command_key); - CFRelease(cf_client_options_key); - CFRelease(cf_browse_value); - CFRelease(dict_command); + CFRelease(cf_bundle_id_key); + CFRelease(cf_config_key); + CFRelease(cf_return_attributes_array); + CFRelease(cf_app_type_key); + CFRelease(cf_return_attrs_key); + CFRelease(cf_user_value); + CFRelease(clinet_opts_dict); + CFRelease(cf_command_key); + CFRelease(cf_client_options_key); + CFRelease(cf_browse_value); + CFRelease(dict_command); std::vector livesync_app_infos; while (true) @@ -1092,10 +1092,10 @@ void device_log(std::string device_identifier, std::string method_id) char *buffer = new char[kDeviceLogBytesToRead]; int bytes_read; - - // inspired by: https://github.com/DerekSelander/mobdevim/blob/a457f119f1576b85e9f8f89be8713f018ee97f59/mobdevim/console.temp_caseinsensitive_rename.m#L27 + + // inspired by: https://github.com/DerekSelander/mobdevim/blob/a457f119f1576b85e9f8f89be8713f018ee97f59/mobdevim/console.temp_caseinsensitive_rename.m#L27 while ((bytes_read = AMDServiceConnectionReceive(serviceInfo.connection, buffer, kDeviceLogBytesToRead)) > 0) - { + { json message; message[kDeviceId] = device_identifier; message[kMessage] = std::string(buffer, bytes_read); @@ -1108,41 +1108,41 @@ void device_log(std::string device_identifier, std::string method_id) void post_notification(std::string device_identifier, PostNotificationInfo post_notification_info, std::string method_id) { - ServiceInfo info = start_secure_service(device_identifier, kNotificationProxy, method_id, true, true); + ServiceInfo info = start_secure_service(device_identifier, kNotificationProxy, method_id, true, true); if (!info.socket) { return; } - - CFStringRef cf_command_key = create_CFString("Command"); - CFStringRef cf_command_value = create_CFString(post_notification_info.command_type.c_str()); - CFStringRef cf_name_key = create_CFString("Name"); - CFStringRef cf_name_value = create_CFString(post_notification_info.notification_name.c_str()); - CFStringRef cf_client_options_key = create_CFString("ClientOptions"); - CFStringRef cf_client_options_value = create_CFString(""); - const void *keys_arr[] = { cf_command_key, cf_name_key, cf_client_options_key }; - const void *values_arr[] = { cf_command_value, cf_name_value, cf_client_options_value }; - CFDictionaryRef dict_command = CFDictionaryCreate(NULL, keys_arr, values_arr, 3, NULL, NULL); - - send_con_message(info.connection, dict_command); - CFRelease(cf_command_key); - CFRelease(cf_command_value); - CFRelease(cf_name_key); - CFRelease(cf_name_value); - CFRelease(cf_client_options_key); - CFRelease(cf_client_options_value); - CFRelease(dict_command); - + + CFStringRef cf_command_key = create_CFString("Command"); + CFStringRef cf_command_value = create_CFString(post_notification_info.command_type.c_str()); + CFStringRef cf_name_key = create_CFString("Name"); + CFStringRef cf_name_value = create_CFString(post_notification_info.notification_name.c_str()); + CFStringRef cf_client_options_key = create_CFString("ClientOptions"); + CFStringRef cf_client_options_value = create_CFString(""); + const void *keys_arr[] = { cf_command_key, cf_name_key, cf_client_options_key }; + const void *values_arr[] = { cf_command_value, cf_name_value, cf_client_options_value }; + CFDictionaryRef dict_command = CFDictionaryCreate(NULL, keys_arr, values_arr, 3, NULL, NULL); + + send_con_message(info.connection, dict_command); + CFRelease(cf_command_key); + CFRelease(cf_command_value); + CFRelease(cf_name_key); + CFRelease(cf_name_value); + CFRelease(cf_client_options_key); + CFRelease(cf_client_options_value); + CFRelease(dict_command); + print(json({ { kResponse, info.connection_id }, { kId, method_id }, { kDeviceId, device_identifier } })); } void await_notification_response(std::string device_identifier, AwaitNotificationResponseInfo await_notification_response_info, std::string method_id) { - ServiceConnRef connection = serviceConnections[(int)await_notification_response_info.socket]; - std::string invalid_connection_error_message = "Invalid connectionId: " + std::to_string(await_notification_response_info.socket); - PRINT_ERROR_AND_RETURN_IF_FAILED_RESULT(connection == nullptr, invalid_connection_error_message.c_str(), device_identifier, method_id); - - ServiceInfo currentNotificationProxy = devices[device_identifier].services[kNotificationProxy]; + ServiceConnRef connection = serviceConnections[(int)await_notification_response_info.socket]; + std::string invalid_connection_error_message = "Invalid connectionId: " + std::to_string(await_notification_response_info.socket); + PRINT_ERROR_AND_RETURN_IF_FAILED_RESULT(connection == nullptr, invalid_connection_error_message.c_str(), device_identifier, method_id); + + ServiceInfo currentNotificationProxy = devices[device_identifier].services[kNotificationProxy]; std::map response = receive_con_message(connection); if (response.size()) { diff --git a/IOSDeviceLib/SocketHelper.h b/IOSDeviceLib/SocketHelper.h index 1f4b2be..f0edb6f 100644 --- a/IOSDeviceLib/SocketHelper.h +++ b/IOSDeviceLib/SocketHelper.h @@ -34,7 +34,7 @@ struct LengthEncodedMessage { }; struct Utf16Message { - std::string message; + std::string message; }; LengthEncodedMessage get_message_with_encoded_length(const char* message, long long length = -1); diff --git a/IOSDeviceLib/StringHelper.cpp b/IOSDeviceLib/StringHelper.cpp index 53533a2..5790ec4 100644 --- a/IOSDeviceLib/StringHelper.cpp +++ b/IOSDeviceLib/StringHelper.cpp @@ -30,39 +30,39 @@ bool starts_with(const std::string& str, const std::string& prefix) std::string trim_end(std::string &str) { - str.erase(std::find_if(str.rbegin(), str.rend(), - std::not1(std::ptr_fun(std::isspace))).base(), str.end()); - return str; + str.erase(std::find_if(str.rbegin(), str.rend(), + std::not1(std::ptr_fun(std::isspace))).base(), str.end()); + return str; } void split(const std::string &s, char delim, std::vector &elems) { - std::stringstream ss; - ss.str(s); - std::string item; - while (std::getline(ss, item, delim)) - { - elems.push_back(item); - } + std::stringstream ss; + ss.str(s); + std::string item; + while (std::getline(ss, item, delim)) + { + elems.push_back(item); + } } std::vector split(const std::string &s, char delim) { - std::vector elems; - split(s, delim, elems); - return elems; + std::vector elems; + split(s, delim, elems); + return elems; } void replace_all(std::string& str, const std::string& from, const std::string& to) { - if (from.empty()) - return; - size_t start_pos = 0; - while ((start_pos = str.find(from, start_pos)) != std::string::npos) - { - str.replace(start_pos, from.length(), to); - start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx' - } + if (from.empty()) + return; + size_t start_pos = 0; + while ((start_pos = str.find(from, start_pos)) != std::string::npos) + { + str.replace(start_pos, from.length(), to); + start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx' + } } std::string url_encode_without_forward_slash_and_colon(const std::string &value) { From 71e6b600392a0efea0ffbbffbf36608cc24ae5b4 Mon Sep 17 00:00:00 2001 From: Dimitar Tachev Date: Fri, 16 Aug 2019 09:11:44 +0300 Subject: [PATCH 4/4] refactor: handle PR comments Co-Authored-By: Rosen Vladimirov --- IOSDeviceLib/IOSDeviceLib.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/IOSDeviceLib/IOSDeviceLib.cpp b/IOSDeviceLib/IOSDeviceLib.cpp index 8d4fcef..1c0db62 100644 --- a/IOSDeviceLib/IOSDeviceLib.cpp +++ b/IOSDeviceLib/IOSDeviceLib.cpp @@ -134,7 +134,6 @@ int start_session(std::string& device_identifier) { const DeviceInfo* device_info = devices[device_identifier].device_info; UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT(AMDeviceConnect(device_info), start_session_mutex); - assert(AMDeviceIsPaired(device_info)); UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT(AMDeviceValidatePairing(device_info), start_session_mutex); UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT(AMDeviceStartSession(device_info), start_session_mutex); } @@ -941,16 +940,15 @@ void get_application_infos(std::string device_identifier, std::string method_id) CFStringRef cf_return_attrs_key = create_CFString("ReturnAttributes"); const void *client_opts_keys_arr[] = { cf_app_type_key, cf_return_attrs_key }; - - CFStringRef cf_user_value = create_CFString("User"); - const void *client_opts_values_arr[] = { cf_user_value, cf_return_attributes_array }; + CFStringRef cf_app_type_value = create_CFString("User"); + const void *client_opts_values_arr[] = { cf_app_type_value, cf_return_attributes_array }; CFDictionaryRef clinet_opts_dict = CFDictionaryCreate(NULL, client_opts_keys_arr, client_opts_values_arr, 2, NULL, NULL); CFStringRef cf_command_key = create_CFString("Command"); CFStringRef cf_client_options_key = create_CFString("ClientOptions"); const void *keys_arr[] = { cf_command_key, cf_client_options_key }; - CFStringRef cf_browse_value = create_CFString("Browse"); - const void *values_arr[] = { cf_browse_value, clinet_opts_dict }; + CFStringRef cf_command_value = create_CFString("Browse"); + const void *values_arr[] = { cf_command_value, clinet_opts_dict }; CFDictionaryRef dict_command = CFDictionaryCreate(NULL, keys_arr, values_arr, 2, NULL, NULL); send_con_message(serviceInfo.connection, dict_command); @@ -959,11 +957,11 @@ void get_application_infos(std::string device_identifier, std::string method_id) CFRelease(cf_return_attributes_array); CFRelease(cf_app_type_key); CFRelease(cf_return_attrs_key); - CFRelease(cf_user_value); + CFRelease(cf_app_type_value); CFRelease(clinet_opts_dict); CFRelease(cf_command_key); CFRelease(cf_client_options_key); - CFRelease(cf_browse_value); + CFRelease(cf_command_value); CFRelease(dict_command); std::vector livesync_app_infos;