Esempio n. 1
0
def get_symbols(binary_path):
    symbols_by_addr = load_symbols(binary_path)

    symbols_by_name = {}
    for addr in symbols_by_addr:
        name, size, returns = symbols_by_addr[addr]
        symbols_by_name[name] = (addr, size, returns)

    return symbols_by_addr, symbols_by_name
def get_symbols(binary_path):
    symbols_by_addr = load_symbols(binary_path)

    symbols_by_name = {}
    for addr in symbols_by_addr:
        name, size, returns = symbols_by_addr[addr]
        symbols_by_name[name] = (addr, size, returns)

    return symbols_by_addr, symbols_by_name
Esempio n. 3
0
def main():

    parser = init_parser()

    args = parser.parse_args()

    # Set default options.
    if not args.recover_all and not args.recover:
        args.recover_all = True

    process_start = time.time()

    filename = os.path.abspath(args.filename)

    if not os.path.isfile(filename):
        print("[-] File not found : {}".format(filename))

        sys.exit(1)

    # Create an instance of BARF.
    try:
        barf = BARF(filename)
    except Exception:
        print("[-] Error opening file : {}".format(filename))

        sys.exit(1)

    # Load symbols.
    print("[+] Parsing symbol table...")

    if args.symbol_file:
        symbols_by_addr = load_symbols_from_file(args.symbol_file)
    else:
        symbols_by_addr = load_symbols(filename)

    # Recover CFGs.
    print("[+] Recovering CFGs...")

    output_dir = create_output_dir(args.output_dir + os.path.sep +
                                   filename.split(os.path.sep)[-1] + "_cfg")

    if args.recover_all:
        cfgs = recover_cfg_all(barf, symbols_by_addr)

    if args.recover:
        addresses = [int(addr, 16) for addr in args.recover.split(",")]

        cfgs = recover_cfg_some(barf, addresses, symbols_by_addr)

    print("[+] Number of CFGs recovered: {:d}".format(len(cfgs)))

    # Saving CFGs to files.
    print("[+] Saving CFGs...")

    save_cfgs(cfgs, output_dir, args.format, args.show_reil, args.brief,
              args.immediate_format)

    process_end = time.time()

    if args.time:
        process_time = process_end - process_start

        print("[+] Process time: {:.3f}s".format(process_time))
Esempio n. 4
0
def main():

    parser = init_parser()

    args = parser.parse_args()

    # Set default options.
    if not args.recover_all and not args.recover:
        args.recover_all = True

    process_start = time.time()

    filename = os.path.abspath(args.filename)

    if not os.path.isfile(filename):
        print("[-] File not found : {}".format(filename))

        sys.exit(1)

    # Create an instance of BARF.
    try:
        barf = BARF(filename)
    except Exception:
        print("[-] Error opening file : {}".format(filename))

        sys.exit(1)

    # Load symbols.
    print("[+] Parsing symbol table...")

    if args.symbol_file:
        symbols_by_addr = load_symbols_from_file(args.symbol_file)
    else:
        symbols_by_addr = load_symbols(filename)

    # Recover CFGs.
    print("[+] Recovering CFGs...")

    if args.recover_all:
        cfgs = recover_cfg_all(barf, symbols_by_addr)

    if args.recover:
        addresses = [int(addr, 16) for addr in args.recover.split(",")]

        cfgs = recover_cfg_some(barf, addresses, symbols_by_addr)

    print("[+] Number of CFGs recovered: {:d}".format(len(cfgs)))

    # Recover CG.
    print("[+] Recovering program CG...")

    cfgs_filtered = []
    for cfg in cfgs:
        if len(cfg.basic_blocks) == 0:
            print("[*] Ignoring empty CFG: {}".format(cfg.name))
            continue

        cfgs_filtered.append(cfg)

    cg = CallGraph(cfgs_filtered)

    cg.save(filename.split(os.path.sep)[-1] + "_cg", format=args.format)

    process_end = time.time()

    if args.time:
        process_time = process_end - process_start

        print("[+] Process time: {:.3f}s".format(process_time))
from barf.core.symbols import load_symbols

if __name__ == "__main__":
    #
    # Open file
    #
    filename = "./samples/bin/example1.x86_64"
    arg = "hello!"

    barf = BARF(filename)

    #
    # Recover CFGs.
    #
    print("[+] Recovering control flow graphs...")
    symbols_by_addr = load_symbols(filename)
    entries = [addr for addr in sorted(symbols_by_addr.keys())]
    cfgs = barf.recover_cfg_all(entries, symbols=symbols_by_addr)

    #
    # Build CG.
    #
    print("[+] Building call graph...")
    cfgs_filtered = []
    for cfg in cfgs:
        if len(cfg.basic_blocks) == 0:
            continue
        cfgs_filtered.append(cfg)
    cg = CallGraph(cfgs_filtered)

    #
Esempio n. 6
0
def main():

    parser = init_parser()

    args = parser.parse_args()

    # Set default options.
    if not args.recover_all and not args.recover:
        args.recover_all = True

    process_start = time.time()

    filename = os.path.abspath(args.filename)

    if not os.path.isfile(filename):
        print("[-] File not found : {}".format(filename))

        sys.exit(1)

    # Create an instance of BARF.
    try:
        barf = BARF(filename)
    except Exception:
        print("[-] Error opening file : {}".format(filename))

        sys.exit(1)

    # Load symbols.
    print("[+] Parsing symbol table...")

    if args.symbol_file:
        symbols_by_addr = load_symbols_from_file(args.symbol_file)
    else:
        symbols_by_addr = load_symbols(filename)

    # Recover CFGs.
    print("[+] Recovering CFGs...")

    output_dir = create_output_dir(args.output_dir + os.path.sep + filename.split(os.path.sep)[-1] + "_cfg")

    if args.recover_all:
        cfgs = recover_cfg_all(barf, symbols_by_addr)

    if args.recover:
        addresses = [int(addr, 16) for addr in args.recover.split(",")]

        cfgs = recover_cfg_some(barf, addresses, symbols_by_addr)

    print("[+] Number of CFGs recovered: {:d}".format(len(cfgs)))

    # Saving CFGs to files.
    print("[+] Saving CFGs...")

    save_cfgs(cfgs, output_dir, args.format, args.show_reil, args.brief, args.immediate_format)

    process_end = time.time()

    if args.time:
        process_time = process_end - process_start

        print("[+] Process time: {:.3f}s".format(process_time))

if __name__ == "__main__":
    #
    # Open file
    #
    filename = "./samples/bin/example1.x86_64"
    arg = "hello!"

    barf = BARF(filename)

    #
    # Recover CFGs.
    #
    print("[+] Recovering control flow graphs...")
    symbols_by_addr = load_symbols(filename)
    entries = [addr for addr in sorted(symbols_by_addr.keys())]
    cfgs = barf.recover_cfg_all(entries, symbols=symbols_by_addr)

    #
    # Build CG.
    #
    print("[+] Building call graph...")
    cfgs_filtered = []
    for cfg in cfgs:
        if len(cfg.basic_blocks) == 0:
            continue
        cfgs_filtered.append(cfg)
    cg = CallGraph(cfgs_filtered)

    #