Line data Source code
1 : use super::Command;
2 : use crate::common::FromFFI;
3 : use lief_ffi as ffi;
4 : use std::marker::PhantomData;
5 :
6 : /// Structure that represents the LC_ENCRYPTION_INFO / LC_ENCRYPTION_INFO_64 commands
7 : ///
8 : /// The encryption info is usually present in Mach-O executables that
9 : /// target iOS to encrypt some sections of the binary
10 : pub struct EncryptionInfo<'a> {
11 : ptr: cxx::UniquePtr<ffi::MachO_EncryptionInfo>,
12 : _owner: PhantomData<&'a ffi::MachO_Binary>,
13 : }
14 :
15 : impl EncryptionInfo<'_> {
16 : /// The beginning of the encrypted area
17 26 : pub fn crypt_offset(&self) -> u32 {
18 26 : self.ptr.crypt_offset()
19 26 : }
20 :
21 : /// The size of the encrypted area
22 26 : pub fn crypt_size(&self) -> u32 {
23 26 : self.ptr.crypt_size()
24 26 : }
25 :
26 : /// The encryption system. 0 means no encrypted
27 26 : pub fn crypt_id(&self) -> u32 {
28 26 : self.ptr.crypt_id()
29 26 : }
30 : }
31 :
32 : impl std::fmt::Debug for EncryptionInfo<'_> {
33 26 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34 26 : let base = self as &dyn Command;
35 26 : f.debug_struct("EncryptionInfo")
36 26 : .field("base", &base)
37 26 : .field("crypt_id", &self.crypt_id())
38 26 : .field("crypt_offset", &self.crypt_offset())
39 26 : .field("crypt_size", &self.crypt_size())
40 26 : .finish()
41 26 : }
42 : }
43 :
44 : impl FromFFI<ffi::MachO_EncryptionInfo> for EncryptionInfo<'_> {
45 26 : fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_EncryptionInfo>) -> Self {
46 26 : Self {
47 26 : ptr: cmd,
48 26 : _owner: PhantomData,
49 26 : }
50 26 : }
51 : }
52 :
53 : impl Command for EncryptionInfo<'_> {
54 104 : fn get_base(&self) -> &ffi::MachO_Command {
55 104 : self.ptr.as_ref().unwrap().as_ref()
56 104 : }
57 : }
|