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,3 +1,5 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.ArithmeticUnary;
|
||||
|
||||
/// <summary>
|
||||
@ -8,11 +10,9 @@ public class DivRm32Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the DivRm32Handler 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 DivRm32Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public DivRm32Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -27,11 +27,10 @@ public class DivRm32Handler : InstructionHandler
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 6 (DIV)
|
||||
int position = Decoder.GetPosition();
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
byte modRM = CodeBuffer[position];
|
||||
byte modRM = Decoder.PeakByte();
|
||||
byte reg = (byte) ((modRM & 0x38) >> 3);
|
||||
|
||||
return reg == 6; // 6 = DIV
|
||||
@ -45,8 +44,8 @@ public class DivRm32Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "div";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Div;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
@ -54,10 +53,16 @@ public class DivRm32Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||
// For DIV r/m32 (0xF7 /6):
|
||||
// - The r/m field with mod specifies the operand (register or memory)
|
||||
var (mod, reg, rm, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = destOperand;
|
||||
// Set the structured operands
|
||||
// DIV has only one operand
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.ArithmeticUnary;
|
||||
|
||||
/// <summary>
|
||||
@ -8,11 +10,9 @@ public class IdivRm32Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the IdivRm32Handler 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 IdivRm32Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public IdivRm32Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -27,11 +27,10 @@ public class IdivRm32Handler : InstructionHandler
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 7 (IDIV)
|
||||
int position = Decoder.GetPosition();
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
byte modRM = CodeBuffer[position];
|
||||
byte modRM = Decoder.PeakByte();
|
||||
byte reg = (byte) ((modRM & 0x38) >> 3);
|
||||
|
||||
return reg == 7; // 7 = IDIV
|
||||
@ -45,8 +44,8 @@ public class IdivRm32Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "idiv";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.IDiv;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
@ -54,10 +53,16 @@ public class IdivRm32Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||
// For IDIV r/m32 (0xF7 /7):
|
||||
// - The r/m field with mod specifies the operand (register or memory)
|
||||
var (mod, reg, rm, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = destOperand;
|
||||
// Set the structured operands
|
||||
// IDIV has only one operand
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.ArithmeticUnary;
|
||||
|
||||
/// <summary>
|
||||
@ -8,11 +10,9 @@ public class ImulRm32Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the ImulRm32Handler 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 ImulRm32Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public ImulRm32Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -27,11 +27,10 @@ public class ImulRm32Handler : InstructionHandler
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 5 (IMUL)
|
||||
int position = Decoder.GetPosition();
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
byte modRM = CodeBuffer[position];
|
||||
byte modRM = Decoder.PeakByte();
|
||||
byte reg = (byte) ((modRM & 0x38) >> 3);
|
||||
|
||||
return reg == 5; // 5 = IMUL
|
||||
@ -45,8 +44,8 @@ public class ImulRm32Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "imul";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.IMul;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
@ -54,10 +53,13 @@ public class ImulRm32Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = destOperand;
|
||||
var (mod, reg, rm, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.ArithmeticUnary;
|
||||
|
||||
/// <summary>
|
||||
@ -8,11 +10,9 @@ public class MulRm32Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the MulRm32Handler 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 MulRm32Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public MulRm32Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -27,11 +27,10 @@ public class MulRm32Handler : InstructionHandler
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 4 (MUL)
|
||||
int position = Decoder.GetPosition();
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
byte modRM = CodeBuffer[position];
|
||||
byte modRM = Decoder.PeakByte();
|
||||
byte reg = (byte) ((modRM & 0x38) >> 3);
|
||||
|
||||
return reg == 4; // 4 = MUL
|
||||
@ -45,8 +44,8 @@ public class MulRm32Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "mul";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Mul;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
@ -54,10 +53,16 @@ public class MulRm32Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||
// For MUL r/m32 (0xF7 /4):
|
||||
// - The r/m field with mod specifies the operand (register or memory)
|
||||
var (mod, reg, rm, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = destOperand;
|
||||
// Set the structured operands
|
||||
// MUL has only one operand
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.ArithmeticUnary;
|
||||
|
||||
/// <summary>
|
||||
@ -8,11 +10,9 @@ public class NegRm32Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the NegRm32Handler 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 NegRm32Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public NegRm32Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -27,11 +27,10 @@ public class NegRm32Handler : InstructionHandler
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 3 (NEG)
|
||||
int position = Decoder.GetPosition();
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
byte modRM = CodeBuffer[position];
|
||||
byte modRM = Decoder.PeakByte();
|
||||
byte reg = (byte) ((modRM & 0x38) >> 3);
|
||||
|
||||
return reg == 3; // 3 = NEG
|
||||
@ -45,8 +44,8 @@ public class NegRm32Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "neg";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Neg;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
@ -54,10 +53,16 @@ public class NegRm32Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||
// For NEG r/m32 (0xF7 /3):
|
||||
// - The r/m field with mod specifies the operand (register or memory)
|
||||
var (mod, reg, rm, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = destOperand;
|
||||
// Set the structured operands
|
||||
// NEG has only one operand
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.ArithmeticUnary;
|
||||
|
||||
/// <summary>
|
||||
@ -8,11 +10,9 @@ public class NotRm32Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the NotRm32Handler 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 NotRm32Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public NotRm32Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -28,11 +28,10 @@ public class NotRm32Handler : InstructionHandler
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 2 (NOT)
|
||||
int position = Decoder.GetPosition();
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
byte modRM = CodeBuffer[position];
|
||||
byte modRM = Decoder.PeakByte();
|
||||
byte reg = (byte) ((modRM & 0x38) >> 3);
|
||||
|
||||
return reg == 2; // 2 = NOT
|
||||
@ -46,13 +45,18 @@ public class NotRm32Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Not;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||
// For NOT r/m32 (0xF7 /2):
|
||||
// - The r/m field with mod specifies the operand (register or memory)
|
||||
var (mod, reg, rm, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Verify this is a NOT instruction
|
||||
if (reg != RegisterIndex.C)
|
||||
@ -60,17 +64,12 @@ public class NotRm32Handler : InstructionHandler
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "not";
|
||||
|
||||
// For direct register addressing (mod == 3), the r/m field specifies a register
|
||||
if (mod == 3)
|
||||
{
|
||||
destOperand = ModRMDecoder.GetRegisterName(rm, 32);
|
||||
}
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = destOperand;
|
||||
// Set the structured operands
|
||||
// NOT has only one operand
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user