Example #1
0
def iterate(fn):
    '''Iterate through all the instructions in each chunk of the specified function'''
    for start,end in chunks(fn):
        for ea in database.iterate(start, end):
            yield ea
        continue
    return
Example #2
0
def iterate(fn):
    '''Iterate through all the instructions in each chunk of the specified function'''
    for start, end in chunks(fn):
        for ea in database.iterate(start, end):
            yield ea
        continue
    return
Example #3
0
def iterate(key=None):
    '''Iterate through all the instructions in each chunk of the specified function'''
    for start,end in chunks(key):
        for ea in itertools.ifilter(database.type.isCode, database.iterate(start, end)):
            yield ea
        continue
    return
Example #4
0
def __process_functions():
    p = ui.progress()
    globals = internal.comment.globals.address()

    funcs = list(database.functions())
    p.update(current=0, max=len(funcs), title="Pre-building tagcache...")
    p.open()
    for i, fn in enumerate(funcs):
        chunks = list(function.chunks(fn))

        text = functools.partial("{:x} : Processing function {:d} of {:d} : ({:d} chunk{:s})".format, fn, i, len(funcs))
        p.update(current=i)

        contents = set(internal.comment.contents.address(fn))
        for ci, (l, r) in enumerate(chunks):
            p.update(text=text(len(chunks), 's' if len(chunks) != 1 else ''), tooltip="Chunk #{:d} : {:x} - {:x}".format(ci, l, r))
            for ea in database.iterate(l, r):
                # FIXME: no need to iterate really since we should have
                #        all of the addresses
                for k, v in database.tag(ea).iteritems():
                    if ea in globals: internal.comment.globals.dec(ea, k)
                    if ea not in contents: internal.comment.contents.inc(ea, k, target=fn)
                continue
            continue
        continue
    p.close()
Example #5
0
 def stackdelta(left, right):
     '''return the minimum,maximum delta of the range of instructions'''
     min,max = 0,0
     for ea in database.iterate(left,right):
         sp = getSpDelta(ea)
         min = sp if sp < min else min
         max = max if sp < max else sp
     return min,max
Example #6
0
 def stackdelta(left, right):
     '''return the minimum,maximum delta of the range of instructions'''
     min, max = 0, 0
     for ea in database.iterate(left, right):
         sp = getSpDelta(ea)
         min = sp if sp < min else min
         max = max if sp < max else sp
     return min, max
Example #7
0
 def __select(fn, q):
     for start,end in chunks(fn):
         for ea in database.iterate(start, end):
             d = database.tag(ea)        # FIXME: bmn noticed .select yielding empty records
             if d and q.has(d):
                 yield ea
             continue
         continue
     return
Example #8
0
 def __select(fn, q):
     for start,end in chunks(fn):
         for ea in database.iterate(start, end):
             d = database.tag(ea)        # FIXME: bmn noticed .select yielding empty records
             if d and q.has(d):
                 yield ea
             continue
         continue
     return
Example #9
0
def removing_func_tail(pfn, tail):
    global State
    if State != state.ready: return
    # tail = area_t
    for ea in database.iterate(tail.startEA, tail.endEA):
        for k in database.tag(ea):
            internal.comment.contents.dec(ea, k, target=pfn.startEA)
            internal.comment.globals.inc(ea, k)
        continue
    return
Example #10
0
def customnames():
    '''Add all custom names defined in the database to the tagcache as "__name__"'''
    # FIXME: first delete all the custom names '__name__' tag
    left, right = db.range()
    for ea in db.iterate(left, right - 1):
        fn = idaapi.get_func(ea)
        ctx = internal.comment.globals if not fn or fn.startEA == ea else internal.comment.contents
        if db.type.has_customname(ea):
            ctx.inc(ea, '__name__')
        continue
    return
Example #11
0
def add_func(pfn):
    global State
    if State != state.ready: return
    # convert all globals into contents
    for (l,r) in function.chunks(pfn):
        for ea in database.iterate(l, r):
            for k in database.tag(ea):
                internal.comment.globals.dec(ea, k)
                internal.comment.contents.inc(ea, k, target=pfn.startEA)
            continue
        continue
    return
Example #12
0
def set_func_end(pfn, new_end):
    global State
    if State != state.ready: return
    # new_end has added addresses to function
    # replace globals with contents
    if new_end > pfn.endEA:
        for ea in database.iterate(pfn.endEA, new_end):
            for k in database.tag(ea):
                internal.comment.globals.dec(ea, k)
                internal.comment.contents.inc(ea, k, target=pfn.startEA)
            continue
        return

    # new_end has removed addresses from function
    # replace contents with globals
    elif new_end < pfn.endEA:
        for ea in database.iterate(new_end, pfn.endEA):
            for k in database.tag(ea):
                internal.comment.contents.dec(ea, k, target=pfn.startEA)
                internal.comment.globals.inc(ea, k)
            continue
        return
    return
Example #13
0
def do_data():
    addr, tags = {}, {}
    left, right = db.range()
    print 'fetching global tags'
    for ea in db.iterate(left, right - 1):
        f = idaapi.get_func(ea)
        if f is not None: continue
        res = db.tag(ea)
        #res.pop('name', None)
        for k, v in res.iteritems():
            addr[ea] = addr.get(ea, 0) + 1
            tags[k] = tags.get(k, 0) + 1
        continue
    return addr, tags
Example #14
0
def extracomments():
    '''Add all extra cmts in the database to the tagcache as "__name__"'''
    # FIXME: first delete all the custom names '__name__' tag
    left, right = db.range()
    for ea in db.iterate(left, right - 1):
        fn = idaapi.get_func(ea)
        ctx = internal.comment.contents if fn else internal.comment.globals

        count = db.extra.count(ea, idaapi.E_PREV)
        if count: [ctx.inc(ea, '__extra_prefix__') for i in xrange(count)]

        count = db.extra.count(ea, idaapi.E_NEXT)
        if count: [ctx.inc(ea, '__extra_suffix__') for i in xrange(count)]
    return
Example #15
0
 def codeRefs(ea):
     fn = top(ea)
     resultData,resultCode = [],[]
     for l,r in chunks(fn):
         for ea in database.iterate(l,r):
             if len(database.down(ea)) == 0:
                 insn = idaapi.ua_mnem(ea)
                 if insn and insn.startswith('call'):
                     resultCode.append((ea, 0))
                 continue
             resultData.extend( (ea,x) for x in database.dxdown(ea) )
             resultCode.extend( (ea,x) for x in database.cxdown(ea) if not contains(fn,x) )
         continue
     return resultData,resultCode
Example #16
0
 def codeRefs(ea):
     fn = top(ea)
     resultData,resultCode = [],[]
     for l,r in chunks(fn):
         for ea in database.iterate(l,r):
             if len(database.down(ea)) == 0:
                 insn = idaapi.ua_mnem(ea)
                 if insn and insn.startswith('call'):
                     resultCode.append((ea, 0))
                 continue
             resultData.extend( (ea,x) for x in database.dxdown(ea) )
             resultCode.extend( (ea,x) for x in database.cxdown(ea) if not contains(fn,x) )
         continue
     return resultData,resultCode
Example #17
0
def del_func(pfn):
    global State
    if State != state.ready: return
    # convert all contents into globals
    for (l,r) in function.chunks(pfn):
        for ea in database.iterate(l, r):
            for k in database.tag(ea):
                internal.comment.contents.dec(ea, k, target=pfn.startEA)
                internal.comment.globals.inc(ea, k)
            continue
        continue

    # remove all function tags
    for k in function.tag(pfn.startEA):
        internal.comment.globals.dec(pfn.startEA, k)
    return
Example #18
0
        SetDelayed = pyml.function("SetDelayed")
        Set = pyml.function("Set")
        List = pyml.function("List")
        Hold = pyml.function("Hold")
        RuleDelayed = pyml.function("RuleDelayed")
        Rule = pyml.function("Rule")

        call = pyml.function("call")
        symcall = pyml.function("symcall")
        
        rules = []
        max = len(database.functions())
        for i,ea in enumerate(database.functions()):
            result = []
            for l,r in function.chunks(ea):
                for x in database.iterate(l,r):
                    address,size,insn = x,idc.ItemSize(x),idc.GetDisasm(x)
                    insn = re.sub(" +", " ", insn)
                    insn = insn.replace("short", "")
                    insn = insn.replace("dword", "")
                    insn = insn.replace("offset", "")
                    insn = insn.replace("large", "")
                    insn = insn.replace("ptr", "")
                    insn = insn.replace("[", "")
                    insn = insn.replace("]", "")
                    if " " in insn:
                        insn = insn.replace(" ", "|", 1)
                        insn = insn.replace(",", "|")
                        insn = insn.replace(" ", "")
                    fn = insn.split("|")
                    name = fn.pop(0)