mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-20 08:18:36 +03:00
Unified ADC accumulator handlers into a single handler
This commit is contained in:
84
X86Disassembler/X86/Handlers/Bit/BsfR32Rm32Handler.cs
Normal file
84
X86Disassembler/X86/Handlers/Bit/BsfR32Rm32Handler.cs
Normal file
@ -0,0 +1,84 @@
|
||||
namespace X86Disassembler.X86.Handlers.Bit;
|
||||
|
||||
using Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for BSF r32, r/m32 instruction (0F BC)
|
||||
/// </summary>
|
||||
public class BsfR32Rm32Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the BsfR32Rm32Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public BsfR32Rm32Handler(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)
|
||||
{
|
||||
// BSF r32, r/m32 is a two-byte opcode: 0F BC
|
||||
if (opcode != 0x0F)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if we have enough bytes to read the second opcode byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the second byte is BC
|
||||
var secondByte = Decoder.PeakByte();
|
||||
|
||||
// Only handle when the operand size prefix is NOT present
|
||||
// This ensures 16-bit handlers get priority when the prefix is present
|
||||
return secondByte == 0xBC && !Decoder.HasOperandSizePrefix();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a BSF r32, r/m32 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.Bsf;
|
||||
|
||||
// Read the second opcode byte (BC)
|
||||
Decoder.ReadByte();
|
||||
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
// For BSF r32, r/m32 (0F BC):
|
||||
// - The reg field specifies the destination register
|
||||
// - The r/m field with mod specifies the source operand (register or memory)
|
||||
var (_, reg, _, sourceOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create the register operand for the reg field
|
||||
var destinationOperand = OperandFactory.CreateRegisterOperand(reg);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
sourceOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
84
X86Disassembler/X86/Handlers/Bit/BsrR32Rm32Handler.cs
Normal file
84
X86Disassembler/X86/Handlers/Bit/BsrR32Rm32Handler.cs
Normal file
@ -0,0 +1,84 @@
|
||||
namespace X86Disassembler.X86.Handlers.Bit;
|
||||
|
||||
using Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for BSR r32, r/m32 instruction (0F BD)
|
||||
/// </summary>
|
||||
public class BsrR32Rm32Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the BsrR32Rm32Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public BsrR32Rm32Handler(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)
|
||||
{
|
||||
// BSR r32, r/m32 is a two-byte opcode: 0F BD
|
||||
if (opcode != 0x0F)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if we have enough bytes to read the second opcode byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the second byte is BD
|
||||
var secondByte = Decoder.PeakByte();
|
||||
|
||||
// Only handle when the operand size prefix is NOT present
|
||||
// This ensures 16-bit handlers get priority when the prefix is present
|
||||
return secondByte == 0xBD && !Decoder.HasOperandSizePrefix();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a BSR r32, r/m32 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.Bsr;
|
||||
|
||||
// Read the second opcode byte (BD)
|
||||
Decoder.ReadByte();
|
||||
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
// For BSR r32, r/m32 (0F BD):
|
||||
// - The reg field specifies the destination register
|
||||
// - The r/m field with mod specifies the source operand (register or memory)
|
||||
var (_, reg, _, sourceOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create the register operand for the reg field
|
||||
var destinationOperand = OperandFactory.CreateRegisterOperand(reg);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
sourceOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
84
X86Disassembler/X86/Handlers/Bit/BtR32Rm32Handler.cs
Normal file
84
X86Disassembler/X86/Handlers/Bit/BtR32Rm32Handler.cs
Normal file
@ -0,0 +1,84 @@
|
||||
namespace X86Disassembler.X86.Handlers.Bit;
|
||||
|
||||
using Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for BT r32, r/m32 instruction (0F A3)
|
||||
/// </summary>
|
||||
public class BtR32Rm32Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the BtR32Rm32Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public BtR32Rm32Handler(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)
|
||||
{
|
||||
// BT r32, r/m32 is a two-byte opcode: 0F A3
|
||||
if (opcode != 0x0F)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if we have enough bytes to read the second opcode byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the second byte is A3
|
||||
var secondByte = Decoder.PeakByte();
|
||||
|
||||
// Only handle when the operand size prefix is NOT present
|
||||
// This ensures 16-bit handlers get priority when the prefix is present
|
||||
return secondByte == 0xA3 && !Decoder.HasOperandSizePrefix();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a BT r32, r/m32 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.Bt;
|
||||
|
||||
// Read the second opcode byte (A3)
|
||||
Decoder.ReadByte();
|
||||
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
// For BT r/m32, r32 (0F A3):
|
||||
// - The r/m field with mod specifies the destination operand (register or memory)
|
||||
// - The reg field specifies the bit index register
|
||||
var (_, reg, _, destinationOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create the register operand for the reg field
|
||||
var bitIndexOperand = OperandFactory.CreateRegisterOperand(reg);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
bitIndexOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
101
X86Disassembler/X86/Handlers/Bit/BtRm32ImmHandler.cs
Normal file
101
X86Disassembler/X86/Handlers/Bit/BtRm32ImmHandler.cs
Normal file
@ -0,0 +1,101 @@
|
||||
namespace X86Disassembler.X86.Handlers.Bit;
|
||||
|
||||
using Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for BT r/m32, imm8 instruction (0F BA /4)
|
||||
/// </summary>
|
||||
public class BtRm32ImmHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the BtRm32ImmHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public BtRm32ImmHandler(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)
|
||||
{
|
||||
// BT r/m32, imm8 is encoded as 0F BA /4
|
||||
if (opcode != 0x0F)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if we have enough bytes to read the second opcode byte
|
||||
if (!Decoder.CanRead(2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var (secondByte, modRm) = Decoder.PeakTwoBytes();
|
||||
|
||||
// Check if the second byte is BA
|
||||
if (secondByte != 0xBA)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 4 (BT)
|
||||
var reg = ModRMDecoder.GetRegFromModRM(modRm);
|
||||
|
||||
// Only handle when the operand size prefix is NOT present
|
||||
// This ensures 16-bit handlers get priority when the prefix is present
|
||||
return reg == 4 && !Decoder.HasOperandSizePrefix();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a BT 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.Bt;
|
||||
|
||||
// Read the second opcode byte (BA)
|
||||
Decoder.ReadByte();
|
||||
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
// For BT r/m32, imm8 (0F BA /4):
|
||||
// - The r/m field with mod specifies the destination operand (register or memory)
|
||||
// - The immediate value specifies the bit index
|
||||
var (_, _, _, destinationOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Check if we have enough bytes for the immediate value
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the immediate byte for the bit position
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Create the immediate operand
|
||||
var bitIndexOperand = OperandFactory.CreateImmediateOperand(imm8, 8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
bitIndexOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
84
X86Disassembler/X86/Handlers/Bit/BtcR32Rm32Handler.cs
Normal file
84
X86Disassembler/X86/Handlers/Bit/BtcR32Rm32Handler.cs
Normal file
@ -0,0 +1,84 @@
|
||||
namespace X86Disassembler.X86.Handlers.Bit;
|
||||
|
||||
using Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for BTC r32, r/m32 instruction (0F BB)
|
||||
/// </summary>
|
||||
public class BtcR32Rm32Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the BtcR32Rm32Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public BtcR32Rm32Handler(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)
|
||||
{
|
||||
// BTC r32, r/m32 is a two-byte opcode: 0F BB
|
||||
if (opcode != 0x0F)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if we have enough bytes to read the second opcode byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the second byte is BB
|
||||
var secondByte = Decoder.PeakByte();
|
||||
|
||||
// Only handle when the operand size prefix is NOT present
|
||||
// This ensures 16-bit handlers get priority when the prefix is present
|
||||
return secondByte == 0xBB && !Decoder.HasOperandSizePrefix();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a BTC r32, r/m32 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.Btc;
|
||||
|
||||
// Read the second opcode byte (BB)
|
||||
Decoder.ReadByte();
|
||||
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
// For BTC r/m32, r32 (0F BB):
|
||||
// - The r/m field with mod specifies the destination operand (register or memory)
|
||||
// - The reg field specifies the bit index register
|
||||
var (_, reg, _, destinationOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create the register operand for the reg field
|
||||
var bitIndexOperand = OperandFactory.CreateRegisterOperand(reg);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
bitIndexOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
101
X86Disassembler/X86/Handlers/Bit/BtcRm32ImmHandler.cs
Normal file
101
X86Disassembler/X86/Handlers/Bit/BtcRm32ImmHandler.cs
Normal file
@ -0,0 +1,101 @@
|
||||
namespace X86Disassembler.X86.Handlers.Bit;
|
||||
|
||||
using Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for BTC r/m32, imm8 instruction (0F BA /7)
|
||||
/// </summary>
|
||||
public class BtcRm32ImmHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the BtcRm32ImmHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public BtcRm32ImmHandler(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)
|
||||
{
|
||||
// BTC r/m32, imm8 is encoded as 0F BA /7
|
||||
if (opcode != 0x0F)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if we have enough bytes to read the second opcode byte
|
||||
if (!Decoder.CanRead(2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var (secondByte, modRm) = Decoder.PeakTwoBytes();
|
||||
|
||||
// Check if the second byte is BA
|
||||
if (secondByte != 0xBA)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 7 (BTC)
|
||||
var reg = ModRMDecoder.GetRegFromModRM(modRm);
|
||||
|
||||
// Only handle when the operand size prefix is NOT present
|
||||
// This ensures 16-bit handlers get priority when the prefix is present
|
||||
return reg == 7 && !Decoder.HasOperandSizePrefix();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a BTC 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.Btc;
|
||||
|
||||
// Read the second opcode byte (BA)
|
||||
Decoder.ReadByte();
|
||||
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
// For BTC r/m32, imm8 (0F BA /7):
|
||||
// - The r/m field with mod specifies the destination operand (register or memory)
|
||||
// - The immediate value specifies the bit index
|
||||
var (_, _, _, destinationOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Check if we have enough bytes for the immediate value
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the immediate byte for the bit position
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Create the immediate operand
|
||||
var bitIndexOperand = OperandFactory.CreateImmediateOperand(imm8, 8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
bitIndexOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
84
X86Disassembler/X86/Handlers/Bit/BtrR32Rm32Handler.cs
Normal file
84
X86Disassembler/X86/Handlers/Bit/BtrR32Rm32Handler.cs
Normal file
@ -0,0 +1,84 @@
|
||||
namespace X86Disassembler.X86.Handlers.Bit;
|
||||
|
||||
using Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for BTR r32, r/m32 instruction (0F B3)
|
||||
/// </summary>
|
||||
public class BtrR32Rm32Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the BtrR32Rm32Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public BtrR32Rm32Handler(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)
|
||||
{
|
||||
// BTR r32, r/m32 is a two-byte opcode: 0F B3
|
||||
if (opcode != 0x0F)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if we have enough bytes to read the second opcode byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the second byte is B3
|
||||
var secondByte = Decoder.PeakByte();
|
||||
|
||||
// Only handle when the operand size prefix is NOT present
|
||||
// This ensures 16-bit handlers get priority when the prefix is present
|
||||
return secondByte == 0xB3 && !Decoder.HasOperandSizePrefix();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a BTR r32, r/m32 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.Btr;
|
||||
|
||||
// Read the second opcode byte (B3)
|
||||
Decoder.ReadByte();
|
||||
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
// For BTR r/m32, r32 (0F B3):
|
||||
// - The r/m field with mod specifies the destination operand (register or memory)
|
||||
// - The reg field specifies the bit index register
|
||||
var (_, reg, _, destinationOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create the register operand for the reg field
|
||||
var bitIndexOperand = OperandFactory.CreateRegisterOperand(reg);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
bitIndexOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
102
X86Disassembler/X86/Handlers/Bit/BtrRm32ImmHandler.cs
Normal file
102
X86Disassembler/X86/Handlers/Bit/BtrRm32ImmHandler.cs
Normal file
@ -0,0 +1,102 @@
|
||||
namespace X86Disassembler.X86.Handlers.Bit;
|
||||
|
||||
using Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for BTR r/m32, imm8 instruction (0F BA /6)
|
||||
/// </summary>
|
||||
public class BtrRm32ImmHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the BtrRm32ImmHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public BtrRm32ImmHandler(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)
|
||||
{
|
||||
// BTR r/m32, imm8 is encoded as 0F BA /6
|
||||
if (opcode != 0x0F)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Check if we have enough bytes to read the second opcode byte
|
||||
if (!Decoder.CanRead(2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var (secondByte, modRm) = Decoder.PeakTwoBytes();
|
||||
|
||||
// Check if the second byte is BA
|
||||
if (secondByte != 0xBA)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 6 (BTR)
|
||||
var reg = ModRMDecoder.GetRegFromModRM(modRm);
|
||||
|
||||
// Only handle when the operand size prefix is NOT present
|
||||
// This ensures 16-bit handlers get priority when the prefix is present
|
||||
return reg == 6 && !Decoder.HasOperandSizePrefix();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a BTR 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.Btr;
|
||||
|
||||
// Read the second opcode byte (BA)
|
||||
Decoder.ReadByte();
|
||||
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
// For BTR r/m32, imm8 (0F BA /6):
|
||||
// - The r/m field with mod specifies the destination operand (register or memory)
|
||||
// - The immediate value specifies the bit index
|
||||
var (_, _, _, destinationOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Check if we have enough bytes for the immediate value
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the immediate byte for the bit position
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Create the immediate operand
|
||||
var bitIndexOperand = OperandFactory.CreateImmediateOperand(imm8, 8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
bitIndexOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
84
X86Disassembler/X86/Handlers/Bit/BtsR32Rm32Handler.cs
Normal file
84
X86Disassembler/X86/Handlers/Bit/BtsR32Rm32Handler.cs
Normal file
@ -0,0 +1,84 @@
|
||||
namespace X86Disassembler.X86.Handlers.Bit;
|
||||
|
||||
using Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for BTS r32, r/m32 instruction (0F AB)
|
||||
/// </summary>
|
||||
public class BtsR32Rm32Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the BtsR32Rm32Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public BtsR32Rm32Handler(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)
|
||||
{
|
||||
// BTS r32, r/m32 is a two-byte opcode: 0F AB
|
||||
if (opcode != 0x0F)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if we have enough bytes to read the second opcode byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the second byte is AB
|
||||
var secondByte = Decoder.PeakByte();
|
||||
|
||||
// Only handle when the operand size prefix is NOT present
|
||||
// This ensures 16-bit handlers get priority when the prefix is present
|
||||
return secondByte == 0xAB && !Decoder.HasOperandSizePrefix();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a BTS r32, r/m32 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.Bts;
|
||||
|
||||
// Read the second opcode byte (AB)
|
||||
Decoder.ReadByte();
|
||||
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
// For BTS r/m32, r32 (0F AB):
|
||||
// - The r/m field with mod specifies the destination operand (register or memory)
|
||||
// - The reg field specifies the bit index register
|
||||
var (_, reg, _, destinationOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create the register operand for the reg field
|
||||
var bitIndexOperand = OperandFactory.CreateRegisterOperand(reg);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
bitIndexOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
101
X86Disassembler/X86/Handlers/Bit/BtsRm32ImmHandler.cs
Normal file
101
X86Disassembler/X86/Handlers/Bit/BtsRm32ImmHandler.cs
Normal file
@ -0,0 +1,101 @@
|
||||
namespace X86Disassembler.X86.Handlers.Bit;
|
||||
|
||||
using Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for BTS r/m32, imm8 instruction (0F BA /5)
|
||||
/// </summary>
|
||||
public class BtsRm32ImmHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the BtsRm32ImmHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public BtsRm32ImmHandler(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)
|
||||
{
|
||||
// BTS r/m32, imm8 is encoded as 0F BA /5
|
||||
if (opcode != 0x0F)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if we have enough bytes to read the second opcode byte
|
||||
if (!Decoder.CanRead(2))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var (secondByte, modRm) = Decoder.PeakTwoBytes();
|
||||
|
||||
// Check if the second byte is BA
|
||||
if (secondByte != 0xBA)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the reg field of the ModR/M byte is 5 (BTS)
|
||||
var reg = ModRMDecoder.GetRegFromModRM(modRm);
|
||||
|
||||
// Only handle when the operand size prefix is NOT present
|
||||
// This ensures 16-bit handlers get priority when the prefix is present
|
||||
return reg == 5 && !Decoder.HasOperandSizePrefix();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a BTS 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.Bts;
|
||||
|
||||
// Read the second opcode byte (BA)
|
||||
Decoder.ReadByte();
|
||||
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
// For BTS r/m32, imm8 (0F BA /5):
|
||||
// - The r/m field with mod specifies the destination operand (register or memory)
|
||||
// - The immediate value specifies the bit index
|
||||
var (_, _, _, destinationOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Check if we have enough bytes for the immediate value
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the immediate byte for the bit position
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
|
||||
// Create the immediate operand
|
||||
var bitIndexOperand = OperandFactory.CreateImmediateOperand(imm8, 8);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
bitIndexOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user