def reverse_file(filename, symbol, options): gctx = GlobalContext() gctx.sectionsname = False gctx.color = False gctx.filename = filename gctx.entry = symbol gctx.quiet = True for o in options: if o == "--raw x86": gctx.raw_type = "x86" elif o == "--raw x64": gctx.raw_type = "x64" elif o.startswith("--rawbase"): gctx.raw_base = int(o.split(" ")[1], 16) if not gctx.load_file(): die() gctx.api = Api(gctx, None) sio = StringIO() with redirect_stdout(sio): o = gctx.get_addr_context(gctx.entry).decompile() if o is not None: o.print() postfix = '{0}.rev'.format('' if symbol is None else '_' + symbol) with open(filename.replace('.bin', postfix)) as f: assert_equal(sio.getvalue(), f.read())
def console_entry(): gctx = GlobalContext() gctx.parse_args() if gctx.color and reverse.lib.colors.VERSION < reverse.lib.colors.CURR_VERSION: info("There is a new version of custom_colors.py. If you did any") info("modifications you can delete it. Otherwise you can copy it") info("somewhere, run again your command then merge the file at hand.") die() if gctx.filename is None: die() if not gctx.load_file(): die() if gctx.interactive_mode: from reverse.lib.ui.console import Console gctx.is_interactive = True Console(gctx) else: gctx.api = Api(gctx, None) if gctx.list_sections: for s in gctx.dis.binary.iter_sections(): s.print_header() sys.exit(0) if gctx.syms: gctx.dis.print_symbols(gctx.sectionsname) sys.exit(0) ctx = gctx.get_addr_context(gctx.entry) if ctx is None: sys.exit(0) if gctx.do_dump: ctx.dump_asm(gctx.nb_lines).print() sys.exit(0) o = ctx.decompile() if gctx.graph: ctx.gph.dot_graph(gctx.dis.jmptables) if o is not None: if gctx.vim: base = os.path.basename(gctx.filename) + "_" + gctx.entry # re-assign if no colors gctx.libarch.process_ast.assign_colors(ctx, ctx.ast) gctx.color = False generate_vim_syntax(ctx, base + ".vim") sys.stdout = open(base + ".rev", "w+") o.print() if gctx.vim: print("run : vim {0}.rev -S {0}.vim".format(base), file=sys.stderr)
def console_entry(): gctx = GlobalContext() gctx.parse_args() if gctx.color and reverse.lib.colors.VERSION < reverse.lib.colors.CURR_VERSION: info("There is a new version of custom_colors.py. If you did any") info("modifications you can delete it. Otherwise you can copy it") info("somewhere, run again your command then merge the file at hand.") die() if gctx.filename is None: die() if not gctx.load_file(): die() if gctx.interactive_mode: from reverse.lib.ui.console import Console i = Console(gctx) else: if gctx.list_sections: for s in gctx.dis.binary.iter_sections(): s.print_header() sys.exit(0) if gctx.syms: gctx.dis.print_symbols(gctx.sectionsname) sys.exit(0) ctx = gctx.get_addr_context(gctx.entry) if ctx is None: sys.exit(0) if gctx.do_dump: ctx.dump_asm(gctx.nb_lines).print() sys.exit(0) o = ctx.decompile() if gctx.graph: ctx.gph.dot_graph(gctx.dis.jmptables) if o is not None: if gctx.vim: base = os.path.basename(gctx.filename) + "_" + gctx.entry # re-assign if no colors gctx.libarch.process_ast.assign_colors(ctx, ctx.ast) gctx.color = False generate_vim_syntax(ctx, base + ".vim") sys.stdout = open(base + ".rev", "w+") o.print() if gctx.vim: print("run : vim {0}.rev -S {0}.vim".format(base), file=sys.stderr)