summaryrefslogtreecommitdiff
path: root/app-pda/libimobiledevice/files/libimobiledevice-1.3.0-python.patch
blob: 28ca6da51ebd29034ff13bdda510ef6f9468336d (plain)
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
https://github.com/libimobiledevice/libimobiledevice/pull/685

From fb337f26c8e58ed0ce0750f7899ccbd5da203dee Mon Sep 17 00:00:00 2001
From: wendyisgr33n <wendyisgr33n@gmail.com>
Date: Mon, 30 Jul 2018 10:43:57 -0700
Subject: [PATCH 1/5] Fixed AFC afc.pxi definitions for Python2/3
 compatibility. Added missing public method 'remove_path_and_contents'

--- a/cython/afc.pxi
+++ b/cython/afc.pxi
@@ -52,6 +52,7 @@ cdef extern from "libimobiledevice/afc.h":
     afc_error_t afc_read_directory(afc_client_t client, char *dir, char ***list)
     afc_error_t afc_get_file_info(afc_client_t client, char *filename, char ***infolist)
     afc_error_t afc_remove_path(afc_client_t client, char *path)
+    afc_error_t afc_remove_path_and_contents(afc_client_t client, char *path)
     afc_error_t afc_rename_path(afc_client_t client, char *f, char *to)
     afc_error_t afc_make_directory(afc_client_t client, char *dir)
     afc_error_t afc_truncate(afc_client_t client, char *path, uint64_t newsize)
@@ -235,17 +236,17 @@ cdef class AfcClient(BaseService):
             afc_file_mode_t c_mode
             uint64_t handle
             AfcFile f
-        if mode == <bytes>'r':
+        if mode == b'r':
             c_mode = AFC_FOPEN_RDONLY
-        elif mode == <bytes>'r+':
+        elif mode == b'r+':
             c_mode = AFC_FOPEN_RW
-        elif mode == <bytes>'w':
+        elif mode == b'w':
             c_mode = AFC_FOPEN_WRONLY
-        elif mode == <bytes>'w+':
+        elif mode == b'w+':
             c_mode = AFC_FOPEN_WR
-        elif mode == <bytes>'a':
+        elif mode == b'a':
             c_mode = AFC_FOPEN_APPEND
-        elif mode == <bytes>'a+':
+        elif mode == b'a+':
             c_mode = AFC_FOPEN_RDAPPEND
         else:
             raise ValueError("mode string must be 'r', 'r+', 'w', 'w+', 'a', or 'a+'")
@@ -282,6 +283,9 @@ cdef class AfcClient(BaseService):
     cpdef remove_path(self, bytes path):
         self.handle_error(afc_remove_path(self._c_client, path))
 
+    cpdef remove_path_and_contents(self, bytes path):
+        self.handle_error(afc_remove_path_and_contents(self._c_client, path))
+
     cpdef rename_path(self, bytes f, bytes t):
         self.handle_error(afc_rename_path(self._c_client, f, t))
 
@@ -308,17 +312,17 @@ cdef class Afc2Client(AfcClient):
             afc_file_mode_t c_mode
             uint64_t handle
             AfcFile f
-        if mode == <bytes>'r':
+        if mode == b'r':
             c_mode = AFC_FOPEN_RDONLY
-        elif mode == <bytes>'r+':
+        elif mode == b'r+':
             c_mode = AFC_FOPEN_RW
-        elif mode == <bytes>'w':
+        elif mode == b'w':
             c_mode = AFC_FOPEN_WRONLY
-        elif mode == <bytes>'w+':
+        elif mode == b'w+':
             c_mode = AFC_FOPEN_WR
-        elif mode == <bytes>'a':
+        elif mode == b'a':
             c_mode = AFC_FOPEN_APPEND
-        elif mode == <bytes>'a+':
+        elif mode == b'a+':
             c_mode = AFC_FOPEN_RDAPPEND
         else:
             raise ValueError("mode string must be 'r', 'r+', 'w', 'w+', 'a', or 'a+'")

From b71e8935949a1d6f419a3f783d804809fb4c309b Mon Sep 17 00:00:00 2001
From: wendyisgr33n <wendyisgr33n@gmail.com>
Date: Mon, 30 Jul 2018 10:44:40 -0700
Subject: [PATCH 2/5] Fixed debugserver.pxi PyString_AsString compatibility
 with Python3

--- a/cython/debugserver.pxi
+++ b/cython/debugserver.pxi
@@ -44,7 +44,12 @@ cdef class DebugServerError(BaseError):
 
 
 # from http://stackoverflow.com/a/17511714
-from cpython.string cimport PyString_AsString
+# https://github.com/libimobiledevice/libimobiledevice/pull/198
+from cpython cimport PY_MAJOR_VERSION
+if PY_MAJOR_VERSION <= 2:
+    from cpython.string cimport PyString_AsString
+else:
+    from cpython.bytes cimport PyBytes_AsString as PyString_AsString
 cdef char ** to_cstring_array(list_str):
     if not list_str:
         return NULL

From 44f54cdc0ebb052e4a642023bbf96504e6139ec9 Mon Sep 17 00:00:00 2001
From: wendyisgr33n <wendyisgr33n@gmail.com>
Date: Mon, 30 Jul 2018 10:45:22 -0700
Subject: [PATCH 3/5] Fixed bytes/strings check in imobiledevice.pyx for
 compatibility with Python2/3

