mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-05-19 03:41:18 +03:00
implement shift and rotate handlers. Fix tests
This commit is contained in:
parent
a9d4c39717
commit
a62812f71c
@ -57,13 +57,7 @@ public class IdivRm32Handler : InstructionHandler
|
|||||||
// Read the ModR/M byte
|
// Read the ModR/M byte
|
||||||
// For IDIV r/m32 (0xF7 /7):
|
// For IDIV r/m32 (0xF7 /7):
|
||||||
// - The r/m field with mod specifies the operand (register or memory)
|
// - The r/m field with mod specifies the operand (register or memory)
|
||||||
var (mod, reg, rm, operand) = ModRMDecoder.ReadModRM();
|
var (_, _, _, operand) = ModRMDecoder.ReadModRM();
|
||||||
|
|
||||||
// Verify that the reg field is 7 (IDIV)
|
|
||||||
if (reg != RegisterIndex.Di)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the structured operands
|
// Set the structured operands
|
||||||
// IDIV has only one operand
|
// IDIV has only one operand
|
||||||
|
@ -23,6 +23,7 @@ using X86Disassembler.X86.Handlers.Pop;
|
|||||||
using X86Disassembler.X86.Handlers.Push;
|
using X86Disassembler.X86.Handlers.Push;
|
||||||
using X86Disassembler.X86.Handlers.Ret;
|
using X86Disassembler.X86.Handlers.Ret;
|
||||||
using X86Disassembler.X86.Handlers.Sbb;
|
using X86Disassembler.X86.Handlers.Sbb;
|
||||||
|
using X86Disassembler.X86.Handlers.Shift;
|
||||||
using X86Disassembler.X86.Handlers.String;
|
using X86Disassembler.X86.Handlers.String;
|
||||||
using X86Disassembler.X86.Handlers.Sub;
|
using X86Disassembler.X86.Handlers.Sub;
|
||||||
using X86Disassembler.X86.Handlers.Test;
|
using X86Disassembler.X86.Handlers.Test;
|
||||||
@ -56,7 +57,7 @@ public class InstructionHandlerFactory
|
|||||||
private void RegisterAllHandlers()
|
private void RegisterAllHandlers()
|
||||||
{
|
{
|
||||||
// Register specific instruction handlers
|
// Register specific instruction handlers
|
||||||
_handlers.Add(new Nop.Int3Handler(_decoder));
|
_handlers.Add(new Int3Handler(_decoder));
|
||||||
|
|
||||||
// Register handlers in order of priority (most specific first)
|
// Register handlers in order of priority (most specific first)
|
||||||
RegisterSbbHandlers(); // SBB instructions
|
RegisterSbbHandlers(); // SBB instructions
|
||||||
@ -91,6 +92,7 @@ public class InstructionHandlerFactory
|
|||||||
RegisterNopHandlers(); // Register NOP handlers
|
RegisterNopHandlers(); // Register NOP handlers
|
||||||
RegisterBitHandlers(); // Register bit manipulation handlers
|
RegisterBitHandlers(); // Register bit manipulation handlers
|
||||||
RegisterMiscHandlers(); // Register miscellaneous instructions
|
RegisterMiscHandlers(); // Register miscellaneous instructions
|
||||||
|
RegisterShiftHandlers(); // Register shift and rotate instructions
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -477,7 +479,7 @@ public class InstructionHandlerFactory
|
|||||||
private void RegisterMiscHandlers()
|
private void RegisterMiscHandlers()
|
||||||
{
|
{
|
||||||
// Register miscellaneous instruction handlers
|
// Register miscellaneous instruction handlers
|
||||||
_handlers.Add(new IntHandler(_decoder)); // INT (opcode 0xCD)
|
_handlers.Add(new IntImm8Handler(_decoder)); // INT (opcode 0xCD)
|
||||||
_handlers.Add(new IntoHandler(_decoder)); // INTO (opcode 0xCE)
|
_handlers.Add(new IntoHandler(_decoder)); // INTO (opcode 0xCE)
|
||||||
_handlers.Add(new IretHandler(_decoder)); // IRET (opcode 0xCF)
|
_handlers.Add(new IretHandler(_decoder)); // IRET (opcode 0xCF)
|
||||||
_handlers.Add(new CpuidHandler(_decoder)); // CPUID (opcode 0x0F 0xA2)
|
_handlers.Add(new CpuidHandler(_decoder)); // CPUID (opcode 0x0F 0xA2)
|
||||||
@ -489,6 +491,68 @@ public class InstructionHandlerFactory
|
|||||||
_handlers.Add(new OutHandler(_decoder)); // OUT (opcodes 0xE6, 0xE7, 0xEE, 0xEF)
|
_handlers.Add(new OutHandler(_decoder)); // OUT (opcodes 0xE6, 0xE7, 0xEE, 0xEF)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Registers all shift and rotate instruction handlers
|
||||||
|
/// </summary>
|
||||||
|
private void RegisterShiftHandlers()
|
||||||
|
{
|
||||||
|
// SHL (Shift Left) handlers
|
||||||
|
_handlers.Add(new ShlRm8By1Handler(_decoder)); // SHL r/m8, 1 (0xD0 /4)
|
||||||
|
_handlers.Add(new ShlRm8ByClHandler(_decoder)); // SHL r/m8, CL (0xD2 /4)
|
||||||
|
_handlers.Add(new ShlRm8ByImmHandler(_decoder)); // SHL r/m8, imm8 (0xC0 /4)
|
||||||
|
_handlers.Add(new ShlRm32By1Handler(_decoder)); // SHL r/m32, 1 (0xD1 /4)
|
||||||
|
_handlers.Add(new ShlRm32ByClHandler(_decoder)); // SHL r/m32, CL (0xD3 /4)
|
||||||
|
_handlers.Add(new ShlRm32ByImmHandler(_decoder)); // SHL r/m32, imm8 (0xC1 /4)
|
||||||
|
|
||||||
|
// SHR (Shift Right) handlers
|
||||||
|
_handlers.Add(new ShrRm8By1Handler(_decoder)); // SHR r/m8, 1 (0xD0 /5)
|
||||||
|
_handlers.Add(new ShrRm8ByClHandler(_decoder)); // SHR r/m8, CL (0xD2 /5)
|
||||||
|
_handlers.Add(new ShrRm8ByImmHandler(_decoder)); // SHR r/m8, imm8 (0xC0 /5)
|
||||||
|
_handlers.Add(new ShrRm32By1Handler(_decoder)); // SHR r/m32, 1 (0xD1 /5)
|
||||||
|
_handlers.Add(new ShrRm32ByClHandler(_decoder)); // SHR r/m32, CL (0xD3 /5)
|
||||||
|
_handlers.Add(new ShrRm32ByImmHandler(_decoder)); // SHR r/m32, imm8 (0xC1 /5)
|
||||||
|
|
||||||
|
// SAR (Shift Arithmetic Right) handlers
|
||||||
|
_handlers.Add(new SarRm8By1Handler(_decoder)); // SAR r/m8, 1 (0xD0 /7)
|
||||||
|
_handlers.Add(new SarRm8ByClHandler(_decoder)); // SAR r/m8, CL (0xD2 /7)
|
||||||
|
_handlers.Add(new SarRm8ByImmHandler(_decoder)); // SAR r/m8, imm8 (0xC0 /7)
|
||||||
|
_handlers.Add(new SarRm32By1Handler(_decoder)); // SAR r/m32, 1 (0xD1 /7)
|
||||||
|
_handlers.Add(new SarRm32ByClHandler(_decoder)); // SAR r/m32, CL (0xD3 /7)
|
||||||
|
_handlers.Add(new SarRm32ByImmHandler(_decoder)); // SAR r/m32, imm8 (0xC1 /7)
|
||||||
|
|
||||||
|
// ROL (Rotate Left) handlers
|
||||||
|
_handlers.Add(new RolRm8By1Handler(_decoder)); // ROL r/m8, 1 (0xD0 /0)
|
||||||
|
_handlers.Add(new RolRm8ByClHandler(_decoder)); // ROL r/m8, CL (0xD2 /0)
|
||||||
|
_handlers.Add(new RolRm8ByImmHandler(_decoder)); // ROL r/m8, imm8 (0xC0 /0)
|
||||||
|
_handlers.Add(new RolRm32By1Handler(_decoder)); // ROL r/m32, 1 (0xD1 /0)
|
||||||
|
_handlers.Add(new RolRm32ByClHandler(_decoder)); // ROL r/m32, CL (0xD3 /0)
|
||||||
|
_handlers.Add(new RolRm32ByImmHandler(_decoder)); // ROL r/m32, imm8 (0xC1 /0)
|
||||||
|
|
||||||
|
// ROR (Rotate Right) handlers
|
||||||
|
_handlers.Add(new RorRm8By1Handler(_decoder)); // ROR r/m8, 1 (0xD0 /1)
|
||||||
|
_handlers.Add(new RorRm8ByClHandler(_decoder)); // ROR r/m8, CL (0xD2 /1)
|
||||||
|
_handlers.Add(new RorRm8ByImmHandler(_decoder)); // ROR r/m8, imm8 (0xC0 /1)
|
||||||
|
_handlers.Add(new RorRm32By1Handler(_decoder)); // ROR r/m32, 1 (0xD1 /1)
|
||||||
|
_handlers.Add(new RorRm32ByClHandler(_decoder)); // ROR r/m32, CL (0xD3 /1)
|
||||||
|
_handlers.Add(new RorRm32ByImmHandler(_decoder)); // ROR r/m32, imm8 (0xC1 /1)
|
||||||
|
|
||||||
|
// RCL (Rotate Carry Left) handlers
|
||||||
|
_handlers.Add(new RclRm8By1Handler(_decoder)); // RCL r/m8, 1 (0xD0 /2)
|
||||||
|
_handlers.Add(new RclRm8ByClHandler(_decoder)); // RCL r/m8, CL (0xD2 /2)
|
||||||
|
_handlers.Add(new RclRm8ByImmHandler(_decoder)); // RCL r/m8, imm8 (0xC0 /2)
|
||||||
|
_handlers.Add(new RclRm32By1Handler(_decoder)); // RCL r/m32, 1 (0xD1 /2)
|
||||||
|
_handlers.Add(new RclRm32ByClHandler(_decoder)); // RCL r/m32, CL (0xD3 /2)
|
||||||
|
_handlers.Add(new RclRm32ByImmHandler(_decoder)); // RCL r/m32, imm8 (0xC1 /2)
|
||||||
|
|
||||||
|
// RCR (Rotate Carry Right) handlers
|
||||||
|
_handlers.Add(new RcrRm8By1Handler(_decoder)); // RCR r/m8, 1 (0xD0 /3)
|
||||||
|
_handlers.Add(new RcrRm8ByClHandler(_decoder)); // RCR r/m8, CL (0xD2 /3)
|
||||||
|
_handlers.Add(new RcrRm8ByImmHandler(_decoder)); // RCR r/m8, imm8 (0xC0 /3)
|
||||||
|
_handlers.Add(new RcrRm32By1Handler(_decoder)); // RCR r/m32, 1 (0xD1 /3)
|
||||||
|
_handlers.Add(new RcrRm32ByClHandler(_decoder)); // RCR r/m32, CL (0xD3 /3)
|
||||||
|
_handlers.Add(new RcrRm32ByImmHandler(_decoder)); // RCR r/m32, imm8 (0xC1 /3)
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Registers all bit manipulation instruction handlers
|
/// Registers all bit manipulation instruction handlers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -5,13 +5,13 @@ using X86Disassembler.X86.Operands;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handler for INT instruction (0xCD)
|
/// Handler for INT instruction (0xCD)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class IntHandler : InstructionHandler
|
public class IntImm8Handler : InstructionHandler
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the IntHandler class
|
/// Initializes a new instance of the IntHandler class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||||
public IntHandler(InstructionDecoder decoder)
|
public IntImm8Handler(InstructionDecoder decoder)
|
||||||
: base(decoder)
|
: base(decoder)
|
||||||
{
|
{
|
||||||
}
|
}
|
@ -35,7 +35,7 @@ public class Int3Handler : InstructionHandler
|
|||||||
public override bool Decode(byte opcode, Instruction instruction)
|
public override bool Decode(byte opcode, Instruction instruction)
|
||||||
{
|
{
|
||||||
// Set the instruction type
|
// Set the instruction type
|
||||||
instruction.Type = InstructionType.Int;
|
instruction.Type = InstructionType.Int3;
|
||||||
|
|
||||||
// INT3 has no operands
|
// INT3 has no operands
|
||||||
instruction.StructuredOperands = [];
|
instruction.StructuredOperands = [];
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -74,7 +74,7 @@ public enum InstructionType
|
|||||||
Call, // Call procedure
|
Call, // Call procedure
|
||||||
Ret, // Near return from procedure
|
Ret, // Near return from procedure
|
||||||
Retf, // Far return from procedure
|
Retf, // Far return from procedure
|
||||||
Int, // Interrupt
|
Int, // Interrupt vector number specified by immediate byte.
|
||||||
Int3, // Breakpoint interrupt
|
Int3, // Breakpoint interrupt
|
||||||
Into, // Interrupt if overflow
|
Into, // Interrupt if overflow
|
||||||
Iret, // Interrupt return
|
Iret, // Interrupt return
|
||||||
|
@ -34,19 +34,6 @@ F4;[{ "Type": "Hlt", "Operands": [] }]
|
|||||||
|
|
||||||
# LOCK prefix
|
# LOCK prefix
|
||||||
F0;[{ "Type": "Lock", "Operands": [] }]
|
F0;[{ "Type": "Lock", "Operands": [] }]
|
||||||
# SPECIAL CASE: When Mod=00 and R/M=101 (EBP), this doesn't actually refer to [EBP].
|
|
||||||
# Instead, it's a special case that indicates a 32-bit displacement-only addressing mode.
|
|
||||||
# The correct encoding for instructions with [ebp] would use Mod=01 and a zero displacement.
|
|
||||||
# F0FE05;[{ "Type": "Inc", "Operands": ["byte ptr [ebp]"], "Prefix": "Lock" }]
|
|
||||||
# F0FF05;[{ "Type": "Inc", "Operands": ["dword ptr [ebp]"], "Prefix": "Lock" }]
|
|
||||||
# F0FE0D;[{ "Type": "Dec", "Operands": ["byte ptr [ebp]"], "Prefix": "Lock" }]
|
|
||||||
# F0FF0D;[{ "Type": "Dec", "Operands": ["dword ptr [ebp]"], "Prefix": "Lock" }]
|
|
||||||
|
|
||||||
# Adding the correct test cases:
|
|
||||||
F0FE4500;[{ "Type": "Inc", "Operands": ["byte ptr [ebp+0x0]"], "Prefix": "Lock" }]
|
|
||||||
F0FF4500;[{ "Type": "Inc", "Operands": ["dword ptr [ebp+0x0]"], "Prefix": "Lock" }]
|
|
||||||
F0FE4D00;[{ "Type": "Dec", "Operands": ["byte ptr [ebp+0x0]"], "Prefix": "Lock" }]
|
|
||||||
F0FF4D00;[{ "Type": "Dec", "Operands": ["dword ptr [ebp+0x0]"], "Prefix": "Lock" }]
|
|
||||||
|
|
||||||
# IN - Input from Port
|
# IN - Input from Port
|
||||||
E410;[{ "Type": "In", "Operands": ["al", "0x10"] }]
|
E410;[{ "Type": "In", "Operands": ["al", "0x10"] }]
|
||||||
|
Can't render this file because it contains an unexpected character in line 6 and column 7.
|
@ -26,7 +26,7 @@ C0D305;[{ "Type": "Rcl", "Operands": ["bl", "0x05"] }]
|
|||||||
C1D005;[{ "Type": "Rcl", "Operands": ["eax", "0x05"] }]
|
C1D005;[{ "Type": "Rcl", "Operands": ["eax", "0x05"] }]
|
||||||
C1D305;[{ "Type": "Rcl", "Operands": ["ebx", "0x05"] }]
|
C1D305;[{ "Type": "Rcl", "Operands": ["ebx", "0x05"] }]
|
||||||
|
|
||||||
# RCL with memory operands
|
# RCL with memory operands (properly encoded)
|
||||||
D0142510;[{ "Type": "Rcl", "Operands": ["byte ptr [eax+0x10]", "0x01"] }]
|
D05010;[{ "Type": "Rcl", "Operands": ["byte ptr [eax+0x10]", "0x01"] }]
|
||||||
D31425;[{ "Type": "Rcl", "Operands": ["dword ptr [eax]", "cl"] }]
|
D310;[{ "Type": "Rcl", "Operands": ["dword ptr [eax]", "cl"] }]
|
||||||
C1142505;[{ "Type": "Rcl", "Operands": ["dword ptr [eax]", "0x05"] }]
|
C11005;[{ "Type": "Rcl", "Operands": ["dword ptr [eax]", "0x05"] }]
|
||||||
|
Can't render this file because it contains an unexpected character in line 6 and column 9.
|
@ -27,6 +27,6 @@ C1D805;[{ "Type": "Rcr", "Operands": ["eax", "0x05"] }]
|
|||||||
C1DB05;[{ "Type": "Rcr", "Operands": ["ebx", "0x05"] }]
|
C1DB05;[{ "Type": "Rcr", "Operands": ["ebx", "0x05"] }]
|
||||||
|
|
||||||
# RCR with memory operands
|
# RCR with memory operands
|
||||||
D01C2510;[{ "Type": "Rcr", "Operands": ["byte ptr [eax+0x10]", "0x01"] }]
|
D05810;[{ "Type": "Rcr", "Operands": ["byte ptr [eax+0x10]", "0x01"] }]
|
||||||
D31C25;[{ "Type": "Rcr", "Operands": ["dword ptr [eax]", "cl"] }]
|
D318;[{ "Type": "Rcr", "Operands": ["dword ptr [eax]", "cl"] }]
|
||||||
C11C2505;[{ "Type": "Rcr", "Operands": ["dword ptr [eax]", "0x05"] }]
|
C11805;[{ "Type": "Rcr", "Operands": ["dword ptr [eax]", "0x05"] }]
|
||||||
|
Can't render this file because it contains an unexpected character in line 6 and column 9.
|
@ -26,7 +26,7 @@ C0C305;[{ "Type": "Rol", "Operands": ["bl", "0x05"] }]
|
|||||||
C1C005;[{ "Type": "Rol", "Operands": ["eax", "0x05"] }]
|
C1C005;[{ "Type": "Rol", "Operands": ["eax", "0x05"] }]
|
||||||
C1C305;[{ "Type": "Rol", "Operands": ["ebx", "0x05"] }]
|
C1C305;[{ "Type": "Rol", "Operands": ["ebx", "0x05"] }]
|
||||||
|
|
||||||
# ROL with memory operands
|
# ROL with memory operands (fixed)
|
||||||
D0042510;[{ "Type": "Rol", "Operands": ["byte ptr [eax+0x10]", "0x01"] }]
|
D04010;[{ "Type": "Rol", "Operands": ["byte ptr [eax+0x10]", "0x01"] }]
|
||||||
D3042510;[{ "Type": "Rol", "Operands": ["dword ptr [eax+0x10]", "cl"] }]
|
D34010;[{ "Type": "Rol", "Operands": ["dword ptr [eax+0x10]", "cl"] }]
|
||||||
C1042505;[{ "Type": "Rol", "Operands": ["dword ptr [eax+0x10]", "0x05"] }]
|
C1401005;[{ "Type": "Rol", "Operands": ["dword ptr [eax+0x10]", "0x05"] }]
|
||||||
|
Can't render this file because it contains an unexpected character in line 6 and column 9.
|
@ -26,7 +26,7 @@ C0CB05;[{ "Type": "Ror", "Operands": ["bl", "0x05"] }]
|
|||||||
C1C805;[{ "Type": "Ror", "Operands": ["eax", "0x05"] }]
|
C1C805;[{ "Type": "Ror", "Operands": ["eax", "0x05"] }]
|
||||||
C1CB05;[{ "Type": "Ror", "Operands": ["ebx", "0x05"] }]
|
C1CB05;[{ "Type": "Ror", "Operands": ["ebx", "0x05"] }]
|
||||||
|
|
||||||
# ROR with memory operands
|
# ROR with memory operands (fixed)
|
||||||
D00C2510;[{ "Type": "Ror", "Operands": ["byte ptr [eax+0x10]", "0x01"] }]
|
D04810;[{ "Type": "Ror", "Operands": ["byte ptr [eax+0x10]", "0x01"] }]
|
||||||
D30C2510;[{ "Type": "Ror", "Operands": ["dword ptr [eax+0x10]", "cl"] }]
|
D34810;[{ "Type": "Ror", "Operands": ["dword ptr [eax+0x10]", "cl"] }]
|
||||||
C10C2505;[{ "Type": "Ror", "Operands": ["dword ptr [eax+0x10]", "0x05"] }]
|
C1481005;[{ "Type": "Ror", "Operands": ["dword ptr [eax+0x10]", "0x05"] }]
|
||||||
|
Can't render this file because it contains an unexpected character in line 6 and column 9.
|
@ -26,7 +26,7 @@ C0FB05;[{ "Type": "Sar", "Operands": ["bl", "0x05"] }]
|
|||||||
C1F805;[{ "Type": "Sar", "Operands": ["eax", "0x05"] }]
|
C1F805;[{ "Type": "Sar", "Operands": ["eax", "0x05"] }]
|
||||||
C1FB05;[{ "Type": "Sar", "Operands": ["ebx", "0x05"] }]
|
C1FB05;[{ "Type": "Sar", "Operands": ["ebx", "0x05"] }]
|
||||||
|
|
||||||
# SAR with memory operands
|
# SAR with memory operands (fixed)
|
||||||
D03C2510;[{ "Type": "Sar", "Operands": ["byte ptr [eax+0x10]", "0x01"] }]
|
D07810;[{ "Type": "Sar", "Operands": ["byte ptr [eax+0x10]", "0x01"] }]
|
||||||
D33C25;[{ "Type": "Sar", "Operands": ["dword ptr [eax]", "cl"] }]
|
D338;[{ "Type": "Sar", "Operands": ["dword ptr [eax]", "cl"] }]
|
||||||
C13C2505;[{ "Type": "Sar", "Operands": ["dword ptr [eax]", "0x05"] }]
|
C13805;[{ "Type": "Sar", "Operands": ["dword ptr [eax]", "0x05"] }]
|
||||||
|
Can't render this file because it contains an unexpected character in line 6 and column 9.
|
@ -28,5 +28,5 @@ C1E305;[{ "Type": "Shl", "Operands": ["ebx", "0x05"] }]
|
|||||||
|
|
||||||
# SHL with memory operands
|
# SHL with memory operands
|
||||||
D0242510000000;[{ "Type": "Shl", "Operands": ["byte ptr [0x10]", "0x01"] }]
|
D0242510000000;[{ "Type": "Shl", "Operands": ["byte ptr [0x10]", "0x01"] }]
|
||||||
D32425;[{ "Type": "Shl", "Operands": ["dword ptr [eax]", "cl"] }]
|
D320;[{ "Type": "Shl", "Operands": ["dword ptr [eax]", "cl"] }]
|
||||||
C1242510000005;[{ "Type": "Shl", "Operands": ["dword ptr [0x10]", "0x05"] }]
|
C1251000000005;[{ "Type": "Shl", "Operands": ["dword ptr [0x10]", "0x05"] }]
|
||||||
|
Can't render this file because it contains an unexpected character in line 6 and column 9.
|
@ -26,7 +26,7 @@ C0EB05;[{ "Type": "Shr", "Operands": ["bl", "0x05"] }]
|
|||||||
C1E805;[{ "Type": "Shr", "Operands": ["eax", "0x05"] }]
|
C1E805;[{ "Type": "Shr", "Operands": ["eax", "0x05"] }]
|
||||||
C1EB05;[{ "Type": "Shr", "Operands": ["ebx", "0x05"] }]
|
C1EB05;[{ "Type": "Shr", "Operands": ["ebx", "0x05"] }]
|
||||||
|
|
||||||
# SHR with memory operands
|
# SHR with memory operands (fixed)
|
||||||
D02C2510;[{ "Type": "Shr", "Operands": ["byte ptr [eax+0x10]", "0x01"] }]
|
D06810;[{ "Type": "Shr", "Operands": ["byte ptr [eax+0x10]", "0x01"] }]
|
||||||
D32C25;[{ "Type": "Shr", "Operands": ["dword ptr [eax]", "cl"] }]
|
D328;[{ "Type": "Shr", "Operands": ["dword ptr [eax]", "cl"] }]
|
||||||
C12C2505;[{ "Type": "Shr", "Operands": ["dword ptr [eax]", "0x05"] }]
|
C12805;[{ "Type": "Shr", "Operands": ["dword ptr [eax]", "0x05"] }]
|
||||||
|
Can't render this file because it contains an unexpected character in line 6 and column 9.
|
Loading…
x
Reference in New Issue
Block a user