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,112 @@
|
|
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 MisAgentError < IdeviceLibError
|
28
|
+
end
|
29
|
+
|
30
|
+
# Used to manage provisioning profiles on the device.
|
31
|
+
class MisAgentClient < C::ManagedOpaquePointer
|
32
|
+
include LibHelpers
|
33
|
+
|
34
|
+
def self.release(ptr)
|
35
|
+
C.misagent_client_free(ptr) unless ptr.null?
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.attach(opts={})
|
39
|
+
_attach_helper("com.apple.misagent", opts) do |idevice, ldsvc, p_ma|
|
40
|
+
err = C.misagent_client_new(idevice, ldsvc, p_ma)
|
41
|
+
raise MisAgentError, "misagent error: #{err}" if err != :SUCCESS
|
42
|
+
|
43
|
+
ma = p_ma.read_pointer
|
44
|
+
raise MisAgentError, "misagent_client_new returned a NULL misagent_client_t pointer" if ma.null?
|
45
|
+
return new(ma)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def status_code
|
50
|
+
C.misagent_get_status_code(self)
|
51
|
+
end
|
52
|
+
|
53
|
+
def profiles
|
54
|
+
FFI::MemoryPointer.new(:pointer) do |p_profiles|
|
55
|
+
err = C.misagent_copy(self, p_profiles)
|
56
|
+
raise MisAgentError, "misagent error: #{err}" if err != :SUCCESS
|
57
|
+
|
58
|
+
profiles = p_profiles.read_pointer.read_plist_t
|
59
|
+
raise MisAgentError, "misagent_copy returned null profiles plist_t" if profiles.nil?
|
60
|
+
return profiles
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def install(profile_hash)
|
65
|
+
err = C.misagent_install(self, Plist_t.from_ruby(profile_hash))
|
66
|
+
raise MisAgentError, "misagent error: #{err}" if err != :SUCCESS
|
67
|
+
|
68
|
+
return status_code
|
69
|
+
end
|
70
|
+
|
71
|
+
def remove(profile_ident)
|
72
|
+
err = C.misagent_remove(self, profile_ident)
|
73
|
+
raise MisAgentError, "misagent error: #{err}" if err != :SUCCESS
|
74
|
+
|
75
|
+
return status_code
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
module C
|
81
|
+
ffi_lib 'imobiledevice'
|
82
|
+
|
83
|
+
typedef enum(
|
84
|
+
:SUCCESS , 0,
|
85
|
+
:INVALID_ARG , -1,
|
86
|
+
:PLIST_ERROR , -2,
|
87
|
+
:CONN_FAILED , -3,
|
88
|
+
:REQUEST_FAILED , -4,
|
89
|
+
:UNKNOWN_ERROR , -256,
|
90
|
+
), :misagent_error_t
|
91
|
+
|
92
|
+
|
93
|
+
#misagent_error_t misagent_client_new(idevice_t device, lockdownd_service_descriptor_t service, misagent_client_t *client);
|
94
|
+
attach_function :misagent_client_new, [Idevice, LockdownServiceDescriptor, :pointer], :misagent_error_t
|
95
|
+
|
96
|
+
#misagent_error_t misagent_client_free(misagent_client_t client);
|
97
|
+
attach_function :misagent_client_free, [MisAgentClient], :misagent_error_t
|
98
|
+
|
99
|
+
#misagent_error_t misagent_install(misagent_client_t client, plist_t profile);
|
100
|
+
attach_function :misagent_install, [MisAgentClient, Plist_t], :misagent_error_t
|
101
|
+
|
102
|
+
#misagent_error_t misagent_copy(misagent_client_t client, plist_t* profiles);
|
103
|
+
attach_function :misagent_copy, [MisAgentClient, :pointer], :misagent_error_t
|
104
|
+
|
105
|
+
#misagent_error_t misagent_remove(misagent_client_t client, const char* profileID);
|
106
|
+
attach_function :misagent_remove, [MisAgentClient, :string], :misagent_error_t
|
107
|
+
|
108
|
+
#int misagent_get_status_code(misagent_client_t client);
|
109
|
+
attach_function :misagent_get_status_code, [MisAgentClient], :int
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,183 @@
|
|
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 MobileBackupError < IdeviceLibError
|
28
|
+
end
|
29
|
+
|
30
|
+
# Used to backup and restore of all device data. (Pre iOS 4)
|
31
|
+
class MobileBackupClient < C::ManagedOpaquePointer
|
32
|
+
include LibHelpers
|
33
|
+
|
34
|
+
def self.release(ptr)
|
35
|
+
C.mobilebackup_client_free(ptr) unless ptr.null?
|
36
|
+
end
|
37
|
+
|
38
|
+
FLAG_RESTORE_NOTIFY_SPRINGBOARD = (1 << 0)
|
39
|
+
FLAG_RESTORE_PRESERVE_SETTINGS = (1 << 1)
|
40
|
+
FLAG_RESTORE_PRESERVE_CAMERA_ROLL = (1 << 2)
|
41
|
+
|
42
|
+
def self.attach(opts={})
|
43
|
+
_attach_helper("com.apple.mobilebackup", opts) do |idevice, ldsvc, p_mb|
|
44
|
+
err = C.mobilebackup_client_new(idevice, ldsvc, p_mb)
|
45
|
+
raise MobileBackupError, "Mobile backup error: #{err}" if err != :SUCCESS
|
46
|
+
|
47
|
+
mb = p_mb.read_pointer
|
48
|
+
raise MisAgentError, "mobilebackup_client_new returned a NULL client" if mb.null?
|
49
|
+
return new(mb)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def receive_plist
|
54
|
+
FFI::MemoryPointer.new(:pointer) do |p_result|
|
55
|
+
err = C.mobilebackup_receive(self, p_result)
|
56
|
+
raise MobileBackupError, "Mobile backup error: #{err}" if err != :SUCCESS
|
57
|
+
|
58
|
+
return p_result.read_pointer.read_plist_t
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def send_plist(dict)
|
63
|
+
err = C.mobilebackup_send(self, Plist_t.from_ruby(dict))
|
64
|
+
raise MobileBackupError, "Mobile backup error: #{err}" if err != :SUCCESS
|
65
|
+
|
66
|
+
return true
|
67
|
+
end
|
68
|
+
|
69
|
+
def request_backup(backup_manifest={})
|
70
|
+
manifest = backup_manifest.dup
|
71
|
+
|
72
|
+
proto_version = manifest.delete(:proto_version) || '1.6'
|
73
|
+
base_path = manifest.delete(:base_path)
|
74
|
+
raise ArgumentError, "The manifest must contain a :base_path key and value" if base_path.nil?
|
75
|
+
|
76
|
+
err = C.mobilebackup_request_backup(self, Plist_t.from_ruby(manifest), base_path, proto_version)
|
77
|
+
raise MobileBackupError, "Mobile backup error: #{err}" if err != :SUCCESS
|
78
|
+
|
79
|
+
return true
|
80
|
+
end
|
81
|
+
|
82
|
+
def send_backup_file_received
|
83
|
+
err = C.mobilebackup_send_backup_file_received(self)
|
84
|
+
raise MobileBackupError, "Mobile backup error: #{err}" if err != :SUCCESS
|
85
|
+
|
86
|
+
return true
|
87
|
+
end
|
88
|
+
|
89
|
+
def request_restore(backup_manifest={})
|
90
|
+
manifest = backup_manifest.dup
|
91
|
+
|
92
|
+
proto_version = manifest.delete(:proto_version) || '1.6'
|
93
|
+
restore_flags = manifest.delete(:restore_flags) || 0
|
94
|
+
|
95
|
+
err = C.mobilebackup_request_restore(self, Plist_t.from_ruby(manifest), restore_flags, proto_version)
|
96
|
+
raise MobileBackupError, "Mobile backup error: #{err}" if err != :SUCCESS
|
97
|
+
|
98
|
+
return true
|
99
|
+
end
|
100
|
+
|
101
|
+
def receive_restore_file_received
|
102
|
+
FFI::MemoryPointer.new(:pointer) do |p_result|
|
103
|
+
err = C.mobilebackup_receive_restore_file_received(self, p_result)
|
104
|
+
raise MobileBackupError, "Mobile backup error: #{err}" if err != :SUCCESS
|
105
|
+
|
106
|
+
return p_result.read_pointer.read_plist_t
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def receive_restore_application_received
|
111
|
+
FFI::MemoryPointer.new(:pointer) do |p_result|
|
112
|
+
err = C.mobilebackup_receive_restore_application_received(self, p_result)
|
113
|
+
raise MobileBackupError, "Mobile backup error: #{err}" if err != :SUCCESS
|
114
|
+
|
115
|
+
return p_result.read_pointer.read_plist_t
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def send_restore_complete
|
120
|
+
err = C.mobilebackup_send_restore_complete(self)
|
121
|
+
raise MobileBackupError, "Mobile backup error: #{err}" if err != :SUCCESS
|
122
|
+
|
123
|
+
return true
|
124
|
+
end
|
125
|
+
|
126
|
+
def send_error(reason)
|
127
|
+
err = C.mobilebackup_send_error(self, reason)
|
128
|
+
raise MobileBackupError, "Mobile backup error: #{err}" if err != :SUCCESS
|
129
|
+
|
130
|
+
return true
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
module C
|
135
|
+
ffi_lib 'imobiledevice'
|
136
|
+
|
137
|
+
typedef enum(
|
138
|
+
:SUCCESS , 0,
|
139
|
+
:INVALID_ARG , -1,
|
140
|
+
:PLIST_ERROR , -2,
|
141
|
+
:MUX_ERROR , -3,
|
142
|
+
:BAD_VERSION , -4,
|
143
|
+
:REPLY_NOT_OK , -5,
|
144
|
+
:UNKNOWN_ERROR, -256,
|
145
|
+
), :mobilebackup_error_t
|
146
|
+
|
147
|
+
typedef :int, :mobilebackup_flags_t
|
148
|
+
|
149
|
+
#mobilebackup_error_t mobilebackup_client_new(idevice_t device, lockdownd_service_descriptor_t service, mobilebackup_client_t * client);
|
150
|
+
attach_function :mobilebackup_client_new, [Idevice, LockdownServiceDescriptor, :pointer], :mobilebackup_error_t
|
151
|
+
|
152
|
+
#mobilebackup_error_t mobilebackup_client_free(mobilebackup_client_t client);
|
153
|
+
attach_function :mobilebackup_client_free, [MobileBackupClient], :mobilebackup_error_t
|
154
|
+
|
155
|
+
#mobilebackup_error_t mobilebackup_receive(mobilebackup_client_t client, plist_t *plist);
|
156
|
+
attach_function :mobilebackup_receive, [MobileBackupClient, :pointer], :mobilebackup_error_t
|
157
|
+
|
158
|
+
#mobilebackup_error_t mobilebackup_send(mobilebackup_client_t client, plist_t plist);
|
159
|
+
attach_function :mobilebackup_send, [MobileBackupClient, Plist_t], :mobilebackup_error_t
|
160
|
+
|
161
|
+
#mobilebackup_error_t mobilebackup_request_backup(mobilebackup_client_t client, plist_t backup_manifest, const char *base_path, const char *proto_version);
|
162
|
+
attach_function :mobilebackup_request_backup, [MobileBackupClient, Plist_t, :string, :string], :mobilebackup_error_t
|
163
|
+
|
164
|
+
#mobilebackup_error_t mobilebackup_send_backup_file_received(mobilebackup_client_t client);
|
165
|
+
attach_function :mobilebackup_send_backup_file_received, [MobileBackupClient], :mobilebackup_error_t
|
166
|
+
|
167
|
+
#mobilebackup_error_t mobilebackup_request_restore(mobilebackup_client_t client, plist_t backup_manifest, mobilebackup_flags_t flags, const char *proto_version);
|
168
|
+
attach_function :mobilebackup_request_restore, [MobileBackupClient, Plist_t, :mobilebackup_flags_t, :string], :mobilebackup_error_t
|
169
|
+
|
170
|
+
#mobilebackup_error_t mobilebackup_receive_restore_file_received(mobilebackup_client_t client, plist_t *result);
|
171
|
+
attach_function :mobilebackup_receive_restore_file_received, [MobileBackupClient, :pointer], :mobilebackup_error_t
|
172
|
+
|
173
|
+
#mobilebackup_error_t mobilebackup_receive_restore_application_received(mobilebackup_client_t client, plist_t *result);
|
174
|
+
attach_function :mobilebackup_receive_restore_application_received, [MobileBackupClient, :pointer], :mobilebackup_error_t
|
175
|
+
|
176
|
+
#mobilebackup_error_t mobilebackup_send_restore_complete(mobilebackup_client_t client);
|
177
|
+
attach_function :mobilebackup_send_restore_complete, [MobileBackupClient], :mobilebackup_error_t
|
178
|
+
|
179
|
+
#mobilebackup_error_t mobilebackup_send_error(mobilebackup_client_t client, const char *reason);
|
180
|
+
attach_function :mobilebackup_send_error, [MobileBackupClient, :string], :mobilebackup_error_t
|
181
|
+
|
182
|
+
end
|
183
|
+
end
|
@@ -0,0 +1,174 @@
|
|
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 MobileBackup2Error < IdeviceLibError
|
28
|
+
end
|
29
|
+
|
30
|
+
# Used to backup and restore of all device data (mobilebackup2, iOS4+ only)
|
31
|
+
class MobileBackup2Client < C::ManagedOpaquePointer
|
32
|
+
include LibHelpers
|
33
|
+
|
34
|
+
def self.release(ptr)
|
35
|
+
C.mobilebackup2_client_free(ptr) unless ptr.null?
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.attach(opts={})
|
39
|
+
_attach_helper("com.apple.mobilebackup2", opts) do |idevice, ldsvc, p_mb2|
|
40
|
+
err = C.mobilebackup2_client_new(idevice, ldsvc, p_mb2)
|
41
|
+
raise MobileBackup2Error, "Mobile backup error: #{err}" if err != :SUCCESS
|
42
|
+
|
43
|
+
mb2 = p_mb2.read_pointer
|
44
|
+
raise MobileBackup2Error, "mobilebackup2_client_new returned a NULL client" if mb2.null?
|
45
|
+
return new(mb2)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def send_message(message, opts=nil)
|
50
|
+
if message.nil? and opts.nil?
|
51
|
+
raise ArgumentError, "Both message and options hash may not be nil"
|
52
|
+
end
|
53
|
+
opts = Plist_t.from_ruby(opts) unless opts.nil?
|
54
|
+
err = C.mobilebackup2_send_message(self, message, opts)
|
55
|
+
raise MobileBackup2Error, "Mobile backup error: #{err}" if err != :SUCCESS
|
56
|
+
|
57
|
+
return true
|
58
|
+
end
|
59
|
+
|
60
|
+
def receive_message
|
61
|
+
FFI::MemoryPointer.new(:pointer) do |p_msg|
|
62
|
+
FFI::MemoryPointer.new(:pointer) do |p_dlmessage|
|
63
|
+
err = C.mobilebackup2_receive_message(self, p_msg, p_dlmessage)
|
64
|
+
raise MobileBackup2Error, "Mobile backup error: #{err}" if err != :SUCCESS
|
65
|
+
|
66
|
+
dlmessage = p_dlmessage.read_pointer
|
67
|
+
msg = p_msg.read_pointer.read_plist_t
|
68
|
+
begin
|
69
|
+
raise MobileBackup2Error, "mobilebackup2_receive_message returned a null message plist" if msg.nil?
|
70
|
+
unless dlmessage.null?
|
71
|
+
msg[:dlmessage] = dlmessage.read_string
|
72
|
+
end
|
73
|
+
return msg
|
74
|
+
ensure
|
75
|
+
C.free(dlmessage) unless dlmessage.nil? or dlmessage.null?
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def send_raw(data)
|
82
|
+
FFI::MemoryPointer.from_bytes(data) do |p_data|
|
83
|
+
FFI::MemoryPointer.new(:uint32) do |p_sentbytes|
|
84
|
+
err = C.mobilebackup2_send_raw(self, p_data, p_data.size, p_sentbytes)
|
85
|
+
raise MobileBackup2Error, "Mobile backup error: #{err}" if err != :SUCCESS
|
86
|
+
|
87
|
+
return p_sentbytes.read_uint32
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def receive_raw(len)
|
93
|
+
FFI::MemoryPointer.new(len) do |p_data|
|
94
|
+
FFI::MemoryPointer.new(:uint32) do |p_rcvdbytes|
|
95
|
+
err = C.mobilebackup2_receive_raw(self, p_data, p_data.size, p_rcvdbytes)
|
96
|
+
raise MobileBackup2Error, "Mobile backup error: #{err}" if err != :SUCCESS
|
97
|
+
|
98
|
+
return p_data.read_bytes(p_rcvdbytes.read_uint32)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def version_exchange(local_versions)
|
104
|
+
local_versions = local_versions.map{|x| x.to_f } # should throw an error if one is not a float/float-able
|
105
|
+
FFI::MemoryPointer.new(FFI::TypeDefs[:double].size * local_versions.count) do |p_local_versions|
|
106
|
+
p_local_versions.write_array_of_double(local_versions)
|
107
|
+
FFI::MemoryPointer.new(:pointer) do |p_remote_version|
|
108
|
+
err = C.mobilebackup2_version_exchange(self, p_local_versions, local_versions.count, p_remote_version)
|
109
|
+
raise MobileBackup2Error, "Mobile backup error: #{err}" if err != :SUCCESS
|
110
|
+
|
111
|
+
return p_remote_version.read_double
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def send_request(request, target_identifier, source_identifier, opts={})
|
117
|
+
err = C.mobilebackup2_send_request(self, request, target_id, source_id, Plist_t.from_ruby(opts))
|
118
|
+
raise MobileBackup2Error, "Mobile backup error: #{err}" if err != :SUCCESS
|
119
|
+
|
120
|
+
return true
|
121
|
+
end
|
122
|
+
|
123
|
+
def send_status_response(status_code, status_message=nil, opts=nil)
|
124
|
+
opts = Plist_t.from_ruby(opts) if opts
|
125
|
+
err = C.mobilebackup2_send_status_response(self, status_code, status_message, opts)
|
126
|
+
raise MobileBackup2Error, "Mobile backup error: #{err}" if err != :SUCCESS
|
127
|
+
|
128
|
+
return true
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
module C
|
133
|
+
ffi_lib 'imobiledevice'
|
134
|
+
|
135
|
+
typedef enum(
|
136
|
+
:SUCCESS , 0,
|
137
|
+
:INVALID_ARG , -1,
|
138
|
+
:PLIST_ERROR , -2,
|
139
|
+
:MUX_ERROR , -3,
|
140
|
+
:BAD_VERSION , -4,
|
141
|
+
:REPLY_NOT_OK , -5,
|
142
|
+
:NO_COMMON_VERSION, -6,
|
143
|
+
:UNKNOWN_ERROR , -256,
|
144
|
+
), :mobilebackup2_error_t
|
145
|
+
|
146
|
+
#mobilebackup2_error_t mobilebackup2_client_new(idevice_t device, lockdownd_service_descriptor_t service, mobilebackup2_client_t * client);
|
147
|
+
attach_function :mobilebackup2_client_new, [Idevice, LockdownServiceDescriptor, :pointer], :mobilebackup2_error_t
|
148
|
+
|
149
|
+
#mobilebackup2_error_t mobilebackup2_client_free(mobilebackup2_client_t client);
|
150
|
+
attach_function :mobilebackup2_client_free, [MobileBackup2Client], :mobilebackup2_error_t
|
151
|
+
|
152
|
+
#mobilebackup2_error_t mobilebackup2_send_message(mobilebackup2_client_t client, const char *message, plist_t options);
|
153
|
+
attach_function :mobilebackup2_send_message, [MobileBackup2Client, :string, Plist_t], :mobilebackup2_error_t
|
154
|
+
|
155
|
+
#mobilebackup2_error_t mobilebackup2_receive_message(mobilebackup2_client_t client, plist_t *msg_plist, char **dlmessage);
|
156
|
+
attach_function :mobilebackup2_receive_message, [MobileBackup2Client, :pointer, :pointer], :mobilebackup2_error_t
|
157
|
+
|
158
|
+
#mobilebackup2_error_t mobilebackup2_send_raw(mobilebackup2_client_t client, const char *data, uint32_t length, uint32_t *bytes);
|
159
|
+
attach_function :mobilebackup2_send_raw, [MobileBackup2Client, :pointer, :uint32, :pointer], :mobilebackup2_error_t
|
160
|
+
|
161
|
+
#mobilebackup2_error_t mobilebackup2_receive_raw(mobilebackup2_client_t client, char *data, uint32_t length, uint32_t *bytes);
|
162
|
+
attach_function :mobilebackup2_receive_raw, [MobileBackup2Client, :pointer, :uint32, :pointer], :mobilebackup2_error_t
|
163
|
+
|
164
|
+
#mobilebackup2_error_t mobilebackup2_version_exchange(mobilebackup2_client_t client, double local_versions[], char count, double *remote_version);
|
165
|
+
attach_function :mobilebackup2_version_exchange, [MobileBackup2Client, :pointer, :char, :pointer], :mobilebackup2_error_t
|
166
|
+
|
167
|
+
#mobilebackup2_error_t mobilebackup2_send_request(mobilebackup2_client_t client, const char *request, const char *target_identifier, const char *source_identifier, plist_t options);
|
168
|
+
attach_function :mobilebackup2_send_request, [MobileBackup2Client, :string, :string, :string, Plist_t], :mobilebackup2_error_t
|
169
|
+
|
170
|
+
#mobilebackup2_error_t mobilebackup2_send_status_response(mobilebackup2_client_t client, int status_code, const char *status1, plist_t status2);
|
171
|
+
attach_function :mobilebackup2_send_status_response, [MobileBackup2Client, :int, :string, Plist_t], :mobilebackup2_error_t
|
172
|
+
|
173
|
+
end
|
174
|
+
end
|