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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
// jkcoxson
use libc::c_uint;
use std::ffi::CString;
use crate::{
bindings as unsafe_bindings, error::DiagnosticsRelayError, idevice::Device,
services::lockdownd::LockdowndService,
};
use plist_plus::Plist;
/// Relays diagnostic logs from the iOS device to the host
pub struct DiagnosticsRelay<'a> {
pub(crate) pointer: unsafe_bindings::diagnostics_relay_client_t,
phantom: std::marker::PhantomData<&'a Device>,
}
impl DiagnosticsRelay<'_> {
/// Creates a new diagnostics relay service from a lockdown service
/// # Arguments
/// * `device` - The device to create the sevice with
/// * `service` - The lockdown service to connect on
/// # Returns
/// A struct containing the handle to the service
///
/// ***Verified:*** False
pub fn new(device: &Device, service: LockdowndService) -> Result<Self, DiagnosticsRelayError> {
let mut pointer = std::ptr::null_mut();
let result = unsafe {
unsafe_bindings::diagnostics_relay_client_new(
device.pointer,
service.pointer,
&mut pointer,
)
}
.into();
if result != DiagnosticsRelayError::Success {
return Err(result);
}
Ok(DiagnosticsRelay {
pointer,
phantom: std::marker::PhantomData,
})
}
/// Starts a new service with diagnostic relay
/// # Arguments
/// * `device` - The device to create the sevice with
/// * `label` - The label to give the connection
/// # Returns
/// A struct containing the handle to the service
///
/// ***Verified:*** False
pub fn start_service(
device: &Device,
label: impl Into<String>,
) -> Result<Self, DiagnosticsRelayError> {
let mut pointer = std::ptr::null_mut();
let label_c_string = CString::new(label.into()).unwrap();
let result = unsafe {
unsafe_bindings::diagnostics_relay_client_start_service(
device.pointer,
&mut pointer,
label_c_string.as_ptr(),
)
}
.into();
if result != DiagnosticsRelayError::Success {
return Err(result);
}
Ok(DiagnosticsRelay {
pointer,
phantom: std::marker::PhantomData,
})
}
/// Sends a goodbye to the service, terminating the connection.
/// This consumes the DiagnosticsRelayClient.
/// # Arguments
/// *none*
/// # Returns
/// *none*
///
/// ***Verified:*** False
pub fn goodbye(self) -> Result<(), DiagnosticsRelayError> {
let result = unsafe { unsafe_bindings::diagnostics_relay_goodbye(self.pointer) }.into();
if result != DiagnosticsRelayError::Success {
return Err(result);
}
Ok(())
}
/// Puts the connected device to sleep, breaking the connection.
/// # Arguments
/// *none*
/// # Returns
/// *none*
///
/// ***Verified:*** False
pub fn sleep(self) -> Result<(), DiagnosticsRelayError> {
let result = unsafe { unsafe_bindings::diagnostics_relay_sleep(self.pointer) }.into();
if result != DiagnosticsRelayError::Success {
return Err(result);
}
Ok(())
}
/// Restarts the connected device, breaking the connection.
/// # Arguments
/// * `flag` - A flag to determine actions for the restart
/// # Returns
/// *none*
///
/// ***Verified:*** False
pub fn restart(self, flag: c_uint) -> Result<(), DiagnosticsRelayError> {
let result =
unsafe { unsafe_bindings::diagnostics_relay_restart(self.pointer, flag) }.into();
if result != DiagnosticsRelayError::Success {
return Err(result);
}
Ok(())
}
/// Shuts the device off, breaking the connection.
/// # Arguments
/// * `flag` - A flag to determine actions for the restart
/// # Returns
/// *none*
///
/// ***Verified:*** False
pub fn shutdown(self, flag: c_uint) -> Result<(), DiagnosticsRelayError> {
let result =
unsafe { unsafe_bindings::diagnostics_relay_shutdown(self.pointer, flag) }.into();
if result != DiagnosticsRelayError::Success {
return Err(result);
}
Ok(())
}
/// Requests diagnostics from the device
/// # Arguments
/// * `type_` - The type of diagnostics to request
/// # Returns
/// A plist containing the diagnostics data
///
/// ***Verified:*** False
pub fn request_diagnostics(
&self,
type_: impl Into<String>,
) -> Result<Plist, DiagnosticsRelayError> {
let mut plist = std::ptr::null_mut();
let type_c_string = CString::new(type_.into()).unwrap();
let result = unsafe {
unsafe_bindings::diagnostics_relay_request_diagnostics(
self.pointer,
type_c_string.as_ptr(),
&mut plist,
)
}
.into();
if result != DiagnosticsRelayError::Success {
return Err(result);
}
Ok(plist.into())
}
/// Usage unknown
/// # Arguments
/// `keys` - Unknown
/// # Returns
/// A plist with unknown usage
///
/// ***Verified:*** False
pub fn query_mobilegestalt(&self, keys: Plist) -> Result<Plist, DiagnosticsRelayError> {
let mut plist = std::ptr::null_mut();
let result = unsafe {
unsafe_bindings::diagnostics_relay_query_mobilegestalt(
self.pointer,
keys.get_pointer(),
&mut plist,
)
}
.into();
if result != DiagnosticsRelayError::Success {
return Err(result);
}
Ok(plist.into())
}
/// Requests data from the device's IO registry
/// # Arguments
/// * `entry_name` - The name to request
/// * `entry_class` - The class to request
/// # Returns
/// A plist containing the entry
///
/// ***Verified:*** False
pub fn query_ioregistry_entry(
&self,
entry_name: impl Into<String>,
entry_class: impl Into<String>,
) -> Result<Plist, DiagnosticsRelayError> {
let mut plist = std::ptr::null_mut();
let entry_name_c_string = CString::new(entry_name.into()).unwrap();
let entry_class_c_string = CString::new(entry_class.into()).unwrap();
let result = unsafe {
unsafe_bindings::diagnostics_relay_query_ioregistry_entry(
self.pointer,
entry_name_c_string.as_ptr(),
entry_class_c_string.as_ptr(),
&mut plist,
)
}
.into();
if result != DiagnosticsRelayError::Success {
return Err(result);
}
Ok(plist.into())
}
/// Usage unknown
/// # Arguments
/// * `plane` - Unknown
/// # Returns
/// A plist containing the requested data
///
/// ***Verified:*** False
pub fn query_ioregistry_plane(
&self,
plane: impl Into<String>,
) -> Result<Plist, DiagnosticsRelayError> {
let mut plist = std::ptr::null_mut();
let plane_c_string = CString::new(plane.into()).unwrap();
let result = unsafe {
unsafe_bindings::diagnostics_relay_query_ioregistry_plane(
self.pointer,
plane_c_string.as_ptr(),
&mut plist,
)
}
.into();
if result != DiagnosticsRelayError::Success {
return Err(result);
}
Ok(plist.into())
}
}
pub enum DiagnosticsRelayAction {
WaitForDisconnect,
DisplayPass,
DisplayFail,
}
impl From<DiagnosticsRelayAction> for c_uint {
fn from(action: DiagnosticsRelayAction) -> Self {
match action {
DiagnosticsRelayAction::WaitForDisconnect => 2,
DiagnosticsRelayAction::DisplayPass => 4,
DiagnosticsRelayAction::DisplayFail => 8,
}
}
}
impl Drop for DiagnosticsRelay<'_> {
fn drop(&mut self) {
unsafe {
unsafe_bindings::diagnostics_relay_client_free(self.pointer);
}
}
}