コード例 #1
0
ファイル: data.py プロジェクト: neophack/epanos
 def make_input(d, fn):
     # NOTE mutates d
     var_map = ida.get_stkvar_map(ida.loc_by_name(fn))
     if var_map == {}:
         pass
     else:
         d[fn] = var_map
     return d
コード例 #2
0
ファイル: gen.py プロジェクト: nihilus/epanos
def run(externs, our_fns, cpp_filter, cpp_all, decompile=True):
    '''frozenset(str) -> frozenset(str) -> str -> str -> opt:bool -> [c_ast]'''
    global OUR_FNS, EXTERN_REG_MAP, STKVAR_MAP  # for repl convenience
    OUR_FNS = our_fns

    fn_segs = data.get_segs(['extern', '.text'])
    rodata_segs = data.get_segs(['.rodata', '.srdata'])
    data_segs = data.get_segs(['.data', '.bss'])
    lit_segs = data.get_segs(['.lit4', '.lit8'])

    num_lits = data.get_num_literals(lit_segs)
    str_lits = data.get_str_literals(rodata_segs)
    data_txt = data.get_data(data_segs, cpp_filter)

    # XXX FIXME this will be going away once we've added emitting numeric and
    # string constants directly at their site of use
    if decompile is True:
        for (k, v) in num_lits.iteritems():
            ty = type(v)
            if ty is ep_ct.cfloat:
                print 'float %s = %s;' % (k, v)
            elif ty is ep_ct.cdouble:
                print 'double %s = %s;' % (k, v)
            else:
                raise Exception('o no')
        for (k, v) in str_lits.iteritems():
            print 'const char *%s = %s;' % (k, data.c_stringify(v))

    protos = map(cdecl.make_internal_fn_decl, our_fns)

    (lib_fns, tds) = data.get_fns_and_types(fn_segs, externs, cpp_all)
    all_tds = {x.name: x for x in tds}
    typedefs = cdecl.resolve_typedefs(all_tds)
    EXTERN_REG_MAP = data.get_fn_arg_map(lib_fns, typedefs)
    STKVAR_MAP = data.get_stkvars(our_fns)
    stkvar_decls = data.make_stkvar_txt(our_fns, STKVAR_MAP, cpp_filter)

    if decompile is True:
        print XXX_INTRO_HACK
        return gen_from_node(c_ast.FileAST(
            data_txt +
            protos +
            list(generate(ida.loc_by_name(decl.name), decl, our_fns,
                          EXTERN_REG_MAP, STKVAR_MAP, stkvar_decls)
                 for decl in protos)))
    else:
        return
コード例 #3
0
ファイル: gen.py プロジェクト: neophack/epanos
def run(externs, our_fns, cpp_filter, cpp_all, decompile=True):
    '''frozenset(str) -> frozenset(str) -> str -> str -> opt:bool -> [c_ast]'''
    global OUR_FNS, EXTERN_REG_MAP, STKVAR_MAP  # for repl convenience
    OUR_FNS = our_fns

    fn_segs = data.get_segs(['extern', '.text'])
    rodata_segs = data.get_segs(['.rodata', '.srdata'])
    data_segs = data.get_segs(['.data', '.bss'])
    lit_segs = data.get_segs(['.lit4', '.lit8'])

    num_lits = data.get_num_literals(lit_segs)
    str_lits = data.get_str_literals(rodata_segs)
    data_txt = data.get_data(data_segs, cpp_filter)

    # XXX FIXME this will be going away once we've added emitting numeric and
    # string constants directly at their site of use
    if decompile is True:
        for (k, v) in num_lits.iteritems():
            ty = type(v)
            if ty is ep_ct.cfloat:
                print 'float %s = %s;' % (k, v)
            elif ty is ep_ct.cdouble:
                print 'double %s = %s;' % (k, v)
            else:
                raise Exception('o no')
        for (k, v) in str_lits.iteritems():
            print 'const char *%s = %s;' % (k, data.c_stringify(v))

    protos = map(cdecl.make_internal_fn_decl, our_fns)

    (lib_fns, tds) = data.get_fns_and_types(fn_segs, externs, cpp_all)
    all_tds = {x.name: x for x in tds}
    typedefs = cdecl.resolve_typedefs(all_tds)
    EXTERN_REG_MAP = data.get_fn_arg_map(lib_fns, typedefs)
    STKVAR_MAP = data.get_stkvars(our_fns)
    stkvar_decls = data.make_stkvar_txt(our_fns, STKVAR_MAP, cpp_filter)

    if decompile is True:
        print XXX_INTRO_HACK
        return gen_from_node(
            c_ast.FileAST(data_txt + protos + list(
                generate(ida.loc_by_name(decl.name), decl, our_fns,
                         EXTERN_REG_MAP, STKVAR_MAP, stkvar_decls)
                for decl in protos)))
    else:
        return