Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: heimdallibrary (expose decompiler as library) #36

Merged
merged 2 commits into from Dec 29, 2022

Conversation

perama-v
Copy link
Contributor

@perama-v perama-v commented Dec 29, 2022

What was wrong?

No access the decompiler within external rust code.

What was changed?

  • Exposed the decompiler as a module (use heimdall::decompile;)
  • Exposed CLI flags as methods in a builder pattern (DecompileBuilder::new(BYTECODE).decompile();)
    • This just wraps the existing DecompilerArgs inside the builder for a nice interface.
  • Added an example to showcase use as library (cargo run --example decompile)
  • Added simple test using the bytecode from test: benchmark_decompile_simple.
  • Added basic docs for the builder
    • doctest set to no_run because the bytecode is truncated in the doc example: "7312/* snip */04ad"

Examples

Minimal use

use heimdall::decompile::DecompileBuilder;

const SOURCE: &'static str = "7312/* snip */04ad";

DecompileBuilder::new(SOURCE)
    .decompile();

Use of all builder (flag) methods:

use heimdall::decompile::DecompileBuilder;

const SOURCE: &'static str = "7312/* snip */04ad";

DecompileBuilder::new(SOURCE)
    .default(false)
    .include_sol(false)
    .output("my_contract_dir")
    .rpc("https://127.0.0.1:8545")
    .skip_resolving(true)
    .verbosity(5)
    .decompile();

Unchanged

The decode method was not exposed because, unlike the decompile method, no files are emitted.
It seemed less likely to be useful in the context of a library

Formatting

I did not run cargo fmt, as this produced changes across the codebase.

Linting

Clippy is happy, with some silencing with #[allow(dead_code)] on the builder pattern methods
(which are not technically called).

@perama-v
Copy link
Contributor Author

I have also inadvertently included some whitespace trimming, my apologies

@Jon-Becker Jon-Becker changed the title feat: heimdallibrary (expose decompiler as library) ✨ feat: heimdallibrary (expose decompiler as library) Dec 29, 2022
Copy link
Owner

@Jon-Becker Jon-Becker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I've added you to contributors, let me know if you need me to change any of the info there :)

I'll run some more tests later today and merge this ❤️ 🦦

heimdall/src/decompile/mod.rs Outdated Show resolved Hide resolved
@Jon-Becker Jon-Becker merged commit 79ad51e into Jon-Becker:main Dec 29, 2022
@perama-v perama-v deleted the feat-lib branch December 30, 2022 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants