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