mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-05-19 03:41:18 +03:00
Implemented additional SBB instruction handlers for register-register and register-memory operations
This commit is contained in:
parent
33dc0b0fa2
commit
4d2db05a07
@ -100,6 +100,18 @@ public class InstructionHandlerFactory
|
||||
/// </summary>
|
||||
private void RegisterSbbHandlers()
|
||||
{
|
||||
// SBB register-register and register-memory handlers for 8-bit operands
|
||||
_handlers.Add(new SbbRm8R8Handler(_decoder)); // SBB r/m8, r8 (opcode 18)
|
||||
_handlers.Add(new SbbR8Rm8Handler(_decoder)); // SBB r8, r/m8 (opcode 1A)
|
||||
|
||||
// SBB register-register and register-memory handlers for 16-bit operands (with 0x66 prefix)
|
||||
_handlers.Add(new SbbRm16R16Handler(_decoder)); // SBB r/m16, r16 (opcode 19 with 0x66 prefix)
|
||||
_handlers.Add(new SbbR16Rm16Handler(_decoder)); // SBB r16, r/m16 (opcode 1B with 0x66 prefix)
|
||||
|
||||
// SBB register-register and register-memory handlers for 32-bit operands
|
||||
_handlers.Add(new SbbRm32R32Handler(_decoder)); // SBB r/m32, r32 (opcode 19)
|
||||
_handlers.Add(new SbbR32Rm32Handler(_decoder)); // SBB r32, r/m32 (opcode 1B)
|
||||
|
||||
// SBB immediate handlers for 8-bit operands
|
||||
_handlers.Add(new SbbImmFromRm8Handler(_decoder)); // SBB r/m8, imm8 (opcode 80 /3)
|
||||
_handlers.Add(new SbbAlImmHandler(_decoder)); // SBB AL, imm8 (opcode 1C)
|
||||
|
65
X86Disassembler/X86/Handlers/Sbb/SbbR16Rm16Handler.cs
Normal file
65
X86Disassembler/X86/Handlers/Sbb/SbbR16Rm16Handler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Sbb;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SBB r16, r/m16 instruction (0x1B with 0x66 prefix)
|
||||
/// </summary>
|
||||
public class SbbR16Rm16Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the SbbR16Rm16Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public SbbR16Rm16Handler(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)
|
||||
{
|
||||
// Only handle opcode 0x1B when the operand size prefix IS present
|
||||
return opcode == 0x1B && Decoder.HasOperandSizePrefix();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SBB r16, r/m16 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.Sbb;
|
||||
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
// For SBB r16, r/m16 (0x1B with 0x66 prefix):
|
||||
// - The reg field specifies the destination register
|
||||
// - The r/m field with mod specifies the source operand (register or memory)
|
||||
var (_, reg, _, sourceOperand) = ModRMDecoder.ReadModRM16();
|
||||
|
||||
// Create the register operand for the reg field (16-bit)
|
||||
var destinationOperand = OperandFactory.CreateRegisterOperand(reg, 16);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
sourceOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
66
X86Disassembler/X86/Handlers/Sbb/SbbR32Rm32Handler.cs
Normal file
66
X86Disassembler/X86/Handlers/Sbb/SbbR32Rm32Handler.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Sbb;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SBB r32, r/m32 instruction (0x1B)
|
||||
/// </summary>
|
||||
public class SbbR32Rm32Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the SbbR32Rm32Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public SbbR32Rm32Handler(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)
|
||||
{
|
||||
// Only handle opcode 0x1B when the operand size prefix is NOT present
|
||||
// This ensures 16-bit handlers get priority when the prefix is present
|
||||
return opcode == 0x1B && !Decoder.HasOperandSizePrefix();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SBB 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.Sbb;
|
||||
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
// For SBB r32, r/m32 (0x1B):
|
||||
// - 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;
|
||||
}
|
||||
}
|
64
X86Disassembler/X86/Handlers/Sbb/SbbR8Rm8Handler.cs
Normal file
64
X86Disassembler/X86/Handlers/Sbb/SbbR8Rm8Handler.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Sbb;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SBB r8, r/m8 instruction (0x1A)
|
||||
/// </summary>
|
||||
public class SbbR8Rm8Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the SbbR8Rm8Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public SbbR8Rm8Handler(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)
|
||||
{
|
||||
return opcode == 0x1A;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SBB r8, r/m8 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.Sbb;
|
||||
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
// For SBB r8, r/m8 (0x1A):
|
||||
// - The reg field specifies the destination register
|
||||
// - The r/m field with mod specifies the source operand (register or memory)
|
||||
var (_, reg, _, sourceOperand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Create the register operand for the reg field (8-bit)
|
||||
var destinationOperand = OperandFactory.CreateRegisterOperand8(reg);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
sourceOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
65
X86Disassembler/X86/Handlers/Sbb/SbbRm16R16Handler.cs
Normal file
65
X86Disassembler/X86/Handlers/Sbb/SbbRm16R16Handler.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Sbb;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SBB r/m16, r16 instruction (0x19 with 0x66 prefix)
|
||||
/// </summary>
|
||||
public class SbbRm16R16Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the SbbRm16R16Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public SbbRm16R16Handler(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)
|
||||
{
|
||||
// Only handle opcode 0x19 when the operand size prefix IS present
|
||||
return opcode == 0x19 && Decoder.HasOperandSizePrefix();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SBB r/m16, r16 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.Sbb;
|
||||
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
// For SBB r/m16, r16 (0x19 with 0x66 prefix):
|
||||
// - The r/m field with mod specifies the destination operand (register or memory)
|
||||
// - The reg field specifies the source register
|
||||
var (_, reg, _, destinationOperand) = ModRMDecoder.ReadModRM16();
|
||||
|
||||
// Create the register operand for the reg field (16-bit)
|
||||
var sourceOperand = OperandFactory.CreateRegisterOperand(reg, 16);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
sourceOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
66
X86Disassembler/X86/Handlers/Sbb/SbbRm32R32Handler.cs
Normal file
66
X86Disassembler/X86/Handlers/Sbb/SbbRm32R32Handler.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Sbb;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SBB r/m32, r32 instruction (0x19)
|
||||
/// </summary>
|
||||
public class SbbRm32R32Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the SbbRm32R32Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public SbbRm32R32Handler(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)
|
||||
{
|
||||
// Only handle opcode 0x19 when the operand size prefix is NOT present
|
||||
// This ensures 16-bit handlers get priority when the prefix is present
|
||||
return opcode == 0x19 && !Decoder.HasOperandSizePrefix();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SBB r/m32, r32 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.Sbb;
|
||||
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
// For SBB r/m32, r32 (0x19):
|
||||
// - The r/m field with mod specifies the destination operand (register or memory)
|
||||
// - The reg field specifies the source register
|
||||
var (_, reg, _, destinationOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Create the register operand for the reg field
|
||||
var sourceOperand = OperandFactory.CreateRegisterOperand(reg);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
sourceOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
64
X86Disassembler/X86/Handlers/Sbb/SbbRm8R8Handler.cs
Normal file
64
X86Disassembler/X86/Handlers/Sbb/SbbRm8R8Handler.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
namespace X86Disassembler.X86.Handlers.Sbb;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for SBB r/m8, r8 instruction (0x18)
|
||||
/// </summary>
|
||||
public class SbbRm8R8Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the SbbRm8R8Handler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public SbbRm8R8Handler(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)
|
||||
{
|
||||
return opcode == 0x18;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a SBB r/m8, r8 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.Sbb;
|
||||
|
||||
// Check if we have enough bytes for the ModR/M byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the ModR/M byte
|
||||
// For SBB r/m8, r8 (0x18):
|
||||
// - The r/m field with mod specifies the destination operand (register or memory)
|
||||
// - The reg field specifies the source register
|
||||
var (_, reg, _, destinationOperand) = ModRMDecoder.ReadModRM8();
|
||||
|
||||
// Create the register operand for the reg field (8-bit)
|
||||
var sourceOperand = OperandFactory.CreateRegisterOperand8(reg);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
destinationOperand,
|
||||
sourceOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user