def alloc(size, name): """Allocates a segment of the given size.""" # first lets get the last segment in this binary last_seg_end = idaapi.get_last_seg().endEA # and the first first_seg_start = idaapi.get_first_seg().startEA # now see how many bytes we have from there to 0xFFFFFFFF bytes_high = 0xFFFFFFFF - last_seg_end # now see how many bytes we have from 0x0 to the first segments start bytes_low = first_seg_start # check where we have more room if bytes_high > bytes_low: print "[*] segment.py: there is room above current segments" new_seg_start = last_seg_end + 0x10000 new_seg_start = new_seg_start & 0xFFFF0000 else: print "[*] segment.py: there is room below current segments" new_seg_start = 0 + 0x1000 idc.SegCreate(new_seg_start, new_seg_start + size, 0, True, 3, 2) idc.SegRename(new_seg_start, name) return new_seg_start
def alloc(size, name): '''Allocates a segment of the given size.''' # first lets get the last segment in this binary last_seg_end = idaapi.get_last_seg().endEA # and the first first_seg_start = idaapi.get_first_seg().startEA # now see how many bytes we have from there to 0xFFFFFFFF bytes_high = 0xFFFFFFFF - last_seg_end # now see how many bytes we have from 0x0 to the first segments start bytes_low = first_seg_start # check where we have more room if bytes_high > bytes_low: print "[*] segment.py: there is room above current segments" new_seg_start = last_seg_end + 0x10000 new_seg_start = new_seg_start & 0xFFFF0000 else: print "[*] segment.py: there is room below current segments" new_seg_start = 0 + 0x1000 idc.SegCreate(new_seg_start, new_seg_start + size, 0, True, 3, 2) idc.SegRename(new_seg_start, name) return new_seg_start
def enum_all_segments(): segm = idaapi.get_first_seg() segments = list() while segm is not None: segments.append(segm) segm = idaapi.get_next_seg(segm.start_ea) return segments
def end_address(): last_ea = idc.BADADDR seg = idaapi.get_first_seg() while seg: last_ea = seg.endEA seg = idaapi.get_next_seg(last_ea) return last_ea
def ida_iter_segments(): seg = idaapi.get_first_seg() while seg: # TODO: CRITICAL!! Figure out how to calculate segment file size yield SegmentTuple(name=idaapi.get_segm_name(seg), perm=seg.perm, startEA=seg.startEA, endEA=seg.endEA, offset=ida_loader.get_fileregion_offset( seg.startEA)) seg = idaapi.get_next_seg(seg.startEA)
def run(self, arg): global qira_address idaapi.msg("[QIRA Plugin] Syncing with Qira\n") # sync names for i in range(idaapi.get_nlist_size()): ws_send("setname 0x%x %s" % (idaapi.get_nlist_ea(i), idaapi.get_nlist_name(i))) # sync comment addr = idaapi.get_segm_base(idaapi.get_first_seg()) while addr != idaapi.BADADDR: for rpt in [True, False]: update_comment(addr, rpt) addr = idaapi.nextaddr(addr)
def send_comments(self): start = idaapi.get_segm_base(idaapi.get_first_seg()) cur = start while True: if cur != idc.BADADDR: cmt = idaapi.get_cmt(cur, 0) if (cmt is not None) and (cmt != idc.BADADDR): self.cmd = "setcmt 0x%x %s" % (cur, cmt) # debugging if DEBUG: idaapi.msg( "[%s] send_comments: EA [0x%x], Comment [%s]\n" % (self.wanted_name, cur, cmt,)) self.ws_send(self.cmd) else: break cur = idc.NextAddr(cur) return True
def start_address(): return idaapi.get_first_seg().startEA