Hi Suzuran,
If you're using long mode (64 bit), you could try my disassembler:
https://gitlab.com/bztsrc/osz/blob/master/src/core/x86_64/disasm.h. It has one function only:
Code:
virt_t disasm(virt_t addr, char *str)
Where "virt_t" is a virtual address, uint64_t. This function receives an address, and returns the address of the next instruction. You obviously won't need the disassembled string, so just pass NULL as the second argument.
Code:
nextinst = disasm(exceptioninst, NULL);
For protected mode (32 bit), you might want to take a look at OpenBSD's version:
https://github.com/openbsd/src/blob/master/sys/arch/i386/i386/db_disasm.c. It has a very similar interface:
Code:
vaddr_t db_disasm(vaddr_t loc, int altfmt);
but it is not that trivial to reuse this code as it is a bit tied up with other parts of the BSD kernel (but not particularly hard either, just provide you own db_access implementation), and you'll have to manually remove the disassembled string writes from the code (all those db_print* calls). But at the end, it will do the job.
Cheers,
bzt