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
// jkcoxson
use crate::{
bindings as unsafe_bindings, error::MisagentError, idevice::Device,
services::lockdownd::LockdowndService,
};
use std::{ffi::CString, os::raw::c_char};
use plist_plus::Plist;
/// Manges and checks provisioning profiles
pub struct MisagentClient<'a> {
pub(crate) pointer: unsafe_bindings::misagent_client_t,
phantom: std::marker::PhantomData<&'a Device>,
}
impl MisagentClient<'_> {
/// Creates a new misagent service connection to the device
/// The use of this function is unknown
/// # Arguments
/// * `device` - The device to create the service with
/// # Returns
/// The lockdownd service
///
/// ***Verified:*** False
pub fn new(device: &Device, descriptor: LockdowndService) -> Result<Self, MisagentError> {
let mut pointer = unsafe { std::mem::zeroed() };
let result = unsafe {
unsafe_bindings::misagent_client_new(device.pointer, descriptor.pointer, &mut pointer)
}
.into();
if result != MisagentError::Success {
return Err(result);
}
Ok(MisagentClient {
pointer,
phantom: std::marker::PhantomData,
})
}
/// Starts an misagent service connection to the device
/// # Arguments
/// * `device` - The device to create the service with
/// * `service_name` - The name of the service to start
/// # Returns
/// An misagent service connection
///
/// ***Verified:*** False
pub fn start_service(device: &Device, label: impl Into<String>) -> Result<Self, MisagentError> {
let mut pointer = unsafe { std::mem::zeroed() };
let result = unsafe {
unsafe_bindings::misagent_client_start_service(
device.pointer,
&mut pointer,
label.into().as_ptr() as *const c_char,
)
}
.into();
if result != MisagentError::Success {
return Err(result);
}
Ok(MisagentClient {
pointer,
phantom: std::marker::PhantomData,
})
}
/// Installs a provisioning profile on the device
/// # Arguments
/// * `profile` - The profile as a plist
/// # Returns
/// *none*
///
/// ***Verified:*** False
pub fn install(&self, profile: Plist) -> Result<(), MisagentError> {
let result =
unsafe { unsafe_bindings::misagent_install(self.pointer, profile.get_pointer()) }
.into();
if result != MisagentError::Success {
return Err(result);
}
Ok(())
}
/// Retrieves provisioning profiles from the device
/// # Arguments
/// * `low_version` - Whether the device verion is lower than iOS 9.3
/// # Returns
/// A plist containing the results
///
/// ***Verified:*** False
pub fn copy(&self, low_version: bool) -> Result<Plist, MisagentError> {
let mut plist = unsafe { std::mem::zeroed() };
let result = if low_version {
unsafe { unsafe_bindings::misagent_copy(self.pointer, &mut plist) }.into()
} else {
unsafe { unsafe_bindings::misagent_copy_all(self.pointer, &mut plist) }.into()
};
if result != MisagentError::Success {
return Err(result);
}
Ok(plist.into())
}
/// Removes a provisioning profile from the device
/// # Arguments
/// * `id` - The ID of the provisioning profile
/// # Returns
/// *none*
///
/// ***Verified:*** False
pub fn remove(&self, id: impl Into<String>) -> Result<(), MisagentError> {
let id_c_string = CString::new(id.into()).unwrap();
let result =
unsafe { unsafe_bindings::misagent_remove(self.pointer, id_c_string.as_ptr()) }.into();
if result != MisagentError::Success {
return Err(result);
}
Ok(())
}
/// Gets the status code of the last operation
/// # Arguments
/// *none*
/// # Returns
/// The status code
pub fn get_status_code(&self) -> Result<i32, MisagentError> {
let result = unsafe { unsafe_bindings::misagent_get_status_code(self.pointer) };
if result == -1 {
return Err(MisagentError::InvalidArg);
}
Ok(result)
}
}
impl Drop for MisagentClient<'_> {
fn drop(&mut self) {
unsafe {
unsafe_bindings::misagent_client_free(self.pointer);
}
}
}