From 996be18172d9133ae5eded740ca2c4588f6a30be Mon Sep 17 00:00:00 2001 From: bird_egop Date: Mon, 14 Apr 2025 00:11:55 +0300 Subject: [PATCH] Simplified JmpRel32Handler by improving target address calculation and code organization --- .../X86/Handlers/Jump/JmpRel32Handler.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/X86Disassembler/X86/Handlers/Jump/JmpRel32Handler.cs b/X86Disassembler/X86/Handlers/Jump/JmpRel32Handler.cs index 5c8aff9..9b48f7c 100644 --- a/X86Disassembler/X86/Handlers/Jump/JmpRel32Handler.cs +++ b/X86Disassembler/X86/Handlers/Jump/JmpRel32Handler.cs @@ -37,20 +37,21 @@ public class JmpRel32Handler : InstructionHandler // Set the mnemonic instruction.Mnemonic = "jmp"; + // Check if we have enough bytes for the offset int position = Decoder.GetPosition(); - if (position + 4 > Length) { return false; } - // Read the relative offset - uint offset = Decoder.ReadUInt32(); + // Read the offset and calculate target address + int offset = (int)Decoder.ReadUInt32(); - // Calculate the target address - uint targetAddress = (uint)(position + offset + 4); + // Calculate target address (instruction address + instruction length + offset) + // For JMP rel32, the instruction is 5 bytes: opcode (1 byte) + offset (4 bytes) + uint targetAddress = (uint)(instruction.Address + 5 + offset); - // Set the operands + // Format the target address instruction.Operands = $"0x{targetAddress:X8}"; return true;