def getregs(self): # TODO, change to MI? info_register_text = gdb.execute("info registers", False, True) # first, uniform the output line_per_register = filter(None, info_register_text.replace('\t', ' ').split('\n')) # then, get with the first two fields, the name and its value names_and_values = dict(map(lambda line: line.split()[:2], line_per_register)) regs_struct = ptrace_registers_t() field_names = map(lambda definition: definition[0], regs_struct._fields_) if RUNNING_LINUX: for n in field_names: if n in ("fs_base", "gs_base"): continue # TODO see https://www.sourceware.org/ml/gdb-patches/2015-11/msg00078.html if n.startswith("__"): #__cs, __ds, __es, __fs, __gs, __ss v = names_and_values[n[2:]] # TODO use the value of xx for __xx? elif n == 'orig_eax': #beware! no all the registers are shown in "info registers" v = hex(int(gdb.execute("print $orig_eax", False, True).split("=")[1])) elif n == 'orig_rax': #beware! no all the registers are shown in "info registers" v = hex(int(gdb.execute("print $orig_rax", False, True).split("=")[1])) else: v = names_and_values[n] if v.endswith("L"): v = v[:-1] setattr(regs_struct, n, int(v, 16)) # gdb returns the values in hex else: raise NotImplementedError("Not implemented yet!: The get registers may be supported for other architectures in the future.") return regs_struct
def ptrace_getregs(pid): regs = ptrace_registers_t() iov = iovec_struct() setattr(iov, "buf", addressof(regs)) setattr(iov, "len", sizeof(regs)) ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, addressof(iov)) return regs
def ptrace_getregs(pid): regs = ptrace_registers_t() ptrace(PTRACE_GETREGS, pid, addressof(regs)) return regs