diff --git a/src/lib.rs b/src/lib.rs index f58f4d6..03a301e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,7 @@ use pyo3::{exceptions::PyTypeError, prelude::*}; mod exports; mod header; mod imports; +mod load_commands; mod sections; mod segments; mod symbols; @@ -16,6 +17,7 @@ mod symbols; use exports::Export; use header::Header; use imports::Import; +use load_commands::LoadCommand; use sections::{Section, Sections}; use segments::Segment; use symbols::Symbols; @@ -149,6 +151,14 @@ impl Object { .map_err(|_| PyErr::new::("failed"))?; Ok(imports.into_iter().map(|exp| exp.into()).collect()) } + + fn load_commands(&self) -> Vec { + self.macho() + .load_commands + .iter() + .map(|cmd| cmd.into()) + .collect() + } } impl Drop for Object { diff --git a/src/load_commands.rs b/src/load_commands.rs new file mode 100644 index 0000000..b2746d8 --- /dev/null +++ b/src/load_commands.rs @@ -0,0 +1,26 @@ +use pyo3::prelude::*; + +#[derive(Debug, Clone)] +#[pyclass] +pub struct LoadCommand { + #[pyo3(get)] + offset: usize, + #[pyo3(get)] + command: String, +} + +#[pymethods] +impl LoadCommand { + fn __repr__(&self) -> String { + format!("{:?}", self) + } +} + +impl From<&goblin::mach::load_command::LoadCommand> for LoadCommand { + fn from(lcmd: &goblin::mach::load_command::LoadCommand) -> Self { + LoadCommand { + offset: lcmd.offset, + command: format!("{:?}", lcmd.command), + } + } +} diff --git a/test.py b/test.py index caaff38..0137e42 100644 --- a/test.py +++ b/test.py @@ -34,3 +34,7 @@ for segment in g.segments(): print("sections") for section in g.sections(): print(f"{section}") + +print("load commands") +for lcmd in g.load_commands(): + print(lcmd)