0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-06-20 00:18:02 +03:00

basic decompiler and fixes

This commit is contained in:
bird_egop
2025-04-14 02:07:17 +03:00
parent 157171fa90
commit c516e063e7
10 changed files with 1314 additions and 16 deletions

View File

@ -15,7 +15,7 @@ public class Disassembler
private readonly int _length;
// The base address of the code
private readonly uint _baseAddress;
private readonly ulong _baseAddress;
// Segment override prefixes
private static readonly byte[] SegmentOverridePrefixes = { 0x26, 0x2E, 0x36, 0x3E, 0x64, 0x65 };
@ -25,7 +25,7 @@ public class Disassembler
/// </summary>
/// <param name="codeBuffer">The buffer containing the code to disassemble</param>
/// <param name="baseAddress">The base address of the code</param>
public Disassembler(byte[] codeBuffer, uint baseAddress)
public Disassembler(byte[] codeBuffer, ulong baseAddress)
{
_codeBuffer = codeBuffer;
_length = codeBuffer.Length;

View File

@ -43,13 +43,11 @@ public class JgeRel8Handler : InstructionHandler
instruction.Operands = "??";
return true;
}
// Read the offset and calculate target address
int position = Decoder.GetPosition();
sbyte offset = (sbyte)Decoder.ReadByte();
// Calculate target address (instruction address + instruction length + offset)
uint targetAddress = (uint)(instruction.Address + 2 + offset);
ulong targetAddress = instruction.Address + 2UL + (uint)offset;
// Format the target address
instruction.Operands = $"0x{targetAddress:X8}";

View File

@ -38,8 +38,7 @@ public class JmpRel32Handler : InstructionHandler
instruction.Mnemonic = "jmp";
// Check if we have enough bytes for the offset (4 bytes)
int position = Decoder.GetPosition();
if (position + 4 > Length)
if (!Decoder.CanReadUInt())
{
return false;
}

View File

@ -42,13 +42,11 @@ public class JmpRel8Handler : InstructionHandler
{
return true;
}
// Read the offset and calculate target address
int position = Decoder.GetPosition();
sbyte offset = (sbyte)Decoder.ReadByte();
// Calculate target address (instruction address + instruction length + offset)
uint targetAddress = (uint)(instruction.Address + 2 + offset);
ulong targetAddress = instruction.Address + 2UL + (uint)offset;
// Format the target address
instruction.Operands = $"0x{targetAddress:X8}";

View File

@ -55,8 +55,6 @@ public class TwoByteConditionalJumpHandler : InstructionHandler
/// <returns>True if the instruction was successfully decoded</returns>
public override bool Decode(byte opcode, Instruction instruction)
{
int position = Decoder.GetPosition();
// Check if we have enough bytes for the second byte
if (!Decoder.CanReadByte())
{

View File

@ -8,7 +8,7 @@ public class Instruction
/// <summary>
/// Gets or sets the address of the instruction
/// </summary>
public uint Address { get; set; }
public ulong Address { get; set; }
/// <summary>
/// Gets or sets the mnemonic of the instruction