Skip to content

Commit

Permalink
Adds constants to gef.py for M68K support (in gef-extras) (#757)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugsy committed Dec 6, 2021
1 parent 702858c commit 3efb77b
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ class Elf:
AARCH64 = 0xb7
RISCV = 0xf3
IA64 = 0x32
M68K = 0x04

ET_RELOC = 1
ET_EXEC = 2
Expand Down Expand Up @@ -2740,6 +2741,20 @@ def mprotect_asm(cls, addr, size, perm):
return "; ".join(insns)


SUPPORTED_ARCHITECTURES = {
"ARM": ARM, Elf.ARM: ARM,
"AARCH64": AARCH64, "ARM64": AARCH64, Elf.AARCH64: AARCH64,
"X86": X86, Elf.X86_32: X86,
"X86_64": X86_64, Elf.X86_64: X86_64, "i386:x86-64": X86_64,
"PowerPC": PowerPC, "PPC": PowerPC, Elf.POWERPC: PowerPC,
"PowerPC64": PowerPC64, "PPC64": PowerPC64, Elf.POWERPC64: PowerPC64,
"RISCV": RISCV, Elf.RISCV: RISCV,
"SPARC": SPARC, Elf.SPARC: SPARC,
"SPARC64": SPARC64, Elf.SPARC64: SPARC64,
"MIPS": MIPS, Elf.MIPS: MIPS,
}


def write_memory(address, buffer, length=0x10):
"""Write `buffer` at address `address`."""
return gdb.selected_inferior().write_memory(address, buffer, length)
Expand Down Expand Up @@ -3759,23 +3774,11 @@ def set_arch(arch=None, default=None):
set that arch.
Return the selected arch, or raise an OSError.
"""
arches = {
"ARM": ARM, Elf.ARM: ARM,
"AARCH64": AARCH64, "ARM64": AARCH64, Elf.AARCH64: AARCH64,
"X86": X86, Elf.X86_32: X86,
"X86_64": X86_64, Elf.X86_64: X86_64, "i386:x86-64": X86_64,
"PowerPC": PowerPC, "PPC": PowerPC, Elf.POWERPC: PowerPC,
"PowerPC64": PowerPC64, "PPC64": PowerPC64, Elf.POWERPC64: PowerPC64,
"RISCV": RISCV, Elf.RISCV: RISCV,
"SPARC": SPARC, Elf.SPARC: SPARC,
"SPARC64": SPARC64, Elf.SPARC64: SPARC64,
"MIPS": MIPS, Elf.MIPS: MIPS,
}
global current_arch, current_elf

if arch:
try:
current_arch = arches[arch.upper()]()
current_arch = SUPPORTED_ARCHITECTURES[arch.upper()]()
return current_arch
except KeyError:
raise OSError("Specified arch {:s} is not supported".format(arch.upper()))
Expand All @@ -3786,11 +3789,11 @@ def set_arch(arch=None, default=None):

arch_name = current_elf.e_machine if current_elf else get_arch()
try:
current_arch = arches[arch_name]()
current_arch = SUPPORTED_ARCHITECTURES[arch_name]()
except KeyError:
if default:
try:
current_arch = arches[default.upper()]()
current_arch = SUPPORTED_ARCHITECTURES[default.upper()]()
except KeyError:
raise OSError("CPU not supported, neither is default {:s}".format(default.upper()))
else:
Expand Down Expand Up @@ -8022,6 +8025,7 @@ def do_invoke(self, argv, *args, **kwargs):
Elf.AARCH64 : "AArch64",
Elf.RISCV : "RISC-V",
Elf.IA64 : "IA-64",
Elf.M68K : "M68K",
}

filename = args.filename or get_filepath()
Expand Down

0 comments on commit 3efb77b

Please sign in to comment.