mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-20 08:18:36 +03:00
remove more special cases. use standardized api
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
namespace X86Disassembler.X86.Handlers.Call;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for CALL r/m32 instruction (0xFF /2)
|
||||
/// Handler for CALL r/m32 instruction (FF /2)
|
||||
/// </summary>
|
||||
public class CallRm32Handler : InstructionHandler
|
||||
{
|
||||
@ -23,7 +23,26 @@ public class CallRm32Handler : InstructionHandler
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
return opcode == 0xFF;
|
||||
// CALL r/m32 is encoded as FF /2
|
||||
if (opcode != 0xFF)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if we have enough bytes to read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Peek at the ModR/M byte without advancing the position
|
||||
byte modRM = CodeBuffer[Decoder.GetPosition()];
|
||||
|
||||
// Extract the reg field (bits 3-5)
|
||||
byte reg = (byte)((modRM & 0x38) >> 3);
|
||||
|
||||
// CALL r/m32 is encoded as FF /2 (reg field = 2)
|
||||
return reg == 2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -34,6 +53,7 @@ public class CallRm32Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
@ -42,12 +62,6 @@ public class CallRm32Handler : InstructionHandler
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// CALL r/m32 is encoded as FF /2
|
||||
if (reg != RegisterIndex.C)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "call";
|
||||
|
||||
|
@ -49,37 +49,27 @@ public class CmpImmWithRm32Handler : InstructionHandler
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, memOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Get the position after decoding the ModR/M byte
|
||||
int position = Decoder.GetPosition();
|
||||
|
||||
// Check if we have enough bytes for the immediate value
|
||||
if (!Decoder.CanReadUInt())
|
||||
{
|
||||
return false; // Not enough bytes for the immediate value
|
||||
}
|
||||
|
||||
// Read the immediate value
|
||||
if (!Decoder.CanReadUInt())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
uint imm32 = Decoder.ReadUInt32();
|
||||
|
||||
// Format the destination operand based on addressing mode
|
||||
string destOperand;
|
||||
if (mod == 3) // Register addressing mode
|
||||
{
|
||||
// Get 32-bit register name
|
||||
destOperand = ModRMDecoder.GetRegisterName(rm, 32);
|
||||
}
|
||||
else // Memory addressing mode
|
||||
{
|
||||
// Memory operand already includes dword ptr prefix
|
||||
destOperand = memOperand;
|
||||
memOperand = ModRMDecoder.GetRegisterName(rm, 32);
|
||||
}
|
||||
|
||||
// Format the immediate value
|
||||
string immStr = $"0x{imm32:X8}";
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"{destOperand}, {immStr}";
|
||||
instruction.Operands = $"{memOperand}, {immStr}";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -48,8 +48,6 @@ public class CmpImmWithRm32SignExtendedHandler : InstructionHandler
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "cmp";
|
||||
|
||||
int position = Decoder.GetPosition();
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
|
@ -50,9 +50,6 @@ public class CmpImmWithRm8Handler : InstructionHandler
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, memOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Get the position after decoding the ModR/M byte
|
||||
int position = Decoder.GetPosition();
|
||||
|
||||
// Check if we have enough bytes for the immediate value
|
||||
if (!Decoder.CanReadByte())
|
||||
|
Reference in New Issue
Block a user