Iterate through a fat mach-o file to find the first single-arch mach-o part
This commit is contained in:
parent
1297ce2668
commit
53708c2bb4
2 changed files with 25 additions and 2 deletions
20
src/lib.rs
20
src/lib.rs
|
@ -3,7 +3,7 @@ use std::{
|
|||
io::Read,
|
||||
};
|
||||
|
||||
use goblin::mach::Mach;
|
||||
use goblin::mach::{Mach, SingleArch};
|
||||
use pyo3::{exceptions::PyTypeError, prelude::*};
|
||||
|
||||
mod exports;
|
||||
|
@ -57,6 +57,24 @@ impl Object {
|
|||
|
||||
let macho = match object {
|
||||
goblin::Object::Mach(Mach::Binary(macho)) => macho,
|
||||
goblin::Object::Mach(Mach::Fat(march)) => {
|
||||
let mut macho = None;
|
||||
for arch in &march {
|
||||
let arch = arch.map_err(|_| {
|
||||
PyErr::new::<PyTypeError, _>("cannot parse single arch from Mach-O file")
|
||||
})?;
|
||||
|
||||
if let SingleArch::MachO(m) = arch {
|
||||
macho = Some(m);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
match macho {
|
||||
Some(macho) => macho,
|
||||
None => return Err(PyErr::new::<PyTypeError, _>("not a macho file")),
|
||||
}
|
||||
}
|
||||
_ => return Err(PyErr::new::<PyTypeError, _>("not a macho file")),
|
||||
};
|
||||
|
||||
|
|
7
test.py
7
test.py
|
@ -1,6 +1,11 @@
|
|||
import sys
|
||||
import oelf
|
||||
|
||||
g = oelf.Object("target/debug/liboelf.dylib")
|
||||
path = "target/debug/liboelf.dylib"
|
||||
if len(sys.argv) > 1:
|
||||
path = sys.argv[1]
|
||||
|
||||
g = oelf.Object(path)
|
||||
print(f"{g.header=}")
|
||||
print(f"{g.name=}")
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue