mirror of
https://codeberg.org/unspeaker/vestal.git
synced 2025-12-06 19:26:42 +01:00
with_pe; stub execute command
This commit is contained in:
parent
940814470f
commit
c0cf91b7af
6 changed files with 536 additions and 57 deletions
|
|
@ -7,4 +7,6 @@ edition = "2021"
|
|||
exe = "0.5.6"
|
||||
goblin = "0.9.2"
|
||||
clap = { version = "4.5.4", features = [ "derive" ] }
|
||||
|
||||
lancelot = "0.8.6"
|
||||
syscalls = "0.6.18"
|
||||
#falcon = "0.5.5"
|
||||
|
|
|
|||
17
crates/vestal/src/execute.rs
Normal file
17
crates/vestal/src/execute.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
use crate::*;
|
||||
|
||||
impl Vestal {
|
||||
pub fn execute (&self, path: impl AsRef<Path>) -> Usually<()> {
|
||||
Self::with_pe(&path, |pe|{
|
||||
println!("PE: {}", path.as_ref().display());
|
||||
let mut main = None;
|
||||
for export in pe.exports.iter() {
|
||||
if let Some("VSTPluginMain") = export.name {
|
||||
println!("VSTPluginMain: {:?} + {:?}", &export.rva, &export.offset);
|
||||
main = Some(export);
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
44
crates/vestal/src/inspect.rs
Normal file
44
crates/vestal/src/inspect.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
use crate::*;
|
||||
|
||||
impl Vestal {
|
||||
pub fn inspect (&self, path: impl AsRef<Path>) -> Usually<()> {
|
||||
Self::with_pe(&path, |pe|{
|
||||
println!("PE: {}", path.as_ref().display());
|
||||
for export in pe.exports.iter() {
|
||||
if let Some("VSTPluginMain") = export.name {
|
||||
println!("VSTPluginMain: {:?} + {:?}", &export.rva, &export.offset);
|
||||
break
|
||||
}
|
||||
}
|
||||
use std::collections::HashMap;
|
||||
let mut imports: HashMap<String, Vec<&goblin::pe::import::Import>> = Default::default();
|
||||
println!("Imports: {:#?}", &pe.imports.len());
|
||||
for import in pe.imports.iter() {
|
||||
let dll = import.dll.clone();
|
||||
if !imports.contains_key(dll) {
|
||||
imports.insert(dll.to_string(), vec![]);
|
||||
}
|
||||
imports.get_mut(dll).unwrap().push(import);
|
||||
}
|
||||
println!("Dependencies: {:#?}", &imports.len());
|
||||
for (dll, imports) in imports.iter() {
|
||||
println!("- {dll}");
|
||||
for import in imports.iter() {
|
||||
println!(" {:8} + {:8} {:32}", import.rva, import.offset, import.name);
|
||||
}
|
||||
}
|
||||
})
|
||||
//let image = VecPE::from_disk_file(path)?;
|
||||
//let import_directory = ImportDirectory::parse(&image)?;
|
||||
//for descriptor in import_directory.descriptors {
|
||||
//let name = descriptor.get_name(&image)?.as_str()?;
|
||||
//println!("\n{name}:");
|
||||
//for import in descriptor.get_imports(&image).unwrap() {
|
||||
//match import {
|
||||
//ImportData::Ordinal(x) => println!("{name} #{x}"),
|
||||
//ImportData::ImportByName(s) => println!("{name} {s}")
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,62 +1,41 @@
|
|||
pub(crate) use std::path::Path;
|
||||
pub(crate) use goblin::{error, Object, pe::PE, pe::import::Import};
|
||||
//pub(crate) use exe::pe::{PE, VecPE};
|
||||
//pub(crate) use exe::types::{ImportDirectory, ImportData, CCharString};
|
||||
use clap::Parser;
|
||||
use std::path::Path;
|
||||
use goblin::{error, Object};
|
||||
use exe::pe::{PE, VecPE};
|
||||
use exe::types::{ImportDirectory, ImportData, CCharString};
|
||||
|
||||
mod execute;
|
||||
mod inspect;
|
||||
|
||||
type Usually<T> = Result<T, Box<dyn std::error::Error>>;
|
||||
|
||||
fn main () -> Usually<()> {
|
||||
VestalCli::parse().run()
|
||||
Vestal::parse().run()
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(version, about, long_about = None)]
|
||||
pub enum VestalCli {
|
||||
pub enum Vestal {
|
||||
/// Inspect a DLL
|
||||
Inspect {
|
||||
path: String
|
||||
}
|
||||
Inspect { path: String },
|
||||
/// Load a VST DLL into memory
|
||||
Execute { path: String },
|
||||
}
|
||||
|
||||
impl VestalCli {
|
||||
fn run (&self) -> Usually<()> {
|
||||
impl Vestal {
|
||||
pub fn run (&self) -> Usually<()> {
|
||||
match self {
|
||||
Self::Inspect { path } => self.inspect(path.as_str())
|
||||
Self::Inspect { path } => self.inspect(path.as_str()),
|
||||
Self::Execute { path } => self.execute(path.as_str()),
|
||||
}
|
||||
}
|
||||
fn inspect (&self, path: impl AsRef<Path>) -> Usually<()> {
|
||||
pub fn with_pe (path: &impl AsRef<Path>, cb: impl Fn(&PE<'_>)) -> Usually<()> {
|
||||
let buffer = std::fs::read(path.as_ref())?;
|
||||
match Object::parse(&buffer)? {
|
||||
Object::PE(pe) => {
|
||||
println!("PE: {}", path.as_ref().display());
|
||||
println!("\nExports: {}", &pe.exports.len());
|
||||
for export in pe.exports.iter() {
|
||||
println!("| {:?} | {:?} | {:?} |",
|
||||
export.offset, export.name, export.rva
|
||||
);
|
||||
}
|
||||
println!("\nImports: {:#?}", &pe.imports.len());
|
||||
for import in pe.imports.iter() {
|
||||
println!("| {:16} | {:32} | {} | {} | {} |",
|
||||
import.dll, import.name, import.size, import.offset, import.rva
|
||||
);
|
||||
}
|
||||
},
|
||||
_ => panic!("not a PE")
|
||||
if let Object::PE(ref pe) = Object::parse(&buffer)? {
|
||||
cb(pe);
|
||||
Ok(())
|
||||
} else {
|
||||
Err("not a PE".into())
|
||||
}
|
||||
//let image = VecPE::from_disk_file(path)?;
|
||||
//let import_directory = ImportDirectory::parse(&image)?;
|
||||
//for descriptor in import_directory.descriptors {
|
||||
//let name = descriptor.get_name(&image)?.as_str()?;
|
||||
//println!("\n{name}:");
|
||||
//for import in descriptor.get_imports(&image).unwrap() {
|
||||
//match import {
|
||||
//ImportData::Ordinal(x) => println!("{name} #{x}"),
|
||||
//ImportData::ImportByName(s) => println!("{name} {s}")
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue