Skip to content

Commit

Permalink
pe: Force return ppcle
Browse files Browse the repository at this point in the history
  • Loading branch information
dd86k committed Oct 12, 2024
1 parent e48566c commit 3098e25
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
3 changes: 2 additions & 1 deletion dumper/dumper.d
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 4 additions & 8 deletions src/adbg/disassembler.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/adbg/objects/pe.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3098e25

Please sign in to comment.