From bf84317c3cc7d7c35ec247ff942dedbdb9693049 Mon Sep 17 00:00:00 2001 From: Jon-Becker Date: Sat, 7 Dec 2024 14:04:16 -0500 Subject: [PATCH] wip --- crates/decompile/src/core/postprocess.rs | 4 ++-- .../decompile/src/utils/heuristics/extcall.rs | 23 ++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/crates/decompile/src/core/postprocess.rs b/crates/decompile/src/core/postprocess.rs index 6219dd26..fff35e49 100644 --- a/crates/decompile/src/core/postprocess.rs +++ b/crates/decompile/src/core/postprocess.rs @@ -130,8 +130,8 @@ impl PostprocessOrchestrator { // Note: this can't be done with a postprocessor because it needs all lines if !function.payable && (function.pure || function.view) && function.arguments.is_empty() { // check for RLP encoding. very naive check, but it works for now - if function.logic.iter().any(|line| line.contains("0x0100 *")) && - function.logic.iter().any(|line| line.contains("0x01) &")) + if function.logic.iter().any(|line| line.contains("0x0100 *")) + && function.logic.iter().any(|line| line.contains("0x01) &")) { // find any storage accesses let joined = function.logic.join(" "); diff --git a/crates/decompile/src/utils/heuristics/extcall.rs b/crates/decompile/src/utils/heuristics/extcall.rs index d7a7a654..168f179d 100644 --- a/crates/decompile/src/utils/heuristics/extcall.rs +++ b/crates/decompile/src/utils/heuristics/extcall.rs @@ -1,5 +1,8 @@ +use std::fmt::format; + +use alloy::primitives::U256; use futures::future::BoxFuture; -use heimdall_common::utils::hex::ToLowerHex; +use heimdall_common::utils::{hex::ToLowerHex, strings::encode_hex_reduced}; use heimdall_vm::{ core::{opcodes::opcode_name, vm::State}, w_gas, w_push0, @@ -162,17 +165,31 @@ pub fn extcall_heuristic<'a>( ) { function.logic.push(precompile_logic); } else if let Some(decoded) = decoded { + let start_slot = instruction.inputs[2] + U256::from(4); + function.logic.push(format!( "(bool success, bytes memory ret0) = address({}).{}{}({}); // {}", address, modifier, decoded.decoded.name, - decoded.decoded.inputs.join(", "), + decoded + .decoded + .inputs + .iter() + .enumerate() + .map(|(i, _)| { + format!( + "memory[{}]", + encode_hex_reduced(start_slot + U256::from(i * 32)) + ) + }) + .collect::>() + .join(", "), opcode_name(instruction.opcode).to_lowercase(), )); } else { function.logic.push(format!( - "(bool success, bytes memory ret0) = address({}).Unresolved_{}{}(msg.data[{}:{}]); // {}", + "(bool success, bytes memory ret0) = address({}).Unresolved_{}{}(memory[{}:{}]); // {}", address, extcalldata.get(2..10).unwrap_or(""), modifier,