use iced_x86::{Decoder, DecoderOptions, Formatter, Instruction, IntelFormatter};
#[allow(dead_code)]
pub(crate) fn disassemble_bytes(bytes: &[u8], bitness: u32, offset: usize, max_instr: u32) {
let bytes = &bytes[offset..];
const HEXBYTES_COLUMN_BYTE_LENGTH: usize = 12;
let mut decoder = Decoder::with_ip(bitness, bytes, 0, DecoderOptions::NONE);
let mut formatter = IntelFormatter::new();
let mut output = String::new();
let mut instruction = Instruction::default();
let mut nb_of_instr = 0;
while decoder.can_decode() && nb_of_instr < max_instr {
nb_of_instr += 1;
decoder.decode_out(&mut instruction);
output.clear();
formatter.format(&instruction, &mut output);
let start_index = (instruction.ip() - 0) as usize;
let instr_bytes = &bytes[start_index..start_index + instruction.len()];
for b in instr_bytes.iter() {
print!("{:02X}", b);
}
if instr_bytes.len() < HEXBYTES_COLUMN_BYTE_LENGTH {
for _ in 0..HEXBYTES_COLUMN_BYTE_LENGTH - instr_bytes.len() {
print!(" ");
}
}
println!(" {}", output);
}
}