From 2c6f2d69af425674851968c64ce3b5334d6ba102 Mon Sep 17 00:00:00 2001 From: Jonathan Becker Date: Sat, 7 Dec 2024 16:44:05 -0600 Subject: [PATCH] fix(decode): respect `skip_resolving` in `inspect` and `decompile` modules (#527) --- crates/decompile/src/core/analyze.rs | 9 +++++++-- crates/decompile/src/core/mod.rs | 1 + crates/decompile/src/utils/heuristics/extcall.rs | 6 +++--- crates/inspect/src/core/mod.rs | 3 ++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/crates/decompile/src/core/analyze.rs b/crates/decompile/src/core/analyze.rs index 6178f1fd..06017bc8 100644 --- a/crates/decompile/src/core/analyze.rs +++ b/crates/decompile/src/core/analyze.rs @@ -57,6 +57,8 @@ pub(crate) struct AnalyzerState { pub conditional_stack: Vec, /// Tracks which analyzer type we are using pub analyzer_type: AnalyzerType, + /// Whether to skip resolving internal calls + pub skip_resolving: bool, } /// The analyzer, which will analyze a [`VMTrace`] generated by symbolic execution and build an @@ -66,6 +68,8 @@ pub(crate) struct AnalyzerState { pub struct Analyzer { /// The type of analyzer to use typ: AnalyzerType, + /// Whether to skip resolving internal calls + skip_resolving: bool, /// The function to build during analysis function: AnalyzedFunction, /// A list of registered heuristics with the Heuristic Trait @@ -74,8 +78,8 @@ pub struct Analyzer { impl Analyzer { /// Build a new analyzer with the given type, function, and trace - pub fn new(typ: AnalyzerType, function: AnalyzedFunction) -> Self { - Self { typ, function, heuristics: Vec::new() } + pub fn new(typ: AnalyzerType, skip_resolving: bool, function: AnalyzedFunction) -> Self { + Self { typ, function, skip_resolving, heuristics: Vec::new() } } /// Register heuristics for the given function and trace @@ -121,6 +125,7 @@ impl Analyzer { jumped_conditional: None, conditional_stack: Vec::new(), analyzer_type: self.typ, + skip_resolving: self.skip_resolving, }; // Perform analysis diff --git a/crates/decompile/src/core/mod.rs b/crates/decompile/src/core/mod.rs index 4234fcc1..7c5ed1e8 100644 --- a/crates/decompile/src/core/mod.rs +++ b/crates/decompile/src/core/mod.rs @@ -161,6 +161,7 @@ pub async fn decompile(args: DecompilerArgs) -> Result { async move { let mut analyzer = Analyzer::new( analyzer_type, + args.skip_resolving, AnalyzedFunction::new(&selector, selector == "fallback"), ); diff --git a/crates/decompile/src/utils/heuristics/extcall.rs b/crates/decompile/src/utils/heuristics/extcall.rs index b4c51305..8b9de466 100644 --- a/crates/decompile/src/utils/heuristics/extcall.rs +++ b/crates/decompile/src/utils/heuristics/extcall.rs @@ -16,7 +16,7 @@ use heimdall_decoder::{decode, DecodeArgsBuilder}; pub fn extcall_heuristic<'a>( function: &'a mut AnalyzedFunction, state: &'a State, - _: &'a mut AnalyzerState, + analyzer_state: &'a mut AnalyzerState, ) -> BoxFuture<'a, Result<(), Error>> { Box::pin(async move { let instruction = &state.last_instruction; @@ -66,6 +66,7 @@ pub fn extcall_heuristic<'a>( DecodeArgsBuilder::new() .target(extcalldata_clone) .raw(true) + .skip_resolving(analyzer_state.skip_resolving) .build() .expect("Failed to build DecodeArgs"), ) @@ -156,6 +157,7 @@ pub fn extcall_heuristic<'a>( DecodeArgsBuilder::new() .target(extcalldata_clone) .raw(true) + .skip_resolving(analyzer_state.skip_resolving) .build() .expect("Failed to build DecodeArgs"), ) @@ -219,5 +221,3 @@ pub fn extcall_heuristic<'a>( Ok(()) }) } - -// TODO: handle skip_resolving (need to fix in inspect mod too) diff --git a/crates/inspect/src/core/mod.rs b/crates/inspect/src/core/mod.rs index 3fab8526..90c12edc 100644 --- a/crates/inspect/src/core/mod.rs +++ b/crates/inspect/src/core/mod.rs @@ -12,7 +12,7 @@ use heimdall_common::{ rpc::{get_block_logs, get_trace, get_transaction}, signatures::cache_signatures_from_abi, }, - utils::{hex::ToLowerHex, io::logging::TraceFactory}, + utils::{env::set_env, hex::ToLowerHex, io::logging::TraceFactory}, }; use crate::{ @@ -35,6 +35,7 @@ impl InspectResult { pub async fn inspect(args: InspectArgs) -> Result { // init let start_time = Instant::now(); + set_env("SKIP_RESOLVING", &args.skip_resolving.to_string()); // parse and cache signatures from the ABI, if provided if let Some(abi_path) = args.abi.as_ref() {