try a bunch of things

This commit is contained in:
🪞👃🪞 2025-02-19 21:39:59 +02:00
parent 50e271e71b
commit 686f47a3cf
5 changed files with 174 additions and 114 deletions

View file

@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2021"
[dependencies]
object = { version = "0.36.7", features = [ "read_core", "write_core", "elf", "pe" ] }
exe = "0.5.6"
elf = "0.7.4"
goblin = "0.9.3"

View file

@ -136,3 +136,16 @@ impl Default for AEffect {
}
}
}
/// You can manually patch DLLs by prepending
/// a `#!/usr/bin/env vestal` line to them.
pub fn slice_shebang (buffer: &[u8]) -> (Vec<u8>, Vec<u8>) {
if buffer.get(0) == Some(&b'#') && buffer.get(1) == Some(&b'!') {
if let Some((bang, data)) = buffer.split_once(|x|*x==0x0a) {
(bang.to_vec(), data.to_vec())
} else {
(buffer.to_vec(), vec![])
}
} else {
(vec![], buffer.to_vec())
}
}

View file

@ -3,6 +3,10 @@ use elf::file::Elf64_Ehdr;
use std::fmt::{Debug, Display};
use syscalls::{Sysno, Errno, syscall};
pub fn relink (context: &crate::dll::PEContext) -> Usually<()> {
Ok(())
}
static EMPTY: &'static [u8] = &[b'\0'];
static CMD: &'static [u8] = &[b'/',b'p',b'r',b'o',b'c',b'/',b's',b'e',b'l',b'f',b'/',b'f',b'd',b'/',b'3',b'\0'];
static ARGS: &'static [u8] = &[b'\0',b'\0'];
@ -89,3 +93,12 @@ fn make_elf () -> Vec<u8> {
}));
buffer
}
/// From https://stackoverflow.com/a/42186553
pub fn any_as_u8_slice<T: Sized>(p: &T) -> &[u8] {
unsafe {
::core::slice::from_raw_parts(
(p as *const T) as *const u8,
::core::mem::size_of::<T>(),
)
}
}

View file

@ -7,6 +7,8 @@ pub(crate) use std::collections::HashMap;
pub(crate) use std::fs::{read, canonicalize};
pub(crate) use lancelot::loader::pe::{PE, reloc::apply_relocations};
pub(crate) use goblin::{error, Object, pe::{import::Import, export::Export}};
pub(crate) use object::read::pe::PeFile;
pub(crate) use object::write::elf::Writer as ElfWriter;
use clap::{arg, command, value_parser, ArgAction, Command};
type Usually<T> = Result<T, Box<dyn std::error::Error>>;
fn main () -> Usually<()> {
@ -16,32 +18,17 @@ fn main () -> Usually<()> {
//.arg(arg!(-s --stub <VALUE> "Provide stub import").required(false))
.get_matches();
if let Some(path) = matches.get_one::<PathBuf>("path") {
let mut context = crate::dll::PEContext::default();
context.load("main", &canonicalize(&path)?)?;
Ok(())
relink(path)
//let mut context = crate::dll::PEContext::default();
//context.load("main", &canonicalize(&path)?)?;
//crate::exec::relink(&context)?;
} else {
panic!("Pass a path to a VST DLL.")
}
}
/// From https://stackoverflow.com/a/42186553
pub fn any_as_u8_slice<T: Sized>(p: &T) -> &[u8] {
unsafe {
::core::slice::from_raw_parts(
(p as *const T) as *const u8,
::core::mem::size_of::<T>(),
)
}
}
/// You can manually patch DLLs by prepending
/// a `#!/usr/bin/env vestal` line to them.
pub fn slice_shebang (buffer: &[u8]) -> (Vec<u8>, Vec<u8>) {
if buffer.get(0) == Some(&b'#') && buffer.get(1) == Some(&b'!') {
if let Some((bang, data)) = buffer.split_once(|x|*x==0x0a) {
(bang.to_vec(), data.to_vec())
} else {
(buffer.to_vec(), vec![])
}
} else {
(vec![], buffer.to_vec())
}
fn relink (path: &PathBuf) -> Usually<()> {
let (bang, data) = crate::dll::slice_shebang(read(path)?.as_slice());
let pe = PeFile::parse(data.as_slice())?;
Ok(())
}