Example #1
0
    def decompile(self):
        self.is_dump = False
        self.gph, pe_nb_new_syms = self.gctx.dis.get_graph(self.entry)

        if self.gph is None:
            error("capstone can't disassemble here")
            return None
        self.gph.simplify()

        if self.gctx.db.loaded and pe_nb_new_syms:
            self.gctx.db.modified = True
        
        try:
            self.gph.loop_detection(self.entry)
            ast, correctly_ended = generate_ast(self)
            if not correctly_ended:
                debug__("Second try...")
                self.gph.loop_detection(self.entry, True)
                ast, _ = generate_ast(self)

            self.ast = ast
        except ExcIfelse as e:
            error("can't have a ifelse here     %x" % e.addr)
            if self.gctx.interactive_mode:
                return None
            die()

        o = self.gctx.libarch.output.Output(self)
        o._ast(self.entry, ast)
        self.output = o
        return o
Example #2
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)
Example #3
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)
Example #4
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.loaded 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_mode:
            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
Example #5
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.loaded 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_mode:
            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