Exemplo n.º 1
0
def simulate(directory):
    config_file = os.path.join(directory, 'config')
    mutants_list = os.path.join(directory, 'mutants')
    commands_list = os.path.join(directory, 'commands')

    if not os.path.exists(config_file):
        print 'Config file does not exist! Please run mutants generator first.'
        sys.exit(2)
    if not os.path.exists(mutants_list):
        print 'Mutants list does not exist! Please run mutants generator first.'
        sys.exit(2)

    with open(config_file, 'rb') as handle:
        config = json.load(handle)

    with open(mutants_list, 'rb') as handle:
        mutants = json.load(handle)

    if not os.path.exists(commands_list):
        generateCommands(100, 1800, 1200, directory)

    commands = [line.rstrip('\n') for line in open(commands_list)]
    report_path = os.path.join(config['file'], 'report',
                               strftime('%Y%m%d%H%M%S'))
    os.makedirs(report_path)

    original_apk = config['file'] + '.apk'

    executeOriginal(config['package'], config['start_activity'], original_apk,
                    report_path, commands)

    for m in mutants:
        # if m['id'] <= 476:
        #     continue
        new_apk_path = os.path.join(
            directory, '{}_{}.apk'.format(config['file'], m['id']))
        m['killed'], m['crashed'] = executeMutant(config['package'],
                                                  config['start_activity'],
                                                  original_apk, new_apk_path,
                                                  report_path, commands)
        print m['id'], m['killed']

    new_mutants_list = os.path.join(report_path, 'mutants')
    with open(new_mutants_list, 'wb') as handle:
        json.dump(mutants, handle)

    return report_path
Exemplo n.º 2
0
def simulate(directory):
    config_file = os.path.join(directory, 'config')
    mutants_list = os.path.join(directory, 'mutants')
    commands_list = os.path.join(directory, 'commands')

    if not os.path.exists(config_file):
        print 'Config file does not exist! Please run mutants generator first.'
        sys.exit(2)
    if not os.path.exists(mutants_list):
        print 'Mutants list does not exist! Please run mutants generator first.'
        sys.exit(2)

    with open(config_file, 'rb') as handle:
        config = json.load(handle)

    with open(mutants_list, 'rb') as handle:
        mutants = json.load(handle)

    if not os.path.exists(commands_list):
        generateCommands(100, 1800, 1200, directory)

    commands = [line.rstrip('\n') for line in open(commands_list)]
    report_path = os.path.join(config['file'], 'report', strftime('%Y%m%d%H%M%S'))
    os.makedirs(report_path)
    
    original_apk = config['file']+'.apk'

    executeOriginal(config['package'], config['start_activity'], original_apk, report_path, commands)

    for m in mutants:
        # if m['id'] <= 476:
        #     continue
        new_apk_path = os.path.join(directory, '{}_{}.apk'.format(config['file'], m['id']))
        m['killed'], m['crashed'] = executeMutant(config['package'], config['start_activity'], original_apk, new_apk_path, report_path, commands)
        print m['id'], m['killed']

    new_mutants_list = os.path.join(report_path, 'mutants')
    with open(new_mutants_list, 'wb') as handle:
        json.dump(mutants, handle)

    return report_path
Exemplo n.º 3
0
    for m in mutants:
        # if m['id'] <= 476:
        #     continue
        new_apk_path = os.path.join(directory, '{}_{}.apk'.format(config['file'], m['id']))
        m['killed'], m['crashed'] = executeMutant(config['package'], config['start_activity'], original_apk, new_apk_path, report_path, commands)
        print m['id'], m['killed']

    new_mutants_list = os.path.join(report_path, 'mutants')
    with open(new_mutants_list, 'wb') as handle:
        json.dump(mutants, handle)

    return report_path

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument('dir', help='Directory contains apk mutants.')
    args = parser.parse_args()

    commands_list = os.path.join(args.dir, 'commands')
    if not os.path.exists(commands_list):
        print 'Command list does not exist!'
        height = input('Please enter maximum height of command:')
        width = input('Please enter maximum width of command:')
        number = input('Please enter total number of commands:')
        generateCommands(number, height, width, args.dir)

    commands = [line.rstrip('\n') for line in open(commands_list)]

    simulate(args.dir)
Exemplo n.º 4
0
from mutant_generator import generateMutants
from input_generator import generateCommands
from interaction_simulator import simulate
from result_analyzer import analyze_results


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument('apk', help='apk file')
    args = parser.parse_args()

    apk_file = args.apk
    if not apk_file.endswith('.apk'):
        print 'Input must be an Android Apk file!'
        sys.exit(2)

    file_name = apk_file[:-4]

    if not os.path.exists(os.path.join(file_name, 'commands')):
        if not os.path.exists(file_name):
            os.mkdir(file_name)
        print 'Command list does not exist!'
        height = input('Please enter maximum height of command:')
        width = input('Please enter maximum width of command:')
        number = input('Please enter total number of commands:')
        generateCommands(number, height, width, file_name)

    directory = generateMutants(apk_file)
    result_directory = simulate(directory)
    analyze_results(file_name, result_directory)
Exemplo n.º 5
0
            directory, '{}_{}.apk'.format(config['file'], m['id']))
        m['killed'], m['crashed'] = executeMutant(config['package'],
                                                  config['start_activity'],
                                                  original_apk, new_apk_path,
                                                  report_path, commands)
        print m['id'], m['killed']

    new_mutants_list = os.path.join(report_path, 'mutants')
    with open(new_mutants_list, 'wb') as handle:
        json.dump(mutants, handle)

    return report_path


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument('dir', help='Directory contains apk mutants.')
    args = parser.parse_args()

    commands_list = os.path.join(args.dir, 'commands')
    if not os.path.exists(commands_list):
        print 'Command list does not exist!'
        height = input('Please enter maximum height of command:')
        width = input('Please enter maximum width of command:')
        number = input('Please enter total number of commands:')
        generateCommands(number, height, width, args.dir)

    commands = [line.rstrip('\n') for line in open(commands_list)]

    simulate(args.dir)
Exemplo n.º 6
0
from mutation_analyser import MutationAnalyser
from mutant_generator import generateMutants
from input_generator import generateCommands
from interaction_simulator import simulate
from result_analyzer import analyze_results

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument('apk', help='apk file')
    args = parser.parse_args()

    apk_file = args.apk
    if not apk_file.endswith('.apk'):
        print 'Input must be an Android Apk file!'
        sys.exit(2)

    file_name = apk_file[:-4]

    if not os.path.exists(os.path.join(file_name, 'commands')):
        if not os.path.exists(file_name):
            os.mkdir(file_name)
        print 'Command list does not exist!'
        height = input('Please enter maximum height of command:')
        width = input('Please enter maximum width of command:')
        number = input('Please enter total number of commands:')
        generateCommands(number, height, width, file_name)

    directory = generateMutants(apk_file)
    result_directory = simulate(directory)
    analyze_results(file_name, result_directory)