mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-20 08:18:36 +03:00
Updated instruction handlers to use Type and StructuredOperands instead of Mnemonic and Operands
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
namespace X86Disassembler.X86.Handlers.Push;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for PUSH imm32 instruction (0x68)
|
||||
/// </summary>
|
||||
@ -8,11 +10,9 @@ public class PushImm32Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the PushImm32Handler class
|
||||
/// </summary>
|
||||
/// <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 PushImm32Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public PushImm32Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -34,8 +34,8 @@ public class PushImm32Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "push";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Push;
|
||||
|
||||
if(!Decoder.CanReadUInt())
|
||||
{
|
||||
@ -45,8 +45,14 @@ public class PushImm32Handler : InstructionHandler
|
||||
// Read the immediate value
|
||||
uint imm32 = Decoder.ReadUInt32();
|
||||
|
||||
// Set the operands with 8-digit padding to match test expectations
|
||||
instruction.Operands = $"0x{imm32:X8}";
|
||||
// Create the immediate operand
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm32);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
namespace X86Disassembler.X86.Handlers.Push;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for PUSH imm8 instruction (0x6A)
|
||||
/// </summary>
|
||||
@ -8,11 +10,9 @@ public class PushImm8Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the PushImm8Handler class
|
||||
/// </summary>
|
||||
/// <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 PushImm8Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public PushImm8Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -34,8 +34,8 @@ public class PushImm8Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "push";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Push;
|
||||
|
||||
if(!Decoder.CanReadByte())
|
||||
{
|
||||
@ -45,8 +45,15 @@ public class PushImm8Handler : InstructionHandler
|
||||
// Read the immediate value
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"0x{imm8:X2}";
|
||||
// Create the immediate operand
|
||||
// Sign-extend the 8-bit value to 32-bit for proper stack alignment
|
||||
var immOperand = OperandFactory.CreateImmediateOperand((sbyte)imm8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
namespace X86Disassembler.X86.Handlers.Push;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for PUSH r32 instruction (0x50-0x57)
|
||||
/// </summary>
|
||||
@ -8,11 +10,9 @@ public class PushRegHandler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the PushRegHandler class
|
||||
/// </summary>
|
||||
/// <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 PushRegHandler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public PushRegHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -34,15 +34,20 @@ public class PushRegHandler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "push";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Push;
|
||||
|
||||
// Register is encoded in the low 3 bits of the opcode
|
||||
RegisterIndex reg = (RegisterIndex) (opcode & 0x07);
|
||||
string regName = ModRMDecoder.GetRegisterName(reg, 32);
|
||||
RegisterIndex reg = (RegisterIndex)(opcode & 0x07);
|
||||
|
||||
// Create the register operand
|
||||
var regOperand = OperandFactory.CreateRegisterOperand(reg, 32);
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = regName;
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
regOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Push;
|
||||
|
||||
/// <summary>
|
||||
@ -8,11 +10,9 @@ public class PushRm32Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the PushRm32Handler class
|
||||
/// </summary>
|
||||
/// <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 PushRm32Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public PushRm32Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ public class PushRm32Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Peek at the ModR/M byte without advancing the position
|
||||
byte modRM = CodeBuffer[Decoder.GetPosition()];
|
||||
byte modRM = Decoder.PeakByte();
|
||||
|
||||
// Extract the reg field (bits 3-5)
|
||||
byte reg = (byte)((modRM & 0x38) >> 3);
|
||||
@ -53,8 +53,8 @@ public class PushRm32Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "push";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Push;
|
||||
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
@ -63,18 +63,16 @@ public class PushRm32Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||
// For PUSH r/m32 (FF /6):
|
||||
// - The r/m field with mod specifies the operand (register or memory)
|
||||
var (mod, reg, rm, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// For memory operands, set the operand
|
||||
if (mod != 3) // Memory operand
|
||||
{
|
||||
instruction.Operands = destOperand;
|
||||
}
|
||||
else // Register operand
|
||||
{
|
||||
string rmName = ModRMDecoder.GetRegisterName(rm, 32);
|
||||
instruction.Operands = rmName;
|
||||
}
|
||||
// Set the structured operands
|
||||
// PUSH has only one operand
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user