Skip to content

Commit e5e472d

Browse files
committed
fix: use the secure uninstall application (the old one is not working on wifi devices)
1 parent d818a3f commit e5e472d

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

IOSDeviceLib/Constants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static const unsigned kCFStringEncodingUTF8 = 0x08000100;
2424
static const unsigned kAMDNotFoundError = 0xe8000008;
2525
static const unsigned kAMDAPIInternalError = 0xe8000067;
2626
static const int kUSBInterfaceType = 1;
27+
static const int kWIFIInterfaceType = 2;
2728
static const unsigned kAppleServiceNotStartedErrorCode = 0xE8000063;
2829
static const unsigned kMountImageAlreadyMounted = 0xE8000076; // Note: This error code is actually named kAMDMobileImageMounterImageMountFailed but AppBuilder CLI and other sources think that getting this exit code during a mount is okay
2930
static const unsigned kIncompatibleSignature = 0xE8000033; // Note: This error code is actually named kAMDInvalidDiskImageError but CLI and other sources think that getting this exit code during a mount is okay
@@ -69,6 +70,7 @@ static const char *kResponseCommandType = "responseCommandType";
6970
static const char *kResponsePropertyName = "responsePropertyName";
7071
static const char *kShouldWaitForResponse = "shouldWaitForResponse";
7172
static const char *kCommandType = "commandType";
73+
static const char *kConnectionType = "connectionType";
7274
static const char *kTimeout = "timeout";
7375
static const char *kPort = "port";
7476
static const char *kHost = "host";

IOSDeviceLib/Declarations.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ typedef void(__cdecl *cfdictionary_get_keys_and_values)(CFDictionaryRef, const v
168168
typedef CFStringRef(__cdecl *cfstring_create_with_cstring)(void*, const char*, unsigned);
169169
typedef CFArrayRef(__cdecl *cfarray_create)(void*, const void**, long, void**);
170170
typedef unsigned(__cdecl *device_secure_operation_with_path)(int, const DeviceInfo*, CFURLRef, CFDictionaryRef, void(*f)(), int);
171-
typedef unsigned(__cdecl *device_secure_operation_with_bundle_id)(int, const DeviceInfo*, CFStringRef, int, void(*f)(), int);
171+
typedef unsigned(__cdecl *device_secure_operation_with_bundle_id)(ServiceConnRef connection, const DeviceInfo*, CFStringRef *bundleIdentifier, CFDictionaryRef *params, void (*installCallback)(CFDictionaryRef*, void *));
172172
typedef void(__cdecl *cfrelease)(CFStringRef);
173173

174174
typedef CFDictionaryRef(__cdecl *cfdictionary_create)(void *, void*, void*, int, void*, void*);
@@ -276,8 +276,8 @@ extern "C"
276276
unsigned AMDeviceCreateHouseArrestService(const DeviceInfo*, CFStringRef identifier, void * unknown, AFCConnectionRef * handle);
277277
int AMDeviceGetConnectionID(const DeviceInfo*);
278278
int AMDeviceGetInterfaceType(const DeviceInfo*);
279+
unsigned AMDeviceSecureUninstallApplication(ServiceConnRef connection, const DeviceInfo*, CFStringRef bundleIdentifier, CFDictionaryRef params, void (*installCallback)(CFDictionaryRef*, void *));
279280
unsigned AMDeviceUninstallApplication(HANDLE, CFStringRef, void*, void(*f)(), void*);
280-
unsigned AMDeviceSecureUninstallApplication(int, const DeviceInfo*, CFStringRef, int, void(*f)(), int);
281281
unsigned AMDeviceStartSession(const DeviceInfo*);
282282
unsigned AMDeviceStopSession(const DeviceInfo*);
283283
unsigned AMDeviceConnect(const DeviceInfo*);

IOSDeviceLib/IOSDeviceLib.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ int start_session(std::string& device_identifier)
134134
{
135135
const DeviceInfo* device_info = devices[device_identifier].device_info;
136136
UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT(AMDeviceConnect(device_info), start_session_mutex);
137+
assert(AMDeviceIsPaired(device_info));
137138
UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT(AMDeviceValidatePairing(device_info), start_session_mutex);
138139
UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT(AMDeviceStartSession(device_info), start_session_mutex);
139140
}
@@ -242,6 +243,10 @@ void get_device_properties(std::string device_identifier, json &result)
242243
result["deviceName"] = get_device_property_value(device_identifier, "DeviceName");
243244
result["productVersion"] = get_device_property_value(device_identifier, kProductVersion);
244245
result["deviceColor"] = get_device_property_value(device_identifier, "DeviceColor");
246+
// available values:
247+
// "BluetoothAddress","BoardId","CPUArchitecture","ChipID","DeviceClass",
248+
// "DeviceColor","DeviceName","FirmwareVersion","HardwareModel",
249+
// "ModelNumber","ProductType","ProductVersion","UniqueDeviceID","WiFiAddress"
245250
}
246251

