Beispiel #1
0
def disasm(ctx):
    ctx.gph = ctx.dis.get_graph(ctx.entry_addr)
    if ctx.gph == None:
        error("capstone can't disassemble here")
        return
    ctx.gph.graph_init(ctx)
    
    if ctx.graph:
        ctx.gph.html_graph()

    try:
        ast = generate_ast(ctx)
    except ExcIfelse as e:
        error("can't have a ifelse here     %x" % e.addr)
        if ctx.interactive:
            return
        die()

    if ctx.vim:
        base = os.path.basename(ctx.filename) + "_" + ctx.entry
        # re-assign if no colors
        ctx.libarch.process_ast.assign_colors(ctx, ast)
        ctx.color = False
        generate_vim_syntax(ctx, base + ".vim")
        sys.stdout = open(base + ".rev", "w+")

    o = ctx.libarch.output.Output(ctx)
    o.print_ast(ctx.entry_addr, ast)

    if ctx.vim:
        print("Run :  vim {0}.rev -S {0}.vim".format(base), file=sys.stderr)
Beispiel #2
0
def reverse(ctx):
    if not load_file(ctx):
        die()

    if ctx.list_sections:
        for name, start, end in ctx.dis.binary.iter_sections():
           ctx.dis.print_section_meta(name, start, end) 
        return

    if ctx.syms:
        ctx.dis.print_symbols(ctx.sectionsname)
        return

    init_entry_addr(ctx)

    if ctx.calls_in_section is not None:
        ctx.dis.print_calls(ctx)
        return

    if ctx.dump:
        if ctx.vim:
            base = os.path.basename(ctx.filename) + "_" + ctx.entry
            ctx.color = False
            sys.stdout = open(base + ".rev", "w+")

        if ctx.dump:
            ctx.dis.dump_asm(ctx, ctx.lines)

        if ctx.vim:
            generate_vim_syntax(ctx, base + ".vim")
            print("Run :  vim {0}.rev -S {0}.vim".format(base), file=sys.stderr)
        return

    disasm(ctx)
Beispiel #3
0
def reverse(ctx):
    if not load_file(ctx):
        die()

    if ctx.syms:
        ctx.dis.print_symbols(ctx.sectionsname)
        return

    init_addr(ctx)

    if ctx.calls:
        ctx.dis.print_calls(ctx)
        return

    if ctx.dump:
        if ctx.vim:
            base = os.path.basename(ctx.filename)
            ctx.color = False
            sys.stdout = open(base + ".rev", "w+")

        ctx.dis.dump(ctx, ctx.lines)

        if ctx.vim:
            generate_vim_syntax(ctx, base + ".vim")
            print("Run :  vim {0}.rev -S {0}.vim".format(base), file=sys.stderr)
        return

    disasm(ctx)
Beispiel #4
0
def reverse(ctx):
    if not load_file(ctx):
        die()

    if ctx.list_sections:
        for name, start, end in ctx.dis.binary.iter_sections():
            ctx.dis.print_section_meta(name, start, end)
        return

    if ctx.syms:
        ctx.dis.print_symbols(ctx.sectionsname)
        return

    init_entry_addr(ctx)

    if ctx.calls_in_section is not None:
        ctx.dis.print_calls(ctx)
        return

    if ctx.dump:
        if ctx.vim:
            base = os.path.basename(ctx.filename) + "_" + ctx.entry
            ctx.color = False
            sys.stdout = open(base + ".rev", "w+")

        if ctx.dump:
            ctx.dis.dump_asm(ctx, ctx.lines)

        if ctx.vim:
            generate_vim_syntax(ctx, base + ".vim")
            print("Run :  vim {0}.rev -S {0}.vim".format(base),
                  file=sys.stderr)
        return

    disasm(ctx)
Beispiel #5
0
def disasm(ctx):
    ctx.gph = ctx.dis.get_graph(ctx.entry_addr)
    if ctx.gph == None:
        error("capstone can't disassemble here")
        return
    ctx.gph.graph_init(ctx)

    if ctx.graph:
        ctx.gph.html_graph(ctx.dis.jmptables)

    try:
        ast = generate_ast(ctx)
    except ExcIfelse as e:
        error("can't have a ifelse here     %x" % e.addr)
        if ctx.interactive:
            return
        die()

    if ctx.vim:
        base = os.path.basename(ctx.filename) + "_" + ctx.entry
        # re-assign if no colors
        ctx.libarch.process_ast.assign_colors(ctx, ast)
        ctx.color = False
        generate_vim_syntax(ctx, base + ".vim")
        sys.stdout = open(base + ".rev", "w+")

    o = ctx.libarch.output.Output(ctx)
    o.print_ast(ctx.entry_addr, ast)

    if ctx.vim:
        print("Run :  vim {0}.rev -S {0}.vim".format(base), file=sys.stderr)
Beispiel #6
0
def reverse(ctx):
    if not load_file(ctx):
        die()

    if ctx.syms:
        ctx.dis.print_symbols(ctx.sectionsname)
        return

    init_addr(ctx)

    if ctx.calls:
        ctx.dis.print_calls(ctx)
        return

    if ctx.dump:
        if ctx.vim:
            base = os.path.basename(ctx.filename)
            ctx.color = False
            sys.stdout = open(base + ".rev", "w+")

        ctx.dis.dump(ctx, ctx.lines)

        if ctx.vim:
            generate_vim_syntax(ctx, base + ".vim")
            print("Run :  vim {0}.rev -S {0}.vim".format(base),
                  file=sys.stderr)
        return

    disasm(ctx)
Beispiel #7
0
def disasm(ctx):
    ctx.gph, pe_nb_new_syms = ctx.dis.get_graph(ctx.entry_addr)
    if ctx.gph == None:
        error("capstone can't disassemble here")
        return None
    ctx.gph.simplify()

    if ctx.db is not None and pe_nb_new_syms:
        ctx.db_modified = True
    
    try:
        ctx.gph.loop_detection(ctx, ctx.entry_addr)
        ast, correctly_ended = generate_ast(ctx)
        if not correctly_ended:
            debug__("Second try...")
            ctx.gph.loop_detection(ctx, ctx.entry_addr, True)
            ast, _ = generate_ast(ctx)
    except ExcIfelse as e:
        error("can't have a ifelse here     %x" % e.addr)
        if ctx.interactive:
            return None
        die()

    if ctx.graph:
        ctx.gph.dot_graph(ctx.dis.jmptables)

    if ctx.vim:
        base = os.path.basename(ctx.filename) + "_" + ctx.entry
        # re-assign if no colors
        ctx.libarch.process_ast.assign_colors(ctx, ast)
        ctx.color = False
        generate_vim_syntax(ctx, base + ".vim")
        sys.stdout = open(base + ".rev", "w+")

    o = ctx.libarch.output.Output(ctx)
    o._ast(ctx.entry_addr, ast)

    if ctx.vim:
        print("Run :  vim {0}.rev -S {0}.vim".format(base), file=sys.stderr)

    return o