Skip to content

Commit

Permalink
Add decodeOpcode
Browse files Browse the repository at this point in the history
  • Loading branch information
hainest committed Dec 14, 2023
1 parent 433cb1d commit ec3683b
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion instructionAPI/src/x86/decoder.C
Expand Up @@ -3,7 +3,11 @@

#include "capstone/capstone.h"
#include "capstone/x86.h"

#include "x86/decoder.h"
#include "x86/register-xlat.h"
#include "mnemonic-xlat.h"
#include "debug.h"

namespace Dyninst { namespace InstructionAPI {

Expand Down Expand Up @@ -43,7 +47,28 @@ namespace Dyninst { namespace InstructionAPI {
}

void x86_decoder::doDelayedDecode(Instruction const*) {}
void x86_decoder::decodeOpcode(InstructionDecoder::buffer&) {}

void x86_decoder::decodeOpcode(InstructionDecoder::buffer& buf) {
auto* code = buf.start;
size_t codeSize = buf.end - buf.start;
uint64_t cap_addr = 0;

// We want this to be as fast as possible, so don't have Capstone provide all details.
auto &dis = dis_without_detail;

// The iterator form of disassembly allows reuse of the instruction object, reducing
// the number of memory allocations.
if(!cs_disasm_iter(dis.handle, &code, &codeSize, &cap_addr, dis.insn)) {
decode_printf("Failed to disassemble instruction at %p: %s\n", code, cs_strerror(cs_errno(dis.handle)));
m_Operation = Operation(e_No_Entry, "INVALID", m_Arch);
return;
}

entryID e = x86::translate_opcode(static_cast<x86_insn>(dis.insn->id));
m_Operation = Operation(e, dis.insn->mnemonic, m_Arch);
buf.start += dis.insn->size;
}

bool x86_decoder::decodeOperands(Instruction const*) { return true; }

}}

0 comments on commit ec3683b

Please sign in to comment.