1
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-12-10 08:01:21 +04:00

Fixed TEST instruction handlers and tests. Updated TestImmWithRm8Handler and TestImmWithRm32Handler to properly check opcode in CanHandle and validate reg field in Decode. Improved test cases to use InstructionDecoder directly.

This commit is contained in:
bird_egop
2025-04-12 21:21:03 +03:00
parent bf5fcdd2ff
commit fe0b04f5a1
10 changed files with 330 additions and 74 deletions

View File

@@ -57,14 +57,30 @@ public class TestRegMem8Handler : InstructionHandler
byte reg = (byte)((modRM & 0x38) >> 3);
byte rm = (byte)(modRM & 0x07);
// Decode the destination operand
string destOperand = _modRMDecoder.DecodeModRM(mod, rm, true);
// Get the source register
string srcReg = GetRegister8(reg);
// Set the operands
instruction.Operands = $"{destOperand}, {srcReg}";
// For direct register addressing (mod == 3), the r/m field specifies a register
if (mod == 3)
{
// Get the register names
string rmReg = GetRegister8(rm);
string regReg = GetRegister8(reg);
// Set the operands (TEST r/m8, r8)
// In x86 assembly, the TEST instruction has the operand order r/m8, r8
// According to Ghidra and standard x86 assembly convention, it should be TEST CL,AL
// where CL is the r/m operand and AL is the reg operand
instruction.Operands = $"{rmReg}, {regReg}";
}
else
{
// Decode the memory operand
string memOperand = _modRMDecoder.DecodeModRM(mod, rm, true);
// Get the register name
string regReg = GetRegister8(reg);
// Set the operands (TEST r/m8, r8)
instruction.Operands = $"{memOperand}, {regReg}";
}
return true;
}