forked from jkcoxson/idevice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisagent.cpp
More file actions
71 lines (60 loc) · 1.99 KB
/
Copy pathmisagent.cpp
File metadata and controls
71 lines (60 loc) · 1.99 KB
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
// Jackson Coxson
#include <idevice++/bindings.hpp>
#include <idevice++/ffi.hpp>
#include <idevice++/misagent.hpp>
#include <idevice++/provider.hpp>
namespace IdeviceFFI {
Result<Misagent, FfiError> Misagent::connect(Provider& provider) {
MisagentClientHandle* out = nullptr;
FfiError e(::misagent_connect(provider.raw(), &out));
if (e) {
provider.release();
return Err(e);
}
return Ok(Misagent::adopt(out));
}
Result<Misagent, FfiError> Misagent::connect_rsd(AdapterHandle* adapter, RsdHandshakeHandle* handshake) {
MisagentClientHandle* out = nullptr;
FfiError e(::misagent_connect_rsd(adapter, handshake, &out));
if (e) {
return Err(e);
}
return Ok(Misagent::adopt(out));
}
Result<void, FfiError> Misagent::install(const uint8_t* profile_data, size_t profile_len) {
FfiError e(::misagent_install(handle_.get(), profile_data, profile_len));
if (e) {
return Err(e);
}
return Ok();
}
Result<void, FfiError> Misagent::remove(const std::string& profile_id) {
FfiError e(::misagent_remove(handle_.get(), profile_id.c_str()));
if (e) {
return Err(e);
}
return Ok();
}
Result<std::vector<std::vector<uint8_t>>, FfiError> Misagent::copy_all() {
uint8_t** profiles = nullptr;
size_t* profiles_len = nullptr;
size_t count = 0;
FfiError e(::misagent_copy_all(handle_.get(), &profiles, &profiles_len, &count));
if (e) {
return Err(e);
}
std::vector<std::vector<uint8_t>> result;
if (profiles && profiles_len) {
result.reserve(count);
for (size_t i = 0; i < count; ++i) {
if (profiles[i] && profiles_len[i] > 0) {
result.emplace_back(profiles[i], profiles[i] + profiles_len[i]);
} else {
result.emplace_back();
}
}
::misagent_free_profiles(profiles, profiles_len, count);
}
return Ok(std::move(result));
}
} // namespace IdeviceFFI