Exemplo n.º 1
0
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()

    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())
Exemplo n.º 2
0
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()

    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())
Exemplo n.º 3
0
if __name__ == '__main__':
    gctx = GlobalContext()
    gctx.parse_args()

    if gctx.color and lib.colors.VERSION < 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.interactive_mode:
        from lib.ui.console import Console
        i = Console(gctx)

    elif gctx.filename is not None:
        if not gctx.load_file():
            die()

        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)
Exemplo n.º 4
0
if __name__ == '__main__':
    gctx = GlobalContext()
    gctx.parse_args()

    if gctx.color and lib.colors.VERSION < 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.interactive_mode:
        from lib.ui.console import Console
        i = Console(gctx)

    elif gctx.filename is not None:
        if not gctx.load_file():
            die()

        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)