def dis(num, addr=None): """ Disassemble 'num' opcodes from the current seek and returns the output """ if addr == None: return r.cmd("pd %d"%num) return r.cmd("pd %d @ 0x%x"%(num,addr))
def str(addr=None): """ Returns a zero-terminated string found in current seek """ if addr == None: return r.cmd("pz").strip() return r.cmd("pz @ 0x%x"%addr).strip()
def dis(num, addr=None): """ Disassemble 'num' opcodes from the current seek and returns the output """ if addr == None: return r.cmd("pd %d" % num) return r.cmd("pd %d @ 0x%x" % (num, addr))
def str(addr=None): """ Returns a zero-terminated string found in current seek """ if addr == None: return r.cmd("pz").strip() return r.cmd("pz @ 0x%x" % addr).strip()
def analyze_block(addr=None): """ Returns a hashtable containing the information of the analysis of the basic block found in the current seek. This is: 'offset', 'type', 'size', 'call#', 'n_calls', 'true', 'false' and 'bytes' """ if addr == None: return __str_to_hash(r.cmd("ab")) return __str_to_hash(r.cmd("ab @ 0x%x"%addr))
def analyze_opcode(addr=None): """ Returns a hashtable containing the information of the analysis of the opcode in the current seek. This is: 'opcode', 'size', 'type', 'bytes', 'offset', 'ref', 'jump' and 'fail' """ if addr == None: return __str_to_hash(r.cmd("ao")) return __str_to_hash(r.cmd("ao @ 0x%x"%addr))
def analyze_opcode(addr=None): """ Returns a hashtable containing the information of the analysis of the opcode in the current seek. This is: 'opcode', 'size', 'type', 'bytes', 'offset', 'ref', 'jump' and 'fail' """ if addr == None: return __str_to_hash(r.cmd("ao")) return __str_to_hash(r.cmd("ao @ 0x%x" % addr))
def analyze_block(addr=None): """ Returns a hashtable containing the information of the analysis of the basic block found in the current seek. This is: 'offset', 'type', 'size', 'call#', 'n_calls', 'true', 'false' and 'bytes' """ if addr == None: return __str_to_hash(r.cmd("ab")) return __str_to_hash(r.cmd("ab @ 0x%x" % addr))
def update(self): self.arch = r.cmd("e asm.arch") self.bits = eval(r.cmd("e asm.bits")) self.os = r.cmd("e asm.os") self.type = r.cmd("e file.type") self.size = eval(r.cmd("i~size[1]#1")) self.vaddr = eval(r.cmd("e io.vaddr")) self.paddr = eval(r.cmd("e io.paddr")) self.bigendian = r.cmd("e cfg.bigendian") self.entrypoint = eval(r.cmd("?v entrypoint"))
def update(): self.list = [] for a in r.cmd("CC").split('\n'): words = a.split('@') c = Comment() c.addr = eval(words[1]) c.comment = words[0][3:] self.list.append(cmt)
def seek_history(): ret = [] list = r.cmd("u*").split("\n") for i in range(1, len(list)): w = list[i].split(" ") if len(w) > 3: t = {} t["addr"] = w[0].strip() ret.append(t) return ret
def update(self): self.list = [] items = r.cmd("CF").split('\n') for a in items: words = a.split(' ') fun = Function() fun.size = eval(words[1]) fun.addr = eval(words[3]) fun.name = words[5] self.list.append(fun)
def update(self, addr): self.list = [] for a in r.cmd("Cx").split("\n"): words = a.split(' ') a_addr = eval(words[1]) a_endaddr = eval(words[3]) if addr == None or addr == a_endaddr: x = Xref() x.addr = a_addr x.endaddr = a_endaddr self.list.append(x)
def update(self): self.list = [] items = r.cmd("f~sym.").split('\n') for a in items: # addr size name words = a.split(' ') sec = Symbol() sec.name = words[2].replace('sym.','') sec.addr = eval(words[0]) sec.size = eval(words[1]) sec.endaddr = sec.addr + sec.size self.list.append(sec)
def dbg_backtrace(): ret = [] list = r.cmd("!bt").split("\n") for i in range(1, len(list)): w = list[i].split(" ") if len(w) > 3: t = {} t["addr"] = long(w[1].strip(),16) t["framesz"] = long(w[2].strip(),10) t["varsz"] = long(w[3].strip(),10) ret.append(t) return ret
def flag_list(mask): ret = [] list = r.cmd("f~%s"%mask).split("\n") for i in range(1, len(list)): w = list[i].split(" ") if len(w) > 3: t = {} t["addr"] = long(w[1].strip(),16) t["size"] = long(w[3].strip(),10) t["name"] = w[4].strip() ret.append(t) return ret
def write_history(): ret = [] list = r.cmd("wu").split("\n") for i in range(1, len(list)): w = list[i].split(" ") if len(w) > 3: t = {} t["size"] = long(w[2].strip(), 10) t["addr"] = long(w[3].strip(), 16) # TODO moar nfo here ret.append(t) return ret
def flag_list(mask): ret = [] list = r.cmd("f~%s" % mask).split("\n") for i in range(1, len(list)): w = list[i].split(" ") if len(w) > 3: t = {} t["addr"] = long(w[1].strip(), 16) t["size"] = long(w[3].strip(), 10) t["name"] = w[4].strip() ret.append(t) return ret
def dbg_backtrace(): ret = [] list = r.cmd("!bt").split("\n") for i in range(1, len(list)): w = list[i].split(" ") if len(w) > 3: t = {} t["addr"] = long(w[1].strip(), 16) t["framesz"] = long(w[2].strip(), 10) t["varsz"] = long(w[3].strip(), 10) ret.append(t) return ret
def update(self): self.list = [] items = r.cmd("f~sym.").split('\n') for a in items: # addr size name words = a.split(' ') sec = Symbol() sec.name = words[2].replace('sym.', '') sec.addr = eval(words[0]) sec.size = eval(words[1]) sec.endaddr = sec.addr + sec.size self.list.append(sec)
def write_history(): ret = [] list = r.cmd("wu").split("\n") for i in range(1, len(list)): w = list[i].split(" ") if len(w) > 3: t = {} t["size"] = long(w[2].strip(),10) t["addr"] = long(w[3].strip(),16) # TODO moar nfo here ret.append(t) return ret
def update(self): self.list = [] items = r.cmd("f~section.").split('\n') sec = Section() for a in items: words = a.split(' ') if a.find('_end') == -1: sec = Section() sec.addr = eval(words[0]) sec.name = words[2].replace('section.','') else: sec.endaddr = eval(words[0]) sec.size = sec.endaddr - sec.addr if sec.name != '': self.list.append(sec)
def update(self): self.list = [] items = r.cmd("f~section.").split('\n') sec = Section() for a in items: words = a.split(' ') if a.find('_end') == -1: sec = Section() sec.addr = eval(words[0]) sec.name = words[2].replace('section.', '') else: sec.endaddr = eval(words[0]) sec.size = sec.endaddr - sec.addr if sec.name != '': self.list.append(sec)
def __init__(self, addr): for line in r.cmd("ao@%s" % addr): words = line.split('=') words[0] = words[0][:-1] # strip ' ' if words[0] == 'opcode': self.opcode = words[1] elif words[0] == 'size': self.size = eval(words[1]) elif words[0] == 'stackop': self.stackop = words[1] elif words[0] == 'type': self.type = words[1] elif words[0] == 'bytes': self.bytes = words[1] elif words[0] == 'offset': self.addr = words[1] elif words[0] == 'ref': self.ref = eval(words[1]) elif words[0] == 'jump': self.j_true = eval(words[1]) elif words[0] == 'fail': self.j_false = eval(words[1])
def update(self, addr): self.list = [] bb = BasicBlock() for line in r.cmd("ab 128 @ %s" % addr).split('\n'): words = line.split('=') words[0] = words[0][:-1] # strip ' ' if words[0] == 'offset': bb = BasicBlock() bb.addr = eval(words[1]) elif words[0] == 'type': bb.type = words[1] elif words[0] == 'size': bb.size = eval(words[1]) elif words[0] == 'true': bb.j_true = eval(words[1]) elif words[0] == 'false': bb.j_false = eval(words[1]) elif words[0] == 'bytes': bb.bytes = words[1] self.list.append(bb) elif words[0][:4] == 'call': bb.calls.append(eval(words[1]))
def __init__(self, addr): for line in r.cmd("ao@%s"%addr): words = line.split('=') words[0] = words[0][:-1] # strip ' ' if words[0] == 'opcode': self.opcode = words[1] elif words[0] == 'size': self.size = eval(words[1]) elif words[0] == 'stackop': self.stackop = words[1] elif words[0] == 'type': self.type = words[1] elif words[0] == 'bytes': self.bytes = words[1] elif words[0] == 'offset': self.addr = words[1] elif words[0] == 'ref': self.ref = eval(words[1]) elif words[0] == 'jump': self.j_true = eval(words[1]) elif words[0] == 'fail': self.j_false = eval(words[1])
def update(self, addr): self.list = [] bb = BasicBlock() for line in r.cmd("ab 128 @ %s"%addr).split('\n'): words = line.split('=') words[0] = words[0][:-1] # strip ' ' if words[0] == 'offset': bb = BasicBlock() bb.addr = eval(words[1]) elif words[0] == 'type': bb.type = words[1] elif words[0] == 'size': bb.size = eval(words[1]) elif words[0] == 'true': bb.j_true = eval(words[1]) elif words[0] == 'false': bb.j_false = eval(words[1]) elif words[0] == 'bytes': bb.bytes = words[1] self.list.append(bb) elif words[0][:4] == 'call': bb.calls.append(eval(words[1]))
def disassemble(addr, n): return r.cmd("pd %s@%d"%(n,addr))
def dbg_free(addr): r.cmd("!free %s" % addr)
def remove(addr): r.cmd("CF-@%s"%addr) r.cmd("f -%s"%addr)
def hash(algo, size): return r.cmd("#%s %d" % (algo, size))
def trace_reset(): r.cmd("at-")
def trace_at(addr): return __str_to_hash(r.cmd("at %s" % addr))
def dbg_register_get(name): r.cmd("!reg %s" % (name))
def make_dot(addr, file): r.cmd("s %s"%addr) r.cmd("agd %s"%file)
def make_png(addr, file): r.cmd("s %s"%addr) r.cmd("agd %s.dot"%file) r.cmd("!!dot -Tpng -o %s %s.dot"%(file,file)); r.cmd("!!rm %s.dot"%file);
def add_node(addr, size, cmd): r.cmd("gun %s %s %s"%(addr, size, cmd))
def remove(addr, str): r.cmd("CC -%s@%s"%(str, addr))
def add(addr, str): r.cmd("CC %s@%s"%(str, addr))
def add_edge(addr, endaddr): r.cmd("gue %s %s"%(addr, endaddr))
def dbg_dump(name): r.cmd("!dump %s" % name)
def dbg_restore(name): r.cmd("!restore %s" % name)
def analyze(addr): r.cmd(".af*@%s"%addr)
def dbg_register_set(name, value): r.cmd("!reg %s=%s" % (name, value))
def cmd(str): return r.cmd(str)
def trace_list(): return r.cmd("at*").split("\n")
def dot(file): r.cmd("gud > %s"%file)
def trace_ranges(): return r.cmd("at").split("\n")
def add(name, addr, size): r.cmd("CF %s@%s"%(size,addr)) r.cmd("f %s@%s"%(name,addr))
def graph(addr=None): if addr == None: r.cmd("ag") else: r.cmd("ag @ %s" % addr)
def reset(): r.cmd("gur")
def quit(num): r.cmd("q! %d" % num)
def dbg_alloc(size): return r.cmd("!alloc %s" % size)
def idc_import(file): r.cmd(".!rsc idc2rdb %s"%file)
def view(): r.cmd("guv")