summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2011-09-03 02:10:48 +0200
committerGravatar Martin Szulecki2012-03-18 20:40:54 +0100
commitdcb85727c3649c254c985d840aa2efb36f727872 (patch)
tree0f6f551b70bd845f57d5a044915e617a1bd40ac6
parent6a83ef58a1032e3b336587e2f3a19659ae325c25 (diff)
downloadlibimobiledevice-dcb85727c3649c254c985d840aa2efb36f727872.tar.gz
libimobiledevice-dcb85727c3649c254c985d840aa2efb36f727872.tar.bz2
Completely remove glib dependency.
-rw-r--r--configure.ac16
-rw-r--r--dev/Makefile.am14
-rw-r--r--dev/ideviceclient.c9
-rw-r--r--include/libimobiledevice/installation_proxy.h3
-rw-r--r--include/libimobiledevice/mobilesync.h3
-rw-r--r--src/Makefile.am4
-rw-r--r--src/afc.c28
-rw-r--r--src/afc.h16
-rw-r--r--src/debug.c3
-rw-r--r--src/debug.h17
-rw-r--r--src/house_arrest.h2
-rw-r--r--src/lockdown.c5
-rw-r--r--src/mobilesync.c1
-rw-r--r--src/property_list_service.c5
-rw-r--r--src/restore.c1
-rw-r--r--src/userpref.c492
-rw-r--r--src/userpref.h19
-rw-r--r--tools/Makefile.am18
-rw-r--r--tools/ideviceimagemounter.c25
-rw-r--r--tools/ideviceinfo.c66
-rw-r--r--tools/idevicepair.c3
-rw-r--r--tools/idevicesyslog.c3
22 files changed, 583 insertions, 170 deletions
diff --git a/configure.ac b/configure.ac
index 5078afd..98b0008 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,12 +27,15 @@ AC_PROG_LIBTOOL
27 27
28# Checks for libraries. 28# Checks for libraries.
29PKG_CHECK_MODULES(libusbmuxd, libusbmuxd >= 0.1.4) 29PKG_CHECK_MODULES(libusbmuxd, libusbmuxd >= 0.1.4)
30PKG_CHECK_MODULES(libglib2, glib-2.0 >= 2.14.1)
31PKG_CHECK_MODULES(libgnutls, gnutls >= 2.2.0) 30PKG_CHECK_MODULES(libgnutls, gnutls >= 2.2.0)
32PKG_CHECK_MODULES(libtasn1, libtasn1 >= 1.1) 31PKG_CHECK_MODULES(libtasn1, libtasn1 >= 1.1)
33PKG_CHECK_MODULES(libplist, libplist >= 0.15) 32PKG_CHECK_MODULES(libplist, libplist >= 0.15)
34PKG_CHECK_MODULES(libplistmm, libplist++ >= 0.15) 33PKG_CHECK_MODULES(libplistmm, libplist++ >= 0.15)
35AC_CHECK_LIB(gcrypt, gcry_control, [AC_SUBST(libgcrypt_LIBS,[-lgcrypt])], [AC_MSG_ERROR([libgcrypt is required to build libimobiledevice])]) 34AC_CHECK_LIB(gcrypt, gcry_control, [AC_SUBST(libgcrypt_LIBS,[-lgcrypt])], [AC_MSG_ERROR([libgcrypt is required to build libimobiledevice])])
35AC_CHECK_LIB(pthread, [pthread_create, pthread_mutex_lock], [AC_SUBST(libpthread_LIBS,[-lpthread])], [AC_MSG_ERROR([libpthread is required to build libimobiledevice])])
36
37PKG_CHECK_MODULES(libglib2, glib-2.0 >= 2.14.1, enable_glib2=yes, enable_glib2=no)
38AM_CONDITIONAL([HAVE_GLIB2],[test "x$enable_glib2" == "xyes"])
36 39
37# Checks for header files. 40# Checks for header files.
38AC_HEADER_STDC 41AC_HEADER_STDC
@@ -51,6 +54,17 @@ AC_FUNC_MALLOC
51AC_FUNC_REALLOC 54AC_FUNC_REALLOC
52AC_CHECK_FUNCS([strcasecmp strdup strerror strndup]) 55AC_CHECK_FUNCS([strcasecmp strdup strerror strndup])
53 56
57AC_DEFINE(LITTLE_ENDIAN,0,[little endian])
58AC_DEFINE(BIG_ENDIAN,1,[big endian])
59AC_C_BIGENDIAN([ac_cv_c_bigendian="yes"], [ac_cv_c_bigendian="no"], [], [])
60if test "x$ac_cv_c_bigendian" = "xyes"; then
61 AC_DEFINE(BYTE_ORDER,1,[big endian byte order])
62else
63 AC_DEFINE(BYTE_ORDER,0,[little endian byte order])
64fi
65
66
67
54AC_ARG_WITH([swig], 68AC_ARG_WITH([swig],
55 [AS_HELP_STRING([--without-swig], 69 [AS_HELP_STRING([--without-swig],
56 [build Python bindings using swig (default is yes)])], 70 [build Python bindings using swig (default is yes)])],
diff --git a/dev/Makefile.am b/dev/Makefile.am
index 72c00a3..c1d2b45 100644
--- a/dev/Makefile.am
+++ b/dev/Makefile.am
@@ -1,10 +1,14 @@
1AM_CPPFLAGS = -I$(top_srcdir)/include 1AM_CPPFLAGS = -I$(top_srcdir)/include
2 2
3AM_CFLAGS = $(GLOBAL_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS) 3AM_CFLAGS = $(GLOBAL_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(LFS_CFLAGS)
4AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) 4AM_LDFLAGS = $(libgnutls_LIBS) $(libtasn1_LIBS) $(libpthread_LIBS)
5 5
6if ENABLE_DEVTOOLS 6if ENABLE_DEVTOOLS
7noinst_PROGRAMS = ideviceclient lckd-client afccheck filerelaytest housearresttest 7noinst_PROGRAMS = ideviceclient afccheck filerelaytest housearresttest
8
9if HAVE_GLIB2
10noinst_PROGRAMS += lckd-client
11endif
8 12
9ideviceclient_SOURCES = ideviceclient.c 13ideviceclient_SOURCES = ideviceclient.c
10ideviceclient_CFLAGS = $(AM_CFLAGS) 14ideviceclient_CFLAGS = $(AM_CFLAGS)
@@ -12,8 +16,8 @@ ideviceclient_LDFLAGS = $(AM_LDFLAGS)
12ideviceclient_LDADD = ../src/libimobiledevice.la 16ideviceclient_LDADD = ../src/libimobiledevice.la
13 17
14lckd_client_SOURCES = lckdclient.c 18lckd_client_SOURCES = lckdclient.c
15lckd_client_CFLAGS = $(AM_CFLAGS) 19lckd_client_CFLAGS = $(AM_CFLAGS) $(libglib2_CFLAGS)
16lckd_client_LDFLAGS = -lreadline $(AM_LDFLAGS) 20lckd_client_LDFLAGS = -lreadline $(AM_LDFLAGS) $(libglib2_LIBS)
17lckd_client_LDADD = ../src/libimobiledevice.la 21lckd_client_LDADD = ../src/libimobiledevice.la
18 22
19afccheck_SOURCES = afccheck.c 23afccheck_SOURCES = afccheck.c
diff --git a/dev/ideviceclient.c b/dev/ideviceclient.c
index d952594..0400fed 100644
--- a/dev/ideviceclient.c
+++ b/dev/ideviceclient.c
@@ -23,7 +23,6 @@
23#include <stdlib.h> 23#include <stdlib.h>
24#include <string.h> 24#include <string.h>
25#include <errno.h> 25#include <errno.h>
26#include <glib.h>
27 26
28#include <libimobiledevice/libimobiledevice.h> 27#include <libimobiledevice/libimobiledevice.h>
29#include <libimobiledevice/lockdown.h> 28#include <libimobiledevice/lockdown.h>
@@ -138,18 +137,20 @@ int main(int argc, char *argv[])
138 printf("Directory time.\n"); 137 printf("Directory time.\n");
139 for (i = 0; dirs[i]; i++) { 138 for (i = 0; dirs[i]; i++) {
140 printf("/%s\n", dirs[i]); 139 printf("/%s\n", dirs[i]);
140 free(dirs[i]);
141 } 141 }
142 142 if (dirs)
143 g_strfreev(dirs); 143 free(dirs);
144 144
145 dirs = NULL; 145 dirs = NULL;
146 afc_get_device_info(afc, &dirs); 146 afc_get_device_info(afc, &dirs);
147 if (dirs) { 147 if (dirs) {
148 for (i = 0; dirs[i]; i += 2) { 148 for (i = 0; dirs[i]; i += 2) {
149 printf("%s: %s\n", dirs[i], dirs[i + 1]); 149 printf("%s: %s\n", dirs[i], dirs[i + 1]);
150 free(dirs[i]);
150 } 151 }
152 free(dirs);
151 } 153 }
152 g_strfreev(dirs);
153 154
154 uint64_t my_file = 0; 155 uint64_t my_file = 0;
155 char **info = NULL; 156 char **info = NULL;
diff --git a/include/libimobiledevice/installation_proxy.h b/include/libimobiledevice/installation_proxy.h
index f5f00e8..11fb66e 100644
--- a/include/libimobiledevice/installation_proxy.h
+++ b/include/libimobiledevice/installation_proxy.h
@@ -28,7 +28,6 @@ extern "C" {
28#endif 28#endif
29 29
30#include <libimobiledevice/libimobiledevice.h> 30#include <libimobiledevice/libimobiledevice.h>
31#include <glib.h>
32 31
33/** @name Error Codes */ 32/** @name Error Codes */
34/*@{*/ 33/*@{*/
@@ -66,7 +65,7 @@ instproxy_error_t instproxy_restore(instproxy_client_t client, const char *appid
66instproxy_error_t instproxy_remove_archive(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data); 65instproxy_error_t instproxy_remove_archive(instproxy_client_t client, const char *appid, plist_t client_options, instproxy_status_cb_t status_cb, void *user_data);
67 66
68plist_t instproxy_client_options_new(); 67plist_t instproxy_client_options_new();
69void instproxy_client_options_add(plist_t client_options, ...) G_GNUC_NULL_TERMINATED; 68void instproxy_client_options_add(plist_t client_options, ...);
70void instproxy_client_options_free(plist_t client_options); 69void instproxy_client_options_free(plist_t client_options);
71 70
72#ifdef __cplusplus 71#ifdef __cplusplus
diff --git a/include/libimobiledevice/mobilesync.h b/include/libimobiledevice/mobilesync.h
index 7658b7d..bd717ee 100644
--- a/include/libimobiledevice/mobilesync.h
+++ b/include/libimobiledevice/mobilesync.h
@@ -29,7 +29,6 @@ extern "C" {
29#endif 29#endif
30 30
31#include <libimobiledevice/libimobiledevice.h> 31#include <libimobiledevice/libimobiledevice.h>
32#include <glib.h>
33 32
34/** @name Error Codes */ 33/** @name Error Codes */
35/*@{*/ 34/*@{*/
@@ -93,7 +92,7 @@ mobilesync_anchors_t mobilesync_anchors_new(const char *device_anchor, const cha
93void mobilesync_anchors_free(mobilesync_anchors_t anchors); 92void mobilesync_anchors_free(mobilesync_anchors_t anchors);
94 93
95plist_t mobilesync_actions_new(); 94plist_t mobilesync_actions_new();
96void mobilesync_actions_add(plist_t actions, ...) G_GNUC_NULL_TERMINATED; 95void mobilesync_actions_add(plist_t actions, ...);
97void mobilesync_actions_free(plist_t actions); 96void mobilesync_actions_free(plist_t actions);
98 97
99#ifdef __cplusplus 98#ifdef __cplusplus
diff --git a/src/Makefile.am b/src/Makefile.am
index f42ac08..5531f8d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,7 +1,7 @@
1AM_CPPFLAGS = -I$(top_srcdir)/include 1AM_CPPFLAGS = -I$(top_srcdir)/include
2 2
3AM_CFLAGS = $(GLOBAL_CFLAGS) $(libusbmuxd_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(libplist_CFLAGS) $(LFS_CFLAGS) 3AM_CFLAGS = $(GLOBAL_CFLAGS) $(libusbmuxd_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libplist_CFLAGS) $(LFS_CFLAGS)
4AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) $(libplist_LIBS) $(libusbmuxd_LIBS) $(libgcrypt_LIBS) 4AM_LDFLAGS = $(libgnutls_LIBS) $(libtasn1_LIBS) $(libplist_LIBS) $(libusbmuxd_LIBS) $(libgcrypt_LIBS) ${libpthread_LIBS}
5 5
6lib_LTLIBRARIES = libimobiledevice.la 6lib_LTLIBRARIES = libimobiledevice.la
7libimobiledevice_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LIBIMOBILEDEVICE_SO_VERSION) -no-undefined 7libimobiledevice_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LIBIMOBILEDEVICE_SO_VERSION) -no-undefined
diff --git a/src/afc.c b/src/afc.c
index fd5143a..a0869ca 100644
--- a/src/afc.c
+++ b/src/afc.c
@@ -364,7 +364,7 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, uint3
364 } 364 }
365 365
366 if (current_count >= sizeof(uint64_t)) { 366 if (current_count >= sizeof(uint64_t)) {
367 param1 = GUINT64_FROM_LE(*(uint64_t*)(*dump_here)); 367 param1 = le64toh(*(uint64_t*)(*dump_here));
368 } 368 }
369 369
370 debug_info("packet data size = %i", current_count); 370 debug_info("packet data size = %i", current_count);
@@ -577,8 +577,10 @@ afc_error_t afc_get_device_info_key(afc_client_t client, const char *key, char *
577 break; 577 break;
578 } 578 }
579 } 579 }
580 580 for (ptr = kvps; *ptr; ptr++) {
581 g_strfreev(kvps); 581 free(*ptr);
582 }
583 free(kvps);
582 584
583 return ret; 585 return ret;
584} 586}
@@ -764,7 +766,7 @@ idevice_error_t
764afc_file_open(afc_client_t client, const char *filename, 766afc_file_open(afc_client_t client, const char *filename,
765 afc_file_mode_t file_mode, uint64_t *handle) 767 afc_file_mode_t file_mode, uint64_t *handle)
766{ 768{
767 uint64_t file_mode_loc = GUINT64_TO_LE(file_mode); 769 uint64_t file_mode_loc = htole64(file_mode);
768 uint32_t bytes = 0; 770 uint32_t bytes = 0;
769 char *data = (char *) malloc(sizeof(char) * (8 + strlen(filename) + 1)); 771 char *data = (char *) malloc(sizeof(char) * (8 + strlen(filename) + 1));
770 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 772 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
@@ -842,7 +844,7 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length,
842 /* Send the read command */ 844 /* Send the read command */
843 AFCFilePacket *packet = (AFCFilePacket *) malloc(sizeof(AFCFilePacket)); 845 AFCFilePacket *packet = (AFCFilePacket *) malloc(sizeof(AFCFilePacket));
844 packet->filehandle = handle; 846 packet->filehandle = handle;
845 packet->size = GUINT64_TO_LE(((length - current_count) < MAXIMUM_READ_SIZE) ? (length - current_count) : MAXIMUM_READ_SIZE); 847 packet->size = htole64(((length - current_count) < MAXIMUM_READ_SIZE) ? (length - current_count) : MAXIMUM_READ_SIZE);
846 client->afc_packet->operation = AFC_OP_READ; 848 client->afc_packet->operation = AFC_OP_READ;
847 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 849 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
848 ret = afc_dispatch_packet(client, (char *) packet, sizeof(AFCFilePacket), &bytes_loc); 850 ret = afc_dispatch_packet(client, (char *) packet, sizeof(AFCFilePacket), &bytes_loc);
@@ -1035,7 +1037,7 @@ afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t op
1035{ 1037{
1036 char *buffer = malloc(16); 1038 char *buffer = malloc(16);
1037 uint32_t bytes = 0; 1039 uint32_t bytes = 0;
1038 uint64_t op = GUINT64_TO_LE(operation); 1040 uint64_t op = htole64(operation);
1039 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1041 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1040 1042
1041 if (!client || (handle == 0)) 1043 if (!client || (handle == 0))
@@ -1084,8 +1086,8 @@ afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t op
1084afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence) 1086afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence)
1085{ 1087{
1086 char *buffer = (char *) malloc(sizeof(char) * 24); 1088 char *buffer = (char *) malloc(sizeof(char) * 24);
1087 int64_t offset_loc = (int64_t)GUINT64_TO_LE(offset); 1089 int64_t offset_loc = (int64_t)htole64(offset);
1088 uint64_t whence_loc = GUINT64_TO_LE(whence); 1090 uint64_t whence_loc = htole64(whence);
1089 uint32_t bytes = 0; 1091 uint32_t bytes = 0;
1090 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1092 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1091 1093
@@ -1156,7 +1158,7 @@ afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *positi
1156 if (bytes > 0 && buffer) { 1158 if (bytes > 0 && buffer) {
1157 /* Get the position */ 1159 /* Get the position */
1158 memcpy(position, buffer, sizeof(uint64_t)); 1160 memcpy(position, buffer, sizeof(uint64_t));
1159 *position = GUINT64_FROM_LE(*position); 1161 *position = le64toh(*position);
1160 } 1162 }
1161 if (buffer) 1163 if (buffer)
1162 free(buffer); 1164 free(buffer);
@@ -1182,7 +1184,7 @@ afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t new
1182{ 1184{
1183 char *buffer = (char *) malloc(sizeof(char) * 16); 1185 char *buffer = (char *) malloc(sizeof(char) * 16);
1184 uint32_t bytes = 0; 1186 uint32_t bytes = 0;
1185 uint64_t newsize_loc = GUINT64_TO_LE(newsize); 1187 uint64_t newsize_loc = htole64(newsize);
1186 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1188 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1187 1189
1188 if (!client || (handle == 0)) 1190 if (!client || (handle == 0))
@@ -1227,7 +1229,7 @@ afc_error_t afc_truncate(afc_client_t client, const char *path, uint64_t newsize
1227 char *response = NULL; 1229 char *response = NULL;
1228 char *send = (char *) malloc(sizeof(char) * (strlen(path) + 1 + 8)); 1230 char *send = (char *) malloc(sizeof(char) * (strlen(path) + 1 + 8));
1229 uint32_t bytes = 0; 1231 uint32_t bytes = 0;
1230 uint64_t size_requested = GUINT64_TO_LE(newsize); 1232 uint64_t size_requested = htole64(newsize);
1231 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1233 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1232 1234
1233 if (!client || !path || !client->afc_packet || !client->connection) 1235 if (!client || !path || !client->afc_packet || !client->connection)
@@ -1271,7 +1273,7 @@ afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const c
1271 char *response = NULL; 1273 char *response = NULL;
1272 char *send = (char *) malloc(sizeof(char) * (strlen(target)+1 + strlen(linkname)+1 + 8)); 1274 char *send = (char *) malloc(sizeof(char) * (strlen(target)+1 + strlen(linkname)+1 + 8));
1273 uint32_t bytes = 0; 1275 uint32_t bytes = 0;
1274 uint64_t type = GUINT64_TO_LE(linktype); 1276 uint64_t type = htole64(linktype);
1275 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1277 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1276 1278
1277 if (!client || !target || !linkname || !client->afc_packet || !client->connection) 1279 if (!client || !target || !linkname || !client->afc_packet || !client->connection)
@@ -1319,7 +1321,7 @@ afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mt
1319 char *response = NULL; 1321 char *response = NULL;
1320 char *send = (char *) malloc(sizeof(char) * (strlen(path) + 1 + 8)); 1322 char *send = (char *) malloc(sizeof(char) * (strlen(path) + 1 + 8));
1321 uint32_t bytes = 0; 1323 uint32_t bytes = 0;
1322 uint64_t mtime_loc = GUINT64_TO_LE(mtime); 1324 uint64_t mtime_loc = htole64(mtime);
1323 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1325 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1324 1326
1325 if (!client || !path || !client->afc_packet || !client->connection) 1327 if (!client || !path || !client->afc_packet || !client->connection)
diff --git a/src/afc.h b/src/afc.h
index 79078ec..c86828c 100644
--- a/src/afc.h
+++ b/src/afc.h
@@ -33,16 +33,16 @@ typedef struct {
33} AFCPacket; 33} AFCPacket;
34 34
35#define AFCPacket_to_LE(x) \ 35#define AFCPacket_to_LE(x) \
36 (x)->entire_length = GUINT64_TO_LE((x)->entire_length); \ 36 (x)->entire_length = htole64((x)->entire_length); \
37 (x)->this_length = GUINT64_TO_LE((x)->this_length); \ 37 (x)->this_length = htole64((x)->this_length); \
38 (x)->packet_num = GUINT64_TO_LE((x)->packet_num); \ 38 (x)->packet_num = htole64((x)->packet_num); \
39 (x)->operation = GUINT64_TO_LE((x)->operation); 39 (x)->operation = htole64((x)->operation);
40 40
41#define AFCPacket_from_LE(x) \ 41#define AFCPacket_from_LE(x) \
42 (x)->entire_length = GUINT64_FROM_LE((x)->entire_length); \ 42 (x)->entire_length = le64toh((x)->entire_length); \
43 (x)->this_length = GUINT64_FROM_LE((x)->this_length); \ 43 (x)->this_length = le64toh((x)->this_length); \
44 (x)->packet_num = GUINT64_FROM_LE((x)->packet_num); \ 44 (x)->packet_num = le64toh((x)->packet_num); \
45 (x)->operation = GUINT64_FROM_LE((x)->operation); 45 (x)->operation = le64toh((x)->operation);
46 46
47typedef struct { 47typedef struct {
48 uint64_t filehandle, size; 48 uint64_t filehandle, size;
diff --git a/src/debug.c b/src/debug.c
index 26a9678..ece2b1d 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -29,6 +29,7 @@
29#include <stdio.h> 29#include <stdio.h>
30#include <stdint.h> 30#include <stdint.h>
31#include <stdlib.h> 31#include <stdlib.h>
32#include <time.h>
32 33
33#include "debug.h" 34#include "debug.h"
34#include "libimobiledevice/libimobiledevice.h" 35#include "libimobiledevice/libimobiledevice.h"
@@ -54,7 +55,7 @@ static void debug_print_line(const char *func, const char *file, int line, const
54 time_t the_time; 55 time_t the_time;
55 56
56 time(&the_time); 57 time(&the_time);
57 str_time = g_new0 (gchar, 255); 58 str_time = (char*)malloc(255);
58 strftime(str_time, 254, "%H:%M:%S", localtime (&the_time)); 59 strftime(str_time, 254, "%H:%M:%S", localtime (&the_time));
59 60
60 /* generate header text */ 61 /* generate header text */
diff --git a/src/debug.h b/src/debug.h
index 2fd0960..cb1bf97 100644
--- a/src/debug.h
+++ b/src/debug.h
@@ -24,7 +24,14 @@
24#define DEBUG_H 24#define DEBUG_H
25 25
26#include <plist/plist.h> 26#include <plist/plist.h>
27#include <glib.h> 27
28#ifndef LIBIMOBILEDEVICE_INTERNAL
29#ifdef WIN32
30#define LIBIMOBILEDEVICE_INTERNAL
31#else
32#define LIBIMOBILEDEVICE_INTERNAL __attribute__((visibility("hidden")))
33#endif
34#endif
28 35
29#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && !defined(STRIP_DEBUG_CODE) 36#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && !defined(STRIP_DEBUG_CODE)
30#define debug_info(...) debug_info_real (__func__, __FILE__, __LINE__, __VA_ARGS__) 37#define debug_info(...) debug_info_real (__func__, __FILE__, __LINE__, __VA_ARGS__)
@@ -37,14 +44,14 @@
37#define debug_plist(a) 44#define debug_plist(a)
38#endif 45#endif
39 46
40G_GNUC_INTERNAL inline void debug_info_real(const char *func, 47LIBIMOBILEDEVICE_INTERNAL inline void debug_info_real(const char *func,
41 const char *file, 48 const char *file,
42 int line, 49 int line,
43 const char *format, ...); 50 const char *format, ...);
44 51
45G_GNUC_INTERNAL inline void debug_buffer(const char *data, const int length); 52LIBIMOBILEDEVICE_INTERNAL inline void debug_buffer(const char *data, const int length);
46G_GNUC_INTERNAL inline void debug_buffer_to_file(const char *file, const char *data, const int length); 53LIBIMOBILEDEVICE_INTERNAL inline void debug_buffer_to_file(const char *file, const char *data, const int length);
47G_GNUC_INTERNAL inline void debug_plist_real(const char *func, 54LIBIMOBILEDEVICE_INTERNAL inline void debug_plist_real(const char *func,
48 const char *file, 55 const char *file,
49 int line, 56 int line,
50 plist_t plist); 57 plist_t plist);
diff --git a/src/house_arrest.h b/src/house_arrest.h
index 6d13a88..708f1b5 100644
--- a/src/house_arrest.h
+++ b/src/house_arrest.h
@@ -21,8 +21,6 @@
21#ifndef IHOUSE_ARREST_H 21#ifndef IHOUSE_ARREST_H
22#define IHOUSE_ARREST_H 22#define IHOUSE_ARREST_H
23 23
24#include <glib.h>
25
26#include "libimobiledevice/house_arrest.h" 24#include "libimobiledevice/house_arrest.h"
27#include "property_list_service.h" 25#include "property_list_service.h"
28 26
diff --git a/src/lockdown.c b/src/lockdown.c
index 1783df6..424cf89 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -26,7 +26,6 @@
26#define __USE_GNU 1 26#define __USE_GNU 1
27#include <stdio.h> 27#include <stdio.h>
28#include <ctype.h> 28#include <ctype.h>
29#include <glib.h>
30#include <libtasn1.h> 29#include <libtasn1.h>
31#include <gnutls/x509.h> 30#include <gnutls/x509.h>
32#include <plist/plist.h> 31#include <plist/plist.h>
@@ -1200,8 +1199,8 @@ lockdownd_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datu
1200 memcpy(oroot_cert->data, pem_root_cert.data, pem_root_cert.size); 1199 memcpy(oroot_cert->data, pem_root_cert.data, pem_root_cert.size);
1201 oroot_cert->size = pem_root_cert.size; 1200 oroot_cert->size = pem_root_cert.size;
1202 1201
1203 g_free(pem_root_cert.data); 1202 free(pem_root_cert.data);
1204 g_free(pem_host_cert.data); 1203 free(pem_host_cert.data);
1205 1204
1206 if (dev_pem.data) 1205 if (dev_pem.data)
1207 gnutls_free(dev_pem.data); 1206 gnutls_free(dev_pem.data);
diff --git a/src/mobilesync.c b/src/mobilesync.c
index e600452..9b31ad5 100644
--- a/src/mobilesync.c
+++ b/src/mobilesync.c
@@ -27,7 +27,6 @@
27#include <string.h> 27#include <string.h>
28#include <stdlib.h> 28#include <stdlib.h>
29#include <stdio.h> 29#include <stdio.h>
30#include <glib.h>
31 30
32#include "mobilesync.h" 31#include "mobilesync.h"
33#include "device_link_service.h" 32#include "device_link_service.h"
diff --git a/src/property_list_service.c b/src/property_list_service.c
index 8af958e..47b119f 100644
--- a/src/property_list_service.c
+++ b/src/property_list_service.c
@@ -20,7 +20,6 @@
20 */ 20 */
21#include <stdlib.h> 21#include <stdlib.h>
22#include <string.h> 22#include <string.h>
23#include <glib.h>
24 23
25#include "property_list_service.h" 24#include "property_list_service.h"
26#include "idevice.h" 25#include "idevice.h"
@@ -138,7 +137,7 @@ static property_list_service_error_t internal_plist_send(property_list_service_c
138 return PROPERTY_LIST_SERVICE_E_PLIST_ERROR; 137 return PROPERTY_LIST_SERVICE_E_PLIST_ERROR;
139 } 138 }
140 139
141 nlen = GUINT32_TO_BE(length); 140 nlen = htobe32(length);
142 debug_info("sending %d bytes", length); 141 debug_info("sending %d bytes", length);
143 idevice_connection_send(client->connection, (const char*)&nlen, sizeof(nlen), (uint32_t*)&bytes); 142 idevice_connection_send(client->connection, (const char*)&nlen, sizeof(nlen), (uint32_t*)&bytes);
144 if (bytes == sizeof(nlen)) { 143 if (bytes == sizeof(nlen)) {
@@ -226,7 +225,7 @@ static property_list_service_error_t internal_plist_receive_timeout(property_lis
226 debug_info("initial read failed!"); 225 debug_info("initial read failed!");
227 return PROPERTY_LIST_SERVICE_E_MUX_ERROR; 226 return PROPERTY_LIST_SERVICE_E_MUX_ERROR;
228 } else { 227 } else {
229 pktlen = GUINT32_FROM_BE(pktlen); 228 pktlen = be32toh(pktlen);
230 if (pktlen < (1 << 24)) { /* prevent huge buffers */ 229 if (pktlen < (1 << 24)) { /* prevent huge buffers */
231 uint32_t curlen = 0; 230 uint32_t curlen = 0;
232 char *content = NULL; 231 char *content = NULL;
diff --git a/src/restore.c b/src/restore.c
index 031eaea..eedddab 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -23,7 +23,6 @@
23#include <errno.h> 23#include <errno.h>
24#include <string.h> 24#include <string.h>
25#include <stdlib.h> 25#include <stdlib.h>
26#include <glib.h>
27#include <plist/plist.h> 26#include <plist/plist.h>
28 27
29#include "property_list_service.h" 28#include "property_list_service.h"
diff --git a/src/userpref.c b/src/userpref.c
index 4aab67b..d44d5aa 100644
--- a/src/userpref.c
+++ b/src/userpref.c
@@ -19,9 +19,6 @@
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */ 20 */
21 21
22#include <glib.h>
23#include <glib/gstdio.h>
24#include <glib/gprintf.h>
25#include <stdio.h> 22#include <stdio.h>
26#include <stdint.h> 23#include <stdint.h>
27#include <stdlib.h> 24#include <stdlib.h>
@@ -30,6 +27,15 @@
30#include <gnutls/x509.h> 27#include <gnutls/x509.h>
31#include <gcrypt.h> 28#include <gcrypt.h>
32 29
30#include <dirent.h>
31#include <libgen.h>
32#include <sys/stat.h>
33#include <errno.h>
34
35#ifdef WIN32
36#include <shlobj.h>
37#endif
38
33#include "userpref.h" 39#include "userpref.h"
34#include "debug.h" 40#include "debug.h"
35 41
@@ -41,18 +47,239 @@
41#define LIBIMOBILEDEVICE_ROOT_CERTIF "RootCertificate.pem" 47#define LIBIMOBILEDEVICE_ROOT_CERTIF "RootCertificate.pem"
42#define LIBIMOBILEDEVICE_HOST_CERTIF "HostCertificate.pem" 48#define LIBIMOBILEDEVICE_HOST_CERTIF "HostCertificate.pem"
43 49
50#ifdef WIN32
51#define DIR_SEP '\\'
52#define DIR_SEP_S "\\"
53#else
54#define DIR_SEP '/'
55#define DIR_SEP_S "/"
56#endif
57
58static char __config_dir[512] = {0, };
59
60#ifdef WIN32
61static char *userpref_utf16_to_utf8(wchar_t *unistr, long len, long *items_read, long *items_written)
62{
63 if (!unistr || (len <= 0)) return NULL;
64 char *outbuf = (char*)malloc(3*(len+1));
65 int p = 0;
66 int i = 0;
67
68 wchar_t wc;
69
70 while (i < len) {
71 wc = unistr[i++];
72 if (wc >= 0x800) {
73 outbuf[p++] = (char)(0xE0 + ((wc >> 12) & 0xF));
74 outbuf[p++] = (char)(0x80 + ((wc >> 6) & 0x3F));
75 outbuf[p++] = (char)(0x80 + (wc & 0x3F));
76 } else if (wc >= 0x80) {
77 outbuf[p++] = (char)(0xC0 + ((wc >> 6) & 0x1F));
78 outbuf[p++] = (char)(0x80 + (wc & 0x3F));
79 } else {
80 outbuf[p++] = (char)(wc & 0x7F);
81 }
82 }
83 if (items_read) {
84 *items_read = i;
85 }
86 if (items_written) {
87 *items_written = p;
88 }
89 outbuf[p] = 0;
90
91 return outbuf;
92}
93#endif
94
95static const char *userpref_get_config_dir()
96{
97 if (__config_dir[0]) return __config_dir;
98#ifdef WIN32
99 wchar_t path[MAX_PATH+1];
100 HRESULT hr;
101 LPITEMIDLIST pidl = NULL;
102 BOOL b = FALSE;
103
104 hr = SHGetSpecialFolderLocation (NULL, CSIDL_LOCAL_APPDATA, &pidl);
105 if (hr == S_OK) {
106 b = SHGetPathFromIDListW (pidl, path);
107 if (b) {
108 char *cdir = userpref_utf16_to_utf8 (path, wcslen(path), NULL, NULL);
109 strcpy(__config_dir, cdir);
110 free(cdir);
111 CoTaskMemFree (pidl);
112 }
113 }
114#else
115 const char *cdir = getenv("XDG_CONFIG_HOME");
116 if (!cdir) {
117 cdir = getenv("HOME");
118 strcpy(__config_dir, cdir);
119 strcat(__config_dir, DIR_SEP_S);
120 strcat(__config_dir, ".config");
121 } else {
122 strcpy(__config_dir, cdir);
123 }
124#endif
125 strcat(__config_dir, DIR_SEP_S);
126 strcat(__config_dir, LIBIMOBILEDEVICE_CONF_DIR);
127
128 int i = strlen(__config_dir)-1;
129 while ((i > 0) && (__config_dir[i] == DIR_SEP)) {
130 __config_dir[i--] = '\0';
131 }
132
133 return __config_dir;
134}
135
136static int mkdir_with_parents(const char *dir, int mode)
137{
138 if (!dir) return -1;
139 if (mkdir(dir, mode) == 0) {
140 return 0;
141 } else {
142 if (errno == EEXIST) return 0;
143 }
144 int res;
145 char *parent = strdup(dir);
146 parent = dirname(parent);
147 if (parent) {
148 res = mkdir_with_parents(parent, mode);
149 } else {
150 res = -1;
151 }
152 free(parent);
153 if (res == 0) {
154 mkdir_with_parents(dir, mode);
155 }
156 return res;
157}
158
159static int config_write(const char *cfgfile, plist_t dict)
160{
161 if (!cfgfile || !dict || (plist_get_node_type(dict) != PLIST_DICT)) {
162 return -1;
163 }
164 int res = -1;
165
166#if 1 // old style config
167 plist_t hostid = plist_dict_get_item(dict, "HostID");
168 if (hostid && (plist_get_node_type(hostid) == PLIST_STRING)) {
169 char *hostidstr = NULL;
170 plist_get_string_val(hostid, &hostidstr);
171 if (hostidstr) {
172 FILE *fd = fopen(cfgfile, "w");
173 if (fd) {
174 fprintf(fd, "\n[Global]\nHostID=%s\n", hostidstr);
175 fclose(fd);
176 res = 0;
177 }
178 free(hostidstr);
179 }
180 }
181#endif
182#if 0
183 char *xml = NULL;
184 uint32_t length = 0;
185
186 plist_to_xml(dict, &xml, &length);
187 if (!xml) {
188 return res;
189 }
190
191 FILE *fd = fopen(cfgfile, "w");
192 if (!fd) {
193 free(xml);
194 return res;
195 }
196
197 if (fwrite(xml, 1, length, fd) == length) {
198 res = 0;
199 } else {
200 fprintf(stderr, "%s: ERROR: failed to write configuration to '%s'\n", __func__, cfgfile);
201 }
202 fclose(fd);
203
204 free(xml);
205#endif
206 return res;
207}
208
209static int config_read(const char *cfgfile, plist_t *dict)
210{
211 if (!cfgfile || !dict) {
212 return -1;
213 }
214
215 int res = -1;
216 FILE *fd = fopen(cfgfile, "r+");
217 if (!fd) {
218 return -1;
219 }
220
221 fseek(fd, 0, SEEK_END);
222 unsigned long int size = ftell(fd);
223 fseek(fd, 0, SEEK_SET);
224 unsigned char *contents = NULL;
225
226 contents = malloc(size);
227 if (fread(contents, 1, size, fd) != size) {
228 free(contents);
229 fclose(fd);
230 return -1;
231 }
232 plist_t plist = NULL;
233
234 if (!memcmp(contents, "bplist00", 8)) {
235 plist_from_bin((const char*)contents, (uint32_t)size, &plist);
236 fclose(fd);
237 } else {
238 if (memchr(contents, '<', size)) {
239 plist_from_xml((const char*)contents, (uint32_t)size, &plist);
240 }
241 if (plist) {
242 fclose(fd);
243 } else {
244 // try parsing old format config file
245 char line[256];
246 fseek(fd, 0, SEEK_SET);
247 while (fgets(line, 256, fd)) {
248 size_t llen = strlen(line)-1;
249 while ((llen > 0) && ((line[llen] == '\n') || (line[llen] == '\r'))) {
250 line[llen] = '\0';
251 }
252 if (!strncmp(line, "HostID=", 7)) {
253 plist = plist_new_dict();
254 plist_dict_insert_item(plist, "HostID", plist_new_string(line+7));
255 break;
256 }
257 }
258 fclose(fd);
259 if (plist) {
260 // write new format config
261 config_write(cfgfile, plist);
262 }
263 }
264 }
265 free(contents);
266 if (plist) {
267 *dict = plist;
268 res = 0;
269 }
270 return res;
271}
44 272
45/** 273/**
46 * Creates a freedesktop compatible configuration directory. 274 * Creates a freedesktop compatible configuration directory.
47 */ 275 */
48static void userpref_create_config_dir(void) 276static void userpref_create_config_dir(void)
49{ 277{
50 gchar *config_dir = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, NULL); 278 const char *config_path = userpref_get_config_dir();
51 279 struct stat st;
52 if (!g_file_test(config_dir, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))) 280 if (stat(config_path, &st) != 0) {
53 g_mkdir_with_parents(config_dir, 0755); 281 mkdir_with_parents(config_path, 0755);
54 282 }
55 g_free(config_dir);
56} 283}
57 284
58static int get_rand(int min, int max) 285static int get_rand(int min, int max)
@@ -94,10 +321,8 @@ static char *userpref_generate_host_id()
94 */ 321 */
95static int userpref_set_host_id(const char *host_id) 322static int userpref_set_host_id(const char *host_id)
96{ 323{
97 GKeyFile *key_file; 324 const char *config_path;
98 gsize length; 325 char *config_file;
99 gchar *buf, *config_file;
100 GIOChannel *file;
101 326
102 if (!host_id) 327 if (!host_id)
103 return 0; 328 return 0;
@@ -105,24 +330,34 @@ static int userpref_set_host_id(const char *host_id)
105 /* Make sure config directory exists */ 330 /* Make sure config directory exists */
106 userpref_create_config_dir(); 331 userpref_create_config_dir();
107 332
333 config_path = userpref_get_config_dir();
334 config_file = (char*)malloc(strlen(config_path)+1+strlen(LIBIMOBILEDEVICE_CONF_FILE)+1);
335 strcpy(config_file, config_path);
336 strcat(config_file, DIR_SEP_S);
337 strcat(config_file, LIBIMOBILEDEVICE_CONF_FILE);
338
108 /* Now parse file to get the HostID */ 339 /* Now parse file to get the HostID */
109 key_file = g_key_file_new(); 340 plist_t config = NULL;
341 config_read(config_file, &config);
342 if (!config) {
343 config = plist_new_dict();
344 plist_dict_insert_item(config, "HostID", plist_new_string(host_id));
345 } else {
346 plist_t n = plist_dict_get_item(config, "HostID");
347 if (n) {
348 plist_set_string_val(n, host_id);
349 } else {
350 plist_dict_insert_item(config, "HostID", plist_new_string(host_id));
351 }
352 }
110 353
111 /* Store in config file */ 354 /* Store in config file */
112 debug_info("setting hostID to %s", host_id); 355 debug_info("setting hostID to %s", host_id);
113 g_key_file_set_value(key_file, "Global", "HostID", host_id); 356
114 357 config_write(config_file, config);
115 /* Write config file on disk */ 358 plist_free(config);
116 buf = g_key_file_to_data(key_file, &length, NULL); 359
117 config_file = 360 free(config_file);
118 g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, LIBIMOBILEDEVICE_CONF_FILE, NULL);
119 file = g_io_channel_new_file(config_file, "w", NULL);
120 g_free(config_file);
121 g_io_channel_write_chars(file, buf, length, NULL, NULL);
122 g_io_channel_shutdown(file, TRUE, NULL);
123 g_io_channel_unref(file);
124
125 g_key_file_free(key_file);
126 return 1; 361 return 1;
127} 362}
128 363
@@ -135,23 +370,25 @@ static int userpref_set_host_id(const char *host_id)
135 */ 370 */
136void userpref_get_host_id(char **host_id) 371void userpref_get_host_id(char **host_id)
137{ 372{
138 gchar *config_file; 373 const char *config_path;
139 GKeyFile *key_file; 374 char *config_file;
140 gchar *loc_host_id;
141 375
142 config_file = 376 config_path = userpref_get_config_dir();
143 g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, LIBIMOBILEDEVICE_CONF_FILE, NULL); 377 config_file = (char*)malloc(strlen(config_path)+1+strlen(LIBIMOBILEDEVICE_CONF_FILE)+1);
378 strcpy(config_file, config_path);
379 strcat(config_file, DIR_SEP_S);
380 strcat(config_file, LIBIMOBILEDEVICE_CONF_FILE);
144 381
145 /* now parse file to get the HostID */ 382 /* now parse file to get the HostID */
146 key_file = g_key_file_new(); 383 plist_t config = NULL;
147 if (g_key_file_load_from_file(key_file, config_file, G_KEY_FILE_KEEP_COMMENTS, NULL)) { 384 if (config_read(config_file, &config) == 0) {
148 loc_host_id = g_key_file_get_value(key_file, "Global", "HostID", NULL); 385 plist_t n_host_id = plist_dict_get_item(config, "HostID");
149 if (loc_host_id) 386 if (n_host_id && (plist_get_node_type(n_host_id) == PLIST_STRING)) {
150 *host_id = strdup((char *) loc_host_id); 387 plist_get_string_val(n_host_id, host_id);
151 g_free(loc_host_id); 388 }
152 } 389 }
153 g_key_file_free(key_file); 390 plist_free(config);
154 g_free(config_file); 391 free(config_file);
155 392
156 if (!*host_id) { 393 if (!*host_id) {
157 /* no config, generate host_id */ 394 /* no config, generate host_id */
@@ -173,15 +410,23 @@ void userpref_get_host_id(char **host_id)
173int userpref_has_device_public_key(const char *uuid) 410int userpref_has_device_public_key(const char *uuid)
174{ 411{
175 int ret = 0; 412 int ret = 0;
176 gchar *config_file; 413 const char *config_path;
414 char *config_file;
415 struct stat st;
416
417 if (!uuid) return 0;
177 418
178 /* first get config file */ 419 /* first get config file */
179 gchar *device_file = g_strconcat(uuid, ".pem", NULL); 420 config_path = userpref_get_config_dir();
180 config_file = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, device_file, NULL); 421 config_file = (char*)malloc(strlen(config_path)+1+strlen(uuid)+4+1);
181 if (g_file_test(config_file, (G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR))) 422 strcpy(config_file, config_path);
423 strcat(config_file, DIR_SEP_S);
424 strcat(config_file, uuid);
425 strcat(config_file, ".pem");
426
427 if ((stat(config_file, &st) == 0) && S_ISREG(st.st_mode))
182 ret = 1; 428 ret = 1;
183 g_free(config_file); 429 free(config_file);
184 g_free(device_file);
185 return ret; 430 return ret;
186} 431}
187 432
@@ -202,10 +447,13 @@ int userpref_has_device_public_key(const char *uuid)
202 */ 447 */
203userpref_error_t userpref_get_paired_uuids(char ***list, unsigned int *count) 448userpref_error_t userpref_get_paired_uuids(char ***list, unsigned int *count)
204{ 449{
205 GDir *config_dir; 450 struct slist_t {
206 gchar *config_path; 451 char *name;
207 const gchar *dir_file; 452 void *next;
208 GList *uuids = NULL; 453 };
454 DIR *config_dir;
455 const char *config_path;
456 struct slist_t *uuids = NULL;
209 unsigned int i; 457 unsigned int i;
210 unsigned int found = 0; 458 unsigned int found = 0;
211 459
@@ -218,29 +466,44 @@ userpref_error_t userpref_get_paired_uuids(char ***list, unsigned int *count)
218 *count = 0; 466 *count = 0;
219 } 467 }
220 468
221 config_path = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, NULL); 469 config_path = userpref_get_config_dir();
222 470 config_dir = opendir(config_path);
223 config_dir = g_dir_open(config_path,0,NULL);
224 if (config_dir) { 471 if (config_dir) {
225 while ((dir_file = g_dir_read_name(config_dir))) { 472 struct dirent *entry;
226 if (g_str_has_suffix(dir_file, ".pem") && (strlen(dir_file) == 44)) { 473 struct slist_t *listp = uuids;
227 uuids = g_list_append(uuids, g_strndup(dir_file, strlen(dir_file)-4)); 474 while ((entry = readdir(config_dir))) {
475 char *ext = strstr(entry->d_name, ".pem");
476 if (ext && ((ext - entry->d_name) == 40) && (strlen(entry->d_name) == 44)) {
477 struct slist_t *ne = (struct slist_t*)malloc(sizeof(struct slist_t));
478 ne->name = (char*)malloc(41);
479 strncpy(ne->name, entry->d_name, 40);
480 ne->name[40] = 0;
481 ne->next = NULL;
482 if (!listp) {
483 listp = ne;
484 uuids = listp;
485 } else {
486 listp->next = ne;
487 listp = listp->next;
488 }
228 found++; 489 found++;
229 } 490 }
230 } 491 }
231 g_dir_close(config_dir); 492 closedir(config_dir);
232 } 493 }
233 *list = (char**)malloc(sizeof(char*) * (found+1)); 494 *list = (char**)malloc(sizeof(char*) * (found+1));
234 for (i = 0; i < found; i++) { 495 i = 0;
235 (*list)[i] = g_list_nth_data(uuids, i); 496 while (uuids) {
497 (*list)[i++] = uuids->name;
498 struct slist_t *old = uuids;
499 uuids = uuids->next;
500 free(old);
236 } 501 }
237 (*list)[i] = NULL; 502 (*list)[i] = NULL;
238 503
239 if (count) { 504 if (count) {
240 *count = found; 505 *count = found;
241 } 506 }
242 g_list_free(uuids);
243 g_free(config_path);
244 507
245 return USERPREF_E_SUCCESS; 508 return USERPREF_E_SUCCESS;
246} 509}
@@ -266,15 +529,18 @@ userpref_error_t userpref_set_device_public_key(const char *uuid, gnutls_datum_t
266 userpref_create_config_dir(); 529 userpref_create_config_dir();
267 530
268 /* build file path */ 531 /* build file path */
269 gchar *device_file = g_strconcat(uuid, ".pem", NULL); 532 const char *config_path = userpref_get_config_dir();
270 gchar *pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, device_file, NULL); 533 char *pem = (char*)malloc(strlen(config_path)+1+strlen(uuid)+4+1);
534 strcpy(pem, config_path);
535 strcat(pem, DIR_SEP_S);
536 strcat(pem, uuid);
537 strcat(pem, ".pem");
271 538
272 /* store file */ 539 /* store file */
273 FILE *pFile = fopen(pem, "wb"); 540 FILE *pFile = fopen(pem, "wb");
274 fwrite(public_key.data, 1, public_key.size, pFile); 541 fwrite(public_key.data, 1, public_key.size, pFile);
275 fclose(pFile); 542 fclose(pFile);
276 g_free(pem); 543 free(pem);
277 g_free(device_file);
278 544
279 return USERPREF_E_SUCCESS; 545 return USERPREF_E_SUCCESS;
280} 546}
@@ -292,14 +558,17 @@ userpref_error_t userpref_remove_device_public_key(const char *uuid)
292 return USERPREF_E_SUCCESS; 558 return USERPREF_E_SUCCESS;
293 559
294 /* build file path */ 560 /* build file path */
295 gchar *device_file = g_strconcat(uuid, ".pem", NULL); 561 const char *config_path = userpref_get_config_dir();
296 gchar *pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, device_file, NULL); 562 char *pem = (char*)malloc(strlen(config_path)+1+strlen(uuid)+4+1);
563 strcpy(pem, config_path);
564 strcat(pem, DIR_SEP_S);
565 strcat(pem, uuid);
566 strcat(pem, ".pem");
297 567
298 /* remove file */ 568 /* remove file */
299 g_remove(pem); 569 remove(pem);
300 570
301 g_free(pem); 571 free(pem);
302 g_free(device_file);
303 572
304 return USERPREF_E_SUCCESS; 573 return USERPREF_E_SUCCESS;
305} 574}
@@ -314,18 +583,50 @@ userpref_error_t userpref_remove_device_public_key(const char *uuid)
314 */ 583 */
315static int userpref_get_file_contents(const char *file, gnutls_datum_t * data) 584static int userpref_get_file_contents(const char *file, gnutls_datum_t * data)
316{ 585{
317 gboolean success; 586 int success;
318 gsize size; 587 unsigned long int size = 0;
319 char *content; 588 unsigned char *content = NULL;
320 gchar *filepath; 589 const char *config_path;
590 char *filepath;
591 FILE *fd;
321 592
322 if (NULL == file || NULL == data) 593 if (NULL == file || NULL == data)
323 return 0; 594 return 0;
324 595
325 /* Read file */ 596 /* Read file */
326 filepath = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, file, NULL); 597 config_path = userpref_get_config_dir();
327 success = g_file_get_contents(filepath, &content, &size, NULL); 598 filepath = (char*)malloc(strlen(config_path)+1+strlen(file)+1);
328 g_free(filepath); 599 strcpy(filepath, config_path);
600 strcat(filepath, DIR_SEP_S);
601 strcat(filepath, file);
602
603 fd = fopen(filepath, "rb");
604 if (fd) {
605 fseek(fd, 0, SEEK_END);
606 size = ftell(fd);
607 fseek(fd, 0, SEEK_SET);
608
609 // prevent huge files
610 if (size > 0xFFFFFF) {
611 fprintf(stderr, "%s: file is too big (> 16MB). Refusing to read the contents to memory!", __func__);
612 } else {
613 size_t p = 0;
614 content = (unsigned char*)malloc(size);
615 while (!feof(fd)) {
616 p += fread(content+p, 1, size-p, fd);
617 if (ferror(fd) != 0) {
618 break;
619 }
620 if (p >= size) {
621 success = 1;
622 break;
623 }
624 }
625 }
626 fclose(fd);
627 }
628
629 free(filepath);
329 630
330 /* Add it to the gnutls_datnum_t structure */ 631 /* Add it to the gnutls_datnum_t structure */
331 if (success) { 632 if (success) {
@@ -549,8 +850,8 @@ userpref_error_t userpref_get_certs_as_pem(gnutls_datum_t *pem_root_cert, gnutls
549 if (userpref_get_file_contents(LIBIMOBILEDEVICE_ROOT_CERTIF, pem_root_cert) && userpref_get_file_contents(LIBIMOBILEDEVICE_HOST_CERTIF, pem_host_cert)) 850 if (userpref_get_file_contents(LIBIMOBILEDEVICE_ROOT_CERTIF, pem_root_cert) && userpref_get_file_contents(LIBIMOBILEDEVICE_HOST_CERTIF, pem_host_cert))
550 return USERPREF_E_SUCCESS; 851 return USERPREF_E_SUCCESS;
551 else { 852 else {
552 g_free(pem_root_cert->data); 853 gnutls_free(pem_root_cert->data);
553 g_free(pem_host_cert->data); 854 gnutls_free(pem_host_cert->data);
554 } 855 }
555 return USERPREF_E_INVALID_CONF; 856 return USERPREF_E_INVALID_CONF;
556} 857}
@@ -570,7 +871,8 @@ userpref_error_t userpref_get_certs_as_pem(gnutls_datum_t *pem_root_cert, gnutls
570userpref_error_t userpref_set_keys_and_certs(gnutls_datum_t * root_key, gnutls_datum_t * root_cert, gnutls_datum_t * host_key, gnutls_datum_t * host_cert) 871userpref_error_t userpref_set_keys_and_certs(gnutls_datum_t * root_key, gnutls_datum_t * root_cert, gnutls_datum_t * host_key, gnutls_datum_t * host_cert)
571{ 872{
572 FILE *pFile; 873 FILE *pFile;
573 gchar *pem; 874 char *pem;
875 const char *config_path;
574 876
575 if (!root_key || !host_key || !root_cert || !host_cert) 877 if (!root_key || !host_key || !root_cert || !host_cert)
576 return USERPREF_E_INVALID_ARG; 878 return USERPREF_E_INVALID_ARG;
@@ -578,30 +880,44 @@ userpref_error_t userpref_set_keys_and_certs(gnutls_datum_t * root_key, gnutls_d
578 /* Make sure config directory exists */ 880 /* Make sure config directory exists */
579 userpref_create_config_dir(); 881 userpref_create_config_dir();
580 882
883 config_path = userpref_get_config_dir();
884
581 /* Now write keys and certificates to disk */ 885 /* Now write keys and certificates to disk */
582 pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, LIBIMOBILEDEVICE_ROOT_PRIVKEY, NULL); 886 pem = (char*)malloc(strlen(config_path)+1+strlen(LIBIMOBILEDEVICE_ROOT_PRIVKEY)+1);
887 strcpy(pem, config_path);
888 strcat(pem, DIR_SEP_S);
889 strcat(pem, LIBIMOBILEDEVICE_ROOT_PRIVKEY);
583 pFile = fopen(pem, "wb"); 890 pFile = fopen(pem, "wb");
584 fwrite(root_key->data, 1, root_key->size, pFile); 891 fwrite(root_key->data, 1, root_key->size, pFile);
585 fclose(pFile); 892 fclose(pFile);
586 g_free(pem); 893 free(pem);
587 894
588 pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, LIBIMOBILEDEVICE_HOST_PRIVKEY, NULL); 895 pem = (char*)malloc(strlen(config_path)+1+strlen(LIBIMOBILEDEVICE_HOST_PRIVKEY)+1);
896 strcpy(pem, config_path);
897 strcat(pem, DIR_SEP_S);
898 strcat(pem, LIBIMOBILEDEVICE_HOST_PRIVKEY);
589 pFile = fopen(pem, "wb"); 899 pFile = fopen(pem, "wb");
590 fwrite(host_key->data, 1, host_key->size, pFile); 900 fwrite(host_key->data, 1, host_key->size, pFile);
591 fclose(pFile); 901 fclose(pFile);
592 g_free(pem); 902 free(pem);
593 903
594 pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, LIBIMOBILEDEVICE_ROOT_CERTIF, NULL); 904 pem = (char*)malloc(strlen(config_path)+1+strlen(LIBIMOBILEDEVICE_ROOT_CERTIF)+1);
905 strcpy(pem, config_path);
906 strcat(pem, DIR_SEP_S);
907 strcat(pem, LIBIMOBILEDEVICE_ROOT_CERTIF);
595 pFile = fopen(pem, "wb"); 908 pFile = fopen(pem, "wb");
596 fwrite(root_cert->data, 1, root_cert->size, pFile); 909 fwrite(root_cert->data, 1, root_cert->size, pFile);
597 fclose(pFile); 910 fclose(pFile);
598 g_free(pem); 911 free(pem);
599 912
600 pem = g_build_path(G_DIR_SEPARATOR_S, g_get_user_config_dir(), LIBIMOBILEDEVICE_CONF_DIR, LIBIMOBILEDEVICE_HOST_CERTIF, NULL); 913 pem = (char*)malloc(strlen(config_path)+1+strlen(LIBIMOBILEDEVICE_HOST_CERTIF)+1);
914 strcpy(pem, config_path);
915 strcat(pem, DIR_SEP_S);
916 strcat(pem, LIBIMOBILEDEVICE_HOST_CERTIF);
601 pFile = fopen(pem, "wb"); 917 pFile = fopen(pem, "wb");
602 fwrite(host_cert->data, 1, host_cert->size, pFile); 918 fwrite(host_cert->data, 1, host_cert->size, pFile);
603 fclose(pFile); 919 fclose(pFile);
604 g_free(pem); 920 free(pem);
605 921
606 return USERPREF_E_SUCCESS; 922 return USERPREF_E_SUCCESS;
607} 923}
diff --git a/src/userpref.h b/src/userpref.h
index f9d3913..e16fd65 100644
--- a/src/userpref.h
+++ b/src/userpref.h
@@ -23,7 +23,14 @@
23#define USERPREF_H 23#define USERPREF_H
24 24
25#include <gnutls/gnutls.h> 25#include <gnutls/gnutls.h>
26#include <glib.h> 26
27#ifndef LIBIMOBILEDEVICE_INTERNAL
28#ifdef WIN32
29#define LIBIMOBILEDEVICE_INTERNAL
30#else
31#define LIBIMOBILEDEVICE_INTERNAL __attribute__((visibility("hidden")))
32#endif
33#endif
27 34
28#define USERPREF_E_SUCCESS 0 35#define USERPREF_E_SUCCESS 0
29#define USERPREF_E_INVALID_ARG -1 36#define USERPREF_E_INVALID_ARG -1
@@ -34,12 +41,12 @@
34 41
35typedef int16_t userpref_error_t; 42typedef int16_t userpref_error_t;
36 43
37G_GNUC_INTERNAL userpref_error_t userpref_get_keys_and_certs(gnutls_x509_privkey_t root_privkey, gnutls_x509_crt_t root_crt, gnutls_x509_privkey_t host_privkey, gnutls_x509_crt_t host_crt); 44LIBIMOBILEDEVICE_INTERNAL userpref_error_t userpref_get_keys_and_certs(gnutls_x509_privkey_t root_privkey, gnutls_x509_crt_t root_crt, gnutls_x509_privkey_t host_privkey, gnutls_x509_crt_t host_crt);
38G_GNUC_INTERNAL userpref_error_t userpref_set_keys_and_certs(gnutls_datum_t * root_key, gnutls_datum_t * root_cert, gnutls_datum_t * host_key, gnutls_datum_t * host_cert); 45LIBIMOBILEDEVICE_INTERNAL userpref_error_t userpref_set_keys_and_certs(gnutls_datum_t * root_key, gnutls_datum_t * root_cert, gnutls_datum_t * host_key, gnutls_datum_t * host_cert);
39G_GNUC_INTERNAL userpref_error_t userpref_get_certs_as_pem(gnutls_datum_t *pem_root_cert, gnutls_datum_t *pem_host_cert); 46LIBIMOBILEDEVICE_INTERNAL userpref_error_t userpref_get_certs_as_pem(gnutls_datum_t *pem_root_cert, gnutls_datum_t *pem_host_cert);
40G_GNUC_INTERNAL userpref_error_t userpref_set_device_public_key(const char *uuid, gnutls_datum_t public_key); 47LIBIMOBILEDEVICE_INTERNAL userpref_error_t userpref_set_device_public_key(const char *uuid, gnutls_datum_t public_key);
41userpref_error_t userpref_remove_device_public_key(const char *uuid); 48userpref_error_t userpref_remove_device_public_key(const char *uuid);
42G_GNUC_INTERNAL int userpref_has_device_public_key(const char *uuid); 49LIBIMOBILEDEVICE_INTERNAL int userpref_has_device_public_key(const char *uuid);
43userpref_error_t userpref_get_paired_uuids(char ***list, unsigned int *count); 50userpref_error_t userpref_get_paired_uuids(char ***list, unsigned int *count);
44void userpref_get_host_id(char **host_id); 51void userpref_get_host_id(char **host_id);
45 52
diff --git a/tools/Makefile.am b/tools/Makefile.am
index bb13eb9..f23b0b1 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,9 +1,13 @@
1AM_CPPFLAGS = -I$(top_srcdir)/include 1AM_CPPFLAGS = -I$(top_srcdir)/include
2 2
3AM_CFLAGS = $(GLOBAL_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS) 3AM_CFLAGS = $(GLOBAL_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(LFS_CFLAGS)
4AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) 4AM_LDFLAGS = $(libgnutls_LIBS) $(libtasn1_LIBS)
5 5
6bin_PROGRAMS = idevice_id ideviceinfo idevicepair idevicesyslog idevicebackup idevicebackup2 ideviceimagemounter idevicescreenshot ideviceenterrecovery idevicedate 6bin_PROGRAMS = idevice_id ideviceinfo idevicepair idevicesyslog ideviceimagemounter idevicescreenshot ideviceenterrecovery idevicedate
7
8if HAVE_GLIB2
9bin_PROGRAMS += idevicebackup idevicebackup2
10endif
7 11
8ideviceinfo_SOURCES = ideviceinfo.c 12ideviceinfo_SOURCES = ideviceinfo.c
9ideviceinfo_CFLAGS = $(AM_CFLAGS) 13ideviceinfo_CFLAGS = $(AM_CFLAGS)
@@ -26,13 +30,13 @@ idevice_id_LDFLAGS = $(AM_LDFLAGS)
26idevice_id_LDADD = ../src/libimobiledevice.la 30idevice_id_LDADD = ../src/libimobiledevice.la
27 31
28idevicebackup_SOURCES = idevicebackup.c 32idevicebackup_SOURCES = idevicebackup.c
29idevicebackup_CFLAGS = $(AM_CFLAGS) 33idevicebackup_CFLAGS = $(AM_CFLAGS) $(libglib2_CFLAGS)
30idevicebackup_LDFLAGS = $(AM_LDFLAGS) 34idevicebackup_LDFLAGS = $(AM_LDFLAGS) $(libglib2_LIBS)
31idevicebackup_LDADD = ../src/libimobiledevice.la 35idevicebackup_LDADD = ../src/libimobiledevice.la
32 36
33idevicebackup2_SOURCES = idevicebackup2.c 37idevicebackup2_SOURCES = idevicebackup2.c
34idevicebackup2_CFLAGS = $(AM_CFLAGS) 38idevicebackup2_CFLAGS = $(AM_CFLAGS) $(libglib2_CFLAGS)
35idevicebackup2_LDFLAGS = $(AM_LDFLAGS) 39idevicebackup2_LDFLAGS = $(AM_LDFLAGS) $(libglib2_LIBS)
36idevicebackup2_LDADD = ../src/libimobiledevice.la 40idevicebackup2_LDADD = ../src/libimobiledevice.la
37 41
38ideviceimagemounter_SOURCES = ideviceimagemounter.c 42ideviceimagemounter_SOURCES = ideviceimagemounter.c
diff --git a/tools/ideviceimagemounter.c b/tools/ideviceimagemounter.c
index 3fb4ac5..b4512f5 100644
--- a/tools/ideviceimagemounter.c
+++ b/tools/ideviceimagemounter.c
@@ -28,8 +28,9 @@
28#include <string.h> 28#include <string.h>
29#include <getopt.h> 29#include <getopt.h>
30#include <errno.h> 30#include <errno.h>
31#include <glib.h>
32#include <libgen.h> 31#include <libgen.h>
32#include <time.h>
33#include <sys/time.h>
33 34
34#include <libimobiledevice/libimobiledevice.h> 35#include <libimobiledevice/libimobiledevice.h>
35#include <libimobiledevice/lockdown.h> 36#include <libimobiledevice/lockdown.h>
@@ -165,7 +166,7 @@ static void plist_node_to_string(plist_t node)
165 double d; 166 double d;
166 uint8_t b; 167 uint8_t b;
167 uint64_t u = 0; 168 uint64_t u = 0;
168 GTimeVal tv = { 0, 0 }; 169 struct timeval tv = { 0, 0 };
169 170
170 plist_type t; 171 plist_type t;
171 172
@@ -214,9 +215,23 @@ static void plist_node_to_string(plist_t node)
214 215
215 case PLIST_DATE: 216 case PLIST_DATE:
216 plist_get_date_val(node, (int32_t*)&tv.tv_sec, (int32_t*)&tv.tv_usec); 217 plist_get_date_val(node, (int32_t*)&tv.tv_sec, (int32_t*)&tv.tv_usec);
217 s = g_time_val_to_iso8601(&tv); 218 {
218 printf("%s\n", s); 219 time_t ti = (time_t)tv.tv_sec;
219 free(s); 220 struct tm *btime = localtime(&ti);
221 if (btime) {
222 s = (char*)malloc(24);
223 memset(s, 0, 24);
224 if (strftime(s, 24, "%Y-%m-%dT%H:%M:%SZ", btime) <= 0) {
225 free (s);
226 s = NULL;
227 }
228 }
229 }
230 if (s) {
231 puts(s);
232 free(s);
233 }
234 puts("\n");
220 break; 235 break;
221 236
222 case PLIST_ARRAY: 237 case PLIST_ARRAY:
diff --git a/tools/ideviceinfo.c b/tools/ideviceinfo.c
index c5c060e..6633459 100644
--- a/tools/ideviceinfo.c
+++ b/tools/ideviceinfo.c
@@ -23,7 +23,8 @@
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#include <time.h>
27#include <sys/time.h>
27 28
28#include <libimobiledevice/libimobiledevice.h> 29#include <libimobiledevice/libimobiledevice.h>
29#include <libimobiledevice/lockdown.h> 30#include <libimobiledevice/lockdown.h>
@@ -58,6 +59,36 @@ static const char *domains[] = {
58 NULL 59 NULL
59}; 60};
60 61
62static const char base64_str[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
63static const char base64_pad = '=';
64
65static char *base64encode(const unsigned char *buf, size_t size)
66{
67 if (!buf || !(size > 0)) return NULL;
68 int outlen = (size / 3) * 4;
69 char *outbuf = (char*)malloc(outlen+5); // 4 spare bytes + 1 for '\0'
70 size_t n = 0;
71 size_t m = 0;
72 unsigned char input[3];
73 unsigned int output[4];
74 while (n < size) {
75 input[0] = buf[n];
76 input[1] = (n+1 < size) ? buf[n+1] : 0;
77 input[2] = (n+2 < size) ? buf[n+2] : 0;
78 output[0] = input[0] >> 2;
79 output[1] = ((input[0] & 3) << 4) + (input[1] >> 4);
80 output[2] = ((input[1] & 15) << 2) + (input[2] >> 6);
81 output[3] = input[2] & 63;
82 outbuf[m++] = base64_str[(int)output[0]];
83 outbuf[m++] = base64_str[(int)output[1]];
84 outbuf[m++] = (n+1 < size) ? base64_str[(int)output[2]] : base64_pad;
85 outbuf[m++] = (n+2 < size) ? base64_str[(int)output[3]] : base64_pad;
86 n+=3;
87 }
88 outbuf[m] = 0; // 0-termination!
89 return outbuf;
90}
91
61static int indent_level = 0; 92static int indent_level = 0;
62 93
63static int is_domain_known(char *domain) 94static int is_domain_known(char *domain)
@@ -121,7 +152,7 @@ static void plist_node_to_string(plist_t node)
121 double d; 152 double d;
122 uint8_t b; 153 uint8_t b;
123 uint64_t u = 0; 154 uint64_t u = 0;
124 GTimeVal tv = { 0, 0 }; 155 struct timeval tv = { 0, 0 };
125 156
126 plist_type t; 157 plist_type t;
127 158
@@ -161,10 +192,14 @@ static void plist_node_to_string(plist_t node)
161 case PLIST_DATA: 192 case PLIST_DATA:
162 plist_get_data_val(node, &data, &u); 193 plist_get_data_val(node, &data, &u);
163 if (u > 0) { 194 if (u > 0) {
164 s = g_base64_encode((guchar *)data, u); 195 s = base64encode((unsigned char*)data, u);
165 free(data); 196 free(data);
166 printf("%s\n", s); 197 if (s) {
167 g_free(s); 198 printf("%s\n", s);
199 free(s);
200 } else {
201 printf("\n");
202 }
168 } else { 203 } else {
169 printf("\n"); 204 printf("\n");
170 } 205 }
@@ -172,9 +207,24 @@ static void plist_node_to_string(plist_t node)
172 207
173 case PLIST_DATE: 208 case PLIST_DATE:
174 plist_get_date_val(node, (int32_t*)&tv.tv_sec, (int32_t*)&tv.tv_usec); 209 plist_get_date_val(node, (int32_t*)&tv.tv_sec, (int32_t*)&tv.tv_usec);
175 s = g_time_val_to_iso8601(&tv); 210 {
176 printf("%s\n", s); 211 time_t ti = (time_t)tv.tv_sec;
177 free(s); 212 struct tm *btime = localtime(&ti);
213 if (btime) {
214 s = (char*)malloc(24);
215 memset(s, 0, 24);
216 if (strftime(s, 24, "%Y-%m-%dT%H:%M:%SZ", btime) <= 0) {
217 free (s);
218 s = NULL;
219 }
220 }
221 }
222 if (s) {
223 printf("%s\n", s);
224 free(s);
225 } else {
226 printf("\n");
227 }
178 break; 228 break;
179 229
180 case PLIST_ARRAY: 230 case PLIST_ARRAY:
diff --git a/tools/idevicepair.c b/tools/idevicepair.c
index b9676b9..9eebc5c 100644
--- a/tools/idevicepair.c
+++ b/tools/idevicepair.c
@@ -148,9 +148,10 @@ int main(int argc, char **argv)
148 userpref_get_paired_uuids(&uuids, &count); 148 userpref_get_paired_uuids(&uuids, &count);
149 for (i = 0; i < count; i++) { 149 for (i = 0; i < count; i++) {
150 printf("%s\n", uuids[i]); 150 printf("%s\n", uuids[i]);
151 free(uuids[i]);
151 } 152 }
152 if (uuids) 153 if (uuids)
153 g_strfreev(uuids); 154 free(uuids);
154 if (uuid) 155 if (uuid)
155 free(uuid); 156 free(uuid);
156 return EXIT_SUCCESS; 157 return EXIT_SUCCESS;
diff --git a/tools/idevicesyslog.c b/tools/idevicesyslog.c
index 30e0c55..05e614f 100644
--- a/tools/idevicesyslog.c
+++ b/tools/idevicesyslog.c
@@ -24,7 +24,6 @@
24#include <errno.h> 24#include <errno.h>
25#include <signal.h> 25#include <signal.h>
26#include <stdlib.h> 26#include <stdlib.h>
27#include <glib.h>
28 27
29#include <libimobiledevice/libimobiledevice.h> 28#include <libimobiledevice/libimobiledevice.h>
30#include <libimobiledevice/lockdown.h> 29#include <libimobiledevice/lockdown.h>
@@ -123,7 +122,7 @@ int main(int argc, char *argv[])
123 break; 122 break;
124 } 123 }
125 124
126 datalen = GUINT32_FROM_BE(datalen); 125 datalen = be32toh(datalen);
127 126
128 if (datalen == 0) 127 if (datalen == 0)
129 continue; 128 continue;