--- a/cython/imobiledevice.pyx
+++ b/cython/imobiledevice.pyx
@@ -171,7 +171,7 @@ from libc.stdlib cimport *
 cdef class iDevice(Base):
     def __cinit__(self, object udid=None, *args, **kwargs):
         cdef char* c_udid = NULL
-        if isinstance(udid, basestring):
+        if isinstance(udid, (str, bytes)):
             c_udid = <bytes>udid
         elif udid is not None:
             raise TypeError("iDevice's constructor takes a string or None as the udid argument")

From 8908619973e751b778d3fb73dc309cd5cb7f4122 Mon Sep 17 00:00:00 2001
From: wendyisgr33n <wendyisgr33n@gmail.com>
Date: Mon, 30 Jul 2018 10:45:55 -0700
Subject: [PATCH 4/5] Fixed bytes/strings checks in lockdown.pxi for
 compatibility with Python2/3

--- a/cython/lockdown.pxi
+++ b/cython/lockdown.pxi
@@ -230,9 +230,9 @@ cdef class LockdownClient(PropertyListService):
 
         if issubclass(service, BaseService) and \
             service.__service_name__ is not None \
-            and isinstance(service.__service_name__, basestring):
+            and isinstance(service.__service_name__, (str, bytes)):
             c_service_name = <bytes>service.__service_name__
-        elif isinstance(service, basestring):
+        elif isinstance(service, (str, bytes)):
             c_service_name = <bytes>service
         else:
             raise TypeError("LockdownClient.start_service() takes a BaseService or string as its first argument")
@@ -253,7 +253,7 @@ cdef class LockdownClient(PropertyListService):
 
         if not hasattr(service_class, '__service_name__') and \
             not service_class.__service_name__ is not None \
-            and not isinstance(service_class.__service_name__, basestring):
+            and not isinstance(service_class.__service_name__, (str, bytes)):
             raise TypeError("LockdownClient.get_service_client() takes a BaseService as its first argument")
 
         descriptor = self.start_service(service_class)

From e59cbdbf4e7dba98ef57a54e314a89edfea0a3dc Mon Sep 17 00:00:00 2001
From: wendyisgr33n <wendyisgr33n@gmail.com>
Date: Mon, 30 Jul 2018 10:47:48 -0700
Subject: [PATCH 5/5] Fixed method visibility in mobilebackup2.pxi API

--- a/cython/mobilebackup2.pxi
+++ b/cython/mobilebackup2.pxi
@@ -54,10 +54,10 @@ cdef class MobileBackup2Client(PropertyListService):
     cdef inline BaseError _error(self, int16_t ret):
         return MobileBackup2Error(ret)
 
-    cdef send_message(self, bytes message, plist.Node options):
+    cpdef send_message(self, bytes message, plist.Node options):
         self.handle_error(mobilebackup2_send_message(self._c_client, message, options._c_node))
 
-    cdef tuple receive_message(self):
+    cpdef tuple receive_message(self):
         cdef:
             char* dlmessage = NULL
             plist.plist_t c_node = NULL
@@ -73,29 +73,34 @@ cdef class MobileBackup2Client(PropertyListService):
                 free(dlmessage)
             raise
 
-    cdef int send_raw(self, bytes data, int length):
+    cpdef int send_raw(self, bytes data, int length):
         cdef:
-            uint32_t bytes = 0
+            uint32_t bytes_recvd = 0
             mobilebackup2_error_t err
-        err = mobilebackup2_send_raw(self._c_client, data, length, &bytes)
+        err = mobilebackup2_send_raw(self._c_client, data, length, &bytes_recvd)
         try:
             self.handle_error(err)
-            return <bint>bytes
+            return <bint>bytes_recvd
         except BaseError, e:
             raise
 
-    cdef int receive_raw(self, bytes data, int length):
+    cpdef int receive_raw(self, bytearray data, int length):
         cdef:
-            uint32_t bytes = 0
+            uint32_t bytes_recvd = 0
             mobilebackup2_error_t err
-        err = mobilebackup2_receive_raw(self._c_client, data, length, &bytes)
+        err = mobilebackup2_receive_raw(self._c_client, data, length, &bytes_recvd)
+
+        # Throwing an exception when we test if theres more data to read is excessive
+        if err == -1 and bytes_recvd == 0:
+            return 0
+
         try:
             self.handle_error(err)
-            return <bint>bytes
+            return <bint>bytes_recvd
         except BaseError, e:
             raise
 
-    cdef float version_exchange(self, double[::1] local_versions):
+    cpdef float version_exchange(self, double[::1] local_versions):
         cdef:
             double[::1] temp = None
             double remote_version = 0.0
@@ -107,8 +112,8 @@ cdef class MobileBackup2Client(PropertyListService):
         except BaseError, e:
             raise
 
-    cdef send_request(self, bytes request, bytes target_identifier, bytes source_identifier, plist.Node options):
+    cpdef send_request(self, bytes request, bytes target_identifier, bytes source_identifier, plist.Node options):
         self.handle_error(mobilebackup2_send_request(self._c_client, request, target_identifier, source_identifier, options._c_node))
 
-    cdef send_status_response(self, int status_code, bytes status1, plist.Node status2):
+    cpdef send_status_response(self, int status_code, bytes status1, plist.Node status2):
         self.handle_error(mobilebackup2_send_status_response(self._c_client, status_code, status1, status2._c_node))