mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-06-20 08:18:36 +03:00
Fix all tests
This commit is contained in:
74
X86Disassembler/X86/Handlers/Stack/EnterHandler.cs
Normal file
74
X86Disassembler/X86/Handlers/Stack/EnterHandler.cs
Normal file
@ -0,0 +1,74 @@
|
||||
namespace X86Disassembler.X86.Handlers.Stack;
|
||||
|
||||
using X86Disassembler.X86.Operands;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for ENTER instruction (0xC8)
|
||||
/// Creates a stack frame for a procedure with nested procedures
|
||||
/// </summary>
|
||||
public class EnterHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the EnterHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public EnterHandler(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)
|
||||
{
|
||||
// ENTER is 0xC8
|
||||
return opcode == 0xC8;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes an ENTER 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)
|
||||
{
|
||||
// ENTER requires 3 bytes: 1 opcode + 2-byte size operand + 1-byte nesting level
|
||||
// Check if we can read the 16-bit size operand
|
||||
if (!Decoder.CanReadUShort())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the size operand (16-bit immediate value)
|
||||
ushort size = Decoder.ReadUInt16();
|
||||
|
||||
// Check if we can read the nesting level byte
|
||||
if (!Decoder.CanReadByte())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Read the nesting level (8-bit immediate value)
|
||||
byte nestingLevel = Decoder.ReadByte();
|
||||
|
||||
// Set the instruction type
|
||||
instruction.Type = InstructionType.Enter;
|
||||
|
||||
// Create immediate operands for size and nesting level
|
||||
var sizeOperand = OperandFactory.CreateImmediateOperand(size);
|
||||
var nestingLevelOperand = OperandFactory.CreateImmediateOperand(nestingLevel);
|
||||
|
||||
// Set the structured operands
|
||||
instruction.StructuredOperands =
|
||||
[
|
||||
sizeOperand,
|
||||
nestingLevelOperand
|
||||
];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
45
X86Disassembler/X86/Handlers/Stack/LeaveHandler.cs
Normal file
45
X86Disassembler/X86/Handlers/Stack/LeaveHandler.cs
Normal file
@ -0,0 +1,45 @@
|
||||
namespace X86Disassembler.X86.Handlers.Stack;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for LEAVE instruction (0xC9)
|
||||
/// High-level procedure exit that releases the stack frame set up by a previous ENTER instruction
|
||||
/// </summary>
|
||||
public class LeaveHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the LeaveHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public LeaveHandler(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)
|
||||
{
|
||||
// LEAVE is 0xC9
|
||||
return opcode == 0xC9;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a LEAVE 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.Leave;
|
||||
|
||||
// LEAVE has no operands
|
||||
instruction.StructuredOperands = [];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
45
X86Disassembler/X86/Handlers/Stack/PopadHandler.cs
Normal file
45
X86Disassembler/X86/Handlers/Stack/PopadHandler.cs
Normal file
@ -0,0 +1,45 @@
|
||||
namespace X86Disassembler.X86.Handlers.Stack;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for POPAD instruction (0x61)
|
||||
/// Pops all general-purpose registers from the stack in the order: EDI, ESI, EBP, ESP (ignored), EBX, EDX, ECX, EAX
|
||||
/// </summary>
|
||||
public class PopadHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the PopadHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public PopadHandler(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)
|
||||
{
|
||||
// POPAD is 0x61
|
||||
return opcode == 0x61;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a POPAD 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.Popad;
|
||||
|
||||
// POPAD has no operands
|
||||
instruction.StructuredOperands = [];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
45
X86Disassembler/X86/Handlers/Stack/PopfdHandler.cs
Normal file
45
X86Disassembler/X86/Handlers/Stack/PopfdHandler.cs
Normal file
@ -0,0 +1,45 @@
|
||||
namespace X86Disassembler.X86.Handlers.Stack;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for POPFD instruction (0x9D)
|
||||
/// Pops the value from the stack and loads it into the EFLAGS register
|
||||
/// </summary>
|
||||
public class PopfdHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the PopfdHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public PopfdHandler(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)
|
||||
{
|
||||
// POPFD is 0x9D
|
||||
return opcode == 0x9D;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a POPFD 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.Popfd;
|
||||
|
||||
// POPFD has no operands
|
||||
instruction.StructuredOperands = [];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
45
X86Disassembler/X86/Handlers/Stack/PushadHandler.cs
Normal file
45
X86Disassembler/X86/Handlers/Stack/PushadHandler.cs
Normal file
@ -0,0 +1,45 @@
|
||||
namespace X86Disassembler.X86.Handlers.Stack;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for PUSHAD instruction (0x60)
|
||||
/// Pushes all general-purpose registers onto the stack in the order: EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI
|
||||
/// </summary>
|
||||
public class PushadHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the PushadHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public PushadHandler(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)
|
||||
{
|
||||
// PUSHAD is 0x60
|
||||
return opcode == 0x60;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a PUSHAD 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.Pushad;
|
||||
|
||||
// PUSHAD has no operands
|
||||
instruction.StructuredOperands = [];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
45
X86Disassembler/X86/Handlers/Stack/PushfdHandler.cs
Normal file
45
X86Disassembler/X86/Handlers/Stack/PushfdHandler.cs
Normal file
@ -0,0 +1,45 @@
|
||||
namespace X86Disassembler.X86.Handlers.Stack;
|
||||
|
||||
/// <summary>
|
||||
/// Handler for PUSHFD instruction (0x9C)
|
||||
/// Pushes the EFLAGS register onto the stack
|
||||
/// </summary>
|
||||
public class PushfdHandler : InstructionHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the PushfdHandler class
|
||||
/// </summary>
|
||||
/// <param name="decoder">The instruction decoder that owns this handler</param>
|
||||
public PushfdHandler(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)
|
||||
{
|
||||
// PUSHFD is 0x9C
|
||||
return opcode == 0x9C;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a PUSHFD 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.Pushfd;
|
||||
|
||||
// PUSHFD has no operands
|
||||
instruction.StructuredOperands = [];
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user