mirror of
https://codeberg.org/unspeaker/vestal.git
synced 2025-12-06 12:56: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 crate::*;
|
||||||
|
use syscalls::{Sysno, syscall};
|
||||||
|
static NAME: &'static [char] = &['\0'];
|
||||||
impl Vestal {
|
impl Vestal {
|
||||||
pub fn execute (&self, path: impl AsRef<Path>) -> Usually<()> {
|
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 {
|
impl Vestal {
|
||||||
pub fn inspect (&self, path: impl AsRef<Path>) -> Usually<()> {
|
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 {
|
if let Some(main) = main {
|
||||||
println!("VSTPluginMain: {:?} + {:?}", &main.rva, &main.offset);
|
println!("VSTPluginMain: {:?} + {:?}", &main.rva, &main.offset);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ impl Vestal {
|
||||||
}
|
}
|
||||||
pub fn with_pe (
|
pub fn with_pe (
|
||||||
path: &impl AsRef<Path>,
|
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<()> {
|
) -> Usually<()> {
|
||||||
println!("PE: {}", path.as_ref().display());
|
println!("PE: {}", path.as_ref().display());
|
||||||
let buffer = std::fs::read(path.as_ref())?;
|
let buffer = std::fs::read(path.as_ref())?;
|
||||||
|
|
@ -50,7 +50,7 @@ impl Vestal {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cb(pe, main, imports);
|
cb(&buffer, pe, main, imports);
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err("not a PE".into())
|
Err("not a PE".into())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue