diff --git a/crates/vestal/src/execute.rs b/crates/vestal/src/execute.rs index b70dae8..8b4a458 100644 --- a/crates/vestal/src/execute.rs +++ b/crates/vestal/src/execute.rs @@ -1,9 +1,25 @@ use crate::*; - +use syscalls::{Sysno, syscall}; +static NAME: &'static [char] = &['\0']; impl Vestal { pub fn execute (&self, path: impl AsRef) -> Usually<()> { - Self::with_pe(&path, |pe, main, deps|{ - + Self::with_pe(&path, |buffer, pe, main, deps|{ + let fd = Self::get_fd(); + // TODO: compose in-memory ELF binary out of PE sections and Wine libraries + Self::write(fd, buffer); + println!("{fd}"); }) } + fn get_fd () -> usize { + match unsafe { syscall!(Sysno::memfd_create, NAME.as_ptr(), 0x0001, 0) } { + Err(no) => panic!("memfd_create failed: {no}"), + Ok(fd) => fd, + } + } + fn write (fd: usize, buffer: &[u8]) { + match unsafe { syscall!(Sysno::write, fd, buffer.as_ptr()) } { + Err(no) => panic!("write failed: {no}"), + Ok(_) => (), + } + } } diff --git a/crates/vestal/src/inspect.rs b/crates/vestal/src/inspect.rs index 39fee96..2cf5e26 100644 --- a/crates/vestal/src/inspect.rs +++ b/crates/vestal/src/inspect.rs @@ -2,7 +2,7 @@ use crate::*; impl Vestal { pub fn inspect (&self, path: impl AsRef) -> Usually<()> { - Self::with_pe(&path, |pe, main, deps|{ + Self::with_pe(&path, |buffer, pe, main, deps|{ if let Some(main) = main { println!("VSTPluginMain: {:?} + {:?}", &main.rva, &main.offset); } else { diff --git a/crates/vestal/src/main.rs b/crates/vestal/src/main.rs index df0162b..d4e5ab9 100644 --- a/crates/vestal/src/main.rs +++ b/crates/vestal/src/main.rs @@ -29,7 +29,7 @@ impl Vestal { } pub fn with_pe ( path: &impl AsRef, - cb: impl Fn(&PE, Option<&Export>, HashMap>) + cb: impl Fn(&[u8], &PE, Option<&Export>, HashMap>) ) -> Usually<()> { println!("PE: {}", path.as_ref().display()); let buffer = std::fs::read(path.as_ref())?; @@ -50,7 +50,7 @@ impl Vestal { break } } - cb(pe, main, imports); + cb(&buffer, pe, main, imports); Ok(()) } else { Err("not a PE".into())