From 2f08c7b812b9fc24cc7274d052a24cd8f6f9ac6f Mon Sep 17 00:00:00 2001 From: Kevin Phoenix Date: Tue, 10 Dec 2024 18:12:58 -0700 Subject: [PATCH] Implement disasm for ArchPcode (#254) --- archinfo/arch_pcode.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/archinfo/arch_pcode.py b/archinfo/arch_pcode.py index 512b174..6d18406 100644 --- a/archinfo/arch_pcode.py +++ b/archinfo/arch_pcode.py @@ -143,3 +143,9 @@ def _get_language_by_id(lang_id) -> "pypcode.ArchLanguage": if lang.id == lang_id: return lang raise ArchError("Language not found") + + def disasm(self, bytestring, addr=0, thumb=False): + ctx = pypcode.Context(self.name) + ctx.setVariableDefault("TMode", 1 if thumb else 0) + instructions = ctx.disassemble(bytestring, addr, 0, len(bytestring), 0).instructions + return "\n".join(f"{insn.addr.offset:#x}:\t{insn.mnem} {insn.body}" for insn in instructions)