mirror of
https://codeberg.org/unspeaker/vestal.git
synced 2025-12-06 12:56: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 {
|
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|{
|
Self::with_pe(&path, |pe, main, deps|{
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,26 +2,15 @@ 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|{
|
Self::with_pe(&path, |pe, main, deps|{
|
||||||
println!("PE: {}", path.as_ref().display());
|
if let Some(main) = main {
|
||||||
for export in pe.exports.iter() {
|
println!("VSTPluginMain: {:?} + {:?}", &main.rva, &main.offset);
|
||||||
if let Some("VSTPluginMain") = export.name {
|
} else {
|
||||||
println!("VSTPluginMain: {:?} + {:?}", &export.rva, &export.offset);
|
panic!("VSTPluginMain not found. This is not a valid VST plugin.");
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
use std::collections::HashMap;
|
|
||||||
let mut imports: HashMap<String, Vec<&goblin::pe::import::Import>> = Default::default();
|
|
||||||
println!("Imports: {:#?}", &pe.imports.len());
|
println!("Imports: {:#?}", &pe.imports.len());
|
||||||
for import in pe.imports.iter() {
|
println!("Dependencies: {:#?}", &deps.len());
|
||||||
let dll = import.dll.clone();
|
for (dll, imports) in deps.iter() {
|
||||||
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}");
|
println!("- {dll}");
|
||||||
for import in imports.iter() {
|
for import in imports.iter() {
|
||||||
println!(" {:8} + {:8} {:32}", import.rva, import.offset, import.name);
|
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 execute;
|
||||||
mod inspect;
|
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>>;
|
type Usually<T> = Result<T, Box<dyn std::error::Error>>;
|
||||||
|
|
||||||
|
|
@ -29,10 +27,30 @@ impl Vestal {
|
||||||
Self::Execute { path } => self.execute(path.as_str()),
|
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())?;
|
let buffer = std::fs::read(path.as_ref())?;
|
||||||
if let Object::PE(ref pe) = Object::parse(&buffer)? {
|
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(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err("not a PE".into())
|
Err("not a PE".into())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue