Esempio n. 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()
Esempio n. 2
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()