Crate bad64[][src]

bad64

bad64 is a set of Rust bindings to the Binja Arm64 Disassembler.

For more information about the disassembler, please see the upstream repo.

There are two main entry points:

  1. decode for decoding a single instruction.
use bad64::{decode, Operation};
// nop - "\x1f\x20\x03\xd5"
let decoded = decode(0xd503201f, 0x1000).unwrap();

assert_eq!(decoded.address(), 0x1000);
assert_eq!(decoded.num_operands(), 0);
assert_eq!(decoded.operation(), Operation::NOP);
assert_eq!(decoded.mnem(), "nop");
  1. disassemble for disassembling a byte sequence.
use bad64::{disassemble, Operation, Operand, Reg, Imm};

// 1000: str   x0, [sp, #-16]! ; "\xe0\x0f\x1f\xf8"
// 1004: ldr   x0, [sp], #16   ; "\xe0\x07\x41\xf8"
let mut decoded_iter = disassemble(b"\xe0\x0f\x1f\xf8\xe0\x07\x41\xf8", 0x1000);

let push = decoded_iter.next().unwrap().unwrap();

// check out the push
assert_eq!(push.address(), 0x1000);
assert_eq!(push.num_operands(), 2);
assert_eq!(push.operation(), Operation::STR);
assert_eq!(push.operand(0), Some(Operand::Reg { reg: Reg::X0, shift: None }));
assert_eq!(push.operand(1), Some(Operand::MemPreIdx { reg: Reg::SP, offset: 16 }));
assert_eq!(push.operand(2), None);

let pop = decoded_iter.next().unwrap().unwrap();

// check out the pop
assert_eq!(pop.address(), 0x1004);
assert_eq!(pop.num_operands(), 2);
assert_eq!(pop.operation(), Operation::LDR);
assert_eq!(
    pop.operand(0),
    Some(Operand::Reg { reg: Reg::X0, shift: None }));
assert_eq!(
    pop.operand(1),
    Some(Operand::MemPostIdxImm { reg: Reg::SP, imm: Imm { neg: false, val: 16 }}));
assert_eq!(pop.operand(2), None);

// make sure there's nothing left
assert_eq!(decoded_iter.next(), None);

Structs

Imm

An instruction immediate

Instruction

A decoded instruction

Enums

DecodeError

Decoding errors types

Operand

An instruction operand

Operation

An instruction operation

Reg

A register

Shift

A register or immediate shift in an operand

SysReg

A system register

Functions

decode

Decode a single instruction

disassemble

Disassemble byte slice