canonicalize path and expose it
This commit is contained in:
parent
f91e918c18
commit
c57a484ab6
|
@ -1,4 +1,4 @@
|
|||
use std::{fs::File, io::Read};
|
||||
use std::{fs::{File, self}, io::Read};
|
||||
|
||||
use goblin::mach::Mach;
|
||||
use pyo3::{exceptions::PyTypeError, prelude::*};
|
||||
|
@ -19,6 +19,8 @@ use symbols::Symbols;
|
|||
struct Object {
|
||||
len: usize,
|
||||
ptr: *mut u8,
|
||||
#[pyo3(get)]
|
||||
path: String,
|
||||
inner: Option<goblin::Object<'static>>,
|
||||
}
|
||||
|
||||
|
@ -29,7 +31,8 @@ unsafe impl Send for Object {}
|
|||
impl Object {
|
||||
#[new]
|
||||
fn new(path: String) -> Self {
|
||||
let mut file = File::open(path).unwrap();
|
||||
let path = fs::canonicalize(path).unwrap();
|
||||
let mut file = File::open(&path).unwrap();
|
||||
let size = file.metadata().map(|m| m.len() as usize).ok();
|
||||
let mut vec = Vec::with_capacity(size.unwrap_or(0));
|
||||
file.read_to_end(&mut vec).unwrap();
|
||||
|
@ -46,6 +49,7 @@ impl Object {
|
|||
Self {
|
||||
len,
|
||||
ptr,
|
||||
path: path.display().to_string(),
|
||||
inner: Some(object),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,6 +104,7 @@ def register_headers(
|
|||
def dynamic_entries_generator() -> Iterator[dict[str, Any]]:
|
||||
header = gob.header
|
||||
yield {
|
||||
"path": gob.path,
|
||||
"magic": header.magic,
|
||||
"cputype": header.cputype,
|
||||
"cpusubtype": header.cpusubtype,
|
||||
|
@ -116,6 +117,7 @@ def register_headers(
|
|||
|
||||
generator = Generator.make_generator(
|
||||
[
|
||||
"path",
|
||||
"magic",
|
||||
"cputype",
|
||||
"cpusubtype",
|
||||
|
|
Loading…
Reference in a new issue