diff --git a/src/lib.rs b/src/lib.rs index bed8a7a..182bb43 100644 --- a/src/lib.rs +++ b/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::("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::("not a macho file")), + } + } _ => return Err(PyErr::new::("not a macho file")), }; diff --git a/test.py b/test.py index 781648d..30620ab 100644 --- a/test.py +++ b/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=}")