Line data Source code
1 : use super::Command;
2 : use crate::common::FromFFI;
3 : use crate::to_slice;
4 : use lief_ffi as ffi;
5 : use std::marker::PhantomData;
6 :
7 : /// Structure which represents the `LC_FUNCTION_STARTS` command
8 : ///
9 : /// This command is an array of ULEB128 encoded values
10 : pub struct FunctionStarts<'a> {
11 : ptr: cxx::UniquePtr<ffi::MachO_FunctionStarts>,
12 : _owner: PhantomData<&'a ffi::MachO_Binary>,
13 : }
14 :
15 : impl FunctionStarts<'_> {
16 : /// Offset in the ``__LINKEDIT`` segment where *start functions* are located
17 240 : pub fn data_offset(&self) -> u32 {
18 240 : self.ptr.data_offset()
19 240 : }
20 :
21 : /// Size of the functions list in the binary
22 240 : pub fn data_size(&self) -> u32 {
23 240 : self.ptr.data_size()
24 240 : }
25 :
26 : /// Addresses of every function entry point in the executable.
27 : ///
28 : /// This allows functions to exist for which there are no entries in the symbol table.
29 : ///
30 : /// <div class="warning">
31 : /// The address is relative to the __TEXT segment
32 : /// </div>
33 120 : pub fn functions(&self) -> Vec<u64> {
34 120 : Vec::from(self.ptr.functions().as_slice())
35 120 : }
36 :
37 : /// Raw payload as a slice of bytes
38 120 : pub fn content(&self) -> &[u8] {
39 120 : to_slice!(self.ptr.content());
40 120 : }
41 : }
42 :
43 : impl std::fmt::Debug for FunctionStarts<'_> {
44 240 : fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45 240 : let base = self as &dyn Command;
46 240 : f.debug_struct("FunctionStarts")
47 240 : .field("base", &base)
48 240 : .field("data_offset", &self.data_offset())
49 240 : .field("data_size", &self.data_size())
50 240 : .finish()
51 240 : }
52 : }
53 :
54 : impl FromFFI<ffi::MachO_FunctionStarts> for FunctionStarts<'_> {
55 240 : fn from_ffi(cmd: cxx::UniquePtr<ffi::MachO_FunctionStarts>) -> Self {
56 240 : Self {
57 240 : ptr: cmd,
58 240 : _owner: PhantomData,
59 240 : }
60 240 : }
61 : }
62 :
63 : impl Command for FunctionStarts<'_> {
64 960 : fn get_base(&self) -> &ffi::MachO_Command {
65 960 : self.ptr.as_ref().unwrap().as_ref()
66 960 : }
67 : }
|