https://github.com/adamniederer/cargo-disassemble
Disassemble your Rust project with Cargo
https://github.com/adamniederer/cargo-disassemble
cargo-subcommand command-line disassembly optimization
Last synced: 15 days ago
JSON representation
Disassemble your Rust project with Cargo
- Host: GitHub
- URL: https://github.com/adamniederer/cargo-disassemble
- Owner: AdamNiederer
- License: agpl-3.0
- Created: 2018-04-27T22:51:26.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-28T18:38:25.000Z (about 7 years ago)
- Last Synced: 2025-03-28T00:44:02.035Z (about 1 month ago)
- Topics: cargo-subcommand, command-line, disassembly, optimization
- Language: Rust
- Size: 19.5 KB
- Stars: 19
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
- License: LICENSE
Awesome Lists containing this project
README
* cargo-disassemble
Easily disassemble your Rust project** Usage
~cargo-disassemble~ attempts to emulate the command-line interface of other
cargo subcommands. Notice that the ~function~ argument is optional - not
including it will disassemble all functions in the current crate.#+BEGIN_SRC text
USAGE:
cargo-disassemble [FLAGS] [OPTIONS] [function]FLAGS:
--all-features Enable all features
--everything Include functions not defined by the current crate
-h, --help Prints help information
--intel Emit intel-flavored x86 ASM
--no-default-features Enable no_default features
--optimize Optimize the binary as much as possible
--release Compile in release mode
-V, --version Prints version informationOPTIONS:
--features Features to enable, if anyARGS:
The name of the function to be decompiled
#+END_SRC
** Example
Given the function:#+BEGIN_SRC rust
#[inline(never)]
fn is_branch_label(line: &str) -> bool {
line.starts_with(".LBB")
}
#+END_SRCwe can disassemble the optimized version of ~is_branch_label~ with the following
command:#+BEGIN_SRC shell
$ cargo disassemble is_branch_label --release --optimize --intel
#+END_SRCwhich will yield this result:
#+BEGIN_SRC asm
cargo_disassemble::is_branch_label
cmp rsi, 4
je .LBB66_4
cmp rsi, 5
jb .LBB66_3
cmp byte ptr [rdi + 4], -65
jle .LBB66_3
.LBB66_4:
push rbp
mov rbp, rsp
sub rsp, 16
mov qword ptr [rbp - 16], rdi
mov qword ptr [rbp - 8], rsi
mov al, 1
lea rcx, [rip + .Lbyte_str.1e]
cmp rdi, rcx
lea rsp, [rsp + 16]
pop rbp
je .LBB66_6
cmp dword ptr [rdi], 1111641134
je .LBB66_6
.LBB66_3:
xor eax, eax
ret
#+END_SRC
** Caveats
When compiling in release mode, rustc will often aggressively inline smaller
functions. Because inlined functions typically don't have a freestanding copy
in the final binary, they may not be disassembled. Adding the ~#[inline(never)]~
attribute to a function will ensure it's included, but may also change the code
within the function.