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:
@@ -57,14 +57,30 @@ public class TestRegMemHandler : InstructionHandler
|
||||
byte reg = (byte)((modRM & 0x38) >> 3);
|
||||
byte rm = (byte)(modRM & 0x07);
|
||||
|
||||
// Decode the destination operand
|
||||
string destOperand = _modRMDecoder.DecodeModRM(mod, rm, false);
|
||||
|
||||
// Get the source register
|
||||
string srcReg = GetRegister32(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 = GetRegister32(rm);
|
||||
string regReg = GetRegister32(reg);
|
||||
|
||||
// Set the operands (TEST r/m32, r32)
|
||||
// In x86 assembly, the TEST instruction has the operand order r/m32, r32
|
||||
// According to Ghidra and standard x86 assembly convention, it should be TEST ECX,EAX
|
||||
// where ECX is the r/m operand and EAX is the reg operand
|
||||
instruction.Operands = $"{rmReg}, {regReg}";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Decode the memory operand
|
||||
string memOperand = _modRMDecoder.DecodeModRM(mod, rm, false);
|
||||
|
||||
// Get the register name
|
||||
string regReg = GetRegister32(reg);
|
||||
|
||||
// Set the operands (TEST r/m32, r32)
|
||||
instruction.Operands = $"{memOperand}, {regReg}";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user