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