summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/iphoneinfo.c312
1 files changed, 177 insertions, 135 deletions
diff --git a/tools/iphoneinfo.c b/tools/iphoneinfo.c
index 7c41033..5ee92f5 100644
--- a/tools/iphoneinfo.c
+++ b/tools/iphoneinfo.c
@@ -23,6 +23,7 @@
23#include <string.h> 23#include <string.h>
24#include <errno.h> 24#include <errno.h>
25#include <stdlib.h> 25#include <stdlib.h>
26#include <glib.h>
26 27
27#include <libiphone/libiphone.h> 28#include <libiphone/libiphone.h>
28#include <libiphone/lockdown.h> 29#include <libiphone/lockdown.h>
@@ -55,10 +56,161 @@ static const char *domains[] = {
55 NULL 56 NULL
56}; 57};
57 58
58int is_domain_known(char *domain); 59static int indent_level = 0;
59void print_usage(int argc, char **argv); 60
60void plist_node_to_string(plist_t node); 61static int is_domain_known(char *domain)
61void plist_children_to_string(plist_t node); 62{
63 int i = 0;
64 while (domains[i] != NULL) {
65 if (strstr(domain, domains[i++])) {
66 return 1;
67 }
68 }
69 return 0;
70}
71
72static void plist_node_to_string(plist_t node);
73
74static void plist_array_to_string(plist_t node)
75{
76 /* iterate over items */
77 int i, count;
78 plist_t subnode = NULL;
79
80 count = plist_array_get_size(node);
81
82 for (i = 0; i < count; i++) {
83 subnode = plist_array_get_item(node, i);
84 printf("%*s", indent_level, "");
85 printf("%d: ", i);
86 plist_node_to_string(subnode);
87 }
88}
89
90static void plist_dict_to_string(plist_t node)
91{
92 /* iterate over key/value pairs */
93 plist_dict_iter it = NULL;
94
95 char* key = NULL;
96 plist_t subnode = NULL;
97 plist_dict_new_iter(node, &it);
98 plist_dict_next_item(node, it, &key, &subnode);
99 while (subnode)
100 {
101 printf("%*s", indent_level, "");
102 printf("%s", key);
103 if (plist_get_node_type(subnode) == PLIST_ARRAY)
104 printf("[%d]: ", plist_array_get_size(subnode));
105 else
106 printf(": ");
107 free(key);
108 key = NULL;
109 plist_node_to_string(subnode);
110 plist_dict_next_item(node, it, &key, &subnode);
111 }
112 free(it);
113}
114
115static void plist_node_to_string(plist_t node)
116{
117 char *s = NULL;
118 char *data = NULL;
119 double d;
120 uint8_t b;
121 uint64_t u = 0;
122 GTimeVal tv = { 0, 0 };
123
124 plist_type t;
125
126 if (!node)
127 return;
128
129 t = plist_get_node_type(node);
130
131 switch (t) {
132 case PLIST_BOOLEAN:
133 plist_get_bool_val(node, &b);
134 printf("%s\n", (b ? "true" : "false"));
135 break;
136
137 case PLIST_UINT:
138 plist_get_uint_val(node, &u);
139 printf("%llu\n", (long long)u);
140 break;
141
142 case PLIST_REAL:
143 plist_get_real_val(node, &d);
144 printf("%f\n", d);
145 break;
146
147 case PLIST_STRING:
148 plist_get_string_val(node, &s);
149 printf("%s\n", s);
150 free(s);
151 break;
152
153 case PLIST_KEY:
154 plist_get_key_val(node, &s);
155 printf("%s: ", s);
156 free(s);
157 break;
158
159 case PLIST_DATA:
160 plist_get_data_val(node, &data, &u);
161 s = g_base64_encode((guchar *)data, u);
162 free(data);
163 printf("%s\n", s);
164 g_free(s);
165 break;
166
167 case PLIST_DATE:
168 plist_get_date_val(node, (int32_t*)&tv.tv_sec, (int32_t*)&tv.tv_usec);
169 s = g_time_val_to_iso8601(&tv);
170 printf("%s\n", s);
171 free(s);
172 break;
173
174 case PLIST_ARRAY:
175 printf("\n");
176 indent_level++;
177 plist_array_to_string(node);
178 indent_level--;
179 break;
180
181 case PLIST_DICT:
182 printf("\n");
183 indent_level++;
184 plist_dict_to_string(node);
185 indent_level--;
186 break;
187
188 default:
189 break;
190 }
191}
192
193static void print_usage(int argc, char **argv)
194{
195 int i = 0;
196 char *name = NULL;
197
198 name = strrchr(argv[0], '/');
199 printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0]));
200 printf("Show information about the first connected iPhone/iPod Touch.\n\n");
201 printf(" -d, --debug\t\tenable communication debugging\n");
202 printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n");
203 printf(" -q, --domain NAME\tset domain of query to NAME. Default: None\n");
204 printf(" -k, --key NAME\tonly query key specified by NAME. Default: All keys.\n");
205 printf(" -x, --xml\t\toutput information as xml plist instead of key/value pairs\n");
206 printf(" -h, --help\t\tprints usage information\n");
207 printf("\n");
208 printf(" Known domains are:\n\n");
209 while (domains[i] != NULL) {
210 printf(" %s\n", domains[i++]);
211 }
212 printf("\n");
213}
62 214
63int main(int argc, char *argv[]) 215int main(int argc, char *argv[])
64{ 216{
@@ -73,6 +225,7 @@ int main(int argc, char *argv[])
73 char *xml_doc = NULL; 225 char *xml_doc = NULL;
74 uint32_t xml_length; 226 uint32_t xml_length;
75 plist_t node = NULL; 227 plist_t node = NULL;
228 plist_type node_type;
76 uuid[0] = 0; 229 uuid[0] = 0;
77 230
78 /* parse cmdline args */ 231 /* parse cmdline args */
@@ -147,29 +300,30 @@ int main(int argc, char *argv[])
147 } 300 }
148 301
149 /* run query and output information */ 302 /* run query and output information */
150 if(lockdownd_get_value(client, domain, key, &node) == LOCKDOWN_E_SUCCESS) 303 if(lockdownd_get_value(client, domain, key, &node) == LOCKDOWN_E_SUCCESS) {
151 { 304 if (node) {
152 if (plist_get_node_type(node) == PLIST_DICT) { 305 switch (format) {
153 if (plist_dict_get_size(node)) 306 case FORMAT_XML:
154 { 307 plist_to_xml(node, &xml_doc, &xml_length);
155 switch (format) { 308 printf("%s", xml_doc);
156 case FORMAT_XML: 309 free(xml_doc);
157 plist_to_xml(node, &xml_doc, &xml_length); 310 break;
158 printf("%s", xml_doc); 311 case FORMAT_KEY_VALUE:
159 free(xml_doc); 312 node_type = plist_get_node_type(node);
160 break; 313 if (node_type == PLIST_DICT) {
161 case FORMAT_KEY_VALUE: 314 plist_dict_to_string(node);
162 default: 315 } else if (node_type == PLIST_ARRAY) {
163 plist_children_to_string(node); 316 plist_array_to_string(node);
164 break; 317 break;
165 } 318 }
319 default:
320 if (key != NULL)
321 plist_node_to_string(node);
322 break;
166 } 323 }
167 }
168 else if(node && (key != NULL))
169 plist_node_to_string(node);
170 if (node)
171 plist_free(node); 324 plist_free(node);
172 node = NULL; 325 node = NULL;
326 }
173 } 327 }
174 328
175 if (domain != NULL) 329 if (domain != NULL)
@@ -180,115 +334,3 @@ int main(int argc, char *argv[])
180 return 0; 334 return 0;
181} 335}
182 336
183int is_domain_known(char *domain)
184{
185 int i = 0;
186 while (domains[i] != NULL) {
187 if (strstr(domain, domains[i++])) {
188 return 1;
189 }
190 }
191 return 0;
192}
193
194void print_usage(int argc, char **argv)
195{
196 int i = 0;
197 char *name = NULL;
198
199 name = strrchr(argv[0], '/');
200 printf("Usage: %s [OPTIONS]\n", (name ? name + 1: argv[0]));
201 printf("Show information about the first connected iPhone/iPod Touch.\n\n");
202 printf(" -d, --debug\t\tenable communication debugging\n");
203 printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n");
204 printf(" -q, --domain NAME\tset domain of query to NAME. Default: None\n");
205 printf(" -k, --key NAME\tonly query key specified by NAME. Default: All keys.\n");
206 printf(" -x, --xml\t\toutput information as xml plist instead of key/value pairs\n");
207 printf(" -h, --help\t\tprints usage information\n");
208 printf("\n");
209 printf(" Known domains are:\n\n");
210 while (domains[i] != NULL) {
211 printf(" %s\n", domains[i++]);
212 }
213 printf("\n");
214}
215
216void plist_node_to_string(plist_t node)
217{
218 char *s = NULL;
219 double d;
220 uint8_t b;
221
222 uint64_t u = 0;
223
224 plist_type t;
225
226 if (!node)
227 return;
228
229 t = plist_get_node_type(node);
230
231 switch (t) {
232 case PLIST_BOOLEAN:
233 plist_get_bool_val(node, &b);
234 printf("%s\n", (b ? "true" : "false"));
235 break;
236
237 case PLIST_UINT:
238 plist_get_uint_val(node, &u);
239 printf("%llu\n", (long long)u);
240 break;
241
242 case PLIST_REAL:
243 plist_get_real_val(node, &d);
244 printf("%f\n", d);
245 break;
246
247 case PLIST_STRING:
248 plist_get_string_val(node, &s);
249 printf("%s\n", s);
250 free(s);
251 break;
252
253 case PLIST_KEY:
254 plist_get_key_val(node, &s);
255 printf("%s: ", s);
256 free(s);
257 break;
258
259 case PLIST_DATA:
260 printf("\n");
261 break;
262 case PLIST_DATE:
263 printf("\n");
264 break;
265 case PLIST_ARRAY:
266 case PLIST_DICT:
267 printf("\n");
268 plist_children_to_string(node);
269 break;
270 default:
271 break;
272 }
273}
274
275void plist_children_to_string(plist_t node)
276{
277 /* iterate over key/value pairs */
278 plist_dict_iter it = NULL;
279
280 char* key = NULL;
281 plist_t subnode = NULL;
282 plist_dict_new_iter(node, &it);
283 plist_dict_next_item(node, it, &key, &subnode);
284 while (subnode)
285 {
286 printf("%s: ", key);
287 free(key);
288 key = NULL;
289 plist_node_to_string(subnode);
290 plist_dict_next_item(node, it, &key, &subnode);
291 }
292 free(it);
293}
294