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