|
12345678910111213141516171819202122232425262728293031 |
- #include <stdio.h>
- #include <stdlib.h>
- #include "udis86.h"
- #include "misc.h"
-
- void disassemble_func(void* function, size_t numberOfInstr)
- {
- unsigned char* p = function;
- ud_t ud;
-
- ud_init(&ud);
- ud_set_input_buffer(&ud, function, (size_t)function | (0x1000 - 1)); // Can't read further than page boundary - there be dragons
- ud_set_pc(&ud, (uint64_t)function);
- ud_set_mode(&ud, 64);
- ud_set_syntax(&ud, UD_SYN_INTEL);
-
- for(size_t i = 0; i < numberOfInstr; i++)
- {
- size_t instrLen = 0;
- if(!(instrLen = ud_disassemble(&ud)) || ud.error)
- return;
-
- p += instrLen;
-
- printf("%p %s\n", ud_insn_off(&ud), ud_insn_asm(&ud));
-
- // ugly, ugly hack todo: make it work
- if(strcmp(ud_insn_asm(&ud), "jmp qword [rip]") == 0)
- p += 8;
- }
- }
|