Skip to content

Commit

Permalink
MCInst_Init() is arch-independent
Browse files Browse the repository at this point in the history
  • Loading branch information
aquynh committed Jun 16, 2014
1 parent 370b7d7 commit 495295e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
16 changes: 6 additions & 10 deletions MCInst.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@

#define MCINST_CACHE (ARR_SIZE(mcInst->Operands) - 1)

void MCInst_Init(cs_struct *handle, MCInst *inst)
{
switch(handle->arch) {
default:
memset(inst, 0, sizeof(*inst));
break;
case CS_ARCH_X86:
inst->size = 0;
break;
}
void MCInst_Init(MCInst *inst)
{
inst->OpcodePub = 0;
inst->size = 0;

return;
}

void MCInst_clear(MCInst *inst)
Expand Down
4 changes: 2 additions & 2 deletions MCInst.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ MCOperand *MCOperand_CreateImm1(MCInst *inst, int64_t Val);
struct MCInst {
unsigned Opcode;
MCOperand Operands[34];
unsigned OpcodePub;
unsigned size; // number of operands
cs_insn *flat_insn; // insn to be exposed to public
unsigned OpcodePub;
uint64_t address; // address of this insn
cs_struct *csh; // save the main csh
uint8_t x86_imm_size; // save immediate size to print immediate properly
Expand All @@ -105,7 +105,7 @@ struct MCInst {
uint8_t x86_prefix[4];
};

void MCInst_Init(cs_struct *handle, MCInst *inst);
void MCInst_Init(MCInst *inst);

void MCInst_clear(MCInst *inst);

Expand Down
2 changes: 1 addition & 1 deletion arch/ARM/ARMInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ void ARM_printInst(MCInst *MI, SStream *O, void *Info)
if (MCRegisterClass_contains(MRC, Reg)) {
MCInst NewMI;

MCInst_Init(MI->csh, &NewMI);
MCInst_Init(&NewMI);
MCInst_setOpcode(&NewMI, Opcode);

if (isStore)
Expand Down
2 changes: 1 addition & 1 deletion cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ size_t cs_disasm_ex(csh ud, const uint8_t *buffer, size_t size, uint64_t offset,
insn_cache = total;

while (size > 0) {
MCInst_Init(handle, &mci);
MCInst_Init(&mci);
mci.csh = handle;

// relative branches need to know the address & size of current insn
Expand Down

0 comments on commit 495295e

Please sign in to comment.