Пример #1
0
def func(ea, vuu):
    f = idaapi.get_func(ea)
    function_name = idaapi.get_func_name(ea)
    if f is None:
        print('Please position the cursor within a function')

    cfunc = None
    try:
        cfunc = idaapi.decompile(f)
    except ida_hexrays.DecompilationFailure as e:
        print('Failed to decompile %x: %s!' % (ea, function_name))
        raise e

    # Rename decompilation graph
    cg = CFuncGraph(None)
    gb = GraphBuilder(cg)
    gb.apply_to(cfunc.body, None)
    #ac = AddressCollector(cg)
    #ac.collect()
    rg = RenamedGraphBuilder(cg, cfunc, vuu)
    rg.apply_to(cfunc.body, None)

    # Create tree from collected names
    cfunc.build_c_tree()
    new_graph = CFuncGraph(None)
    new_builder = GraphBuilder(new_graph)
    new_builder.apply_to(cfunc.body, None)
    function_info = dict()
    function_info["function"] = function_name
    function_info["ast"] = new_graph.json_tree(0)
    raw_code = ""
    for line in cfunc.get_pseudocode():
        raw_code += idaapi.tag_remove(line.line) + '\n'
    function_info["raw_code"] = raw_code
    return function_info, cfunc
Пример #2
0
def func(ea):
    f = idaapi.get_func(ea)
    if f is None:
        print('Please position the cursor within a function')
        return True
    cfunc = None
    try:
        cfunc = idaapi.decompile(f)
    except ida_hexrays.DecompilationFailure:
        pass

    if cfunc is None:
        print(('Failed to decompile %x!' % ea))
        return True

    # Build decompilation graph
    cg = CollectGraph(None)
    gb = GraphBuilder(cg)
    gb.apply_to(cfunc.body, None)
    cg.collect_vars()
Пример #3
0
def func(ea):

    f = idaapi.get_func(ea)
    if hasattr(idaapi, "GetFunctionName"):
        function_name = GetFunctionName(ea)
    else:
        function_name = get_func_name(ea)
    print("Decompiling %s" % function_name)
    if f is None:
        print('Please position the cursor within a function')

    # Ignore thunk functions
    flags = idc.get_func_flags(ea)
    if flags > 0 and (flags & idaapi.FUNC_THUNK) != 0:
        print("Ignoring thunk function %s" % function_name)
        return None

    cfunc = None
    try:
        cfunc = idaapi.decompile(f)
    except ida_hexrays.DecompilationFailure as e:
        print('Failed to decompile %x: %s!' % (ea, function_name))
        raise e

    # Rename decompilation graph
    cg = CFuncGraph(None)
    gb = GraphBuilder(cg)
    gb.apply_to(cfunc.body, None)
    ac = AddressCollector(cg)
    ac.collect()
    rg = RenamedGraphBuilder(cg, cfunc, ac.addresses)
    rg.apply_to(cfunc.body, None)
    # This will force the function porameters to be renamed even if
    # they aren't used in the body of the function
    for arg in cfunc.arguments:
        rg.visit_var(arg)

    # Create tree from collected names
    cfunc.build_c_tree()
    new_graph = CFuncGraph(None)
    new_builder = GraphBuilder(new_graph)
    new_builder.apply_to(cfunc.body, None)
    function_info = dict()
    function_info["function"] = function_name
    function_info["ast"] = new_graph.json_tree(0)
    raw_code = ""
    for line in cfunc.get_pseudocode():
        raw_code += idaapi.tag_remove(line.line) + '\n'
    function_info["raw_code"] = raw_code
    return function_info