mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-20 08:18:36 +03:00
nice big refactor
This commit is contained in:
@ -11,11 +11,11 @@ public class TestRegMem8Handler : InstructionHandler
|
||||
/// <param name="codeBuffer">The buffer containing the code to decode</param>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
/// <param name="length">The length of the buffer</param>
|
||||
public TestRegMem8Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
public TestRegMem8Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
@ -25,7 +25,7 @@ public class TestRegMem8Handler : InstructionHandler
|
||||
{
|
||||
return opcode == 0x84;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a TEST r/m8, r8 instruction
|
||||
/// </summary>
|
||||
@ -36,30 +36,24 @@ public class TestRegMem8Handler : InstructionHandler
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "test";
|
||||
|
||||
|
||||
int position = Decoder.GetPosition();
|
||||
|
||||
|
||||
if (position >= Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Read the ModR/M byte
|
||||
byte modRM = CodeBuffer[position++];
|
||||
Decoder.SetPosition(position);
|
||||
|
||||
// Extract the fields from the ModR/M byte
|
||||
byte mod = (byte)((modRM & 0xC0) >> 6);
|
||||
byte reg = (byte)((modRM & 0x38) >> 3);
|
||||
byte rm = (byte)(modRM & 0x07);
|
||||
|
||||
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// 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);
|
||||
|
||||
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
|
||||
@ -68,16 +62,13 @@ public class TestRegMem8Handler : InstructionHandler
|
||||
}
|
||||
else
|
||||
{
|
||||
// Decode the memory operand
|
||||
string memOperand = ModRMDecoder.DecodeModRM(mod, rm, true);
|
||||
|
||||
// Get the register name
|
||||
string regReg = GetRegister8(reg);
|
||||
|
||||
string regReg = ModRMDecoder.GetRegisterName(reg, 8);
|
||||
|
||||
// Set the operands (TEST r/m8, r8)
|
||||
instruction.Operands = $"{memOperand}, {regReg}";
|
||||
instruction.Operands = $"{destOperand}, {regReg}";
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user