0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-06-21 00:28:36 +03:00

Simplified jump instruction handlers by using consistent decoder methods and improving code organization

This commit is contained in:
bird_egop
2025-04-14 00:09:44 +03:00
parent 5daab494e1
commit 38770de005
3 changed files with 23 additions and 55 deletions

View File

@ -34,34 +34,26 @@ public class JgeRel8Handler : InstructionHandler
/// <returns>True if the instruction was successfully decoded</returns>
public override bool Decode(byte opcode, Instruction instruction)
{
// Save the original position for raw bytes calculation
int startPosition = Decoder.GetPosition();
// Set the mnemonic
instruction.Mnemonic = "jge";
if (startPosition >= Length)
// Check if we can read the offset byte
if (!Decoder.CanReadByte())
{
instruction.Operands = "??";
instruction.RawBytes = new byte[] { opcode };
return true;
}
// Read the relative offset
sbyte offset = (sbyte)CodeBuffer[startPosition];
Decoder.SetPosition(startPosition + 1);
// Read the offset and calculate target address
int position = Decoder.GetPosition();
sbyte offset = (sbyte)Decoder.ReadByte();
// Calculate the target address
// The target is calculated from the address of the next instruction (EIP + 2)
// EIP + 2 + offset
uint targetAddress = (uint)(instruction.Address + offset + 2);
// Calculate target address (instruction address + instruction length + offset)
uint targetAddress = (uint)(instruction.Address + 2 + offset);
// Set the operands
// Format the target address
instruction.Operands = $"0x{targetAddress:X8}";
// Set the raw bytes
instruction.RawBytes = new byte[] { opcode, (byte)offset };
return true;
}
}