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