Line data Source code
1 : use super::Command;
2 : use lief_ffi as ffi;
3 :
4 : use crate::common::FromFFI;
5 : use crate::to_slice;
6 : use std::marker::PhantomData;
7 :
8 : /// Structure that represents the `LC_DYLIB_CODE_SIGN_DRS` command
9 : pub struct CodeSignatureDir<'a> {
10 : ptr: cxx::UniquePtr<ffi::MachO_CodeSignatureDir>,
11 : _owner: PhantomData<&'a ffi::MachO_Binary>,
12 : }
13 :
14 : impl CodeSignatureDir<'_> {
15 : /// Offset in the binary where the signature starts
16 16 : pub fn data_offset(&self) -> u32 {
17 16 : self.ptr.data_offset()
18 16 : }
19 :
20 : /// Size of the raw signature
21 16 : pub fn data_size(&self) -> u32 {
22 16 : self.ptr.data_size()
23 16 : }
24 :
25 : /// Content of the signature as a slice of bytes
26 8 : pub fn content(&self) -> &[u8] {
27 8 : to_slice!(self.ptr.content());
28 8 : }
29 : }
30 :
31 : impl std::fmt::Debug for CodeSignatureDir<'_> {
32 16 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 16 : let base = self as &dyn Command;
34 16 : f.debug_struct("CodeSignatureDir")
35 16 : .field("base", &base)
36 16 : .field("data_offset", &self.data_offset())
37 16 : .field("data_size", &self.data_size())
38 16 : .finish()
39 16 : }
40 : }
41 :
42 : impl FromFFI<ffi::MachO_CodeSignatureDir> for CodeSignatureDir<'_> {
43 16 : fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_CodeSignatureDir>) -> Self {
44 16 : Self {
45 16 : ptr: cmd,
46 16 : _owner: PhantomData,
47 16 : }
48 16 : }
49 : }
50 :
51 : impl Command for CodeSignatureDir<'_> {
52 64 : fn get_base(&self) -> &ffi::MachO_Command {
53 64 : self.ptr.as_ref().unwrap().as_ref()
54 64 : }
55 : }
|