247252
inline bool has_complete_status(std::map<std::string, boost::any>& dict)
@@ -259,11 +264,12 @@ void on_device_found(const DevicePointer* device_ptr, std::string device_identif
259264
2 - wifi interface type
260265
*/
261266
int interface_type = AMDeviceGetInterfaceType(device_ptr->device_info);
262-
if (interface_type == kUSBInterfaceType) {
267+
if (interface_type == kUSBInterfaceType || interface_type == kWIFIInterfaceType) {
263268
devices[device_identifier] = { device_ptr->device_info, nullptr };
264269
result[kEventString] = eventString;
270+
result[kConnectionType] = interface_type;
265271
get_device_properties(device_identifier, result);
266-
}
272+
}
267273
}
268274

269275
void device_notification_callback(const DevicePointer* device_ptr)
@@ -497,14 +503,16 @@ void uninstall_application(std::string application_identifier, std::string devic
497503
return;
498504
}
499505

500-
HANDLE socket = start_secure_service(device_identifier, kInstallationProxy, method_id, true, false).socket;
501-
if (!socket)
506+
ServiceInfo serviceInfo = start_secure_service(device_identifier, kInstallationProxy, method_id, true, false);
507+
if (!serviceInfo.socket)
502508
{
503509
return;
504510
}
505511

506512
CFStringRef appid_cfstring = create_CFString(application_identifier.c_str());
507-
unsigned result = AMDeviceUninstallApplication(socket, appid_cfstring, NULL, [] {}, NULL);
513+
DeviceInfo* deviceInfo = devices[device_identifier].device_info;
514+
CFDictionaryRef params = CFDictionaryCreate(NULL, {}, {}, 0, NULL, NULL);
515+
unsigned result = AMDeviceSecureUninstallApplication(serviceInfo.connection, deviceInfo, appid_cfstring, params, NULL);
508516
CFRelease(appid_cfstring);
509517

510518
if (result)
@@ -1137,7 +1145,7 @@ void post_notification(std::string device_identifier, PostNotificationInfo post_
11371145
void await_notification_response(std::string device_identifier, AwaitNotificationResponseInfo await_notification_response_info, std::string method_id)
11381146
{
11391147
ServiceConnRef connection = serviceConnections[(int)await_notification_response_info.socket];
1140-
std::string invalid_connection_error_message = "Invalid connectionId: " + std::to_string(await_notification_response_info.socket);
1148+
std::string invalid_connection_error_message = "Invalid socket: " + std::to_string(await_notification_response_info.socket);
11411149
PRINT_ERROR_AND_RETURN_IF_FAILED_RESULT(connection == nullptr, invalid_connection_error_message.c_str(), device_identifier, method_id);
11421150

11431151
ServiceInfo currentNotificationProxy = devices[device_identifier].services[kNotificationProxy];

typings/interfaces.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ declare global {
1010
productType?: string;
1111
productVersion?: string;
1212
status?: string;
13+
connectionType: number;
1314
}
1415

1516
interface IDeviceId {

0 commit comments

Comments
 (0)