summaryrefslogtreecommitdiff
path: root/rust/src/llvm.rs
blob: f74d00e3aa941d488e6ae80479e88f30008018c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use binaryninjacore_sys::BNLlvmServicesDisasmInstruction;
use std::ffi::CStr;

pub fn disas_instruction(triplet: &str, data: &[u8], address64: u64) -> Option<(usize, String)> {
    unsafe {
        let mut buf = vec![0; 256];
        let instr_len = BNLlvmServicesDisasmInstruction(
            triplet.as_ptr() as *const i8,
            data.as_ptr() as *mut u8,
            data.len() as i32,
            address64,
            buf.as_mut_ptr() as *mut i8,
            buf.len(),
        );
        if instr_len > 0 {
            let cstr = CStr::from_ptr(buf.as_ptr() as *const i8);
            let string = cstr.to_str().unwrap().to_string();
            Some((instr_len as usize, string))
        } else {
            None
        }
    }
}