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