idevice 1.1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/NOTICE +202 -0
- data/README.md +74 -0
- data/Rakefile +37 -0
- data/examples/idevimgmount +58 -0
- data/examples/idumplockdownvalues +64 -0
- data/examples/ifetchcrashreports +54 -0
- data/examples/ilistapps +38 -0
- data/examples/ilistudids +26 -0
- data/examples/ilog +35 -0
- data/examples/installipa +51 -0
- data/examples/iremoveapp +42 -0
- data/examples/irestart +26 -0
- data/examples/iscreenshotr +39 -0
- data/idevice.gemspec +33 -0
- data/lib/idevice.rb +69 -0
- data/lib/idevice/afc.rb +518 -0
- data/lib/idevice/c.rb +129 -0
- data/lib/idevice/diagnostics_relay.rb +185 -0
- data/lib/idevice/file_relay.rb +83 -0
- data/lib/idevice/heartbeat.rb +99 -0
- data/lib/idevice/house_arrest.rb +138 -0
- data/lib/idevice/idevice.rb +208 -0
- data/lib/idevice/image_mounter.rb +117 -0
- data/lib/idevice/installation_proxy.rb +193 -0
- data/lib/idevice/lockdown.rb +350 -0
- data/lib/idevice/misagent.rb +112 -0
- data/lib/idevice/mobilebackup.rb +183 -0
- data/lib/idevice/mobilebackup2.rb +174 -0
- data/lib/idevice/mobilesync.rb +306 -0
- data/lib/idevice/notification_proxy.rb +168 -0
- data/lib/idevice/plist.rb +366 -0
- data/lib/idevice/restore.rb +176 -0
- data/lib/idevice/sbservices.rb +152 -0
- data/lib/idevice/screenshotr.rb +88 -0
- data/lib/idevice/version.rb +3 -0
- data/lib/idevice/webinspector.rb +96 -0
- data/spec/afc_devicespec.rb +409 -0
- data/spec/diagnostics_relay_devicespec.rb +125 -0
- data/spec/file_relay_devicespec.rb +45 -0
- data/spec/heartbeat_devicespec.rb +39 -0
- data/spec/idevice_devicespec.rb +93 -0
- data/spec/idevice_spec.rb +29 -0
- data/spec/image_mounter_devicespec.rb +65 -0
- data/spec/installation_proxy_devicespec.rb +54 -0
- data/spec/lockdown_devicespec.rb +106 -0
- data/spec/misagent_devicespec.rb +43 -0
- data/spec/mobilebackup2_devicespec.rb +58 -0
- data/spec/mobilebackup_devicespec.rb +41 -0
- data/spec/mobilesync_devicespec.rb +62 -0
- data/spec/notification_proxy_devicespec.rb +45 -0
- data/spec/plist_spec.rb +176 -0
- data/spec/restore_devicespec.rb +72 -0
- data/spec/samples/plist.bin +0 -0
- data/spec/samples/plist.xml +10 -0
- data/spec/sbservices_devicespec.rb +64 -0
- data/spec/screenshotr_devicespec.rb +39 -0
- data/spec/spec_helper.rb +73 -0
- data/spec/webinspector_devicespec.rb +36 -0
- metadata +233 -0
@@ -0,0 +1,366 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2013 Eric Monti - Bluebox Security
|
3
|
+
#
|
4
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
5
|
+
# or more contributor license agreements. See the NOTICE file
|
6
|
+
# distributed with this work for additional information
|
7
|
+
# regarding copyright ownership. The ASF licenses this file
|
8
|
+
# to you under the Apache License, Version 2.0 (the
|
9
|
+
# "License"); you may not use this file except in compliance
|
10
|
+
# with the License. You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing,
|
15
|
+
# software distributed under the License is distributed on an
|
16
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
17
|
+
# KIND, either express or implied. See the License for the
|
18
|
+
# specific language governing permissions and limitations
|
19
|
+
# under the License.
|
20
|
+
|
21
|
+
require 'idevice/c'
|
22
|
+
require 'plist'
|
23
|
+
|
24
|
+
# extensions on the Plist rubygem module for
|
25
|
+
# working with libplist plist_t objects
|
26
|
+
module Plist
|
27
|
+
|
28
|
+
def self.xml_to_pointer(xml)
|
29
|
+
Idevice::Plist_t.from_xml(xml)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.binary_to_pointer(data)
|
33
|
+
Idevice::Plist_t.from_binary(data)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.parse_binary(data)
|
37
|
+
plist_ptr = binary_to_pointer(data)
|
38
|
+
if plist_ptr
|
39
|
+
res = pointer_to_ruby(plist_ptr)
|
40
|
+
return res
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.pointer_to_ruby(plist_ptr)
|
45
|
+
plist_ptr.to_ruby
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# common extension for array and hash to convert
|
50
|
+
# to a libplist plist_t object
|
51
|
+
module PlistToPointer
|
52
|
+
def to_plist_t
|
53
|
+
::Plist.xml_to_pointer(self.to_plist)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class Array
|
58
|
+
include PlistToPointer
|
59
|
+
end
|
60
|
+
|
61
|
+
class Hash
|
62
|
+
include PlistToPointer
|
63
|
+
end
|
64
|
+
|
65
|
+
module Idevice
|
66
|
+
class Plist_t < C::ManagedOpaquePointer
|
67
|
+
def self.release(ptr)
|
68
|
+
C::plist_free(ptr) unless ptr.null?
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.new_array
|
72
|
+
C.plist_new_array()
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.new_dict
|
76
|
+
C.plist_new_dict()
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.from_xml(xml)
|
80
|
+
FFI::MemoryPointer.from_bytes(xml) do |plist_xml|
|
81
|
+
FFI::MemoryPointer.new(:pointer) do |p_out|
|
82
|
+
C.plist_from_xml(plist_xml, plist_xml.size, p_out)
|
83
|
+
out = p_out.read_pointer
|
84
|
+
if out.null?
|
85
|
+
return nil
|
86
|
+
else
|
87
|
+
return new(out)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.from_binary(data)
|
94
|
+
FFI::MemoryPointer.from_bytes(data) do |plist_bin|
|
95
|
+
FFI::MemoryPointer.new(:pointer) do |p_out|
|
96
|
+
C.plist_from_bin(plist_bin, plist_bin.size, p_out)
|
97
|
+
out = p_out.read_pointer
|
98
|
+
if out.null?
|
99
|
+
return nil
|
100
|
+
else
|
101
|
+
return new(out)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.new_bool(val)
|
108
|
+
C.plist_new_bool(val)
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.new_string(str)
|
112
|
+
C.plist_new_string(str)
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.new_real(val)
|
116
|
+
C.plist_new_real(val)
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.new_uint(val)
|
120
|
+
C.plist_new_uint(val)
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.new_uid(val)
|
124
|
+
C.plist_new_uint(val)
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.new_data(data)
|
128
|
+
FFI::MemoryPointer.from_bytes(data) do |p_data|
|
129
|
+
FFI::MemoryPointer.new(:pointer) do |p_out|
|
130
|
+
return C.plist_new_data(p_data, p_data.size)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.from_ruby(obj)
|
136
|
+
case obj
|
137
|
+
when TrueClass,FalseClass
|
138
|
+
new_bool(obj)
|
139
|
+
when Hash, Array
|
140
|
+
from_xml(obj.to_plist)
|
141
|
+
when String
|
142
|
+
new_string(obj)
|
143
|
+
when StringIO
|
144
|
+
new_data(obj.string)
|
145
|
+
when Float
|
146
|
+
new_real(obj)
|
147
|
+
when Integer
|
148
|
+
new_uint(obj)
|
149
|
+
when Time,DateTime
|
150
|
+
raise NotImplementedError # XXX TODO
|
151
|
+
else
|
152
|
+
raise TypeError, "Unable to convert #{obj.class} to a plist"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def to_ruby
|
157
|
+
FFI::MemoryPointer.new(:pointer) do |plist_xml_p|
|
158
|
+
FFI::MemoryPointer.new(:pointer) do |length_p|
|
159
|
+
C.plist_to_xml(self, plist_xml_p, length_p)
|
160
|
+
length = length_p.read_uint32
|
161
|
+
if plist_xml_p.null?
|
162
|
+
return nil
|
163
|
+
else
|
164
|
+
ptr = plist_xml_p.read_pointer
|
165
|
+
begin
|
166
|
+
res = ::Plist.parse_xml(ptr.read_string_length(length).force_encoding('UTF-8'))
|
167
|
+
ensure
|
168
|
+
C.free(ptr)
|
169
|
+
end
|
170
|
+
return res
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def to_plist_t
|
177
|
+
self
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
# for use with plists via callbacks and other cases
|
182
|
+
# where the ownership of the pointer is not granted
|
183
|
+
class Plist_t_Unmanaged < Plist_t
|
184
|
+
def self.release(ptr)
|
185
|
+
#nop
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
|
190
|
+
module C
|
191
|
+
ffi_lib 'plist'
|
192
|
+
|
193
|
+
#PLIST_API plist_t plist_new_dict(void);
|
194
|
+
attach_function :plist_new_dict, [], Plist_t
|
195
|
+
|
196
|
+
#PLIST_API plist_t plist_new_array(void);
|
197
|
+
attach_function :plist_new_array, [], Plist_t
|
198
|
+
|
199
|
+
#PLIST_API plist_t plist_new_string(const char *val);
|
200
|
+
attach_function :plist_new_string, [:string], Plist_t
|
201
|
+
|
202
|
+
#PLIST_API plist_t plist_new_bool(uint8_t val);
|
203
|
+
attach_function :plist_new_bool, [:bool], Plist_t
|
204
|
+
|
205
|
+
#PLIST_API plist_t plist_new_uint(uint64_t val);
|
206
|
+
attach_function :plist_new_uint, [:uint64], Plist_t
|
207
|
+
|
208
|
+
#PLIST_API plist_t plist_new_real(double val);
|
209
|
+
attach_function :plist_new_real, [:double], Plist_t
|
210
|
+
|
211
|
+
#PLIST_API plist_t plist_new_data(const char *val, uint64_t length);
|
212
|
+
attach_function :plist_new_data, [:pointer, :uint64], Plist_t
|
213
|
+
|
214
|
+
#PLIST_API plist_t plist_new_date(int32_t sec, int32_t usec);
|
215
|
+
attach_function :plist_new_date, [:int32, :int32], Plist_t
|
216
|
+
|
217
|
+
#PLIST_API plist_t plist_new_uid(uint64_t val);
|
218
|
+
attach_function :plist_new_uid, [:uint64], Plist_t
|
219
|
+
|
220
|
+
#PLIST_API plist_t plist_copy(plist_t node);
|
221
|
+
attach_function :plist_copy, [Plist_t], Plist_t
|
222
|
+
|
223
|
+
#PLIST_API uint32_t plist_array_get_size(plist_t node);
|
224
|
+
attach_function :plist_array_get_size, [Plist_t], :uint32
|
225
|
+
|
226
|
+
#PLIST_API plist_t plist_array_get_item(plist_t node, uint32_t n);
|
227
|
+
attach_function :plist_array_get_item, [Plist_t, :uint32], Plist_t
|
228
|
+
|
229
|
+
#PLIST_API uint32_t plist_array_get_item_index(plist_t node);
|
230
|
+
attach_function :plist_array_get_item_index, [Plist_t], :uint32
|
231
|
+
|
232
|
+
#PLIST_API void plist_array_set_item(plist_t node, plist_t item, uint32_t n);
|
233
|
+
attach_function :plist_array_set_item, [Plist_t, Plist_t, :uint32], :void
|
234
|
+
|
235
|
+
#PLIST_API void plist_array_append_item(plist_t node, plist_t item);
|
236
|
+
attach_function :plist_array_append_item, [Plist_t, Plist_t], :void
|
237
|
+
|
238
|
+
#PLIST_API void plist_array_insert_item(plist_t node, plist_t item, uint32_t n);
|
239
|
+
attach_function :plist_array_insert_item, [Plist_t, Plist_t, :uint32], :void
|
240
|
+
|
241
|
+
#PLIST_API void plist_array_remove_item(plist_t node, uint32_t n);
|
242
|
+
attach_function :plist_array_remove_item, [Plist_t, :uint32], :void
|
243
|
+
|
244
|
+
#PLIST_API uint32_t plist_dict_get_size(plist_t node);
|
245
|
+
attach_function :plist_dict_get_size, [Plist_t], :uint32
|
246
|
+
|
247
|
+
typedef :pointer, :plist_dict_iter
|
248
|
+
|
249
|
+
#PLIST_API void plist_dict_new_iter(plist_t node, plist_dict_iter *iter);
|
250
|
+
attach_function :plist_dict_new_iter, [Plist_t, :plist_dict_iter], :void
|
251
|
+
|
252
|
+
#PLIST_API void plist_dict_next_item(plist_t node, plist_dict_iter iter, char **key, plist_t *val);
|
253
|
+
attach_function :plist_dict_next_item, [Plist_t, :plist_dict_iter, :pointer, :pointer], :void
|
254
|
+
|
255
|
+
#PLIST_API void plist_dict_get_item_key(plist_t node, char **key);
|
256
|
+
attach_function :plist_dict_get_item_key, [Plist_t, :pointer], :void
|
257
|
+
|
258
|
+
#PLIST_API plist_t plist_dict_get_item(plist_t node, const char* key);
|
259
|
+
attach_function :plist_dict_get_item, [Plist_t, :string], Plist_t
|
260
|
+
|
261
|
+
#PLIST_API void plist_dict_set_item(plist_t node, const char* key, plist_t item);
|
262
|
+
attach_function :plist_dict_set_item, [Plist_t, :string, Plist_t], :void
|
263
|
+
|
264
|
+
#PLIST_API void plist_dict_insert_item(plist_t node, const char* key, plist_t item);
|
265
|
+
attach_function :plist_dict_insert_item, [Plist_t, :string, Plist_t], :void
|
266
|
+
|
267
|
+
#PLIST_API void plist_dict_remove_item(plist_t node, const char* key);
|
268
|
+
attach_function :plist_dict_remove_item, [Plist_t, :string], :void
|
269
|
+
|
270
|
+
#PLIST_API plist_t plist_get_parent(plist_t node);
|
271
|
+
attach_function :plist_get_parent, [Plist_t], Plist_t
|
272
|
+
|
273
|
+
typedef enum(
|
274
|
+
:BOOLEAN, # Boolean, scalar type
|
275
|
+
:UINT, # Unsigned integer, scalar type
|
276
|
+
:REAL, # Real, scalar type
|
277
|
+
:STRING, # ASCII string, scalar type
|
278
|
+
:ARRAY, # Ordered array, structured type
|
279
|
+
:DICT, # Unordered dictionary (key/value pair), structured type
|
280
|
+
:DATE, # Date, scalar type
|
281
|
+
:DATA, # Binary data, scalar type
|
282
|
+
:KEY, # Key in dictionaries (ASCII String), scalar type
|
283
|
+
:UID, # Special type used for 'keyed encoding'
|
284
|
+
:NONE, # No type
|
285
|
+
), :plist_type
|
286
|
+
|
287
|
+
#PLIST_API plist_type plist_get_node_type(plist_t node);
|
288
|
+
attach_function :plist_get_node_type, [Plist_t], :plist_type
|
289
|
+
|
290
|
+
#PLIST_API void plist_get_key_val(plist_t node, char **val);
|
291
|
+
attach_function :plist_get_key_val, [Plist_t, :pointer], :void
|
292
|
+
|
293
|
+
#PLIST_API void plist_get_string_val(plist_t node, char **val);
|
294
|
+
attach_function :plist_get_string_val, [Plist_t, :pointer], :void
|
295
|
+
|
296
|
+
#PLIST_API void plist_get_bool_val(plist_t node, uint8_t * val);
|
297
|
+
attach_function :plist_get_bool_val, [Plist_t, :pointer], :void
|
298
|
+
|
299
|
+
#PLIST_API void plist_get_uint_val(plist_t node, uint64_t * val);
|
300
|
+
attach_function :plist_get_uint_val, [Plist_t, :pointer], :void
|
301
|
+
|
302
|
+
#PLIST_API void plist_get_real_val(plist_t node, double *val);
|
303
|
+
attach_function :plist_get_real_val, [Plist_t, :pointer], :void
|
304
|
+
|
305
|
+
#PLIST_API void plist_get_data_val(plist_t node, char **val, uint64_t * length);
|
306
|
+
attach_function :plist_get_data_val, [Plist_t, :pointer, :pointer], :void
|
307
|
+
|
308
|
+
#PLIST_API void plist_get_date_val(plist_t node, int32_t * sec, int32_t * usec);
|
309
|
+
attach_function :plist_get_date_val, [Plist_t, :pointer, :pointer], :void
|
310
|
+
|
311
|
+
#PLIST_API void plist_get_uid_val(plist_t node, uint64_t * val);
|
312
|
+
attach_function :plist_get_uid_val, [Plist_t, :pointer], :void
|
313
|
+
|
314
|
+
#PLIST_API void plist_set_type(plist_t node, plist_type type);
|
315
|
+
attach_function :plist_set_type, [Plist_t, :plist_type], :void
|
316
|
+
|
317
|
+
#PLIST_API void plist_set_key_val(plist_t node, const char *val);
|
318
|
+
attach_function :plist_set_key_val, [Plist_t, :string], :void
|
319
|
+
|
320
|
+
#PLIST_API void plist_set_string_val(plist_t node, const char *val);
|
321
|
+
attach_function :plist_set_string_val, [Plist_t, :string], :void
|
322
|
+
|
323
|
+
#PLIST_API void plist_set_bool_val(plist_t node, uint8_t val);
|
324
|
+
attach_function :plist_set_bool_val, [Plist_t, :uint8], :void
|
325
|
+
|
326
|
+
#PLIST_API void plist_set_uint_val(plist_t node, uint64_t val);
|
327
|
+
attach_function :plist_set_uint_val, [Plist_t, :uint64], :void
|
328
|
+
|
329
|
+
#PLIST_API void plist_set_real_val(plist_t node, double val);
|
330
|
+
attach_function :plist_set_real_val, [Plist_t, :double], :void
|
331
|
+
|
332
|
+
#PLIST_API void plist_set_data_val(plist_t node, const char *val, uint64_t length);
|
333
|
+
attach_function :plist_set_data_val, [Plist_t, :string, :uint64], :void
|
334
|
+
|
335
|
+
#PLIST_API void plist_set_date_val(plist_t node, int32_t sec, int32_t usec);
|
336
|
+
attach_function :plist_set_date_val, [Plist_t, :int32, :int32], :void
|
337
|
+
|
338
|
+
#PLIST_API void plist_set_uid_val(plist_t node, uint64_t val);
|
339
|
+
attach_function :plist_set_uid_val, [Plist_t, :int32, :int32], :void
|
340
|
+
|
341
|
+
# void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist);
|
342
|
+
attach_function :plist_from_bin, [:pointer, :uint32, :pointer], :void
|
343
|
+
|
344
|
+
# void plist_from_xml(const char *plist_xml, uint32_t length, plist_t * plist);
|
345
|
+
attach_function :plist_from_xml, [:pointer, :uint32, :pointer], :void
|
346
|
+
|
347
|
+
# void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length);
|
348
|
+
attach_function :plist_to_bin, [Plist_t, :pointer, :pointer], :void
|
349
|
+
|
350
|
+
# void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length);
|
351
|
+
attach_function :plist_to_xml, [Plist_t, :pointer, :pointer], :void
|
352
|
+
|
353
|
+
attach_function :plist_free, [Plist_t], :void
|
354
|
+
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
module FFI
|
359
|
+
class Pointer
|
360
|
+
def read_plist_t
|
361
|
+
unless self.null?
|
362
|
+
return Idevice::Plist_t.new(self).to_ruby
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|
366
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2013 Eric Monti - Bluebox Security
|
3
|
+
#
|
4
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
5
|
+
# or more contributor license agreements. See the NOTICE file
|
6
|
+
# distributed with this work for additional information
|
7
|
+
# regarding copyright ownership. The ASF licenses this file
|
8
|
+
# to you under the Apache License, Version 2.0 (the
|
9
|
+
# "License"); you may not use this file except in compliance
|
10
|
+
# with the License. You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing,
|
15
|
+
# software distributed under the License is distributed on an
|
16
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
17
|
+
# KIND, either express or implied. See the License for the
|
18
|
+
# specific language governing permissions and limitations
|
19
|
+
# under the License.
|
20
|
+
|
21
|
+
require 'idevice/c'
|
22
|
+
require 'idevice/plist'
|
23
|
+
require 'idevice/idevice'
|
24
|
+
require 'idevice/lockdown'
|
25
|
+
|
26
|
+
module Idevice
|
27
|
+
class RestoreErrror < IdeviceLibError
|
28
|
+
end
|
29
|
+
|
30
|
+
# Used to initiate the device restore process or reboot a device.
|
31
|
+
class RestoreClient < C::ManagedOpaquePointer
|
32
|
+
def self.release(ptr)
|
33
|
+
C.restored_client_free(ptr) unless ptr.null?
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.attach(opts={})
|
37
|
+
idevice = opts[:idevice] || Idevice.attach(opts)
|
38
|
+
label = opts[:label] || "ruby-idevice"
|
39
|
+
|
40
|
+
FFI::MemoryPointer.new(:pointer) do |p_rc|
|
41
|
+
err = C.restored_client_new(idevice, p_rc, label)
|
42
|
+
raise RestoreErrror, "Restore Error: #{err}" if err != :SUCCESS
|
43
|
+
|
44
|
+
rc = p_rc.read_pointer
|
45
|
+
raise NPError, "restore_client_new returned a NULL client" if rc.null?
|
46
|
+
return new(rc)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def goodbye
|
51
|
+
err = C.restored_goodbye(self)
|
52
|
+
raise RestoreErrror, "Restore Error: #{err}" if err != :SUCCESS
|
53
|
+
|
54
|
+
return true
|
55
|
+
end
|
56
|
+
|
57
|
+
def query_type
|
58
|
+
FFI::MemoryPointer.new(:pointer) do |p_type|
|
59
|
+
FFI::MemoryPointer.new(:uint64) do |p_vers|
|
60
|
+
err = C.restored_query_type(self, p_type, p_vers)
|
61
|
+
raise RestoreErrror, "Restore Error: #{err}" if err != :SUCCESS
|
62
|
+
|
63
|
+
type = p_type.read_pointer
|
64
|
+
raise RestoreErrror, "restored_query_type returned a null type" if type.null?
|
65
|
+
result = {
|
66
|
+
type: type.read_string,
|
67
|
+
version: p_vers.read_uint64,
|
68
|
+
}
|
69
|
+
C.free(type)
|
70
|
+
return result
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def query_value(key)
|
76
|
+
FFI::MemoryPointer.new(:pointer) do |p_value|
|
77
|
+
err = C.restored_query_value(self, key, p_value)
|
78
|
+
raise RestoreErrror, "Restore Error: #{err}" if err != :SUCCESS
|
79
|
+
|
80
|
+
return p_value.read_pointer.read_plist_t
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def get_value(key)
|
85
|
+
FFI::MemoryPointer.new(:pointer) do |p_value|
|
86
|
+
err = C.restored_get_value(self, key, p_value)
|
87
|
+
raise RestoreErrror, "Restore Error: #{err}" if err != :SUCCESS
|
88
|
+
return p_value.read_pointer.read_plist_t
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def send_plist(dict)
|
93
|
+
err = C.restored_send(self, Plist_t.from_ruby(hash))
|
94
|
+
raise RestoreErrror, "Restore Error: #{err}" if err != :SUCCESS
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
def receive_plist
|
99
|
+
FFI::MemoryPointer.new(:pointer) do |p_value|
|
100
|
+
err = C.restored_receive(self, p_value)
|
101
|
+
raise RestoreErrror, "Restore Error: #{err}" if err != :SUCCESS
|
102
|
+
return p_value.read_pointer.read_plist_t
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def start_restore(version, options={})
|
107
|
+
err = C.restored_start_restore(self, Plist_t.from_ruby(options), version)
|
108
|
+
raise RestoreErrror, "Restore Error: #{err}" if err != :SUCCESS
|
109
|
+
|
110
|
+
return true
|
111
|
+
end
|
112
|
+
|
113
|
+
def reboot
|
114
|
+
err = C.restored_reboot(self)
|
115
|
+
raise RestoreErrror, "Restore Error: #{err}" if err != :SUCCESS
|
116
|
+
|
117
|
+
return true
|
118
|
+
end
|
119
|
+
|
120
|
+
def set_label(label)
|
121
|
+
C.restored_client_set_label(self, label)
|
122
|
+
return true
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
module C
|
128
|
+
ffi_lib 'imobiledevice'
|
129
|
+
|
130
|
+
typedef enum(
|
131
|
+
:SUCCESS , 0,
|
132
|
+
:INVALID_ARG , -1,
|
133
|
+
:INVALID_CONF , -2,
|
134
|
+
:PLIST_ERROR , -3,
|
135
|
+
:DICT_ERROR , -4,
|
136
|
+
:NOT_ENOUGH_DATA , -5,
|
137
|
+
:MUX_ERROR , -6,
|
138
|
+
:START_RESTORE_FAILED, -7,
|
139
|
+
:UNKNOWN_ERROR , -256,
|
140
|
+
), :restored_error_t
|
141
|
+
|
142
|
+
#restored_error_t restored_client_new(idevice_t device, restored_client_t *client, const char *label);
|
143
|
+
attach_function :restored_client_new, [Idevice, :pointer, :string], :restored_error_t
|
144
|
+
|
145
|
+
#restored_error_t restored_client_free(restored_client_t client);
|
146
|
+
attach_function :restored_client_free, [RestoreClient], :restored_error_t
|
147
|
+
|
148
|
+
#restored_error_t restored_query_type(restored_client_t client, char **type, uint64_t *version);
|
149
|
+
attach_function :restored_query_type, [RestoreClient, :pointer, :pointer], :restored_error_t
|
150
|
+
|
151
|
+
#restored_error_t restored_query_value(restored_client_t client, const char *key, plist_t *value);
|
152
|
+
attach_function :restored_query_value, [RestoreClient, :string, :pointer], :restored_error_t
|
153
|
+
|
154
|
+
#restored_error_t restored_get_value(restored_client_t client, const char *key, plist_t *value) ;
|
155
|
+
attach_function :restored_get_value, [RestoreClient, :string, :pointer], :restored_error_t
|
156
|
+
|
157
|
+
#restored_error_t restored_send(restored_client_t client, plist_t plist);
|
158
|
+
attach_function :restored_send, [RestoreClient, Plist_t], :restored_error_t
|
159
|
+
|
160
|
+
#restored_error_t restored_receive(restored_client_t client, plist_t *plist);
|
161
|
+
attach_function :restored_receive, [RestoreClient, :pointer], :restored_error_t
|
162
|
+
|
163
|
+
#restored_error_t restored_goodbye(restored_client_t client);
|
164
|
+
attach_function :restored_goodbye, [RestoreClient], :restored_error_t
|
165
|
+
|
166
|
+
#restored_error_t restored_start_restore(restored_client_t client, plist_t options, uint64_t version);
|
167
|
+
attach_function :restored_start_restore, [RestoreClient, Plist_t, :uint64], :restored_error_t
|
168
|
+
|
169
|
+
#restored_error_t restored_reboot(restored_client_t client);
|
170
|
+
attach_function :restored_reboot, [RestoreClient], :restored_error_t
|
171
|
+
|
172
|
+
#void restored_client_set_label(restored_client_t client, const char *label);
|
173
|
+
attach_function :restored_client_set_label, [RestoreClient, :string], :void
|
174
|
+
|
175
|
+
end
|
176
|
+
end
|