From a416a7ba8305434f4adf4cfb8e28dd0975291c50 Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Mon, 6 May 2024 12:47:19 +0300 Subject: [PATCH] fix conditional jumps in the trampoline sometimes having wrong opcodes --- src/generator/X86Generator.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/generator/X86Generator.cpp b/src/generator/X86Generator.cpp index 3b1d9dc..aae52f5 100644 --- a/src/generator/X86Generator.cpp +++ b/src/generator/X86Generator.cpp @@ -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 jmp = {0x0f, 0, 0, 0, 0, 0}; + std::array 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;