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 20 : pub fn crypt_offset(&self) -> u32 {
18 20 : self.ptr.crypt_offset()
19 20 : }
20 :
21 : /// The size of the encrypted area
22 20 : pub fn crypt_size(&self) -> u32 {
23 20 : self.ptr.crypt_size()
24 20 : }
25 :
26 : /// The encryption system. 0 means no encrypted
27 20 : pub fn crypt_id(&self) -> u32 {
28 20 : self.ptr.crypt_id()
29 20 : }
30 : }
31 :
32 : impl std::fmt::Debug for EncryptionInfo<'_> {
33 20 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34 20 : let base = self as &dyn Command;
35 20 : f.debug_struct("EncryptionInfo")
36 20 : .field("base", &base)
37 20 : .field("crypt_id", &self.crypt_id())
38 20 : .field("crypt_offset", &self.crypt_offset())
39 20 : .field("crypt_size", &self.crypt_size())
40 20 : .finish()
41 20 : }
42 : }
43 :
44 : impl FromFFI<ffi::MachO_EncryptionInfo> for EncryptionInfo<'_> {
45 20 : fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_EncryptionInfo>) -> Self {
46 20 : Self {
47 20 : ptr: cmd,
48 20 : _owner: PhantomData,
49 20 : }
50 20 : }
51 : }
52 :
53 : impl Command for EncryptionInfo<'_> {
54 80 : fn get_base(&self) -> &ffi::MachO_Command {
55 80 : self.ptr.as_ref().unwrap().as_ref()
56 80 : }
57 : }
|