Skip to content

Commit

Permalink
🛠️ refactor: move disassemble into heimdall_core and treat like o…
Browse files Browse the repository at this point in the history
…ther libs (#163)

* 🧹 clean: remove dead docs code

* 🛠️ refactor: move disassemble into `heimdall_core`

* 👷 build: bump version to 0.6.4
  • Loading branch information
Jon-Becker authored Nov 6, 2023
1 parent 637e4f8 commit 03cc51c
Show file tree
Hide file tree
Showing 23 changed files with 97 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ members = [
"core",
"cli",
]
version = "0.6.3"
version = "0.6.4"
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ Heimdall's update and installation manager, `bifrost`, can be installed using th
curl -L http://get.heimdall.rs | bash
```

<!-- Alternatively, you can install through GitHub directly using the following command:
```bash
curl -L https://raw.githubusercontent.com/Jon-Becker/heimdall-rs/main/bifrost/install | 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:
Expand Down
2 changes: 1 addition & 1 deletion cache/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "heimdall-cache"
version = "0.6.3"
version = "0.6.4"
edition = "2021"
license = "MIT"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "heimdall-cli"
version = "0.6.3"
version = "0.6.4"
edition = "2021"
license = "MIT"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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},
};
Expand Down
2 changes: 1 addition & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion common/src/ether/evm/ext/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pub mod disassemble;
pub mod exec;
2 changes: 1 addition & 1 deletion config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "heimdall-config"
version = "0.6.3"
version = "0.6.4"
edition = "2021"
license = "MIT"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions core/src/cfg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
21 changes: 9 additions & 12 deletions core/src/decompile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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::*,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<String, Box<dyn std::error::Error>> {
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",
Expand Down
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod cfg;
pub mod decode;
pub mod decompile;
pub mod disassemble;
pub mod dump;
pub mod snapshot;
18 changes: 9 additions & 9 deletions core/src/snapshot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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(
Expand Down
8 changes: 3 additions & 5 deletions core/tests/test_disassemble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down
5 changes: 3 additions & 2 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"dump",
"decode",
"snapshot",
"decompile"
"decompile",
"disassemble",
]
version = "0.6.3"
version = "0.6.4"
2 changes: 1 addition & 1 deletion examples/cfg/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion examples/decode/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion examples/decompile/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
11 changes: 11 additions & 0 deletions examples/disassemble/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]}
16 changes: 16 additions & 0 deletions examples/disassemble/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use heimdall_core::disassemble::DisassemblerArgsBuilder;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
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(())
}
2 changes: 1 addition & 1 deletion examples/dump/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion examples/snapshot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down

0 comments on commit 03cc51c

Please sign in to comment.