mirror of
https://codeberg.org/unspeaker/vestal.git
synced 2025-12-06 08:36:41 +01:00
first syscalls
This commit is contained in:
parent
957d42b591
commit
a22b17d6de
3 changed files with 22 additions and 6 deletions
|
|
@ -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(_) => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue