Пример #1
0
def func_quick(F):
    dump = F.dump
    select_dump(dump)
    es.resetLog()
    msg = str(F)
    ns = {}
    ns['funcname'] = F.name
    ns['funcaddr'] = hex(F.addr)
    ns['dumpname'] = dump.bin
    ns['sourcefile'] = srcguess.sourcefile(dump, F.addr)
    ns['codeflow'] = ""
    ns['decompiled'] = "in progress..."

    ns['lines'] = disasm_html(dump, F.addr, F.end)
    ns['calls'] = calls_html_quick(dump, F)
    ns['callers'] = callers_html_quick(dump, F.addr, context=0)
    ns['references'] = refs_html(dump, func=F.addr, context=-1)
    
    f = openf(dump.bin, funcfile(F))
    print >> f, Template(file="Func.tmpl", searchList=[ns])
    f.close()        

    f = openf(dump.bin, funcsigfile(F))
    cPickle.dump(refsig(F), f)
    f.close()
Пример #2
0
def func_index(dump):
    print "Creating function index..."
    Fn  = [dump.Fun(a) for a in sorted(dump.FUNCS.keys(), key=lambda x: dump.Fun(x).name.lower())]
    print len(Fn)
    Fa  = [dump.Fun(a) for a in sorted(dump.FUNCS.keys())]
    print len(Fa)
    Fs  = [dump.Fun(a) for a in sorted(dump.FUNCS.keys(), key=lambda x: -dump.Fun(x).size)]
    print len(Fs)
    Fcf = [dump.Fun(a) for a in sorted(dump.FUNCS.keys(), key=lambda x: -len(filter(lambda av: av[1] in dump.FUNCS, find_refs(dump, None, x))))]
    print len(Fcf)
    Fct = [dump.Fun(a) for a in sorted(dump.FUNCS.keys(), key=lambda x: -len(find_refs(dump, x)))]
    print len(Fct)
    Fsf = [dump.Fun(a) for a in sorted(dump.FUNCS.keys(), key=lambda x: srcguess.sourcefile(dump, x) or "~")]
    print len(Fsf)

    dinosaur = [(Fn, "functions-by-name.htm", lambda f: link2func(f), 'name'),
                (Fa, "functions-by-addr.htm", lambda f: link2addr(f.addr), "address"),
                (Fs, "functions-by-size.htm", lambda f: f.size, "size"),
                (Fcf, "functions-by-callsfrom.htm", lambda f: len(filter(lambda av: av[1] in dump.FUNCS, find_refs(dump, None, f.addr))), "callsfrom"),
                (Fct, "functions-by-callsto.htm", lambda f: len(find_refs(dump, f.addr)), "callsto"),
                (Fsf, "functions-by-source.htm", lambda f: srcguess.sourcefile(dump, f.addr), "source")]

    table(dump, "FuncIndex.tmpl", dinosaur)
Пример #3
0
def func_full(F):
    print F
    dump = F.dump
    select_dump(dump)
    es.resetLog()
    msg = str(F)
    ns = {}
    ns['funcname'] = F.name
    ns['funcaddr'] = hex(F.addr)
    ns['dumpname'] = dump.bin
    ns['sourcefile'] = srcguess.sourcefile(dump, F.addr)
    ns['codeflow'] = ""
    ns['decompiled'] = "too complex?"

    try:
        #~ es.resetLog()
        print "code paths..."
        CP = es.find_code_paths(F.addr, timeout=10)

        if len(CP) < 2000:
            try:
                print "decompiling..."
                ns['decompiled'] = deco.P.doprint(deco.decompile(F.addr, CP))
            except:
                ns['decompiled'] = "whoops..."
        else:
            ns['decompiled'] = "too many code paths (%d, limit=2000)" % len(CP)
            
        svg = change_ext(funcfile(F), ".svg")
        svgf = os.path.join(change_ext(dump.bin,""), svg)
        es.create_graph(CP, svgf)
        sv = open(svgf)
        svgdata = sv.read()
        sv.close()
        #svgdata = re.sub("@([a-zA-Z0-9_]+)", '<a xlink:href="\\1.htm" style="fill: blue" xlink:show="new" target="_top">\\1</a>', svgdata)
        for m in re.findall("@([^\ \>]+)", svgdata):
            try:
                fun = dump.Fun(m)
            except:
                continue
            
            svgdata = svgdata.replace("@" + str(fun.name), xlink2func(fun))
        wid = int(re.search('<svg width="([0-9]+)pt"', svgdata).groups()[0])
        sv = open(svgf,"w")
        sv.write(svgdata)
        sv.close()
        es.log.flush()
        #~ align = "align='right'" if wid < 600 else ""
        #~ print >> f, "<embed src='%s' %s >" % (svg,align)
        ns['codeflow'] = svg
        ns['codeflow_width'] = "%spt" % wid
    except:
        traceback.print_exc()
        pass

    ns['lines'] = disasm_html(dump, F.addr, F.end)
    ns['calls'] = calls_html(dump, F)
    ns['callers'] = callers_html(dump, F.addr, context=0)
    ns['references'] = refs_html(dump, func=F.addr, context=-1)
    
    f = openf(dump.bin, funcfile(F))
    print >> f, Template(file="Func.tmpl", searchList=[ns])
    f.close()