0
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-05-19 11:51:17 +03:00

fix various tests

This commit is contained in:
bird_egop 2025-04-15 23:54:51 +03:00
parent 4327464b98
commit 46592d4877
6 changed files with 36 additions and 40 deletions

View File

@ -345,27 +345,17 @@ public class ModRMDecoder
if (_decoder.CanReadUInt()) if (_decoder.CanReadUInt())
{ {
uint disp32 = _decoder.ReadUInt32(); uint disp32 = _decoder.ReadUInt32();
int scaleValue = 1 << scale; // 1, 2, 4, or 8
// Create a scaled index memory operand with displacement but no base register // When both index is ESP (no index) and base is EBP with disp32,
return OperandFactory.CreateScaledIndexMemoryOperand( // this is a direct memory reference [disp32]
index, return OperandFactory.CreateDirectMemoryOperand(disp32, operandSize);
scaleValue,
null,
(int)disp32,
operandSize);
} }
// Fallback for incomplete data // Fallback for incomplete data
return OperandFactory.CreateScaledIndexMemoryOperand( return OperandFactory.CreateDirectMemoryOperand(0, operandSize);
index,
1 << scale,
null,
0,
operandSize);
} }
// Base register only with displacement // When index is ESP (no index), we just have a base register with optional displacement
if (displacement == 0) if (displacement == 0)
{ {
return OperandFactory.CreateBaseRegisterMemoryOperand(@base, operandSize); return OperandFactory.CreateBaseRegisterMemoryOperand(@base, operandSize);
@ -382,6 +372,13 @@ public class ModRMDecoder
uint disp32 = _decoder.ReadUInt32(); uint disp32 = _decoder.ReadUInt32();
int scaleValue = 1 << scale; // 1, 2, 4, or 8 int scaleValue = 1 << scale; // 1, 2, 4, or 8
// If we have a direct memory reference with a specific displacement,
// use a direct memory operand instead of a scaled index memory operand
if (disp32 > 0 && index == RegisterIndex.Sp)
{
return OperandFactory.CreateDirectMemoryOperand(disp32, operandSize);
}
// Create a scaled index memory operand with displacement but no base register // Create a scaled index memory operand with displacement but no base register
return OperandFactory.CreateScaledIndexMemoryOperand( return OperandFactory.CreateScaledIndexMemoryOperand(
index, index,
@ -420,15 +417,13 @@ public class ModRMDecoder
/// <returns>The register name</returns> /// <returns>The register name</returns>
public static string GetRegisterName(RegisterIndex regIndex, int size) public static string GetRegisterName(RegisterIndex regIndex, int size)
{ {
// Convert RegisterIndex to raw index for array access
int index = (int)regIndex;
return size switch return size switch
{ {
8 => RegisterNames8[index], 8 => RegisterNames8[(int)regIndex],
16 => RegisterNames16[index], 16 => RegisterNames16[(int)regIndex],
32 => RegisterNames32[index], 32 => RegisterNames32[(int)regIndex],
_ => RegisterNames32[index] // Default to 32-bit registers 64 => RegisterNames32[(int)regIndex], // For now, reuse 32-bit names for 64-bit
_ => "unknown"
}; };
} }
} }

View File

@ -27,6 +27,6 @@ public class RelativeOffsetOperand : Operand
/// </summary> /// </summary>
public override string ToString() public override string ToString()
{ {
return $"0x{TargetAddress:X}"; return $"0x{TargetAddress:X8}";
} }
} }

View File

@ -54,7 +54,7 @@ RawBytes;Instructions
8004251000000042;[{ "Type": "Add", "Operands": ["byte ptr [0x10]", "0x42"] }] 8004251000000042;[{ "Type": "Add", "Operands": ["byte ptr [0x10]", "0x42"] }]
8104251000000078563412;[{ "Type": "Add", "Operands": ["dword ptr [0x10]", "0x12345678"] }] 8104251000000078563412;[{ "Type": "Add", "Operands": ["dword ptr [0x10]", "0x12345678"] }]
8304251000000042;[{ "Type": "Add", "Operands": ["dword ptr [0x10]", "0x42"] }] 8304251000000042;[{ "Type": "Add", "Operands": ["dword ptr [0x10]", "0x42"] }]
0004251000000000;[{ "Type": "Add", "Operands": ["byte ptr [0x10]", "al"] }] 00042510000000;[{ "Type": "Add", "Operands": ["byte ptr [0x10]", "al"] }]
0204251000000000;[{ "Type": "Add", "Operands": ["al", "byte ptr [0x10]"] }] 02042510000000;[{ "Type": "Add", "Operands": ["al", "byte ptr [0x10]"] }]
0104251000000000;[{ "Type": "Add", "Operands": ["dword ptr [0x10]", "eax"] }] 01042510000000;[{ "Type": "Add", "Operands": ["dword ptr [0x10]", "eax"] }]
0304251000000000;[{ "Type": "Add", "Operands": ["eax", "dword ptr [0x10]"] }] 03042510000000;[{ "Type": "Add", "Operands": ["eax", "dword ptr [0x10]"] }]

Can't render this file because it contains an unexpected character in line 6 and column 11.

View File

@ -52,7 +52,7 @@ RawBytes;Instructions
8024251000000042;[{ "Type": "And", "Operands": ["byte ptr [0x10]", "0x42"] }] 8024251000000042;[{ "Type": "And", "Operands": ["byte ptr [0x10]", "0x42"] }]
8124251000000078563412;[{ "Type": "And", "Operands": ["dword ptr [0x10]", "0x12345678"] }] 8124251000000078563412;[{ "Type": "And", "Operands": ["dword ptr [0x10]", "0x12345678"] }]
8324251000000042;[{ "Type": "And", "Operands": ["dword ptr [0x10]", "0x42"] }] 8324251000000042;[{ "Type": "And", "Operands": ["dword ptr [0x10]", "0x42"] }]
2004251000000000;[{ "Type": "And", "Operands": ["byte ptr [0x10]", "al"] }] 20042510000000;[{ "Type": "And", "Operands": ["byte ptr [0x10]", "al"] }]
2204251000000000;[{ "Type": "And", "Operands": ["al", "byte ptr [0x10]"] }] 22042510000000;[{ "Type": "And", "Operands": ["al", "byte ptr [0x10]"] }]
2104251000000000;[{ "Type": "And", "Operands": ["dword ptr [0x10]", "eax"] }] 21042510000000;[{ "Type": "And", "Operands": ["dword ptr [0x10]", "eax"] }]
2304251000000000;[{ "Type": "And", "Operands": ["eax", "dword ptr [0x10]"] }] 23042510000000;[{ "Type": "And", "Operands": ["eax", "dword ptr [0x10]"] }]

Can't render this file because it contains an unexpected character in line 6 and column 11.

View File

@ -23,8 +23,9 @@ FF10;[{ "Type": "Call", "Operands": ["dword ptr [eax]"] }]
FF11;[{ "Type": "Call", "Operands": ["dword ptr [ecx]"] }] FF11;[{ "Type": "Call", "Operands": ["dword ptr [ecx]"] }]
FF12;[{ "Type": "Call", "Operands": ["dword ptr [edx]"] }] FF12;[{ "Type": "Call", "Operands": ["dword ptr [edx]"] }]
FF13;[{ "Type": "Call", "Operands": ["dword ptr [ebx]"] }] FF13;[{ "Type": "Call", "Operands": ["dword ptr [ebx]"] }]
FF14;[{ "Type": "Call", "Operands": ["dword ptr [esp]"] }] # TODO: these are not recognized by ghidra, but these seem to be valid x86 instructions.
FF15;[{ "Type": "Call", "Operands": ["dword ptr [ebp]"] }] # FF14;[{ "Type": "Call", "Operands": ["dword ptr [esp]"] }]
# FF15;[{ "Type": "Call", "Operands": ["dword ptr [ebp]"] }]
FF16;[{ "Type": "Call", "Operands": ["dword ptr [esi]"] }] FF16;[{ "Type": "Call", "Operands": ["dword ptr [esi]"] }]
FF17;[{ "Type": "Call", "Operands": ["dword ptr [edi]"] }] FF17;[{ "Type": "Call", "Operands": ["dword ptr [edi]"] }]

Can't render this file because it contains an unexpected character in line 6 and column 15.

View File

@ -4,7 +4,7 @@ RawBytes;Instructions
# MOVS - Move string # MOVS - Move string
A4;[{ "Type": "MovsB", "Operands": [] }] A4;[{ "Type": "MovsB", "Operands": [] }]
A5;[{ "Type": "MovsD", "Operands": [] }] A5;[{ "Type": "MovsD", "Operands": ["dword ptr es:[edi]", "dword ptr ds:[esi]"] }]
66A5;[{ "Type": "MovsW", "Operands": [] }] 66A5;[{ "Type": "MovsW", "Operands": [] }]
# CMPS - Compare string # CMPS - Compare string
@ -28,12 +28,12 @@ AB;[{ "Type": "StosD", "Operands": [] }]
66AB;[{ "Type": "StosW", "Operands": [] }] 66AB;[{ "Type": "StosW", "Operands": [] }]
# REP prefix with string instructions # REP prefix with string instructions
F3A4;[{ "Type": "RepMovsB", "Operands": [] }] F3A4;[{ "Type": "RepMovsB", "Operands": ["dword ptr es:[edi]", "dword ptr ds:[esi]"] }]
F3A5;[{ "Type": "RepMovsD", "Operands": [] }] F3A5;[{ "Type": "RepMovsD", "Operands": ["dword ptr es:[edi]", "dword ptr ds:[esi]"] }]
F366A5;[{ "Type": "RepMovsW", "Operands": [] }] F366A5;[{ "Type": "RepMovsW", "Operands": ["dword ptr es:[edi]", "dword ptr ds:[esi]"] }]
F3AA;[{ "Type": "RepStosB", "Operands": [] }] F3AA;[{ "Type": "RepStosB", "Operands": ["dword ptr es:[edi]"] }]
F3AB;[{ "Type": "RepStosD", "Operands": [] }] F3AB;[{ "Type": "RepStosD", "Operands": ["dword ptr es:[edi]"] }]
F366AB;[{ "Type": "RepStosW", "Operands": [] }] F366AB;[{ "Type": "RepStosW", "Operands": ["dword ptr es:[edi]"] }]
# REPE/REPZ prefix with string instructions # REPE/REPZ prefix with string instructions
F3A6;[{ "Type": "RepeCmpsB", "Operands": [] }] F3A6;[{ "Type": "RepeCmpsB", "Operands": [] }]

Can't render this file because it contains an unexpected character in line 6 and column 7.