Skip to content

Repository files navigation

Cargo ASM

Disassemble single symbols in a binary.

TODO

  • Read Cargo Metadata in order to find binaries automatically.

  • Disassemble ELF binaries. Linux

  • Disassemble PE/COFF binaries. Windows GNU

  • Disassemble PE/COFF + PDB binaries. Windows MSVC

  • Disassemble Mach binaries. MacOS

  • Patch call instructions with symbol names.

  • Use DWARF debug information to show Rust code on Linux.

  • Use DWARF debug information to show Rust code on Widnows (GNU).

  • Use DWARF debug information to show Rust code on MacOS.

  • Use PDB debug information to show Rust code on Windows (MSVC).

Examples

These have to be run from within the cargo-asm directory. They also require the the binary is compiled via cargo build first.

Listing symbols in a binary:

cargo run -- list main

Example Output:

[address: 0x2CA6C0] [size: 310 bytes] cargo_asm::main::he7e4b90525b343c2
[address: 0x493590] [size: 247 bytes] core::num::dec2flt::algorithm::round_by_remainder::hf61317af6f74374c
[address: 0x2CC800] [size: 47 bytes] main

Disassembling a symbol

cargo run -- disasm -S cargo_asm::main

Example Output:

cargo_asm::main::he7e4b90525b343c2:fn main() { 2ca6c0: subrsp,0x88 if let Err(err) = run() { 2ca6c7: call cargo_asm::run::hc35cb0c3475c7dfe  2ca6cc: mov qword ptr [rsp+0x18],rax 2ca6d1: jmp0x2ca6dffn main() { 2ca6d3: movrdi, qword ptr [rsp+0x78] 2ca6d8: call0x217180 2ca6dd: ud2 2ca6df: xoreax,eax 2ca6e1: movecx,eax if let Err(err) = run() { 2ca6e3: cmp qword ptr [rsp+0x18],0 2ca6e9: movedx,1 2ca6ee: cmovbe rdx,rcx 2ca6f2: cmprdx,1 2ca6f6: je0x2ca707} 2ca6f8: leardi,[rsp+0x18] 2ca6fd: call core::ptr::drop_in_place::h3ba6e349fe585cc9  2ca702: jmp0x2ca7cf if let Err(err) = run() { 2ca707: movrax, qword ptr [rsp+0x18] 2ca70c: mov qword ptr [rsp+0x20],rax eprintln!("error: {:?}", err); 2ca711: movrsi, qword ptr [rip+0x8057f8] 2ca718: learax,[rsp+0x20] eprintln!("error: {:?}", err); 2ca71d: mov qword ptr [rsp+0x68],rax 2ca722: movrax, qword ptr [rsp+0x68] 2ca727: mov qword ptr [rsp+0x70],rax eprintln!("error: {:?}", err); 2ca72c: movrdi, qword ptr [rsp+0x70] 2ca731: learax,[rip+0xf72e8] 2ca738: mov qword ptr [rsp+0x10],rsi 2ca73d: movrsi,rax 2ca740: call core::fmt::ArgumentV1::new::h9fcfdf5e06891ab6  2ca745: mov qword ptr [rsp+8],rdx 2ca74a: mov qword ptr [rsp],rax 2ca74e: jmp0x2ca750 2ca750: movrax, qword ptr [rsp] eprintln!("error: {:?}", err); 2ca754: mov qword ptr [rsp+0x58],rax 2ca759: movrcx, qword ptr [rsp+8] 2ca75e: mov qword ptr [rsp+0x60],rcx 2ca763: leardi,[rsp+0x28] 2ca768: movedx,2 2ca76d: learcx,[rsp+0x58] 2ca772: movr8d,1 2ca778: movrsi, qword ptr [rsp+0x10] eprintln!("error: {:?}", err); 2ca77d: call core::fmt::Arguments::new_v1::h82cc96922c9a1896 2ca782: jmp0x2ca7af 2ca784: xoreax,eax 2ca786: movecx,eax} 2ca788: cmp qword ptr [rsp+0x18],0 2ca78e: movedx,1 2ca793: cmovbe rdx,rcx 2ca797: cmprdx,1 2ca79b: je0x2ca6d3 2ca7a1: jmp0x2ca7d7 } 2ca7a3: leardi,[rsp+0x20] 2ca7a8: call core::ptr::drop_in_place::h2f9c3b8587adf9a5  2ca7ad: jmp0x2ca784 eprintln!("error: {:?}", err); 2ca7af: learax,[rip+0x4abe9a] 2ca7b6: leardi,[rsp+0x28] 2ca7bb: callrax 2ca7bd: jmp0x2ca7bfstd::process::exit(1); 2ca7bf: learax,[rip+0x4aee7a] 2ca7c6: movedi,1 2ca7cb: callrax 2ca7cd: jmp0x2ca7f4} 2ca7cf: addrsp,0x88 2ca7d6: ret} 2ca7d7: leardi,[rsp+0x18] 2ca7dc: call core::ptr::drop_in_place::h3ba6e349fe585cc9  2ca7e1: jmp0x2ca6d3 2ca7e6: mov qword ptr [rsp+0x78],rax 2ca7eb: mov dword ptr [rsp+0x80],edx 2ca7f2: jmp0x2ca7a3 2ca7f4: ud2

About

Disassemble symbols in Rust binaries and Cargo projects (and more).

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages