1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
extern crate libc;
pub mod instruction;
pub mod constants;
pub mod ffi;
pub mod capstone;
pub use instruction::*;
pub use constants::*;
pub use capstone::Capstone;
#[allow(non_camel_case_types)]
pub type csh = libc::size_t;
#[cfg(test)]
mod test {
use super::*;
static CODE: &'static [u8] = b"\x55\x48\x8b\x05\xb8\x13\x00\x00";
#[test]
fn test_x86_simple() {
match capstone::Capstone::new(constants::CsArch::ARCH_X86,
constants::CsMode::MODE_64) {
Some(cs) => {
if let Some(insns) = cs.disasm(CODE, 0x1000, 0) {
assert_eq!(insns.len(), 2);
let is: Vec<_> = insns.iter().collect();
assert_eq!(is[0].mnemonic().unwrap(), "push");
assert_eq!(is[1].mnemonic().unwrap(), "mov");
assert_eq!(is[0].address, 0x1000);
assert_eq!(is[1].address, 0x1001);
} else {
assert!(false, "Couldn't disasm instructions")
}
},
None => {
assert!(false, "Couldn't create a cs engine");
}
}
}
}