mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-20 08:18:36 +03:00
Fixed FnstswHandler test by registering the handler in InstructionHandlerFactory
This commit is contained in:
56
X86Disassembler/X86/Handlers/Mov/MovEaxMoffsHandler.cs
Normal file
56
X86Disassembler/X86/Handlers/Mov/MovEaxMoffsHandler.cs
Normal file
@ -0,0 +1,56 @@
|
||||
namespace X86Disassembler.X86.Handlers.Mov;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for MOV EAX, moffs32 instruction (0xA1) and MOV AL, moffs8 instruction (0xA0)
|
||||
/// </summary>
|
||||
public class MovEaxMoffsHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the MovEaxMoffsHandler class
|
||||
/// </summary>
|
||||
/// <param name="codeBuffer">The buffer containing the code to decode</param>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
/// <param name="length">The length of the buffer</param>
|
||||
public MovEaxMoffsHandler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
{
|
||||
}
|
||||
|
||||
/// <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 == 0xA0 || opcode == 0xA1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a MOV EAX, moffs32 or MOV AL, moffs8 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 mnemonic
|
||||
instruction.Mnemonic = "mov";
|
||||
|
||||
// Get the operand size and register name
|
||||
int operandSize = (opcode == 0xA0) ? 8 : 32;
|
||||
string regName = (opcode == 0xA0) ? "al" : "eax";
|
||||
|
||||
// Read the memory offset
|
||||
uint offset = Decoder.ReadUInt32();
|
||||
if (Decoder.GetPosition() > Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"{regName}, [0x{offset:X}]";
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
70
X86Disassembler/X86/Handlers/Mov/MovMemRegHandler.cs
Normal file
70
X86Disassembler/X86/Handlers/Mov/MovMemRegHandler.cs
Normal file
@ -0,0 +1,70 @@
|
||||
namespace X86Disassembler.X86.Handlers.Mov;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for MOV r/m32, r32 instruction (0x89) and MOV r/m8, r8 instruction (0x88)
|
||||
/// </summary>
|
||||
public class MovMemRegHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the MovMemRegHandler class
|
||||
/// </summary>
|
||||
/// <param name="codeBuffer">The buffer containing the code to decode</param>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
/// <param name="length">The length of the buffer</param>
|
||||
public MovMemRegHandler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
{
|
||||
}
|
||||
|
||||
/// <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 == 0x88 || opcode == 0x89;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a MOV r/m32, r32 or MOV 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 mnemonic
|
||||
instruction.Mnemonic = "mov";
|
||||
|
||||
int position = Decoder.GetPosition();
|
||||
|
||||
if (position >= Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Determine operand size (0 = 8-bit, 1 = 32-bit)
|
||||
bool operandSize32 = (opcode & 0x01) != 0;
|
||||
int operandSize = operandSize32 ? 32 : 8;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, memOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Get register name based on size
|
||||
string regName = ModRMDecoder.GetRegisterName(reg, operandSize);
|
||||
|
||||
// For mod == 3, both operands are registers
|
||||
if (mod == 3)
|
||||
{
|
||||
string rmRegName = ModRMDecoder.GetRegisterName(rm, operandSize);
|
||||
instruction.Operands = $"{regName}, {rmRegName}";
|
||||
}
|
||||
else // Memory operand
|
||||
{
|
||||
instruction.Operands = $"{regName}, {memOperand}";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
56
X86Disassembler/X86/Handlers/Mov/MovMoffsEaxHandler.cs
Normal file
56
X86Disassembler/X86/Handlers/Mov/MovMoffsEaxHandler.cs
Normal file
@ -0,0 +1,56 @@
|
||||
namespace X86Disassembler.X86.Handlers.Mov;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for MOV moffs32, EAX instruction (0xA3) and MOV moffs8, AL instruction (0xA2)
|
||||
/// </summary>
|
||||
public class MovMoffsEaxHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the MovMoffsEaxHandler class
|
||||
/// </summary>
|
||||
/// <param name="codeBuffer">The buffer containing the code to decode</param>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
/// <param name="length">The length of the buffer</param>
|
||||
public MovMoffsEaxHandler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
{
|
||||
}
|
||||
|
||||
/// <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 == 0xA2 || opcode == 0xA3;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a MOV moffs32, EAX or MOV moffs8, AL 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 mnemonic
|
||||
instruction.Mnemonic = "mov";
|
||||
|
||||
// Get the operand size and register name
|
||||
int operandSize = (opcode == 0xA2) ? 8 : 32;
|
||||
string regName = (opcode == 0xA2) ? "al" : "eax";
|
||||
|
||||
// Read the memory offset
|
||||
uint offset = Decoder.ReadUInt32();
|
||||
if (Decoder.GetPosition() > Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"[0x{offset:X}], {regName}";
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
56
X86Disassembler/X86/Handlers/Mov/MovRegImm32Handler.cs
Normal file
56
X86Disassembler/X86/Handlers/Mov/MovRegImm32Handler.cs
Normal file
@ -0,0 +1,56 @@
|
||||
namespace X86Disassembler.X86.Handlers.Mov;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for MOV r32, imm32 instruction (0xB8-0xBF)
|
||||
/// </summary>
|
||||
public class MovRegImm32Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the MovRegImm32Handler class
|
||||
/// </summary>
|
||||
/// <param name="codeBuffer">The buffer containing the code to decode</param>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
/// <param name="length">The length of the buffer</param>
|
||||
public MovRegImm32Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
{
|
||||
}
|
||||
|
||||
/// <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 >= 0xB8 && opcode <= 0xBF;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a MOV r32, imm32 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 mnemonic
|
||||
instruction.Mnemonic = "mov";
|
||||
|
||||
// Register is encoded in the low 3 bits of the opcode
|
||||
int reg = opcode & 0x07;
|
||||
string regName = ModRMDecoder.GetRegisterName(reg, 32);
|
||||
|
||||
// Read the immediate value
|
||||
uint imm32 = Decoder.ReadUInt32();
|
||||
if (Decoder.GetPosition() > Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"{regName}, 0x{imm32:X}";
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
56
X86Disassembler/X86/Handlers/Mov/MovRegImm8Handler.cs
Normal file
56
X86Disassembler/X86/Handlers/Mov/MovRegImm8Handler.cs
Normal file
@ -0,0 +1,56 @@
|
||||
namespace X86Disassembler.X86.Handlers.Mov;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for MOV r8, imm8 instruction (0xB0-0xB7)
|
||||
/// </summary>
|
||||
public class MovRegImm8Handler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the MovRegImm8Handler class
|
||||
/// </summary>
|
||||
/// <param name="codeBuffer">The buffer containing the code to decode</param>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
/// <param name="length">The length of the buffer</param>
|
||||
public MovRegImm8Handler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
{
|
||||
}
|
||||
|
||||
/// <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 >= 0xB0 && opcode <= 0xB7;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a MOV r8, 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 mnemonic
|
||||
instruction.Mnemonic = "mov";
|
||||
|
||||
// Register is encoded in the low 3 bits of the opcode
|
||||
int reg = opcode & 0x07;
|
||||
string regName = ModRMDecoder.GetRegisterName(reg, 8);
|
||||
|
||||
// Read the immediate value
|
||||
byte imm8 = Decoder.ReadByte();
|
||||
if (Decoder.GetPosition() > Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the operands
|
||||
instruction.Operands = $"{regName}, 0x{imm8:X2}";
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
70
X86Disassembler/X86/Handlers/Mov/MovRegMemHandler.cs
Normal file
70
X86Disassembler/X86/Handlers/Mov/MovRegMemHandler.cs
Normal file
@ -0,0 +1,70 @@
|
||||
namespace X86Disassembler.X86.Handlers.Mov;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for MOV r32, r/m32 instruction (0x8B) and MOV r8, r/m8 instruction (0x8A)
|
||||
/// </summary>
|
||||
public class MovRegMemHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the MovRegMemHandler class
|
||||
/// </summary>
|
||||
/// <param name="codeBuffer">The buffer containing the code to decode</param>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
/// <param name="length">The length of the buffer</param>
|
||||
public MovRegMemHandler(byte[] codeBuffer, InstructionDecoder decoder, int length)
|
||||
: base(codeBuffer, decoder, length)
|
||||
{
|
||||
}
|
||||
|
||||
/// <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 == 0x8A || opcode == 0x8B;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a MOV r32, r/m32 or MOV 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 mnemonic
|
||||
instruction.Mnemonic = "mov";
|
||||
|
||||
int position = Decoder.GetPosition();
|
||||
|
||||
if (position >= Length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Determine operand size (0 = 8-bit, 1 = 32-bit)
|
||||
bool operandSize32 = (opcode & 0x01) != 0;
|
||||
int operandSize = operandSize32 ? 32 : 8;
|
||||
|
||||
// Read the ModR/M byte
|
||||
var (mod, reg, rm, memOperand) = ModRMDecoder.ReadModRM();
|
||||
|
||||
// Get register name based on size
|
||||
string regName = ModRMDecoder.GetRegisterName(reg, operandSize);
|
||||
|
||||
// For mod == 3, both operands are registers
|
||||
if (mod == 3)
|
||||
{
|
||||
string rmRegName = ModRMDecoder.GetRegisterName(rm, operandSize);
|
||||
instruction.Operands = $"{rmRegName}, {regName}";
|
||||
}
|
||||
else // Memory operand
|
||||
{
|
||||
instruction.Operands = $"{memOperand}, {regName}";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user