Skip to content

Commit

Permalink
fix conditional jumps in the trampoline sometimes having wrong opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
HJfod committed May 6, 2024
1 parent ada6508 commit a416a7b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/generator/X86Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,15 @@ Result<> X86HandlerGenerator::relocateInstruction(cs_insn* insn, uint8_t* buffer
trampolineAddress += 5;
}
else {
uint8_t opCode;
switch (id) {
case X86_INS_JE: opCode = 0x74; break;
case X86_INS_JNE: opCode = 0x75; break;
default: opCode = 0x0f; break;
}
// conditional jumps
// res = dst - src - 6
std::array<uint8_t, 6> jmp = {0x0f, 0, 0, 0, 0, 0};
std::array<uint8_t, 6> jmp = {opCode, 0, 0, 0, 0, 0};
int addrBytes = jmpTargetAddr - trampolineAddress - 6;
if (detail->x86.operands[0].size == 1) {
jmp[1] = insn->bytes[0] + 0x10;
Expand Down

1 comment on commit a416a7b

@altalk23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad commit IMO

Please sign in to comment.