Skip to content

Instantly share code, notes, and snippets.

@nikias
Created June 9, 2017 12:29
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikias/b351bf633d62703e0ff4f2fee9628401 to your computer and use it in GitHub Desktop.
Save nikias/b351bf633d62703e0ff4f2fee9628401 to your computer and use it in GitHub Desktop.
diff --git a/src/idevice.c b/src/idevice.c
index 21b10ba..ead9b86 100644
--- a/src/idevice.c
+++ b/src/idevice.c
@@ -256,6 +256,7 @@ LIBIMOBILEDEVICE_API idevice_error_t idevice_new(idevice_t * device, const char
dev->udid = strdup(muxdev.udid);
dev->conn_type = CONNECTION_USBMUXD;
dev->conn_data = (void*)(long)muxdev.handle;
+ dev->version = 0;
*device = dev;
return IDEVICE_E_SUCCESS;
}
diff --git a/src/idevice.h b/src/idevice.h
index 1354cc0..e46a7e5 100644
--- a/src/idevice.h
+++ b/src/idevice.h
@@ -76,6 +76,7 @@ struct idevice_private {
char *udid;
enum connection_type conn_type;
void *conn_data;
+ int version;
};
#endif
diff --git a/src/lockdown.c b/src/lockdown.c
index 5251737..071697d 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -707,6 +707,19 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new_with_handshake(idevi
}
free(type);
+ if (device->version == 0) {
+ plist_t p_version = NULL;
+ if (lockdownd_get_value(client_loc, NULL, "ProductVersion", &p_version) == LOCKDOWN_E_SUCCESS) {
+ int vers[3] = {0, 0, 0};
+ char *s_version = NULL;
+ plist_get_string_val(p_version, &s_version);
+ if (s_version && sscanf(s_version, "%d.%d.%d", &vers[0], &vers[1], &vers[2]) >= 2) {
+ device->version = ((vers[0] & 0xFF) << 16) | ((vers[1] & 0xFF) << 8) | (vers[2] & 0xFF);
+ }
+ free(s_version);
+ }
+ }
+
userpref_read_pair_record(client_loc->udid, &pair_record);
if (pair_record) {
pair_record_get_host_id(pair_record, &host_id);
@@ -723,18 +736,18 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new_with_handshake(idevi
plist_free(pair_record);
pair_record = NULL;
- /* in any case, we need to validate pairing to receive trusted host status */
- ret = lockdownd_validate_pair(client_loc, NULL);
-
- /* if not paired yet, let's do it now */
- if (LOCKDOWN_E_INVALID_HOST_ID == ret) {
- free(host_id);
- host_id = NULL;
- ret = lockdownd_pair(client_loc, NULL);
- if (LOCKDOWN_E_SUCCESS == ret) {
- ret = lockdownd_validate_pair(client_loc, NULL);
- } else if (LOCKDOWN_E_PAIRING_DIALOG_RESPONSE_PENDING == ret) {
- debug_info("Device shows the pairing dialog.");
+ if (device->version < 0x070000) {
+ /* for older devices, we need to validate pairing to receive trusted host status */
+ ret = lockdownd_validate_pair(client_loc, NULL);
+
+ /* if not paired yet, let's do it now */
+ if (LOCKDOWN_E_INVALID_HOST_ID == ret) {
+ free(host_id);
+ host_id = NULL;
+ ret = lockdownd_pair(client_loc, NULL);
+ if (LOCKDOWN_E_SUCCESS == ret) {
+ ret = lockdownd_validate_pair(client_loc, NULL);
+ }
}
}
@krukow
Copy link

krukow commented Jun 11, 2017

❤️

@kamstrup
Copy link

kamstrup commented Aug 7, 2017

Are there any plans on putting this on master? I've been using it locally and everything seems to work both on iOS 11, and older devices.

@SamyQAZ
Copy link

SamyQAZ commented Jan 10, 2018

💯 👍

@fi78
Copy link

fi78 commented Mar 22, 2018

This patch is already upstream since 2017-08-13:

libimobiledevice/libimobiledevice@5a85432

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment