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.Xor;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for XOR AL, imm8 instruction (0x34)
|
||||
/// </summary>
|
||||
@ -8,11 +10,9 @@ public class XorAlImmHandler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the XorAlImmHandler 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 XorAlImmHandler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public XorAlImmHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -34,8 +34,8 @@ public class XorAlImmHandler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "xor";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Xor;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
@ -45,8 +45,18 @@ public class XorAlImmHandler : InstructionHandler
|
||||
// Read the immediate value using the decoder
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"al, 0x{imm8:X2}";
|
||||
// Create the register operand for AL
|
||||
var alOperand = OperandFactory.CreateRegisterOperand(RegisterIndex.A, 8);
|
||||
|
||||
// Create the immediate operand
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm8, 8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
alOperand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
namespace X86Disassembler.X86.Handlers.Xor;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for XOR AX, imm16 instruction (0x35 with 0x66 prefix)
|
||||
/// </summary>
|
||||
@ -8,11 +10,9 @@ public class XorAxImm16Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the XorAxImm16Handler 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 XorAxImm16Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public XorAxImm16Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -35,8 +35,8 @@ public class XorAxImm16Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "xor";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Xor;
|
||||
|
||||
if (!Decoder.CanReadUShort())
|
||||
{
|
||||
@ -46,11 +46,18 @@ public class XorAxImm16Handler : InstructionHandler
|
||||
// Read the immediate value using the decoder
|
||||
ushort imm16 = Decoder.ReadUInt16();
|
||||
|
||||
// Format the immediate value
|
||||
string immStr = $"0x{imm16:X4}";
|
||||
// Create the register operand for AX
|
||||
var axOperand = OperandFactory.CreateRegisterOperand(RegisterIndex.A, 16);
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"ax, {immStr}";
|
||||
// Create the immediate operand
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm16, 16);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
axOperand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
namespace X86Disassembler.X86.Handlers.Xor;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for XOR EAX, imm32 instruction (0x35)
|
||||
/// </summary>
|
||||
@ -8,11 +10,9 @@ public class XorEaxImmHandler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the XorEaxImmHandler 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 XorEaxImmHandler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public XorEaxImmHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -34,8 +34,8 @@ public class XorEaxImmHandler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "xor";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Xor;
|
||||
|
||||
if (!Decoder.CanReadUInt())
|
||||
{
|
||||
@ -45,8 +45,18 @@ public class XorEaxImmHandler : InstructionHandler
|
||||
// Read the immediate value using the decoder
|
||||
uint imm32 = Decoder.ReadUInt32();
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"eax, 0x{imm32:X8}";
|
||||
// Create the register operand for EAX
|
||||
var eaxOperand = OperandFactory.CreateRegisterOperand(RegisterIndex.A);
|
||||
|
||||
// Create the immediate operand
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm32);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
eaxOperand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Xor;
|
||||
|
||||
/// <summary>
|
||||
@ -8,11 +10,9 @@ public class XorImmWithRm16Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the XorImmWithRm16Handler 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 XorImmWithRm16Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public XorImmWithRm16Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ public class XorImmWithRm16Handler : InstructionHandler
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
byte modRM = CodeBuffer[Decoder.GetPosition()];
|
||||
byte modRM = Decoder.PeakByte();
|
||||
byte reg = (byte)((modRM & 0x38) >> 3);
|
||||
|
||||
return reg == 6; // 6 = XOR
|
||||
@ -44,8 +44,8 @@ public class XorImmWithRm16Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "xor";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Xor;
|
||||
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
@ -54,18 +54,10 @@ public class XorImmWithRm16Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||
var (mod, reg, rm, destinationOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// For direct register addressing (mod == 3), use the correct 16-bit register name
|
||||
if (mod == 3)
|
||||
{
|
||||
destOperand = ModRMDecoder.GetRegisterName(rm, 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
// For memory operands, ensure we have the correct size prefix
|
||||
destOperand = destOperand.Replace("dword ptr", "word ptr");
|
||||
}
|
||||
// Ensure the destination operand has the correct size (16-bit)
|
||||
destinationOperand.Size = 16;
|
||||
|
||||
// Check if we have enough bytes for the immediate value
|
||||
if (!Decoder.CanReadUShort())
|
||||
@ -76,11 +68,15 @@ public class XorImmWithRm16Handler : InstructionHandler
|
||||
// Read the immediate value
|
||||
ushort imm16 = Decoder.ReadUInt16();
|
||||
|
||||
// Format the immediate value
|
||||
string immStr = $"0x{imm16:X4}";
|
||||
// Create the source immediate operand
|
||||
var sourceOperand = OperandFactory.CreateImmediateOperand(imm16, 16);
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"{destOperand}, {immStr}";
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
sourceOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Xor;
|
||||
|
||||
/// <summary>
|
||||
@ -8,11 +10,9 @@ public class XorImmWithRm16SignExtendedHandler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the XorImmWithRm16SignExtendedHandler 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 XorImmWithRm16SignExtendedHandler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public XorImmWithRm16SignExtendedHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ public class XorImmWithRm16SignExtendedHandler : InstructionHandler
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
byte modRM = CodeBuffer[Decoder.GetPosition()];
|
||||
byte modRM = Decoder.PeakByte();
|
||||
byte reg = (byte)((modRM & 0x38) >> 3);
|
||||
|
||||
return reg == 6; // 6 = XOR
|
||||
@ -44,8 +44,8 @@ public class XorImmWithRm16SignExtendedHandler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "xor";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Xor;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
@ -53,27 +53,13 @@ public class XorImmWithRm16SignExtendedHandler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, memOperand) = ModRMDecoder.ReadModRM();
|
||||
// For XOR r/m16, imm8 (sign-extended) (0x83 /6 with 0x66 prefix):
|
||||
// - The r/m field with mod specifies the destination operand (register or memory)
|
||||
// - The immediate value is the source operand (sign-extended from 8 to 16 bits)
|
||||
var (mod, reg, rm, destinationOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// For the first operand, handle based on addressing mode
|
||||
string rmOperand;
|
||||
if (mod == 3) // Register addressing mode
|
||||
{
|
||||
// Get 16-bit register name for the operand
|
||||
rmOperand = ModRMDecoder.GetRegisterName(rm, 16);
|
||||
}
|
||||
else // Memory addressing mode
|
||||
{
|
||||
// For memory operands, replace "dword ptr" with "word ptr"
|
||||
if (memOperand.StartsWith("dword ptr "))
|
||||
{
|
||||
rmOperand = memOperand.Replace("dword ptr", "word ptr");
|
||||
}
|
||||
else
|
||||
{
|
||||
rmOperand = memOperand;
|
||||
}
|
||||
}
|
||||
// Adjust the operand size to 16-bit
|
||||
destinationOperand.Size = 16;
|
||||
|
||||
// Read the immediate value (sign-extended from 8 to 16 bits)
|
||||
if (!Decoder.CanReadByte())
|
||||
@ -81,24 +67,18 @@ public class XorImmWithRm16SignExtendedHandler : InstructionHandler
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the immediate value as a signed byte and automatically sign-extend it to short
|
||||
short imm16 = (sbyte)Decoder.ReadByte();
|
||||
|
||||
// Format the immediate value
|
||||
// For 16-bit operations, we want to show the immediate value without leading zeros
|
||||
string immStr;
|
||||
if (imm16 < 0)
|
||||
{
|
||||
// For negative values, show the full sign-extended 16-bit value
|
||||
immStr = $"0x{(ushort)imm16:X}";
|
||||
}
|
||||
else
|
||||
{
|
||||
// For positive values, show without leading zeros
|
||||
immStr = $"0x{imm16:X}";
|
||||
}
|
||||
// Create the source immediate operand with the sign-extended value
|
||||
var sourceOperand = OperandFactory.CreateImmediateOperand(imm16, 16);
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"{rmOperand}, {immStr}";
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
sourceOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
namespace X86Disassembler.X86.Handlers.Xor;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for XOR r/m32, imm32 instruction (0x81 /6)
|
||||
/// </summary>
|
||||
@ -8,11 +10,9 @@ public class XorImmWithRm32Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the XorImmWithRm32Handler 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 XorImmWithRm32Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public XorImmWithRm32Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ public class XorImmWithRm32Handler : InstructionHandler
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
byte modRM = CodeBuffer[Decoder.GetPosition()];
|
||||
byte modRM = Decoder.PeakByte();
|
||||
byte reg = (byte)((modRM & 0x38) >> 3);
|
||||
|
||||
return reg == 6; // 6 = XOR
|
||||
@ -44,8 +44,8 @@ public class XorImmWithRm32Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "xor";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Xor;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
@ -63,11 +63,15 @@ public class XorImmWithRm32Handler : InstructionHandler
|
||||
|
||||
var imm = Decoder.ReadUInt32();
|
||||
|
||||
// Format the immediate value
|
||||
string immStr = $"0x{imm:X}";
|
||||
// Create the immediate operand
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm, 32);
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"{destOperand}, {immStr}";
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destOperand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
namespace X86Disassembler.X86.Handlers.Xor;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for XOR r/m32, imm8 (sign-extended) instruction (0x83 /6)
|
||||
/// </summary>
|
||||
@ -8,11 +10,9 @@ public class XorImmWithRm32SignExtendedHandler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the XorImmWithRm32SignExtendedHandler 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 XorImmWithRm32SignExtendedHandler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public XorImmWithRm32SignExtendedHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ public class XorImmWithRm32SignExtendedHandler : InstructionHandler
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
byte modRM = CodeBuffer[Decoder.GetPosition()];
|
||||
byte modRM = Decoder.PeakByte();
|
||||
byte reg = (byte)((modRM & 0x38) >> 3);
|
||||
|
||||
return reg == 6; // 6 = XOR
|
||||
@ -44,8 +44,8 @@ public class XorImmWithRm32SignExtendedHandler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "xor";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Xor;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
@ -64,21 +64,15 @@ public class XorImmWithRm32SignExtendedHandler : InstructionHandler
|
||||
// Read the immediate value and sign-extend it to 32 bits
|
||||
int imm32 = (sbyte)Decoder.ReadByte();
|
||||
|
||||
// Format the immediate value
|
||||
string immStr;
|
||||
if (imm32 < 0)
|
||||
{
|
||||
// For negative values, show the full sign-extended 32-bit value
|
||||
immStr = $"0x{imm32:X8}";
|
||||
}
|
||||
else
|
||||
{
|
||||
// For positive values, show without leading zeros
|
||||
immStr = $"0x{imm32:X2}";
|
||||
}
|
||||
// Create the immediate operand with sign extension
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm32);
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"{destOperand}, {immStr}";
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destOperand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Xor;
|
||||
|
||||
/// <summary>
|
||||
@ -8,11 +10,9 @@ public class XorImmWithRm8Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the XorImmWithRm8Handler 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 XorImmWithRm8Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public XorImmWithRm8Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ public class XorImmWithRm8Handler : InstructionHandler
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
byte modRM = CodeBuffer[Decoder.GetPosition()];
|
||||
byte modRM = Decoder.PeakByte();
|
||||
byte reg = (byte)((modRM & 0x38) >> 3);
|
||||
|
||||
return reg == 6; // 6 = XOR
|
||||
@ -44,8 +44,8 @@ public class XorImmWithRm8Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "xor";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Xor;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
@ -53,19 +53,13 @@ public class XorImmWithRm8Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||
// For XOR r/m8, imm8 (0x80 /6):
|
||||
// - The r/m field with mod specifies the destination operand (register or memory)
|
||||
// - The immediate value is the source operand
|
||||
var (mod, reg, rm, destinationOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// If mod == 3, then the r/m field specifies a register
|
||||
if (mod == 3)
|
||||
{
|
||||
// Get the r/m register name (8-bit)
|
||||
destOperand = ModRMDecoder.GetRegisterName(rm, 8);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Replace "dword ptr" with "byte ptr" to indicate 8-bit operation
|
||||
destOperand = destOperand.Replace("dword ptr", "byte ptr");
|
||||
}
|
||||
// Adjust the operand size to 8-bit
|
||||
destinationOperand.Size = 8;
|
||||
|
||||
// Read the immediate value
|
||||
if (!Decoder.CanReadByte())
|
||||
@ -76,11 +70,15 @@ public class XorImmWithRm8Handler : InstructionHandler
|
||||
// Read the immediate value
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Format the immediate value
|
||||
string immStr = $"0x{imm8:X2}";
|
||||
// Create the source immediate operand
|
||||
var sourceOperand = OperandFactory.CreateImmediateOperand(imm8, 8);
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"{destOperand}, {immStr}";
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
sourceOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
namespace X86Disassembler.X86.Handlers.Xor;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for XOR r/m32, r32 instruction (0x31)
|
||||
/// </summary>
|
||||
@ -8,11 +10,9 @@ public class XorMemRegHandler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the XorMemRegHandler 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 XorMemRegHandler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public XorMemRegHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -34,8 +34,8 @@ public class XorMemRegHandler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "xor";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Xor;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
@ -45,11 +45,15 @@ public class XorMemRegHandler : InstructionHandler
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Get the source register
|
||||
string srcReg = ModRMDecoder.GetRegisterName(reg, 32);
|
||||
// Create the source register operand
|
||||
var srcOperand = OperandFactory.CreateRegisterOperand(reg, 32);
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"{destOperand}, {srcReg}";
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destOperand,
|
||||
srcOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Xor;
|
||||
|
||||
/// <summary>
|
||||
@ -8,11 +10,9 @@ public class XorR16Rm16Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the XorR16Rm16Handler 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 XorR16Rm16Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public XorR16Rm16Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -35,8 +35,8 @@ public class XorR16Rm16Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "xor";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Xor;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
@ -44,33 +44,23 @@ public class XorR16Rm16Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, memOperand) = ModRMDecoder.ReadModRM();
|
||||
// For XOR r16, r/m16 (0x33 with 0x66 prefix):
|
||||
// - The reg field specifies the destination register
|
||||
// - The r/m field with mod specifies the source operand (register or memory)
|
||||
var (mod, reg, rm, sourceOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Get register name for the first operand (16-bit)
|
||||
string regName = ModRMDecoder.GetRegisterName(reg, 16);
|
||||
// Adjust the operand size to 16-bit
|
||||
sourceOperand.Size = 16;
|
||||
|
||||
// Create the destination register operand
|
||||
var destinationOperand = OperandFactory.CreateRegisterOperand(reg, 16);
|
||||
|
||||
// For the second operand, handle based on addressing mode
|
||||
string rmOperand;
|
||||
if (mod == 3) // Register addressing mode
|
||||
{
|
||||
// Get 16-bit register name for the second operand
|
||||
rmOperand = ModRMDecoder.GetRegisterName(rm, 16);
|
||||
}
|
||||
else // Memory addressing mode
|
||||
{
|
||||
// For memory operands, replace "dword ptr" with "word ptr"
|
||||
if (memOperand.StartsWith("dword ptr "))
|
||||
{
|
||||
rmOperand = memOperand.Replace("dword ptr", "word ptr");
|
||||
}
|
||||
else
|
||||
{
|
||||
rmOperand = memOperand;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"{regName}, {rmOperand}";
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
sourceOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Xor;
|
||||
|
||||
/// <summary>
|
||||
@ -8,11 +10,9 @@ public class XorR8Rm8Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the XorR8Rm8Handler 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 XorR8Rm8Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public XorR8Rm8Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -34,8 +34,8 @@ public class XorR8Rm8Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "xor";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Xor;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
@ -43,27 +43,23 @@ public class XorR8Rm8Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||
// For XOR r8, r/m8 (0x32):
|
||||
// - The reg field specifies the destination register
|
||||
// - The r/m field with mod specifies the source operand (register or memory)
|
||||
var (mod, reg, rm, sourceOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Get register name (8-bit)
|
||||
string regName = ModRMDecoder.GetRegisterName(reg, 8);
|
||||
// Adjust the operand size to 8-bit
|
||||
sourceOperand.Size = 8;
|
||||
|
||||
// If mod == 3, then the r/m field specifies a register
|
||||
if (mod == 3)
|
||||
{
|
||||
// Get the r/m register name (8-bit)
|
||||
string rmRegName = ModRMDecoder.GetRegisterName(rm, 8);
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"{regName}, {rmRegName}";
|
||||
return true;
|
||||
}
|
||||
// Create the destination register operand
|
||||
var destinationOperand = OperandFactory.CreateRegisterOperand(reg, 8);
|
||||
|
||||
// Replace "dword ptr" with "byte ptr" to indicate 8-bit operation
|
||||
string byteOperand = destOperand.Replace("dword ptr", "byte ptr");
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"{regName}, {byteOperand}";
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
sourceOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
namespace X86Disassembler.X86.Handlers.Xor;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for XOR r32, r/m32 instruction (0x33)
|
||||
/// </summary>
|
||||
@ -11,8 +13,8 @@ public class XorRegMemHandler : 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 XorRegMemHandler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public XorRegMemHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -34,8 +36,8 @@ public class XorRegMemHandler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "xor";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Xor;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
@ -45,11 +47,15 @@ public class XorRegMemHandler : InstructionHandler
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, srcOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Get the destination register
|
||||
string destReg = ModRMDecoder.GetRegisterName(reg, 32);
|
||||
// Create the destination register operand
|
||||
var destOperand = OperandFactory.CreateRegisterOperand(reg, 32);
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"{destReg}, {srcOperand}";
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destOperand,
|
||||
srcOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
namespace X86Disassembler.X86.Handlers.Xor;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for XOR r/m16, r16 instruction (0x31 with 0x66 prefix)
|
||||
/// </summary>
|
||||
@ -8,11 +10,9 @@ public class XorRm16R16Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the XorRm16R16Handler 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 XorRm16R16Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public XorRm16R16Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -35,8 +35,8 @@ public class XorRm16R16Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "xor";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Xor;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
@ -44,33 +44,24 @@ public class XorRm16R16Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, memOperand) = ModRMDecoder.ReadModRM();
|
||||
var (mod, reg, rm, destinationOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Get register name for the second operand (16-bit)
|
||||
string regName = ModRMDecoder.GetRegisterName(reg, 16);
|
||||
// Create the source register operand (16-bit)
|
||||
var sourceOperand = OperandFactory.CreateRegisterOperand(reg, 16);
|
||||
|
||||
// For the first operand, handle based on addressing mode
|
||||
string rmOperand;
|
||||
if (mod == 3) // Register addressing mode
|
||||
// For memory operands, we need to adjust the size to 16-bit
|
||||
if (mod != 3) // Memory addressing mode
|
||||
{
|
||||
// Get 16-bit register name for the first operand
|
||||
rmOperand = ModRMDecoder.GetRegisterName(rm, 16);
|
||||
// Adjust memory operand size to 16-bit
|
||||
destinationOperand.Size = 16;
|
||||
}
|
||||
else // Memory addressing mode
|
||||
{
|
||||
// For memory operands, replace "dword ptr" with "word ptr"
|
||||
if (memOperand.StartsWith("dword ptr "))
|
||||
{
|
||||
rmOperand = memOperand.Replace("dword ptr", "word ptr");
|
||||
}
|
||||
else
|
||||
{
|
||||
rmOperand = memOperand;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"{rmOperand}, {regName}";
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
sourceOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Xor;
|
||||
|
||||
/// <summary>
|
||||
@ -8,11 +10,9 @@ public class XorRm8R8Handler : InstructionHandler
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the XorRm8R8Handler 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 XorRm8R8Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
public XorRm8R8Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
@ -34,8 +34,8 @@ public class XorRm8R8Handler : InstructionHandler
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the mnemonic
|
||||
instruction.Mnemonic = "xor";
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Xor;
|
||||
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
@ -43,27 +43,23 @@ public class XorRm8R8Handler : InstructionHandler
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, destOperand) = ModRMDecoder.ReadModRM();
|
||||
// For XOR r/m8, r8 (0x30):
|
||||
// - The r/m field with mod specifies the destination operand (register or memory)
|
||||
// - The reg field specifies the source register
|
||||
var (mod, reg, rm, destinationOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Get register name (8-bit)
|
||||
string regName = ModRMDecoder.GetRegisterName(reg, 8);
|
||||
// Adjust the operand size to 8-bit
|
||||
destinationOperand.Size = 8;
|
||||
|
||||
// If mod == 3, then the r/m field specifies a register
|
||||
if (mod == 3)
|
||||
{
|
||||
// Get the r/m register name (8-bit)
|
||||
string rmRegName = ModRMDecoder.GetRegisterName(rm, 8);
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"{rmRegName}, {regName}";
|
||||
return true;
|
||||
}
|
||||
// Create the source register operand
|
||||
var sourceOperand = OperandFactory.CreateRegisterOperand(reg, 8);
|
||||
|
||||
// Replace "dword ptr" with "byte ptr" to indicate 8-bit operation
|
||||
string byteOperand = destOperand.Replace("dword ptr", "byte ptr");
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"{byteOperand}, {regName}";
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
sourceOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user