diff --git a/Cargo.toml b/Cargo.toml index ed495e40..381e2a37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,4 +5,4 @@ members = [ "core", "cli", ] -version = "0.6.3" +version = "0.6.4" diff --git a/README.md b/README.md index 193efe6a..ec6b22f2 100644 --- a/README.md +++ b/README.md @@ -31,12 +31,6 @@ Heimdall's update and installation manager, `bifrost`, can be installed using th curl -L http://get.heimdall.rs | bash ``` - - If you want to manually install bifrost, you can download the latest release from [here](./bifrost/bifrost). Once you have installed `bifrost`, you can use it to install Heimdall using the following command from a new terminal: diff --git a/cache/Cargo.toml b/cache/Cargo.toml index ef495dbd..2799d409 100644 --- a/cache/Cargo.toml +++ b/cache/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "heimdall-cache" -version = "0.6.3" +version = "0.6.4" edition = "2021" license = "MIT" readme = "README.md" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index e8f4d593..bea052c8 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "heimdall-cli" -version = "0.6.3" +version = "0.6.4" edition = "2021" license = "MIT" readme = "README.md" diff --git a/cli/src/main.rs b/cli/src/main.rs index b4c6b8c8..9efa96e6 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -12,7 +12,6 @@ use crossterm::{ use heimdall_cache::{cache, CacheArgs}; use heimdall_common::{ constants::ADDRESS_REGEX, - ether::evm::ext::disassemble::*, io::{ file::{write_file, write_lines_to_file}, logging::Logger, @@ -24,6 +23,7 @@ use heimdall_core::{ cfg::{cfg, output::write_cfg_to_file, CFGArgs}, decode::{decode, DecodeArgs}, decompile::{decompile, out::abi::ABIStructure, DecompilerArgs}, + disassemble::{disassemble, DisassemblerArgs}, dump::{dump, DumpArgs}, snapshot::{snapshot, util::csv::generate_and_write_contract_csv, SnapshotArgs}, }; diff --git a/common/Cargo.toml b/common/Cargo.toml index 737131d8..29f1f063 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -5,7 +5,7 @@ keywords = ["ethereum", "web3", "decompiler", "evm", "crypto"] license = "MIT" name = "heimdall-common" readme = "README.md" -version = "0.6.3" +version = "0.6.4" [dependencies] async-openai = "0.10.0" diff --git a/common/src/ether/evm/ext/mod.rs b/common/src/ether/evm/ext/mod.rs index 90d6ea56..4b318ea1 100644 --- a/common/src/ether/evm/ext/mod.rs +++ b/common/src/ether/evm/ext/mod.rs @@ -1,2 +1 @@ -pub mod disassemble; pub mod exec; diff --git a/config/Cargo.toml b/config/Cargo.toml index 906ae695..735bd960 100644 --- a/config/Cargo.toml +++ b/config/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "heimdall-config" -version = "0.6.3" +version = "0.6.4" edition = "2021" license = "MIT" readme = "README.md" diff --git a/core/Cargo.toml b/core/Cargo.toml index 0b59bfda..d83ae3eb 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -5,7 +5,7 @@ keywords = ["ethereum", "web3", "decompiler", "evm", "crypto"] license = "MIT" name = "heimdall-core" readme = "README.md" -version = "0.6.3" +version = "0.6.4" [dependencies] backtrace = "0.3" diff --git a/core/src/cfg/mod.rs b/core/src/cfg/mod.rs index 9bc73c99..8921f4b1 100644 --- a/core/src/cfg/mod.rs +++ b/core/src/cfg/mod.rs @@ -10,15 +10,15 @@ use std::{fs, time::Duration}; use clap::{AppSettings, Parser}; use heimdall_common::{ constants::{ADDRESS_REGEX, BYTECODE_REGEX}, - ether::evm::{ - core::vm::VM, - ext::disassemble::{disassemble, DisassemblerArgs}, - }, + ether::evm::core::vm::VM, io::logging::*, }; use petgraph::Graph; -use crate::cfg::graph::build_cfg; +use crate::{ + cfg::graph::build_cfg, + disassemble::{disassemble, DisassemblerArgs}, +}; #[derive(Debug, Clone, Parser, Builder)] #[clap( diff --git a/core/src/decompile/mod.rs b/core/src/decompile/mod.rs index c6e8c826..3cd07e3f 100644 --- a/core/src/decompile/mod.rs +++ b/core/src/decompile/mod.rs @@ -5,11 +5,14 @@ pub mod precompile; pub mod resolve; pub mod util; -use crate::decompile::{ - analyzers::{solidity::analyze_sol, yul::analyze_yul}, - out::{abi::build_abi, solidity::build_solidity_output, yul::build_yul_output}, - resolve::*, - util::*, +use crate::{ + decompile::{ + analyzers::{solidity::analyze_sol, yul::analyze_yul}, + out::{abi::build_abi, solidity::build_solidity_output, yul::build_yul_output}, + resolve::*, + util::*, + }, + disassemble::{disassemble, DisassemblerArgs}, }; use derive_builder::Builder; @@ -27,13 +30,7 @@ use std::{collections::HashMap, fs, time::Duration}; use clap::{AppSettings, Parser}; use heimdall_common::{ constants::{ADDRESS_REGEX, BYTECODE_REGEX}, - ether::{ - evm::{ - core::vm::VM, - ext::disassemble::{disassemble, DisassemblerArgs}, - }, - signatures::*, - }, + ether::{evm::core::vm::VM, signatures::*}, io::logging::*, }; diff --git a/common/src/ether/evm/ext/disassemble.rs b/core/src/disassemble/mod.rs similarity index 84% rename from common/src/ether/evm/ext/disassemble.rs rename to core/src/disassemble/mod.rs index 9aa5a4ee..74f39922 100644 --- a/common/src/ether/evm/ext/disassemble.rs +++ b/core/src/disassemble/mod.rs @@ -1,14 +1,15 @@ use std::fs; -use crate::{ +use clap::{AppSettings, Parser}; +use derive_builder::Builder; +use heimdall_common::{ constants::{ADDRESS_REGEX, BYTECODE_REGEX}, ether::{evm::core::opcodes::opcode, rpc::get_code}, - io::logging::*, + io::logging::Logger, utils::strings::{decode_hex, encode_hex}, }; -use clap::{AppSettings, Parser}; -#[derive(Debug, Clone, Parser)] +#[derive(Debug, Clone, Parser, Builder)] #[clap(about = "Disassemble EVM bytecode to Assembly", after_help = "For more information, read the wiki: https://jbecker.dev/r/heimdall-rs/wiki", global_setting = AppSettings::DeriveDisplayOrder, @@ -31,10 +32,33 @@ pub struct DisassemblerArgs { pub decimal_counter: bool, } +impl DisassemblerArgsBuilder { + pub fn new() -> Self { + Self { + target: Some(String::new()), + verbose: Some(clap_verbosity_flag::Verbosity::new(0, 1)), + rpc_url: Some(String::new()), + decimal_counter: Some(false), + } + } +} + pub async fn disassemble(args: DisassemblerArgs) -> Result> { use std::time::Instant; let now = Instant::now(); + // set logger environment variable if not already set + if std::env::var("RUST_LOG").is_err() { + std::env::set_var( + "RUST_LOG", + match args.verbose.log_level() { + Some(level) => level.as_str(), + None => "SILENT", + }, + ); + } + + // get a new logger let (logger, _) = Logger::new(match args.verbose.log_level() { Some(level) => level.as_str(), None => "SILENT", diff --git a/core/src/lib.rs b/core/src/lib.rs index 3860f2b3..9ba0b185 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -1,5 +1,6 @@ pub mod cfg; pub mod decode; pub mod decompile; +pub mod disassemble; pub mod dump; pub mod snapshot; diff --git a/core/src/snapshot/mod.rs b/core/src/snapshot/mod.rs index 170a40a7..82a097a2 100644 --- a/core/src/snapshot/mod.rs +++ b/core/src/snapshot/mod.rs @@ -17,10 +17,7 @@ use heimdall_common::{ constants::{ADDRESS_REGEX, BYTECODE_REGEX}, ether::{ compiler::detect_compiler, - evm::{ - core::vm::VM, - ext::disassemble::{disassemble, DisassemblerArgs}, - }, + evm::core::vm::VM, rpc::get_code, selectors::{find_function_selectors, resolve_selectors}, signatures::{score_signature, ResolvedError, ResolvedFunction, ResolvedLog}, @@ -30,11 +27,14 @@ use heimdall_common::{ }; use indicatif::ProgressBar; -use crate::snapshot::{ - analyze::snapshot_trace, - resolve::match_parameters, - structures::snapshot::{GasUsed, Snapshot}, - util::tui, +use crate::{ + disassemble::{disassemble, DisassemblerArgs}, + snapshot::{ + analyze::snapshot_trace, + resolve::match_parameters, + structures::snapshot::{GasUsed, Snapshot}, + util::tui, + }, }; #[derive(Debug, Clone, Parser, Builder)] #[clap( diff --git a/core/tests/test_disassemble.rs b/core/tests/test_disassemble.rs index 9aad9d87..5f70c186 100644 --- a/core/tests/test_disassemble.rs +++ b/core/tests/test_disassemble.rs @@ -2,10 +2,8 @@ mod benchmarks { use clap_verbosity_flag::Verbosity; - use heimdall_common::{ - ether::evm::ext::disassemble::{disassemble, DisassemblerArgs}, - testing::benchmarks::async_bench, - }; + use heimdall_common::testing::benchmarks::async_bench; + use heimdall_core::disassemble::{disassemble, DisassemblerArgs}; #[tokio::test] async fn benchmark_disassemble_simple() { @@ -28,7 +26,7 @@ mod integration_tests { use clap_verbosity_flag::Verbosity; - use heimdall_common::ether::evm::ext::disassemble::{disassemble, DisassemblerArgs}; + use heimdall_core::disassemble::{disassemble, DisassemblerArgs}; #[tokio::test] async fn test_disassemble_nominal() { diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 4664c928..705190b3 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -4,6 +4,7 @@ members = [ "dump", "decode", "snapshot", - "decompile" + "decompile", + "disassemble", ] -version = "0.6.3" +version = "0.6.4" diff --git a/examples/cfg/Cargo.toml b/examples/cfg/Cargo.toml index 6831a162..5d1de38e 100644 --- a/examples/cfg/Cargo.toml +++ b/examples/cfg/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "heimdall-rs-cfg-example" -version = "0.6.3" +version = "0.6.4" edition = "2021" description = "Heimdall is an advanced Ethereum smart contract toolkit for forensic and heuristic analysis." keywords = ["ethereum", "web3", "decompiler", "evm", "crypto"] diff --git a/examples/decode/Cargo.toml b/examples/decode/Cargo.toml index e351da1e..1f176875 100644 --- a/examples/decode/Cargo.toml +++ b/examples/decode/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "heimdall-rs-decode-example" -version = "0.6.3" +version = "0.6.4" edition = "2021" description = "Heimdall is an advanced Ethereum smart contract toolkit for forensic and heuristic analysis." keywords = ["ethereum", "web3", "decompiler", "evm", "crypto"] diff --git a/examples/decompile/Cargo.toml b/examples/decompile/Cargo.toml index edc4955f..8418a5a3 100644 --- a/examples/decompile/Cargo.toml +++ b/examples/decompile/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "heimdall-rs-decompile-example" -version = "0.6.3" +version = "0.6.4" edition = "2021" description = "Heimdall is an advanced Ethereum smart contract toolkit for forensic and heuristic analysis." keywords = ["ethereum", "web3", "decompiler", "evm", "crypto"] diff --git a/examples/disassemble/Cargo.toml b/examples/disassemble/Cargo.toml new file mode 100644 index 00000000..ba18f60b --- /dev/null +++ b/examples/disassemble/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "heimdall-rs-disassemble-example" +version = "0.6.4" +edition = "2021" +description = "Heimdall is an advanced Ethereum smart contract toolkit for forensic and heuristic analysis." +keywords = ["ethereum", "web3", "decompiler", "evm", "crypto"] +license = "MIT" + +[dependencies] +heimdall-core = { git = "https://github.com/Jon-Becker/heimdall-rs.git", branch = "main" } +tokio = {version = "1", features = ["full"]} diff --git a/examples/disassemble/src/main.rs b/examples/disassemble/src/main.rs new file mode 100644 index 00000000..705d1806 --- /dev/null +++ b/examples/disassemble/src/main.rs @@ -0,0 +1,16 @@ +use heimdall_core::disassemble::DisassemblerArgsBuilder; + +#[tokio::main] +async fn main() -> Result<(), Box> { + let result = heimdall_core::disassemble::disassemble( + DisassemblerArgsBuilder::new() + .target("0x9f00c43700bc0000Ff91bE00841F8e04c0495000".to_string()) + .rpc_url("https://eth.llamarpc.com".to_string()) + .build()?, + ) + .await?; + + println!("Disassembled contract: {:#?}", result); + + Ok(()) +} diff --git a/examples/dump/Cargo.toml b/examples/dump/Cargo.toml index 292c3377..e8959a8e 100644 --- a/examples/dump/Cargo.toml +++ b/examples/dump/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "heimdall-rs-dump-example" -version = "0.6.3" +version = "0.6.4" edition = "2021" description = "Heimdall is an advanced Ethereum smart contract toolkit for forensic and heuristic analysis." keywords = ["ethereum", "web3", "decompiler", "evm", "crypto"] diff --git a/examples/snapshot/Cargo.toml b/examples/snapshot/Cargo.toml index 816bca8b..72a12c3e 100644 --- a/examples/snapshot/Cargo.toml +++ b/examples/snapshot/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "heimdall-rs-snapshot-example" -version = "0.6.3" +version = "0.6.4" edition = "2021" description = "Heimdall is an advanced Ethereum smart contract toolkit for forensic and heuristic analysis." keywords = ["ethereum", "web3", "decompiler", "evm", "crypto"]