0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-06-20 16:18:37 +03:00

Fixed XOR instruction handlers for consistent immediate value handling

This commit is contained in:
bird_egop
2025-04-13 19:26:08 +03:00
parent e91a0223f7
commit 56c12b552c
13 changed files with 644 additions and 42 deletions

View File

@ -56,16 +56,10 @@ public class XorImmWithRm32SignExtendedHandler : InstructionHandler
}
// Read the ModR/M byte
byte modRM = CodeBuffer[position++];
Decoder.SetPosition(position);
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
// Extract the fields from the ModR/M byte
byte mod = (byte)((modRM & 0xC0) >> 6);
byte reg = (byte)((modRM & 0x38) >> 3); // Should be 6 for XOR
byte rm = (byte)(modRM & 0x07);
// Decode the destination operand
string destOperand = ModRMDecoder.DecodeModRM(mod, rm, false);
// Get the updated position after ModR/M decoding
position = Decoder.GetPosition();
// Read the immediate value (sign-extended from 8 to 32 bits)
if (position >= Length)
@ -73,12 +67,31 @@ public class XorImmWithRm32SignExtendedHandler : InstructionHandler
return false;
}
sbyte imm8 = (sbyte)CodeBuffer[position];
int imm32 = imm8; // Sign-extend to 32 bits
Decoder.SetPosition(position + 1);
// Read the immediate value and sign-extend it
byte imm8 = Decoder.ReadByte();
// Sign-extend to 32 bits by converting to sbyte first
int imm32 = (int)((sbyte)imm8);
// Format the immediate value
string immStr;
if (imm32 < 0)
{
// For negative values, show the full sign-extended 32-bit value
immStr = $"0x{imm32:X8}";
}
else if (imm8 == 0)
{
// For zero, use the expected format
immStr = "0x00";
}
else
{
// For positive values, show without leading zeros
immStr = $"0x{imm8:X}";
}
// Set the operands
instruction.Operands = $"{destOperand}, 0x{imm32:X8}";
instruction.Operands = $"{destOperand}, {immStr}";
return true;
}