MCPcopy Create free account
hub / github.com/b1tg/rust-windows-shellcode / show_disassemble

Function show_disassemble

src/main.rs:59–90  ·  view source on GitHub ↗
(bytes: &[u8], max_line: u32)

Source from the content-addressed store, hash-verified

57 Ok(())
58}
59pub fn show_disassemble(bytes: &[u8], max_line: u32) {
60 let mut decoder = Decoder::new(EXAMPLE_CODE_BITNESS, bytes, DecoderOptions::NONE);
61 decoder.set_ip(EXAMPLE_CODE_RIP);
62 let mut formatter = NasmFormatter::new();
63 formatter.options_mut().set_digit_separator("`");
64 formatter.options_mut().set_first_operand_char_index(10);
65 let mut output = String::new();
66 let mut instruction = Instruction::default();
67 let mut i = 0;
68 while decoder.can_decode() {
69 i += 1;
70 if i > max_line {
71 println!("....\n");
72 break;
73 }
74 decoder.decode_out(&mut instruction);
75 output.clear();
76 formatter.format(&instruction, &mut output);
77 print!("{:016X} ", instruction.ip());
78 let start_index = (instruction.ip() - EXAMPLE_CODE_RIP) as usize;
79 let instr_bytes = &bytes[start_index..start_index + instruction.len()];
80 for b in instr_bytes.iter() {
81 print!("{:02X}", b);
82 }
83 if instr_bytes.len() < HEXBYTES_COLUMN_BYTE_LENGTH {
84 for _ in 0..HEXBYTES_COLUMN_BYTE_LENGTH - instr_bytes.len() {
85 print!(" ");
86 }
87 }
88 println!(" {}", output);
89 }
90}
91
92const HEXBYTES_COLUMN_BYTE_LENGTH: usize = 10;
93const EXAMPLE_CODE_BITNESS: u32 = 64;

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected