0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-06-18 15:49:47 +03:00

Simplified TestRegMem8Handler by removing unused variables and improving code structure

This commit is contained in:
bird_egop
2025-04-14 00:54:16 +03:00
parent b7c6092b7f
commit d3d2c4c63f

View File

@ -37,9 +37,8 @@ public class TestRegMem8Handler : InstructionHandler
// Set the mnemonic
instruction.Mnemonic = "test";
int position = Decoder.GetPosition();
if (position >= Length)
// Check if we have enough bytes for the ModR/M byte
if (!Decoder.CanReadByte())
{
return false;
}
@ -47,26 +46,19 @@ public class TestRegMem8Handler : InstructionHandler
// Read the ModR/M byte
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
// For direct register addressing (mod == 3), the r/m field specifies a register
// Get the register name for the reg field
string regOperand = ModRMDecoder.GetRegisterName(reg, 8);
// For direct register addressing (mod == 3), get the r/m register name
if (mod == 3)
{
// Get the register names
string rmReg = ModRMDecoder.GetRegisterName(rm, 8);
string regReg = ModRMDecoder.GetRegisterName(reg, 8);
// 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}";
string rmOperand = ModRMDecoder.GetRegisterName(rm, 8);
instruction.Operands = $"{rmOperand}, {regOperand}";
}
else
{
// Get the register name
string regReg = ModRMDecoder.GetRegisterName(reg, 8);
// Set the operands (TEST r/m8, r8)
instruction.Operands = $"{destOperand}, {regReg}";
// For memory operands, use the decoded operand string
instruction.Operands = $"{destOperand}, {regOperand}";
}
return true;