1
Fork 0

Expose load commands

This commit is contained in:
Jan-Erik Rediger 2023-12-11 16:42:42 +01:00
parent 6dba4064f2
commit f76597cb7c
3 changed files with 40 additions and 0 deletions

View file

@ -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::<PyTypeError, _>("failed"))?;
Ok(imports.into_iter().map(|exp| exp.into()).collect())
}
fn load_commands(&self) -> Vec<LoadCommand> {
self.macho()
.load_commands
.iter()
.map(|cmd| cmd.into())
.collect()
}
}
impl Drop for Object {

26
src/load_commands.rs Normal file
View file

@ -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),
}
}
}

View file

@ -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)