def disassemble_at(self, start, size, pc=None): code = struct.unpack(f"<{size // 4}I", self.iface.readmem(start, size)) c = ARMAsm(".inst " + ",".join(str(i) for i in code), start) lines = list(c.disassemble()) if pc is not None: idx = (pc - start) // 4 lines[idx] = " *" + lines[idx][2:] for i in lines: print(" " + i)
def handle_impdef(self, ctx): if ctx.esr.ISS == 0x20: return self.handle_msr(ctx, self.u.mrs(AFSR1_EL1)) start = ctx.elr_phys code = struct.unpack("<I", self.iface.readmem(ctx.elr_phys, 4)) c = ARMAsm(".inst " + ",".join(str(i) for i in code), ctx.elr_phys) insn = "; ".join(c.disassemble()) print(f"IMPDEF exception on: {insn}") return False
def exec(self, op, r0=0, r1=0, r2=0, r3=0, *, silent=False, call=None, ignore_exceptions=False): if callable(call): region = REGION_RX_EL1 elif isinstance(call, tuple): call, region = call else: call, region = self.exec_modes[call] if isinstance(op, tuple) or isinstance(op, list): func = struct.pack(f"<{len(op)}II", *op, 0xd65f03c0) # ret elif isinstance(op, int): func = struct.pack("<II", op, 0xd65f03c0) # ret elif isinstance(op, str): c = ARMAsm(op + "; ret", self.code_buffer) func = c.data elif isinstance(op, bytes): func = op else: raise ValueError() assert len(func) < self.CODE_BUFFER_SIZE self.iface.writemem(self.code_buffer, func) self.proxy.dc_cvau(self.code_buffer, len(func)) self.proxy.ic_ivau(self.code_buffer, len(func)) self.proxy.set_exc_guard(GUARD.SKIP | (GUARD.SILENT if silent else 0)) ret = call(self.code_buffer | region, r0, r1, r2, r3) if not ignore_exceptions: cnt = self.proxy.get_exc_count() self.proxy.set_exc_guard(GUARD.OFF) if cnt: raise ProxyError("Exception occurred") else: self.proxy.set_exc_guard(GUARD.OFF) return ret
def exec(self, op, r0=0, r1=0, r2=0, r3=0, *, silent=False, call=None, region=REGION_RX_EL1): if call is None: call = self.proxy.call if isinstance(op, int): func = struct.pack("<II", op, 0xd65f03c0) # ret elif isinstance(op, str): c = ARMAsm(op + "; ret", self.code_buffer) func = c.data else: raise ValueError() self.iface.writemem(self.code_buffer, func) self.proxy.dc_cvau(self.code_buffer, 8) self.proxy.ic_ivau(self.code_buffer, 8) self.proxy.set_exc_guard(GUARD.SKIP | (GUARD.SILENT if silent else 0)) ret = call(self.code_buffer | region, r0, r1, r2, r3) cnt = self.proxy.get_exc_count() self.proxy.set_exc_guard(GUARD.OFF) if cnt: raise ProxyError("Exception occurred") return ret