Skip to content

Commit 2b47e3d

Browse files
authored
Merge pull request #217 from google/ios11_support
iOS11 support
2 parents 55d0a95 + 9157f7b commit 2b47e3d

File tree

8 files changed

+53
-23
lines changed

8 files changed

+53
-23
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@ Please upgrade libimobiledevice to version from master and rebuild ios-webkit-de
181181
brew reinstall --HEAD libimobiledevice
182182
brew reinstall -s ios-webkit-debug-proxy
183183

184+
##### iOS 11
185+
> Could not connect to lockdown. Exiting.: Resource temporarily unavailable
186+
187+
You would need to rebuild libimobiledevice with proposed [patch](https://gist.github.com/nikias/b351bf633d62703e0ff4f2fee9628401), for details follow the https://github.com/libimobiledevice/libimobiledevice/issues/510
188+
189+
> Unable to connect to XXX
190+
> Please verify that Settings > Safari > Advanced > Web Inspector = ON
191+
192+
Build from master `brew reinstall --HEAD ios-webkit-debug-proxy`
193+
184194
##### Can not see Simulator
185195

186196
- Make sure you started simulator before the proxy
@@ -190,6 +200,7 @@ Please upgrade libimobiledevice to version from master and rebuild ios-webkit-de
190200
##### If no luck so far...
191201
Lastly, always try replugging in the USB cable.
192202

203+
193204
## IWDP Clients
194205

195206
JSON-formatted APIs are provided for programmatic clients.
@@ -213,5 +224,5 @@ Copyright 2012 Google Inc. <[email protected]>
213224
The proxy uses the following open-source packages:
214225
- [libplist 1.10](http://cgit.sukimashita.com/libplist.git)
215226
- [libusbmuxd 1.0.8](http://cgit.sukimashita.com/usbmuxd.git/)
216-
- [libimobiledevice 1.1.5](http://cgit.sukimashita.com/libimobiledevice.git)
217-
- libimobiledevice 1.2.1 _if your taget iOS10+_
227+
- [libimobiledevice 1.2.0](http://cgit.sukimashita.com/libimobiledevice.git)
228+
- libimobiledevice 1.2.1 _if your target iOS10+_

examples/wi_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ int main(int argc, char **argv) {
103103
// connect to device
104104
char *device_id2 = NULL;
105105
int recv_timeout = 1000;
106-
int fd = wi_connect(device_id, &device_id2, NULL, recv_timeout);
106+
int fd = wi_connect(device_id, &device_id2, NULL, NULL, recv_timeout);
107107
if (fd < 0) {
108108
return -1;
109109
}

include/ios-webkit-debug-proxy/ios_webkit_debug_proxy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct iwdp_struct {
6868
// @param to_device_name optional selected device name
6969
// @result fd, or -1 for error
7070
int (*attach)(iwdp_t iwdp, const char *device_id, char **to_device_id,
71-
char **to_device_name);
71+
char **to_device_name, int *to_device_version);
7272

7373
// Select the port-scan range for the browser listener.
7474
// @param to_port preferred port, e.g. 9227. If a device is re-attached

include/ios-webkit-debug-proxy/webinspector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ typedef uint8_t wi_status;
3333
// positive for milliseconds.
3434
// @result fd, or -1 for error
3535
int wi_connect(const char *device_id, char **to_device_id,
36-
char **to_device_name, int recv_timeout);
36+
char **to_device_name, int *to_device_version, int recv_timeout);
3737

3838
struct wi_struct;
3939
typedef struct wi_struct *wi_t;
40-
wi_t wi_new(bool is_sim);
40+
wi_t wi_new(bool partials_supported);
4141
void wi_free(wi_t self);
4242

4343
struct wi_private;

src/ios_webkit_debug_proxy.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ struct iwdp_iwi_struct {
128128
ht_t page_num_to_ipage;
129129
};
130130

131-
iwdp_iwi_t iwdp_iwi_new(bool is_sim, bool *is_debug);
131+
iwdp_iwi_t iwdp_iwi_new(bool partials_supported, bool *is_debug);
132132
void iwdp_iwi_free(iwdp_iwi_t iwi);
133133

134134
struct iwdp_ifs_struct;
@@ -404,6 +404,7 @@ dl_status iwdp_on_attach(dl_t dl, const char *device_id, int device_num) {
404404
return DL_SUCCESS;
405405
}
406406
char *device_name = iport->device_name;
407+
int device_version = 0;
407408

408409
// connect to inspector
409410
int wi_fd;
@@ -420,7 +421,7 @@ dl_status iwdp_on_attach(dl_t dl, const char *device_id, int device_num) {
420421
wi_fd = self->connect(self, "localhost", 27753);
421422
} else {
422423
wi_fd = self->attach(self, device_id, NULL,
423-
(device_name ? NULL : &device_name));
424+
(device_name ? NULL : &device_name), &device_version);
424425
}
425426
if (wi_fd < 0) {
426427
self->remove_fd(self, iport->s_fd);
@@ -430,7 +431,8 @@ dl_status iwdp_on_attach(dl_t dl, const char *device_id, int device_num) {
430431
return DL_SUCCESS;
431432
}
432433
iport->device_name = (device_name ? device_name : strdup(device_id));
433-
iwdp_iwi_t iwi = iwdp_iwi_new(is_sim, self->is_debug);
434+
iwdp_iwi_t iwi = iwdp_iwi_new(!is_sim && device_version < 0xb0000,
435+
self->is_debug);
434436
iwi->iport = iport;
435437
iport->iwi = iwi;
436438
if (self->add_fd(self, wi_fd, iwi, false)) {
@@ -1660,7 +1662,7 @@ void iwdp_iwi_free(iwdp_iwi_t iwi) {
16601662
}
16611663
}
16621664

1663-
iwdp_iwi_t iwdp_iwi_new(bool is_sim, bool *is_debug) {
1665+
iwdp_iwi_t iwdp_iwi_new(bool partials_supported, bool *is_debug) {
16641666
iwdp_iwi_t iwi = (iwdp_iwi_t)malloc(sizeof(struct iwdp_iwi_struct));
16651667
if (!iwi) {
16661668
return NULL;
@@ -1670,7 +1672,7 @@ iwdp_iwi_t iwdp_iwi_new(bool is_sim, bool *is_debug) {
16701672
iwi->app_id_to_true = ht_new(HT_STRING_KEYS);
16711673
iwi->page_num_to_ipage = ht_new(HT_INT_KEYS);
16721674
rpc_t rpc = rpc_new();
1673-
wi_t wi = wi_new(is_sim);
1675+
wi_t wi = wi_new(partials_supported);
16741676
if (!rpc || !wi || !iwi->page_num_to_ipage || !iwi->app_id_to_true) {
16751677
iwdp_iwi_free(iwi);
16761678
return NULL;

src/ios_webkit_debug_proxy_main.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ int iwdpm_subscribe(iwdp_t iwdp) {
110110
return dl_connect(-1);
111111
}
112112
int iwdpm_attach(iwdp_t iwdp, const char *device_id, char **to_device_id,
113-
char **to_device_name) {
114-
return wi_connect(device_id, to_device_id, to_device_name, -1);
113+
char **to_device_name, int *to_device_version) {
114+
return wi_connect(device_id, to_device_id, to_device_name,
115+
to_device_version, -1);
115116
}
116117
iwdp_status iwdpm_select_port(iwdp_t iwdp, const char *device_id,
117118
int *to_port, int *to_min_port, int *to_max_port) {

src/rpc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ rpc_status rpc_new_uuid(char **to_uuid);
2727
struct rpc_app_struct {
2828
char *app_id;
2929
char *app_name;
30-
char *host_id;
3130
bool is_proxy;
3231
};
3332
typedef struct rpc_app_struct *rpc_app_t;

src/webinspector.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#define MAX_BODY_LENGTH 1<<24
4141

4242
struct wi_private {
43-
bool is_sim;
43+
bool partials_supported;
4444
cb_t in;
4545
cb_t partial;
4646
bool has_length;
@@ -89,7 +89,7 @@ wi_status idevice_connection_get_fd(idevice_connection_t connection,
8989
#endif
9090

9191
int wi_connect(const char *device_id, char **to_device_id,
92-
char **to_device_name, int recv_timeout) {
92+
char **to_device_name, int *to_device_version, int recv_timeout) {
9393
int ret = -1;
9494

9595
idevice_t phone = NULL;
@@ -122,6 +122,24 @@ int wi_connect(const char *device_id, char **to_device_id,
122122
if (to_device_name &&
123123
!lockdownd_get_value(client, NULL, "DeviceName", &node)) {
124124
plist_get_string_val(node, to_device_name);
125+
plist_free(node);
126+
node = NULL;
127+
}
128+
if (to_device_version &&
129+
!lockdownd_get_value(client, NULL, "ProductVersion", &node)) {
130+
int vers[3] = {0, 0, 0};
131+
char *s_version = NULL;
132+
plist_get_string_val(node, &s_version);
133+
if (s_version && sscanf(s_version, "%d.%d.%d",
134+
&vers[0], &vers[1], &vers[2]) >= 2) {
135+
*to_device_version = ((vers[0] & 0xFF) << 16) |
136+
((vers[1] & 0xFF) << 8) |
137+
(vers[2] & 0xFF);
138+
} else {
139+
*to_device_version = 0;
140+
}
141+
free(s_version);
142+
plist_free(node);
125143
}
126144

127145
// start webinspector, get port
@@ -191,7 +209,6 @@ int wi_connect(const char *device_id, char **to_device_id,
191209
//idevice_disconnect(connection);
192210
free(connection);
193211
lockdownd_client_free(client);
194-
plist_free(node);
195212
idevice_free(phone);
196213
return ret;
197214
}
@@ -238,7 +255,7 @@ wi_status wi_send_plist(wi_t self, plist_t rpc_dict) {
238255
bool is_partial = false;
239256
char *data = NULL;
240257
uint32_t data_len = 0;
241-
if (my->is_sim) {
258+
if (!my->partials_supported) {
242259
data = rpc_bin;
243260
data_len = rpc_len;
244261
rpc_bin = NULL;
@@ -261,7 +278,7 @@ wi_status wi_send_plist(wi_t self, plist_t rpc_dict) {
261278
size_t length = data_len + 4;
262279
char *out_head = (char*)malloc(length * sizeof(char));
263280
if (!out_head) {
264-
if (!my->is_sim) {
281+
if (my->partials_supported) {
265282
free(data);
266283
}
267284
break;
@@ -325,7 +342,7 @@ wi_status wi_parse_plist(wi_t self, const char *from_buf, size_t length,
325342
*to_is_partial = false;
326343
*to_rpc_dict = NULL;
327344

328-
if (my->is_sim) {
345+
if (!my->partials_supported) {
329346
plist_from_bin(from_buf, length, to_rpc_dict);
330347
} else {
331348
plist_t wi_dict = NULL;
@@ -395,7 +412,7 @@ wi_status wi_recv_packet(wi_t self, const char *packet, ssize_t length) {
395412
} else {
396413
cb_asprint(&text, packet, length, 80, 50);
397414
}
398-
wi_status ret = self->on_error(self, "Invalid packet %s\n", text);
415+
wi_status ret = self->on_error(self, "Invalid packet:\n%s\n", text);
399416
free(text);
400417
return ret;
401418
}
@@ -498,7 +515,7 @@ void wi_free(wi_t self) {
498515
free(self);
499516
}
500517
}
501-
wi_t wi_new(bool is_sim) {
518+
wi_t wi_new(bool partials_supported) {
502519
wi_t self = (wi_t)malloc(sizeof(struct wi_struct));
503520
if (!self) {
504521
return NULL;
@@ -513,6 +530,6 @@ wi_t wi_new(bool is_sim) {
513530
wi_free(self);
514531
return NULL;
515532
}
516-
self->private_state->is_sim = is_sim;
533+
self->private_state->partials_supported = partials_supported;
517534
return self;
518535
}

0 commit comments

Comments
 (0)