list output call sites

This commit is contained in:
🪞👃🪞 2025-02-24 01:15:41 +02:00
parent 8f7faca54a
commit 8726b94122
2 changed files with 9 additions and 2 deletions

View file

@ -60,7 +60,7 @@ impl Module {
fn call_site (self: &Arc<Self>, position: usize, opcodes: &[u8]) -> Usually<Arc<CallSite>> { fn call_site (self: &Arc<Self>, position: usize, opcodes: &[u8]) -> Usually<Arc<CallSite>> {
let group = false; let group = false;
let offset = (position + self.code_start) as u32; let offset = (position + self.code_start) as u32;
let source = self.pe.offset_to_rva(Offset((position + self.code_start) as u32))?.0; let source = self.pe.offset_to_rva(Offset(offset))?.0;
let target = CallSite::target(source, opcodes).unwrap_or(0); let target = CallSite::target(source, opcodes).unwrap_or(0);
let import = self.imports.read().unwrap().get(&target).cloned(); let import = self.imports.read().unwrap().get(&target).cloned();
let call_site = Arc::new(CallSite { let call_site = Arc::new(CallSite {
@ -85,6 +85,8 @@ impl Module {
targets.insert(call_site.target, vec![]); targets.insert(call_site.target, vec![]);
} }
targets.get_mut(&call_site.target).unwrap().push(call_site.clone()); targets.get_mut(&call_site.target).unwrap().push(call_site.clone());
let mut call_sites = self.call_sites.write().unwrap();
call_sites.insert(call_site.source, call_site.clone());
} }
/// Follow the call site and resolve the next call site found in the dependency. /// Follow the call site and resolve the next call site found in the dependency.
fn load_call_site_recurse (self: &Arc<Self>, call_site: &Arc<CallSite>, depth: usize) -> Usually<()> { fn load_call_site_recurse (self: &Arc<Self>, call_site: &Arc<CallSite>, depth: usize) -> Usually<()> {

View file

@ -48,7 +48,7 @@ pub struct Module {
/// Addresses of exported methods by name /// Addresses of exported methods by name
pub exports: RwLock<BTreeMap<Arc<str>, ThunkData>>, pub exports: RwLock<BTreeMap<Arc<str>, ThunkData>>,
/// Locations in `.text` section that need to be patched /// Locations in `.text` section that need to be patched
pub call_sites: BTreeMap<u32, Arc<CallSite>>, pub call_sites: RwLock<BTreeMap<u32, Arc<CallSite>>>,
/// More detailed output. /// More detailed output.
pub verbose: bool, pub verbose: bool,
} }
@ -169,6 +169,11 @@ impl Module {
module.name); module.name);
layout.insert(index, self.clone()); layout.insert(index, self.clone());
index += module.code_size.div_ceil(page) * page; index += module.code_size.div_ceil(page) * page;
for (addr, call) in module.call_sites.read().unwrap().iter() {
println!(" {} {:?}::{:?}", fmt_num(*addr as usize),
call.module.as_ref().map(|m|m.name.clone()),
call.method);
}
}; };
append(&self); append(&self);
for module in self.namespace.read().unwrap().values() { for module in self.namespace.read().unwrap().values() {