-
Notifications
You must be signed in to change notification settings - Fork 133
/
Copy pathargs.rs
66 lines (57 loc) · 2.24 KB
/
args.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use clap::Parser;
use derive_builder::Builder;
use eyre::Result;
use heimdall_common::ether::bytecode::get_bytecode_from_target;
use heimdall_config::parse_url_arg;
/// Arguments for the CFG subcommand
#[derive(Debug, Clone, Parser, Builder)]
#[clap(
about = "Generate a visual control flow graph for EVM bytecode",
after_help = "For more information, read the wiki: https://jbecker.dev/r/heimdall-rs/wiki",
override_usage = "heimdall cfg <TARGET> [OPTIONS]"
)]
pub struct CfgArgs {
/// The target to generate a Cfg for, either a file, bytecode, contract address, or ENS name.
#[clap(required = true)]
pub target: String,
/// The RPC provider to use for fetching target bytecode.
/// This can be an explicit URL or a reference to a MESC endpoint.
#[clap(long, short, value_parser = parse_url_arg, default_value = "", hide_default_value = true)]
pub rpc_url: String,
/// When prompted, always select the default value.
#[clap(long, short)]
pub default: bool,
/// Color the edges of the graph based on the JUMPI condition.
/// This is useful for visualizing the flow of if statements.
#[clap(long = "color-edges", short)]
pub color_edges: bool,
/// The output directory to write the output to or 'print' to print to the console
#[clap(long = "output", short = 'o', default_value = "output", hide_default_value = true)]
pub output: String,
/// The name for the output file
#[clap(long, short, default_value = "", hide_default_value = true)]
pub name: String,
/// Timeout for symbolic execution
#[clap(long, short, default_value = "10000", hide_default_value = true)]
pub timeout: u64,
}
impl CfgArgs {
/// Get the bytecode for the target
pub async fn get_bytecode(&self) -> Result<Vec<u8>> {
get_bytecode_from_target(&self.target, &self.rpc_url).await
}
}
impl CfgArgsBuilder {
/// Create a new instance of the [`CfgArgsBuilder`]
pub fn new() -> Self {
Self {
target: Some(String::new()),
rpc_url: Some(String::new()),
default: Some(true),
color_edges: Some(false),
output: Some(String::new()),
name: Some(String::new()),
timeout: Some(10000),
}
}
}