first syscalls

This commit is contained in:
🪞👃🪞 2025-02-18 22:39:44 +02:00
parent 957d42b591
commit a22b17d6de
3 changed files with 22 additions and 6 deletions

View file

@ -1,9 +1,25 @@
use crate::*;
use syscalls::{Sysno, syscall};
static NAME: &'static [char] = &['\0'];
impl Vestal {
pub fn execute (&self, path: impl AsRef<Path>) -> 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(_) => (),
}
}
}

View file

@ -2,7 +2,7 @@ use crate::*;
impl Vestal {
pub fn inspect (&self, path: impl AsRef<Path>) -> 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 {

View file

@ -29,7 +29,7 @@ impl Vestal {
}
pub fn with_pe (
path: &impl AsRef<Path>,
cb: impl Fn(&PE, Option<&Export>, HashMap<String, Vec<&Import>>)
cb: impl Fn(&[u8], &PE, Option<&Export>, HashMap<String, Vec<&Import>>)
) -> 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())