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