mirror of
https://codeberg.org/unspeaker/vestal.git
synced 2025-12-06 12:56:41 +01:00
depth or breadth first?
This commit is contained in:
parent
b629beb5fc
commit
8a404c3bd5
2 changed files with 28 additions and 28 deletions
|
|
@ -13,37 +13,28 @@ impl Module {
|
|||
let instruction = decoder.decode();
|
||||
let opcodes = &self.code[position..position+instruction.len()];
|
||||
if CallSite::matches(&instruction) && !CallSite::skip(opcodes) {
|
||||
let offset = (position + self.code_start) as u32;
|
||||
let source = self.pe.offset_to_rva(Offset(offset))?.0;
|
||||
let target = CallSite::target(source, opcodes).unwrap_or(0);
|
||||
let imports = self.imports.read().unwrap();
|
||||
let label = imports.get(&target)
|
||||
.map(|(module, method)|format!("{module}::{method}"))
|
||||
.unwrap_or_else(||format!("{RED}unresolved{RESET}"));
|
||||
println!(" (call {} {} {} {DIM}{:20}{RESET} {} {BOLD}{}{RESET})",
|
||||
&self.name,
|
||||
fmt_num(offset as usize),
|
||||
fmt_num(source as usize),
|
||||
fmt_bytes(opcodes),
|
||||
fmt_num(target as usize),
|
||||
label);
|
||||
if !targets.contains_key(&target) {
|
||||
targets.insert(target, vec![]);
|
||||
}
|
||||
let import = imports.get(&target).clone();
|
||||
targets.get_mut(&target).unwrap().push(Arc::new(CallSite {
|
||||
let offset = (position + self.code_start) as u32;
|
||||
let source = self.pe.offset_to_rva(Offset((position + self.code_start) as u32))?.0;
|
||||
let target = CallSite::target(source, opcodes).unwrap_or(0);
|
||||
let import = self.imports.read().unwrap().get(&target).cloned();
|
||||
let call_site = Arc::new(CallSite {
|
||||
caller: self.clone(),
|
||||
source,
|
||||
offset,
|
||||
length: opcodes.len(),
|
||||
target,
|
||||
method: import.map(|x|x.1.clone()),
|
||||
length: opcodes.len(),
|
||||
method: import.clone().map(|x|x.1),
|
||||
module: if let Some(import) = import {
|
||||
self.dependencies.read().unwrap().get(&import.0).cloned()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}));
|
||||
});
|
||||
call_site.show(Some(opcodes));
|
||||
if !targets.contains_key(&call_site.target) {
|
||||
targets.insert(call_site.target, vec![]);
|
||||
}
|
||||
targets.get_mut(&call_site.target).unwrap().push(call_site);
|
||||
}
|
||||
}
|
||||
Ok(self)
|
||||
|
|
|
|||
|
|
@ -130,12 +130,21 @@ impl Module {
|
|||
}
|
||||
|
||||
impl CallSite {
|
||||
pub fn show (&self) {
|
||||
let caller = self.caller.name.as_ref();
|
||||
let module = self.module.as_ref();
|
||||
let method = self.method.as_ref();
|
||||
let style = GREEN;
|
||||
println!("╰--------> {caller} -> {style}{module:?}::{method:?}{RESET}");
|
||||
pub fn show (&self, opcodes: Option<&[u8]>) {
|
||||
let label = self.caller.imports.read().unwrap().get(&self.target)
|
||||
.map(|(module, method)|format!("{module}::{method}"))
|
||||
.unwrap_or_else(||format!("{RED}unresolved{RESET}"));
|
||||
println!(" ╰-> (call {} {} {} {DIM}{:20}{RESET} {} {BOLD}{}{RESET})",
|
||||
&self.caller.name,
|
||||
fmt_num(self.offset as usize),
|
||||
fmt_num(self.source as usize),
|
||||
fmt_bytes(opcodes.unwrap_or(&[])),
|
||||
fmt_num(self.target as usize),
|
||||
label);
|
||||
//let caller = self.caller.name.as_ref();
|
||||
//let module = self.module.as_ref();
|
||||
//let method = self.method.as_ref();
|
||||
//println!("╰--------> {caller} -> {label}{RESET}");
|
||||
//module.map(|x|x.as_ref()).unwrap_or(&""),
|
||||
//method.map(|x|x.as_ref()).unwrap_or(&""));
|
||||
//} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue