From 3098e250232e248f6376d444ec656c7639694466 Mon Sep 17 00:00:00 2001
From: dd86k
Date: Sat, 12 Oct 2024 11:38:13 -0400
Subject: [PATCH] pe: Force return ppcle
---
dumper/dumper.d | 3 ++-
src/adbg/disassembler.d | 12 ++++--------
src/adbg/objects/pe.d | 4 ++--
3 files changed, 8 insertions(+), 11 deletions(-)
diff --git a/dumper/dumper.d b/dumper/dumper.d
index 1fd92ab..e3f42f2 100644
--- a/dumper/dumper.d
+++ b/dumper/dumper.d
@@ -571,7 +571,8 @@ Ldisasm:
goto Ldisasm;
case disasmIllegalInstruction:
print_disasm_line(&op, "illegal");
- goto Ldisasm;
+ // NOTE: No instruction length on error, so exit.
+ return 0;
case disasmEndOfData:
return 0;
default:
diff --git a/src/adbg/disassembler.d b/src/adbg/disassembler.d
index 10422b3..d617c6b 100644
--- a/src/adbg/disassembler.d
+++ b/src/adbg/disassembler.d
@@ -20,7 +20,6 @@ import core.stdc.stdlib : malloc, free;
// TODO: Function to format machine code
// TODO: Redo Disassembler API
-// - Rename prefix to adbg_disasm_
// - adbg_disasm_open
// - adbg_disasm_close
// - adbg_disasm_supported_machines
@@ -29,7 +28,7 @@ import core.stdc.stdlib : malloc, free;
// - adbg_disasm_buffer_stepin
// - adbg_disasm (with buffer and its length)
// - Move process wrappers to debugger module
-// - adbg_debugger_disassemble_at(memoryloc)
+// - adbg_debugger_disassemble_at(process, location, opcode)
// NOTE: Longest architectural instruction contest
// x86: 15 bytes
@@ -338,7 +337,7 @@ int adbg_dis_step(adbg_disassembler_t *dasm, adbg_opcode_t *opcode) {
version (Trace) trace("buffer_size=%u", cast(uint)dasm.buffer_size);
- opcode.address = dasm.address_base; // Save before CS modifies it
+ opcode.address = dasm.address_base; // Save address before CS modifies it
//TODO: Consider replacing mnemonic by "error" or "illegal"
// Needs to be something specific (e.g., .bytes 0x11 0x22)
@@ -352,11 +351,8 @@ int adbg_dis_step(adbg_disassembler_t *dasm, adbg_opcode_t *opcode) {
if (cs_errno(dasm.cs_handle) != CS_ERR_OK)
return adbg_oops(AdbgError.libCapstone, &dasm.cs_handle);
- // NOTE: Can't reliably check buffer_size left.
-
- // Can't decode instruction but no errors happened?
- // If there were no other instructions decoded, must be illegal
- if (dasm.decoded_count == 0)
+ // No length: Error.
+ if (dasm.cs_inst.size == 0)
return adbg_oops(AdbgError.disasmIllegalInstruction);
return adbg_oops(AdbgError.disasmEndOfData);
diff --git a/src/adbg/objects/pe.d b/src/adbg/objects/pe.d
index 8bfc95c..c9432f7 100644
--- a/src/adbg/objects/pe.d
+++ b/src/adbg/objects/pe.d
@@ -2263,8 +2263,8 @@ AdbgMachine adbg_object_pe_machine_value(uint machine) {
case PE_MACHINE_MIPS16: return AdbgMachine.mips16;
case PE_MACHINE_MIPSFPU: return AdbgMachine.mipsfpu;
case PE_MACHINE_MIPSFPU16: return AdbgMachine.mips16fpu;
- case PE_MACHINE_POWERPC: return AdbgMachine.ppc;
- case PE_MACHINE_POWERPCFP: return AdbgMachine.ppcfpu;
+ case PE_MACHINE_POWERPC, PE_MACHINE_POWERPCFP:
+ return AdbgMachine.ppcle;
case PE_MACHINE_R3000: return AdbgMachine.mips;
case PE_MACHINE_R4000: return AdbgMachine.mipsii;
case PE_MACHINE_R10000: return AdbgMachine.mipsiv;