Skip to content

Commit

Permalink
Added support for exposing opcode in disassembled object
Browse files Browse the repository at this point in the history
  • Loading branch information
jj16791 authored and FinnWilkinson committed Sep 26, 2024
1 parent a34901e commit 73935f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,9 @@ size_t CAPSTONE_API cs_disasm(csh ud, const uint8_t *buffer, size_t size, uint64
handle->insn_id(handle, insn_cache, mci.Opcode);

handle->printer(&mci, &ss, handle->printer_info);

fill_insn(handle, insn_cache, &ss, &mci, handle->post_printer, buffer);
insn_cache->opcode = mci.Opcode;

// adjust for pseudo opcode (X86)
if (handle->arch == CS_ARCH_X86 && insn_cache->id != X86_INS_VCMP)
Expand Down Expand Up @@ -1446,7 +1448,9 @@ bool CAPSTONE_API cs_disasm_iter(csh ud, const uint8_t **code, size_t *size,

handle->printer(&mci, &ss, handle->printer_info);


fill_insn(handle, insn, &ss, &mci, handle->post_printer, *code);
insn->opcode = mci.Opcode;

// adjust for pseudo opcode (X86)
if (handle->arch == CS_ARCH_X86)
Expand Down
3 changes: 3 additions & 0 deletions include/capstone/capstone.h
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,9 @@ typedef struct cs_insn {
/// NOTE 2: when in Skipdata mode, or when detail mode is OFF, even if this pointer
/// is not NULL, its content is still irrelevant.
cs_detail *detail;

/// The internal opcode of this instruction
unsigned int opcode;
} cs_insn;


Expand Down

0 comments on commit 73935f8

Please sign in to comment.