def main():
    args = get_args()
    if os.path.isfile(args.stat): return
    config = Config()

    config.MODE = config.TRAIN

    config.BINARY_PATH = args.binary_with_symtab
    config.BINARY_NAME = args.binary_with_symtab
    config.BAP_FILE_PATH = args.bap
    config.DEBUG_INFO_PATH = args.debug_info

    config.OUTPUT_BINARY_PATH = args.output
    config.MODIFY_ELF_LIB_PATH = args.elf_modifier
    config.N2P_SERVER_URL = args.n2p_url
    config.STAT_PATH = args.stat

    config.TWO_PASS = args.two_pass
    config.FP_MODEL_PATH = args.fp_model
    if config.TWO_PASS:
        reg_dict = open(os.path.join(config.FP_MODEL_PATH, 'reg.dict'), 'rb')
        reg_model = open(os.path.join(config.FP_MODEL_PATH, 'reg.model'), 'rb')
        reg_support = open(os.path.join(config.FP_MODEL_PATH, 'reg.support'),
                           'rb')
        config.REG_DICT = pickle.load(reg_dict, encoding='latin1')
        config.REG_SUPPORT = pickle.load(reg_support, encoding='latin1')
        config.REG_DICT.restrict(config.REG_SUPPORT.get_support())
        config.REG_MODEL = pickle.load(reg_model, encoding='latin1')
        config.REG_MODEL.n_jobs = 1

        off_dict = open(os.path.join(config.FP_MODEL_PATH, 'off.dict'), 'rb')
        off_model = open(os.path.join(config.FP_MODEL_PATH, 'off.model'), 'rb')
        off_support = open(os.path.join(config.FP_MODEL_PATH, 'off.support'),
                           'rb')
        config.OFF_DICT = pickle.load(off_dict, encoding='latin1')
        config.OFF_SUPPORT = pickle.load(off_support, encoding='latin1')
        config.OFF_DICT.restrict(config.OFF_SUPPORT.get_support())
        config.OFF_MODEL = pickle.load(off_model, encoding='latin1')
        config.OFF_MODEL.n_jobs = 1

    with open(config.BINARY_PATH,
              'rb') as elffile, open(config.DEBUG_INFO_PATH,
                                     'rb') as debug_elffile:
        b = Binary(config, elffile, debug_elffile)
        b.set_test_result_from_server(True)
        b.modify_elf(args.binary_without_symtab)
        if config.STAT_PATH is not None:
            b.dump_stat()

    if config.TWO_PASS:
        reg_dict.close()
        reg_support.close()
        reg_model.close()
        off_dict.close()
        off_support.close()
        off_model.close()
Beispiel #2
0
def main():
    args = get_args()

    config = Config()

    config.MODE = config.TRAIN

    config.BINARY_PATH = args.binary
    config.BINARY_NAME = args.binary
    config.BAP_FILE_PATH = args.bap
    config.DEBUG_INFO_PATH = args.debug_info

    config.N2P_SERVER_URL = args.n2p_url
    config.STAT_PATH = args.stat

    config.TWO_PASS = args.two_pass
    config.FP_MODEL_PATH = args.fp_model
    if config.TWO_PASS:
        reg_dict = open(os.path.join(config.FP_MODEL_PATH, 'reg.dict'), 'rb')
        reg_model = open(os.path.join(config.FP_MODEL_PATH, 'reg.model'), 'rb')
        reg_support = open(os.path.join(config.FP_MODEL_PATH, 'reg.support'), 'rb')
        config.REG_DICT = pickle.load(reg_dict, encoding='latin1')
        config.REG_SUPPORT = pickle.load(reg_support, encoding='latin1')
        config.REG_DICT.restrict(config.REG_SUPPORT.get_support())
        config.REG_MODEL = pickle.load(reg_model, encoding='latin1')
        config.REG_MODEL.n_jobs = 1

        off_dict = open(os.path.join(config.FP_MODEL_PATH, 'off.dict'), 'rb')
        off_model = open(os.path.join(config.FP_MODEL_PATH, 'off.model'), 'rb')
        off_support = open(os.path.join(config.FP_MODEL_PATH, 'off.support'), 'rb')
        config.OFF_DICT = pickle.load(off_dict, encoding='latin1')
        config.OFF_SUPPORT = pickle.load(off_support, encoding='latin1')
        config.OFF_DICT.restrict(config.OFF_SUPPORT.get_support())
        config.OFF_MODEL = pickle.load(off_model, encoding='latin1')
        config.OFF_MODEL.n_jobs = 1

    with open(config.BINARY_PATH, 'rb') as elffile, open(config.DEBUG_INFO_PATH, 'rb') as debug_elffile:
        TIMER.start_scope('0ALL')
        b = Binary(config, elffile, debug_elffile)
        TIMER.start_scope('2CRF')
        b.set_test_result_from_server(True)
        TIMER.end_scope()
        TIMER.end_scope()
        b.dump_stat()

    if config.TWO_PASS:
        reg_dict.close()
        reg_support.close()
        reg_model.close()
        off_dict.close()
        off_support.close()
        off_model.close()
