mirror of
https://codeberg.org/unspeaker/vestal.git
synced 2025-12-06 08:36:41 +01:00
move imports/exports logic to with_pe
This commit is contained in:
parent
c0cf91b7af
commit
957d42b591
3 changed files with 35 additions and 36 deletions
|
|
@ -2,16 +2,8 @@ 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
|
||||
}
|
||||
}
|
||||
Self::with_pe(&path, |pe, main, deps|{
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,26 +2,15 @@ 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
|
||||
}
|
||||
Self::with_pe(&path, |pe, main, deps|{
|
||||
if let Some(main) = main {
|
||||
println!("VSTPluginMain: {:?} + {:?}", &main.rva, &main.offset);
|
||||
} else {
|
||||
panic!("VSTPluginMain not found. This is not a valid VST plugin.");
|
||||
}
|
||||
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!("Dependencies: {:#?}", &deps.len());
|
||||
for (dll, imports) in deps.iter() {
|
||||
println!("- {dll}");
|
||||
for import in imports.iter() {
|
||||
println!(" {:8} + {:8} {:32}", import.rva, import.offset, import.name);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
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;
|
||||
|
||||
mod execute;
|
||||
mod inspect;
|
||||
pub(crate) use std::path::Path;
|
||||
pub(crate) use goblin::{error, Object, pe::{PE, import::Import, export::Export}};
|
||||
use std::collections::HashMap;
|
||||
use clap::Parser;
|
||||
|
||||
type Usually<T> = Result<T, Box<dyn std::error::Error>>;
|
||||
|
||||
|
|
@ -29,10 +27,30 @@ impl Vestal {
|
|||
Self::Execute { path } => self.execute(path.as_str()),
|
||||
}
|
||||
}
|
||||
pub fn with_pe (path: &impl AsRef<Path>, cb: impl Fn(&PE<'_>)) -> Usually<()> {
|
||||
pub fn with_pe (
|
||||
path: &impl AsRef<Path>,
|
||||
cb: impl Fn(&PE, Option<&Export>, HashMap<String, Vec<&Import>>)
|
||||
) -> Usually<()> {
|
||||
println!("PE: {}", path.as_ref().display());
|
||||
let buffer = std::fs::read(path.as_ref())?;
|
||||
if let Object::PE(ref pe) = Object::parse(&buffer)? {
|
||||
cb(pe);
|
||||
let mut main = None;
|
||||
let mut imports: HashMap<_, _> = Default::default();
|
||||
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);
|
||||
}
|
||||
for export in pe.exports.iter() {
|
||||
if let Some("VSTPluginMain") = export.name {
|
||||
println!("VSTPluginMain: {:?} + {:?}", &export.rva, &export.offset);
|
||||
main = Some(export);
|
||||
break
|
||||
}
|
||||
}
|
||||
cb(pe, main, imports);
|
||||
Ok(())
|
||||
} else {
|
||||
Err("not a PE".into())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue