diff --git a/cli/src/main.rs b/cli/src/main.rs index 551ca865..427cd7f6 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -105,14 +105,21 @@ async fn main() -> Result<(), Box> { cmd.rpc_url = configuration.rpc_url; } + // if the user has passed an output filename, override the default filename + let mut filename: String = "disassembled.asm".to_string(); + let given_name = cmd.name.as_str(); + + if !given_name.is_empty() { + filename = format!("{}-{}", given_name, filename); + } + let assembly = disassemble(cmd.clone()).await?; if cmd.output == "print" { print_with_less(&assembly).await?; } else { let output_path = - build_output_path(&cmd.output, &cmd.target, &cmd.rpc_url, "disassembled.asm") - .await?; + build_output_path(&cmd.output, &cmd.target, &cmd.rpc_url, &filename).await?; write_file(&output_path, &assembly); } @@ -124,6 +131,18 @@ async fn main() -> Result<(), Box> { cmd.rpc_url = configuration.rpc_url; } + // if the user has passed an output filename, override the default filename + let mut abi_filename: String = "abi.json".to_string(); + let mut decompiled_output_filename: String = "decompiled".to_string(); + + let given_name = cmd.name.as_str(); + + if !given_name.is_empty() { + abi_filename = format!("{}-{}", given_name, abi_filename); + decompiled_output_filename = + format!("{}-{}", given_name, decompiled_output_filename); + } + let result = decompile(cmd.clone()).await?; if cmd.output == "print" { @@ -144,7 +163,7 @@ async fn main() -> Result<(), Box> { // write the contract ABI if let Some(abi) = result.abi { let output_path = - build_output_path(&cmd.output, &cmd.target, &cmd.rpc_url, "abi.json") + build_output_path(&cmd.output, &cmd.target, &cmd.rpc_url, &abi_filename) .await?; write_file( @@ -174,11 +193,21 @@ async fn main() -> Result<(), Box> { // write the contract source if let Some(source) = &result.source { let output_path = if cmd.include_solidity { - build_output_path(&cmd.output, &cmd.target, &cmd.rpc_url, "decompiled.sol") - .await? + build_output_path( + &cmd.output, + &cmd.target, + &cmd.rpc_url, + &format!("{}.sol", &decompiled_output_filename), + ) + .await? } else { - build_output_path(&cmd.output, &cmd.target, &cmd.rpc_url, "decompiled.yul") - .await? + build_output_path( + &cmd.output, + &cmd.target, + &cmd.rpc_url, + &format!("{}.yul", &decompiled_output_filename,), + ) + .await? }; write_file(&output_path, source); } @@ -208,6 +237,13 @@ async fn main() -> Result<(), Box> { cmd.rpc_url = configuration.rpc_url; } + // if the user has passed an output filename, override the default filename + let mut filename = "cfg.dot".to_string(); + let given_name = cmd.name.as_str(); + + if !given_name.is_empty() { + filename = format!("{}-{}", given_name, filename); + } let cfg = cfg(cmd.clone()).await?; let stringified_dot = build_cfg(&cfg, &cmd); @@ -215,7 +251,7 @@ async fn main() -> Result<(), Box> { print_with_less(&stringified_dot).await?; } else { let output_path = - build_output_path(&cmd.output, &cmd.target, &cmd.rpc_url, "cfg.dot").await?; + build_output_path(&cmd.output, &cmd.target, &cmd.rpc_url, &filename).await?; write_file(&output_path, &stringified_dot); } } @@ -226,6 +262,14 @@ async fn main() -> Result<(), Box> { cmd.rpc_url = configuration.rpc_url; } + // if the user has passed an output filename, override the default filename + let mut filename = "dump.csv".to_string(); + let given_name = cmd.name.as_str(); + + if !given_name.is_empty() { + filename = format!("{}-{}", given_name, filename); + } + // if the user has not specified a transpose api key, use the default if cmd.transpose_api_key.as_str() == "" { cmd.transpose_api_key = configuration.transpose_api_key; @@ -249,7 +293,7 @@ async fn main() -> Result<(), Box> { print_with_less(&lines.join("\n")).await?; } else { let output_path = - build_output_path(&cmd.output, &cmd.target, &cmd.rpc_url, "dump.csv").await?; + build_output_path(&cmd.output, &cmd.target, &cmd.rpc_url, &filename).await?; write_lines_to_file(&output_path, lines); } @@ -261,6 +305,14 @@ async fn main() -> Result<(), Box> { cmd.rpc_url = configuration.rpc_url; } + // if the user has passed an output filename, override the default filename + let mut filename = "snapshot.csv".to_string(); + let given_name = cmd.name.as_str(); + + if !given_name.is_empty() { + filename = format!("{}-{}", given_name, filename); + } + let snapshot_result = snapshot(cmd.clone()).await?; let csv_lines = generate_csv( &snapshot_result.snapshots, @@ -272,8 +324,7 @@ async fn main() -> Result<(), Box> { print_with_less(&csv_lines.join("\n")).await?; } else { let output_path = - build_output_path(&cmd.output, &cmd.target, &cmd.rpc_url, "snapshot.csv") - .await?; + build_output_path(&cmd.output, &cmd.target, &cmd.rpc_url, &filename).await?; write_lines_to_file(&output_path, csv_lines); } diff --git a/core/src/cfg/mod.rs b/core/src/cfg/mod.rs index c7623d99..d6a92451 100644 --- a/core/src/cfg/mod.rs +++ b/core/src/cfg/mod.rs @@ -53,6 +53,10 @@ pub struct CFGArgs { /// 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, } impl CFGArgsBuilder { @@ -64,6 +68,7 @@ impl CFGArgsBuilder { default: Some(true), color_edges: Some(false), output: Some(String::new()), + name: Some(String::new()), } } } @@ -145,6 +150,7 @@ pub async fn cfg(args: CFGArgs) -> Result, Box Result