Beispiel #3
0
def evaluate_binary(binary,
                    bap,
                    debug_info,
                    n2p_url,
                    stat,
                    two_pass,
                    fp_model,
                    output='',
                    elf_modify=''):

    if os.path.isfile(stat):
        return

    config = Config()

    config.MODE = config.TRAIN

    config.BINARY_PATH = binary
    config.BINARY_NAME = binary
    config.BAP_FILE_PATH = bap
    config.DEBUG_INFO_PATH = debug_info

    config.N2P_SERVER_URL = n2p_url
    config.STAT_PATH = stat

    config.TWO_PASS = two_pass
    config.FP_MODEL_PATH = fp_model

    if output and elf_modify:
        config.OUTPUT_BINARY_PATH = output
        config.MODIFY_ELF_LIB_PATH = elf_modify

    if config.TWO_PASS:
        reg_dict = open(os.path.join(config.FP_MODEL_PATH, 'reg.dict'), 'rb')
        reg_model = open(os.path.join(config.FP_MODEL_PATH, 'reg.model'), 'rb')
        reg_support = open(os.path.join(config.FP_MODEL_PATH, 'reg.support'),
                           'rb')
        config.REG_DICT = pickle.load(reg_dict, encoding='latin1')
        config.REG_SUPPORT = pickle.load(reg_support, encoding='latin1')
        config.REG_DICT.restrict(config.REG_SUPPORT.get_support())
        config.REG_MODEL = pickle.load(reg_model, encoding='latin1')
        config.REG_MODEL.n_jobs = 1

        off_dict = open(os.path.join(config.FP_MODEL_PATH, 'off.dict'), 'rb')
        off_model = open(os.path.join(config.FP_MODEL_PATH, 'off.model'), 'rb')
        off_support = open(os.path.join(config.FP_MODEL_PATH, 'off.support'),
                           'rb')
        config.OFF_DICT = pickle.load(off_dict, encoding='latin1')
        config.OFF_SUPPORT = pickle.load(off_support, encoding='latin1')
        config.OFF_DICT.restrict(config.OFF_SUPPORT.get_support())
        config.OFF_MODEL = pickle.load(off_model, encoding='latin1')
        config.OFF_MODEL.n_jobs = 1

    with open(config.BINARY_PATH,
              'rb') as elffile, open(config.DEBUG_INFO_PATH,
                                     'rb') as debug_elffile:
        TIMER.start_scope('0ALL')
        b = Binary(config, elffile, debug_elffile)
        TIMER.start_scope('2CRF')
        b.set_test_result_from_server(True)
        TIMER.end_scope()
        TIMER.end_scope()
        b.dump_stat()

    if config.TWO_PASS:
        reg_dict.close()
        reg_support.close()
        reg_model.close()
        off_dict.close()
        off_support.close()
        off_model.close()