-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimobtest.c
More file actions
277 lines (214 loc) · 6.96 KB
/
imobtest.c
File metadata and controls
277 lines (214 loc) · 6.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/**
imobtest.c
A program to test some of the libimobiledevice APIs.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <gpod/itdb.h>
//#include <glib-2.0/glib.h>
#include <libimobiledevice/libimobiledevice.h>
#include <libimobiledevice/lockdown.h>
#include <libimobiledevice/sbservices.h>
#include <libimobiledevice/afc.h>
#include "lsipod.h"
void test_imobiledevice() ;
void test_springboard(idevice_t device, lockdownd_client_t client) ;
void test_afc(idevice_t device, lockdownd_client_t client) ;
GError *err ;
int main(int argc, char *argv[]) {
char *pa ;
int iarg ;
for(iarg = 1 ; iarg < argc ; iarg++) {
pa = argv[iarg] ;
if('-' == pa[0]) {
switch(pa[1]) {
case 'a':
break ;
case 'd':
break ;
default :
fprintf(stderr, "Unknown option switch:%c\n", pa[1]) ;
}
}
}
test_imobiledevice() ;
exit(0) ;
return 0 ;
}
void notify(const idevice_event_t *ev, void *user_data) {
enum idevice_event_type e = ev->event ;
const char * u = ev->udid ;
switch(e) {
case IDEVICE_DEVICE_ADD :
printf("Device added\n") ;
break;
case IDEVICE_DEVICE_REMOVE :
printf("Device removed\n") ;
break;
default :
printf("Unknown idevice_event_type\n") ;
}
printf("Device udid: %s with: %s\n", u, (char *)user_data) ;
}
void test_imobiledevice() {
char **device_udids ;
int count ;
char user_data[] = "Some user data" ;
idevice_event_subscribe(¬ify, (void *)user_data) ;
idevice_error_t err = idevice_get_device_list(&device_udids, &count) ;
//printf("Sleeping for 5 seconds...\n") ;
//sleep(5) ;
if(err == IDEVICE_E_SUCCESS) {
printf("Found %d ilibmobile devices.\n", count) ;
for(int i = 0 ; i < count ; i++) {
uint32_t handle ;
idevice_t device ;
lockdownd_client_t client ;
idevice_new(&device, device_udids[i]) ;
printf("Just called idevice_new()\n") ;
idevice_get_handle(device, &handle) ;
printf("Just called idevice_get_handle()\n") ;
const char *lockdown_label = "foobar" ;
lockdownd_error_t ld_err = lockdownd_client_new_with_handshake(device, &client, lockdown_label) ;
if(ld_err == LOCKDOWN_E_SUCCESS) {
printf("Successfully created a lockdown client\n") ;
char *device_name ;
ld_err = lockdownd_get_device_name(client, &device_name) ;
if(ld_err == LOCKDOWN_E_SUCCESS) {
printf("Device name: %s\n", device_name) ;
free(device_name) ;
} else {
printf("Could not get device name: %d\n", ld_err) ;
}
char *service_type ;
ld_err = lockdownd_query_type(client, &service_type) ;
if(ld_err == LOCKDOWN_E_SUCCESS) {
printf("Got service type: %s\n", service_type) ;
//test_springboard(device, client) ;
test_afc(device, client) ;
} else {
printf("Could not query service.\n") ;
}
lockdownd_client_free(client) ;
printf("Freed the lockdown client\n") ;
} else {
printf("Could not get a lockdown client\n") ;
}
//printf("%s with handle %d.\n", device_udids[i], handle) ;
idevice_free(device) ;
printf("Just called idevice_free()\n") ;
}
} else {
printf("ilibmobiledevice error\n") ;
}
idevice_device_list_free(device_udids) ;
idevice_event_unsubscribe() ;
}
void test_springboard(idevice_t device, lockdownd_client_t client) {
lockdownd_service_descriptor_t lsd ;
lockdownd_error_t ld_err ;
sbservices_error_t sb_err ;
sbservices_client_t sbclient ;
//const char *service_id = "com.apple.springboardservices" ;
ld_err = lockdownd_start_service(client, SBSERVICES_SERVICE_NAME, &lsd) ;
if(ld_err == LOCKDOWN_E_SUCCESS ){
printf("Started service: %s\n", SBSERVICES_SERVICE_NAME) ;
sb_err = sbservices_client_new(device, lsd, &sbclient) ;
//sb_err = sbservices_client_start_service(device, &sbclient, "foobar" ) ;
if(sb_err == SBSERVICES_E_SUCCESS) {
printf("Connected to springboard service.\n") ;
/*
char *pngdata ;
uint64_t pngsize ;
sb_err = sbservices_get_home_screen_wallpaper_pngdata(sbclient, &pngdata, &pngsize) ;
if(sb_err == SBSERVICES_E_SUCCESS) {
printf("Got wallpaper of size %ld\n", pngsize) ;
} else {
printf("Could not get wallpaper: %d\n", sb_err) ;
}
*/
plist_t plist ;
sb_err = sbservices_get_icon_state(sbclient, &plist, NULL) ;
if(sb_err == SBSERVICES_E_SUCCESS) {
printf("Got icon state\n") ;
plist_type node_type = plist_get_node_type(plist) ;
printf("Node type: %d\n", node_type) ;
if(node_type == PLIST_ARRAY) {
uint32_t array_size = plist_array_get_size(plist) ;
printf("plist is a PLIST_ARRAY of size %d\n", array_size) ;
//plist_t first_elem = plist_array_get_item(plist, 0) ;
/*
char *plist_xml ;
uint32_t xml_len ;
plist_to_xml(plist, &plist_xml, &xml_len) ;
//printf("XML size: %d\n", xml_len) ;
printf("%s\n", plist_xml) ;
free(plist_xml) ;
*/
}
/*
//char *plist_str ;
//plist_get_string_val(plist, &plist_str) ;
//printf("%s", plist_str) ;
*/
free(plist) ;
} else {
printf("Could not get icon state: %d\n", sb_err) ;
}
} else {
printf("Could not connect to springboard service.\n") ;
}
sb_err = sbservices_client_free(sbclient) ;
if(sb_err == SBSERVICES_E_SUCCESS) {
printf("Freed sbservices client.\n") ;
}
} else {
printf("Could not start service: %d\n", ld_err) ;
}
//sbservices_error_t sb_err = sbservices_client_new(device, )
}
void test_afc(idevice_t device, lockdownd_client_t client) {
lockdownd_service_descriptor_t lsd ;
lockdownd_error_t ld_err ;
afc_error_t afc_err ;
afc_client_t afcclient ;
ld_err = lockdownd_start_service(client, AFC_SERVICE_NAME, &lsd) ;
if(ld_err == LOCKDOWN_E_SUCCESS ){
printf("Started service: %s\n", AFC_SERVICE_NAME) ;
afc_err = afc_client_new(device, lsd, &afcclient) ;
if(afc_err == AFC_E_SUCCESS) {
printf("Connected to afc service.\n") ;
/* Get device information*/
char **dev_info ;
afc_err = afc_get_device_info(afcclient, &dev_info) ;
if(afc_err == AFC_E_SUCCESS) {
printf("Got device info.\n") ;
char **pline = dev_info ;
while(pline && *pline) {
printf("%s\n", *pline) ;
++pline ;
}
afc_dictionary_free(dev_info) ;
} else {
printf("Could not get device info.\n") ;
}
/* Read directory */
const char root_path[] = "" ;
char **dir_info ;
afc_err = afc_read_directory(afcclient, root_path, &dir_info) ;
if(afc_err == AFC_E_SUCCESS) {
printf("Got directory: %s\n", root_path) ;
afc_dictionary_free(dir_info) ;
} else {
printf("Could not get directory\n") ;
}
afc_err = afc_client_free(afcclient) ;
} else {
printf("Could not connect to afc service.\n") ;
}
} else {
printf("Could not start service: %d\n", ld_err) ;
}
}