show some import addresses

This commit is contained in:
🪞👃🪞 2025-02-20 02:57:29 +02:00
parent 18fbfe62ac
commit 513166ddd5
4 changed files with 44 additions and 5 deletions

16
Cargo.lock generated
View file

@ -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",

View file

@ -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"

View file

@ -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!(")")

View file

@ -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;