mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-20 08:18:36 +03:00
implement shift and rotate handlers. Fix tests
This commit is contained in:
65
X86Disassembler/X86/Handlers/Shift/RclRm32By1Handler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/RclRm32By1Handler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for RCL r/m32, 1 instruction (0xD1 /2)
|
||||
/// </summary>
|
||||
public class RclRm32By1Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RclRm32By1Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RclRm32By1Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// RCL r/m32, 1 is encoded as 0xD1 /2
|
||||
if (opcode != 0xD1)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 2 (RCL)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 2; // 2 = RCL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a RCL r/m32, 1 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Rcl;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create an immediate operand for the constant 1
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(1);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/RclRm32ByClHandler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/RclRm32ByClHandler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for RCL r/m32, CL instruction (0xD3 /2)
|
||||
/// </summary>
|
||||
public class RclRm32ByClHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RclRm32ByClHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RclRm32ByClHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// RCL r/m32, CL is encoded as 0xD3 /2
|
||||
if (opcode != 0xD3)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 2 (RCL)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 2; // 2 = RCL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a RCL r/m32, CL instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Rcl;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create a register operand for CL
|
||||
var clOperand = OperandFactory.CreateRegisterOperand8(RegisterIndex8.CL);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
clOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
72
X86Disassembler/X86/Handlers/Shift/RclRm32ByImmHandler.cs
Normal file
72
X86Disassembler/X86/Handlers/Shift/RclRm32ByImmHandler.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for RCL r/m32, imm8 instruction (0xC1 /2)
|
||||
/// </summary>
|
||||
public class RclRm32ByImmHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RclRm32ByImmHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RclRm32ByImmHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// RCL r/m32, imm8 is encoded as 0xC1 /2
|
||||
if (opcode != 0xC1)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 2 (RCL)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 2; // 2 = RCL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a RCL r/m32, imm8 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Rcl;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Check if we can read the immediate byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Read the immediate byte (rotate count)
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Create an immediate operand for the rotate count
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/RclRm8By1Handler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/RclRm8By1Handler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for RCL r/m8, 1 instruction (0xD0 /2)
|
||||
/// </summary>
|
||||
public class RclRm8By1Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RclRm8By1Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RclRm8By1Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// RCL r/m8, 1 is encoded as 0xD0 /2
|
||||
if (opcode != 0xD0)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 2 (RCL)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 2; // 2 = RCL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a RCL r/m8, 1 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Rcl;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Create an immediate operand for the constant 1
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(1);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/RclRm8ByClHandler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/RclRm8ByClHandler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for RCL r/m8, CL instruction (0xD2 /2)
|
||||
/// </summary>
|
||||
public class RclRm8ByClHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RclRm8ByClHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RclRm8ByClHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// RCL r/m8, CL is encoded as 0xD2 /2
|
||||
if (opcode != 0xD2)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 2 (RCL)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 2; // 2 = RCL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a RCL r/m8, CL instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Rcl;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Create a register operand for CL
|
||||
var clOperand = OperandFactory.CreateRegisterOperand8(RegisterIndex8.CL);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
clOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
72
X86Disassembler/X86/Handlers/Shift/RclRm8ByImmHandler.cs
Normal file
72
X86Disassembler/X86/Handlers/Shift/RclRm8ByImmHandler.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for RCL r/m8, imm8 instruction (0xC0 /2)
|
||||
/// </summary>
|
||||
public class RclRm8ByImmHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RclRm8ByImmHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RclRm8ByImmHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// RCL r/m8, imm8 is encoded as 0xC0 /2
|
||||
if (opcode != 0xC0)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 2 (RCL)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 2; // 2 = RCL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a RCL r/m8, imm8 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Rcl;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Check if we can read the immediate byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Read the immediate byte (rotate count)
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Create an immediate operand for the rotate count
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/RcrRm32By1Handler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/RcrRm32By1Handler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for RCR r/m32, 1 instruction (0xD1 /3)
|
||||
/// </summary>
|
||||
public class RcrRm32By1Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RcrRm32By1Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RcrRm32By1Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// RCR r/m32, 1 is encoded as 0xD1 /3
|
||||
if (opcode != 0xD1)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 3 (RCR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 3; // 3 = RCR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a RCR r/m32, 1 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Rcr;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create an immediate operand for the constant 1
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(1);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/RcrRm32ByClHandler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/RcrRm32ByClHandler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for RCR r/m32, CL instruction (0xD3 /3)
|
||||
/// </summary>
|
||||
public class RcrRm32ByClHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RcrRm32ByClHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RcrRm32ByClHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// RCR r/m32, CL is encoded as 0xD3 /3
|
||||
if (opcode != 0xD3)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 3 (RCR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 3; // 3 = RCR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a RCR r/m32, CL instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Rcr;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create a register operand for CL
|
||||
var clOperand = OperandFactory.CreateRegisterOperand8(RegisterIndex8.CL);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
clOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
72
X86Disassembler/X86/Handlers/Shift/RcrRm32ByImmHandler.cs
Normal file
72
X86Disassembler/X86/Handlers/Shift/RcrRm32ByImmHandler.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for RCR r/m32, imm8 instruction (0xC1 /3)
|
||||
/// </summary>
|
||||
public class RcrRm32ByImmHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RcrRm32ByImmHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RcrRm32ByImmHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// RCR r/m32, imm8 is encoded as 0xC1 /3
|
||||
if (opcode != 0xC1)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 3 (RCR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 3; // 3 = RCR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a RCR r/m32, imm8 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Rcr;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Check if we can read the immediate byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Read the immediate byte (rotate count)
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Create an immediate operand for the rotate count
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/RcrRm8By1Handler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/RcrRm8By1Handler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for RCR r/m8, 1 instruction (0xD0 /3)
|
||||
/// </summary>
|
||||
public class RcrRm8By1Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RcrRm8By1Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RcrRm8By1Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// RCR r/m8, 1 is encoded as 0xD0 /3
|
||||
if (opcode != 0xD0)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 3 (RCR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 3; // 3 = RCR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a RCR r/m8, 1 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Rcr;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Create an immediate operand for the constant 1
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(1);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/RcrRm8ByClHandler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/RcrRm8ByClHandler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for RCR r/m8, CL instruction (0xD2 /3)
|
||||
/// </summary>
|
||||
public class RcrRm8ByClHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RcrRm8ByClHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RcrRm8ByClHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// RCR r/m8, CL is encoded as 0xD2 /3
|
||||
if (opcode != 0xD2)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 3 (RCR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 3; // 3 = RCR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a RCR r/m8, CL instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Rcr;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Create a register operand for CL
|
||||
var clOperand = OperandFactory.CreateRegisterOperand8(RegisterIndex8.CL);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
clOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
72
X86Disassembler/X86/Handlers/Shift/RcrRm8ByImmHandler.cs
Normal file
72
X86Disassembler/X86/Handlers/Shift/RcrRm8ByImmHandler.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for RCR r/m8, imm8 instruction (0xC0 /3)
|
||||
/// </summary>
|
||||
public class RcrRm8ByImmHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RcrRm8ByImmHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RcrRm8ByImmHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// RCR r/m8, imm8 is encoded as 0xC0 /3
|
||||
if (opcode != 0xC0)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 3 (RCR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 3; // 3 = RCR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a RCR r/m8, imm8 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Rcr;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Check if we can read the immediate byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Read the immediate byte (rotate count)
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Create an immediate operand for the rotate count
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/RolRm32By1Handler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/RolRm32By1Handler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for ROL r/m32, 1 instruction (0xD1 /0)
|
||||
/// </summary>
|
||||
public class RolRm32By1Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RolRm32By1Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RolRm32By1Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// ROL r/m32, 1 is encoded as 0xD1 /0
|
||||
if (opcode != 0xD1)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 0 (ROL)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 0; // 0 = ROL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a ROL r/m32, 1 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Rol;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create an immediate operand for the constant 1
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(1);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/RolRm32ByClHandler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/RolRm32ByClHandler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for ROL r/m32, CL instruction (0xD3 /0)
|
||||
/// </summary>
|
||||
public class RolRm32ByClHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RolRm32ByClHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RolRm32ByClHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// ROL r/m32, CL is encoded as 0xD3 /0
|
||||
if (opcode != 0xD3)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 0 (ROL)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 0; // 0 = ROL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a ROL r/m32, CL instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Rol;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create a register operand for CL
|
||||
var clOperand = OperandFactory.CreateRegisterOperand8(RegisterIndex8.CL);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
clOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
72
X86Disassembler/X86/Handlers/Shift/RolRm32ByImmHandler.cs
Normal file
72
X86Disassembler/X86/Handlers/Shift/RolRm32ByImmHandler.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for ROL r/m32, imm8 instruction (0xC1 /0)
|
||||
/// </summary>
|
||||
public class RolRm32ByImmHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RolRm32ByImmHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RolRm32ByImmHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// ROL r/m32, imm8 is encoded as 0xC1 /0
|
||||
if (opcode != 0xC1)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 0 (ROL)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 0; // 0 = ROL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a ROL r/m32, imm8 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Rol;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Check if we can read the immediate byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Read the immediate byte (rotate count)
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Create an immediate operand for the rotate count
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/RolRm8By1Handler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/RolRm8By1Handler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for ROL r/m8, 1 instruction (0xD0 /0)
|
||||
/// </summary>
|
||||
public class RolRm8By1Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RolRm8By1Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RolRm8By1Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// ROL r/m8, 1 is encoded as 0xD0 /0
|
||||
if (opcode != 0xD0)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 0 (ROL)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 0; // 0 = ROL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a ROL r/m8, 1 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Rol;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Create an immediate operand for the constant 1
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(1);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/RolRm8ByClHandler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/RolRm8ByClHandler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for ROL r/m8, CL instruction (0xD2 /0)
|
||||
/// </summary>
|
||||
public class RolRm8ByClHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RolRm8ByClHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RolRm8ByClHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// ROL r/m8, CL is encoded as 0xD2 /0
|
||||
if (opcode != 0xD2)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 0 (ROL)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 0; // 0 = ROL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a ROL r/m8, CL instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Rol;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Create a register operand for CL
|
||||
var clOperand = OperandFactory.CreateRegisterOperand8(RegisterIndex8.CL);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
clOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
72
X86Disassembler/X86/Handlers/Shift/RolRm8ByImmHandler.cs
Normal file
72
X86Disassembler/X86/Handlers/Shift/RolRm8ByImmHandler.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for ROL r/m8, imm8 instruction (0xC0 /0)
|
||||
/// </summary>
|
||||
public class RolRm8ByImmHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RolRm8ByImmHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RolRm8ByImmHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// ROL r/m8, imm8 is encoded as 0xC0 /0
|
||||
if (opcode != 0xC0)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 0 (ROL)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 0; // 0 = ROL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a ROL r/m8, imm8 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Rol;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Check if we can read the immediate byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Read the immediate byte (rotate count)
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Create an immediate operand for the rotate count
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/RorRm32By1Handler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/RorRm32By1Handler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for ROR r/m32, 1 instruction (0xD1 /1)
|
||||
/// </summary>
|
||||
public class RorRm32By1Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RorRm32By1Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RorRm32By1Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// ROR r/m32, 1 is encoded as 0xD1 /1
|
||||
if (opcode != 0xD1)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 1 (ROR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 1; // 1 = ROR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a ROR r/m32, 1 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Ror;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create an immediate operand for the constant 1
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(1);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/RorRm32ByClHandler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/RorRm32ByClHandler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for ROR r/m32, CL instruction (0xD3 /1)
|
||||
/// </summary>
|
||||
public class RorRm32ByClHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RorRm32ByClHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RorRm32ByClHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// ROR r/m32, CL is encoded as 0xD3 /1
|
||||
if (opcode != 0xD3)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 1 (ROR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 1; // 1 = ROR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a ROR r/m32, CL instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Ror;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create a register operand for CL
|
||||
var clOperand = OperandFactory.CreateRegisterOperand8(RegisterIndex8.CL);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
clOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
72
X86Disassembler/X86/Handlers/Shift/RorRm32ByImmHandler.cs
Normal file
72
X86Disassembler/X86/Handlers/Shift/RorRm32ByImmHandler.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for ROR r/m32, imm8 instruction (0xC1 /1)
|
||||
/// </summary>
|
||||
public class RorRm32ByImmHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RorRm32ByImmHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RorRm32ByImmHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// ROR r/m32, imm8 is encoded as 0xC1 /1
|
||||
if (opcode != 0xC1)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 1 (ROR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 1; // 1 = ROR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a ROR r/m32, imm8 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Ror;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Check if we can read the immediate byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Read the immediate byte (rotate count)
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Create an immediate operand for the rotate count
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/RorRm8By1Handler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/RorRm8By1Handler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for ROR r/m8, 1 instruction (0xD0 /1)
|
||||
/// </summary>
|
||||
public class RorRm8By1Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RorRm8By1Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RorRm8By1Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// ROR r/m8, 1 is encoded as 0xD0 /1
|
||||
if (opcode != 0xD0)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 1 (ROR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 1; // 1 = ROR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a ROR r/m8, 1 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Ror;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Create an immediate operand for the constant 1
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(1);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/RorRm8ByClHandler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/RorRm8ByClHandler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for ROR r/m8, CL instruction (0xD2 /1)
|
||||
/// </summary>
|
||||
public class RorRm8ByClHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RorRm8ByClHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RorRm8ByClHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// ROR r/m8, CL is encoded as 0xD2 /1
|
||||
if (opcode != 0xD2)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 1 (ROR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 1; // 1 = ROR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a ROR r/m8, CL instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Ror;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Create a register operand for CL
|
||||
var clOperand = OperandFactory.CreateRegisterOperand8(RegisterIndex8.CL);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
clOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
72
X86Disassembler/X86/Handlers/Shift/RorRm8ByImmHandler.cs
Normal file
72
X86Disassembler/X86/Handlers/Shift/RorRm8ByImmHandler.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for ROR r/m8, imm8 instruction (0xC0 /1)
|
||||
/// </summary>
|
||||
public class RorRm8ByImmHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the RorRm8ByImmHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public RorRm8ByImmHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// ROR r/m8, imm8 is encoded as 0xC0 /1
|
||||
if (opcode != 0xC0)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 1 (ROR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 1; // 1 = ROR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a ROR r/m8, imm8 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Ror;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Check if we can read the immediate byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Read the immediate byte (rotate count)
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Create an immediate operand for the rotate count
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/SarRm32By1Handler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/SarRm32By1Handler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SAR r/m32, 1 instruction (0xD1 /7)
|
||||
/// </summary>
|
||||
public class SarRm32By1Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the SarRm32By1Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public SarRm32By1Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// SAR r/m32, 1 is encoded as 0xD1 /7
|
||||
if (opcode != 0xD1)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 7 (SAR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 7; // 7 = SAR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SAR r/m32, 1 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Sar;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create an immediate operand for the constant 1
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(1);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/SarRm32ByClHandler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/SarRm32ByClHandler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SAR r/m32, CL instruction (0xD3 /7)
|
||||
/// </summary>
|
||||
public class SarRm32ByClHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the SarRm32ByClHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public SarRm32ByClHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// SAR r/m32, CL is encoded as 0xD3 /7
|
||||
if (opcode != 0xD3)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 7 (SAR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 7; // 7 = SAR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SAR r/m32, CL instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Sar;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create a register operand for CL
|
||||
var clOperand = OperandFactory.CreateRegisterOperand8(RegisterIndex8.CL);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
clOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
72
X86Disassembler/X86/Handlers/Shift/SarRm32ByImmHandler.cs
Normal file
72
X86Disassembler/X86/Handlers/Shift/SarRm32ByImmHandler.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SAR r/m32, imm8 instruction (0xC1 /7)
|
||||
/// </summary>
|
||||
public class SarRm32ByImmHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the SarRm32ByImmHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public SarRm32ByImmHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// SAR r/m32, imm8 is encoded as 0xC1 /7
|
||||
if (opcode != 0xC1)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 7 (SAR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 7; // 7 = SAR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SAR r/m32, imm8 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Sar;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Check if we can read the immediate byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Read the immediate byte (shift count)
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Create an immediate operand for the shift count
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/SarRm8By1Handler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/SarRm8By1Handler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SAR r/m8, 1 instruction (0xD0 /7)
|
||||
/// </summary>
|
||||
public class SarRm8By1Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the SarRm8By1Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public SarRm8By1Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// SAR r/m8, 1 is encoded as 0xD0 /7
|
||||
if (opcode != 0xD0)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 7 (SAR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 7; // 7 = SAR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SAR r/m8, 1 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Sar;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Create an immediate operand for the constant 1
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(1);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/SarRm8ByClHandler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/SarRm8ByClHandler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SAR r/m8, CL instruction (0xD2 /7)
|
||||
/// </summary>
|
||||
public class SarRm8ByClHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the SarRm8ByClHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public SarRm8ByClHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// SAR r/m8, CL is encoded as 0xD2 /7
|
||||
if (opcode != 0xD2)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 7 (SAR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 7; // 7 = SAR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SAR r/m8, CL instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Sar;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Create a register operand for CL
|
||||
var clOperand = OperandFactory.CreateRegisterOperand8(RegisterIndex8.CL);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
clOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
72
X86Disassembler/X86/Handlers/Shift/SarRm8ByImmHandler.cs
Normal file
72
X86Disassembler/X86/Handlers/Shift/SarRm8ByImmHandler.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SAR r/m8, imm8 instruction (0xC0 /7)
|
||||
/// </summary>
|
||||
public class SarRm8ByImmHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the SarRm8ByImmHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public SarRm8ByImmHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// SAR r/m8, imm8 is encoded as 0xC0 /7
|
||||
if (opcode != 0xC0)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 7 (SAR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 7; // 7 = SAR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SAR r/m8, imm8 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Sar;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Check if we can read the immediate byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Read the immediate byte (shift count)
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Create an immediate operand for the shift count
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/ShlRm32By1Handler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/ShlRm32By1Handler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SHL r/m32, 1 instruction (0xD1 /4)
|
||||
/// </summary>
|
||||
public class ShlRm32By1Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the ShlRm32By1Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public ShlRm32By1Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// SHL r/m32, 1 is encoded as 0xD1 /4
|
||||
if (opcode != 0xD1)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 4 (SHL)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 4; // 4 = SHL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SHL r/m32, 1 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Shl;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create an immediate operand for the constant 1
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(1);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/ShlRm32ByClHandler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/ShlRm32ByClHandler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SHL r/m32, CL instruction (0xD3 /4)
|
||||
/// </summary>
|
||||
public class ShlRm32ByClHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the ShlRm32ByClHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public ShlRm32ByClHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// SHL r/m32, CL is encoded as 0xD3 /4
|
||||
if (opcode != 0xD3)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 4 (SHL)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 4; // 4 = SHL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SHL r/m32, CL instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Shl;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create a register operand for CL
|
||||
var clOperand = OperandFactory.CreateRegisterOperand8(RegisterIndex8.CL);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
clOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
72
X86Disassembler/X86/Handlers/Shift/ShlRm32ByImmHandler.cs
Normal file
72
X86Disassembler/X86/Handlers/Shift/ShlRm32ByImmHandler.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SHL r/m32, imm8 instruction (0xC1 /4)
|
||||
/// </summary>
|
||||
public class ShlRm32ByImmHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the ShlRm32ByImmHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public ShlRm32ByImmHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// SHL r/m32, imm8 is encoded as 0xC1 /4
|
||||
if (opcode != 0xC1)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 4 (SHL)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 4; // 4 = SHL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SHL r/m32, imm8 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Shl;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Check if we can read the immediate byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Read the immediate byte (shift count)
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Create an immediate operand for the shift count
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/ShlRm8By1Handler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/ShlRm8By1Handler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SHL r/m8, 1 instruction (0xD0 /4)
|
||||
/// </summary>
|
||||
public class ShlRm8By1Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the ShlRm8By1Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public ShlRm8By1Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// SHL r/m8, 1 is encoded as 0xD0 /4
|
||||
if (opcode != 0xD0)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 4 (SHL)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 4; // 4 = SHL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SHL r/m8, 1 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Shl;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Create an immediate operand for the constant 1
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(1);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/ShlRm8ByClHandler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/ShlRm8ByClHandler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SHL r/m8, CL instruction (0xD2 /4)
|
||||
/// </summary>
|
||||
public class ShlRm8ByClHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the ShlRm8ByClHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public ShlRm8ByClHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// SHL r/m8, CL is encoded as 0xD2 /4
|
||||
if (opcode != 0xD2)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 4 (SHL)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 4; // 4 = SHL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SHL r/m8, CL instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Shl;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Create a register operand for CL
|
||||
var clOperand = OperandFactory.CreateRegisterOperand8(RegisterIndex8.CL);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
clOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
72
X86Disassembler/X86/Handlers/Shift/ShlRm8ByImmHandler.cs
Normal file
72
X86Disassembler/X86/Handlers/Shift/ShlRm8ByImmHandler.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SHL r/m8, imm8 instruction (0xC0 /4)
|
||||
/// </summary>
|
||||
public class ShlRm8ByImmHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the ShlRm8ByImmHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public ShlRm8ByImmHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// SHL r/m8, imm8 is encoded as 0xC0 /4
|
||||
if (opcode != 0xC0)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 4 (SHL)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 4; // 4 = SHL
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SHL r/m8, imm8 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Shl;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Check if we can read the immediate byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Read the immediate byte (shift count)
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Create an immediate operand for the shift count
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/ShrRm32By1Handler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/ShrRm32By1Handler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SHR r/m32, 1 instruction (0xD1 /5)
|
||||
/// </summary>
|
||||
public class ShrRm32By1Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the ShrRm32By1Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public ShrRm32By1Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// SHR r/m32, 1 is encoded as 0xD1 /5
|
||||
if (opcode != 0xD1)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 5 (SHR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 5; // 5 = SHR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SHR r/m32, 1 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Shr;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create an immediate operand for the constant 1
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(1);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/ShrRm32ByClHandler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/ShrRm32ByClHandler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SHR r/m32, CL instruction (0xD3 /5)
|
||||
/// </summary>
|
||||
public class ShrRm32ByClHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the ShrRm32ByClHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public ShrRm32ByClHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// SHR r/m32, CL is encoded as 0xD3 /5
|
||||
if (opcode != 0xD3)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 5 (SHR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 5; // 5 = SHR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SHR r/m32, CL instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Shr;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create a register operand for CL
|
||||
var clOperand = OperandFactory.CreateRegisterOperand8(RegisterIndex8.CL);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
clOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
72
X86Disassembler/X86/Handlers/Shift/ShrRm32ByImmHandler.cs
Normal file
72
X86Disassembler/X86/Handlers/Shift/ShrRm32ByImmHandler.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SHR r/m32, imm8 instruction (0xC1 /5)
|
||||
/// </summary>
|
||||
public class ShrRm32ByImmHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the ShrRm32ByImmHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public ShrRm32ByImmHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// SHR r/m32, imm8 is encoded as 0xC1 /5
|
||||
if (opcode != 0xC1)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 5 (SHR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 5; // 5 = SHR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SHR r/m32, imm8 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Shr;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Check if we can read the immediate byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Read the immediate byte (shift count)
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Create an immediate operand for the shift count
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/ShrRm8By1Handler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/ShrRm8By1Handler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SHR r/m8, 1 instruction (0xD0 /5)
|
||||
/// </summary>
|
||||
public class ShrRm8By1Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the ShrRm8By1Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public ShrRm8By1Handler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// SHR r/m8, 1 is encoded as 0xD0 /5
|
||||
if (opcode != 0xD0)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 5 (SHR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 5; // 5 = SHR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SHR r/m8, 1 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Shr;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Create an immediate operand for the constant 1
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(1);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Shift/ShrRm8ByClHandler.cs
Normal file
65
X86Disassembler/X86/Handlers/Shift/ShrRm8ByClHandler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SHR r/m8, CL instruction (0xD2 /5)
|
||||
/// </summary>
|
||||
public class ShrRm8ByClHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the ShrRm8ByClHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public ShrRm8ByClHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// SHR r/m8, CL is encoded as 0xD2 /5
|
||||
if (opcode != 0xD2)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 5 (SHR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 5; // 5 = SHR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SHR r/m8, CL instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Shr;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Create a register operand for CL
|
||||
var clOperand = OperandFactory.CreateRegisterOperand8(RegisterIndex8.CL);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
clOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
72
X86Disassembler/X86/Handlers/Shift/ShrRm8ByImmHandler.cs
Normal file
72
X86Disassembler/X86/Handlers/Shift/ShrRm8ByImmHandler.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Shift;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SHR r/m8, imm8 instruction (0xC0 /5)
|
||||
/// </summary>
|
||||
public class ShrRm8ByImmHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the ShrRm8ByImmHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public ShrRm8ByImmHandler(InstructionDecoder decoder)
|
||||
: base(decoder)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if this handler can decode the given opcode
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode to check</param>
|
||||
/// <returns>True if this handler can decode the opcode</returns>
|
||||
public override bool CanHandle(byte opcode)
|
||||
{
|
||||
// SHR r/m8, imm8 is encoded as 0xC0 /5
|
||||
if (opcode != 0xC0)
|
||||
return false;
|
||||
|
||||
// Check if we can read the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 5 (SHR)
|
||||
var reg = ModRMDecoder.PeakModRMReg();
|
||||
return reg == 5; // 5 = SHR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SHR r/m8, imm8 instruction
|
||||
/// </summary>
|
||||
/// <param name="opcode">The opcode of the instruction</param>
|
||||
/// <param name="instruction">The instruction object to populate</param>
|
||||
/// <returns>True if the instruction was successfully decoded</returns>
|
||||
public override bool Decode(byte opcode, Instruction instruction)
|
||||
{
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Shr;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (_, _, _, operand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Check if we can read the immediate byte
|
||||
if (!Decoder.CanReadByte())
|
||||
return false;
|
||||
|
||||
// Read the immediate byte (shift count)
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Create an immediate operand for the shift count
|
||||
var immOperand = OperandFactory.CreateImmediateOperand(imm8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
operand,
|
||||
immOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user