From 513166ddd50b984798696a754ee22e27de125cc1 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Thu, 20 Feb 2025 02:57:29 +0200 Subject: [PATCH] show some import addresses --- Cargo.lock | 16 ++++++++++++++++ crates/vestal/Cargo.toml | 1 + crates/vestal/src/main.rs | 31 ++++++++++++++++++++++++++----- crates/vestal/src/util.rs | 1 + 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a2d7891..3e674a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -216,6 +216,12 @@ dependencies = [ "generic-array", ] +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + [[package]] name = "equivalent" version = "1.0.2" @@ -338,6 +344,15 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + [[package]] name = "jack" version = "0.13.0" @@ -685,6 +700,7 @@ dependencies = [ "exe", "hexy", "iced-x86", + "itertools", "object", "pretty-hex", "syscalls", diff --git a/crates/vestal/Cargo.toml b/crates/vestal/Cargo.toml index 55dcfb5..d5ac8f7 100644 --- a/crates/vestal/Cargo.toml +++ b/crates/vestal/Cargo.toml @@ -11,6 +11,7 @@ hexy = "0.1.4" pretty-hex = "0.4.1" exe = "0.5.6" iced-x86 = "1.21.0" +itertools = "0.14.0" #elf = "0.7.4" #goblin = "0.9.3" #lancelot = "0.9.7" diff --git a/crates/vestal/src/main.rs b/crates/vestal/src/main.rs index ee0672e..f0b5da6 100644 --- a/crates/vestal/src/main.rs +++ b/crates/vestal/src/main.rs @@ -140,14 +140,35 @@ impl Vestal { for descriptor in directory.descriptors { let dep = descriptor.get_name(dll)?.as_str()?; let resolved = self.resolve(&dep)?.expect("no path for {name}"); - print!("\n (module\n {dep:?}\n {:?}", &resolved); + print!("\n (module {dep:?} 0x{:>08x} 0x{:>08x}\n {resolved:?}", + &descriptor.first_thunk.0, + &descriptor.original_first_thunk.0); let mut imports = Vec::new(); - for import in descriptor.get_imports(dll)? { + let thunks = descriptor.get_first_thunk(dll)?; + let origs = descriptor.get_original_first_thunk(dll)?; + let lookups = descriptor.get_lookup_thunks(dll)?; + for (thunk, orig, lookup, import) in izip!( + thunks.iter().map(|thunk|format!("0x{:08x}", match thunk { + Thunk::Thunk32(t) => panic!("32 bit thunk"), + Thunk::Thunk64(t) => t.0 + })), + origs.iter().map(|thunk|format!("0x{:08x}", match thunk { + Thunk::Thunk32(t) => panic!("32 bit original thunk"), + Thunk::Thunk64(t) => t.0 + })), + lookups.iter().map(|thunk|format!("0x{:08x}", match thunk { + Thunk::Thunk32(t) => panic!("32 bit original thunk"), + Thunk::Thunk64(t) => t.0 + })), + descriptor.get_imports(dll)? + ) { match import { - ImportData::Ordinal(x) => print!("\n (import-ordinal 0x{x:>04x})"), - ImportData::ImportByName(n) => print!("\n (import-by-name {n:?})"), + ImportData::Ordinal(x) => + print!("\n (import-ordinal {thunk} 0x{x:>04x})"), + ImportData::ImportByName(n) => + print!("\n (import-by-name {thunk} {n:?})"), } - imports.push(import); + imports.push((thunk, orig, import)); } import_map.insert(dep, (resolved, imports)); println!(")") diff --git a/crates/vestal/src/util.rs b/crates/vestal/src/util.rs index 9392e1b..276d57f 100644 --- a/crates/vestal/src/util.rs +++ b/crates/vestal/src/util.rs @@ -4,6 +4,7 @@ pub(crate) use std::error::Error; pub(crate) use std::path::{Path, PathBuf}; pub(crate) use std::collections::{HashMap, HashSet}; pub(crate) use std::fs::{read, canonicalize}; +pub(crate) use itertools::izip; //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::endian::LittleEndian;