Пример #1
0
def run_optimization(filename):
    filepath = os.path.join(bin_location, filename)

    target_filepath = os.path.join('/', 'tmp', 'optimized_binaries',
                                   os.path.basename(filename))
    rr_filepath = target_filepath + ".rr"
    cp_filepath = target_filepath + ".cp"

    # register reallocation first
    b1 = ReassemblerBackend(filepath, debugging=True)
    cp = BinaryOptimization(filepath, b1, {'register_reallocation'})
    #cp = BinaryOptimization(filepath, b1, {'redundant_stack_variable_removal'})
    patches = cp.get_patches()
    b1.apply_patches(patches)
    r = b1.save(rr_filepath)

    if not r:
        print "Compiler says:"
        print b1._compiler_stdout
        print b1._compiler_stderr

    # other optimization techniques
    b2 = ReassemblerBackend(rr_filepath, debugging=True)
    #cp = BinaryOptimization(rr_filepath, b2, {'constant_propagation', 'redundant_stack_variable_removal'})
    cp = BinaryOptimization(rr_filepath, b2, {'constant_propagation'})
    patches = cp.get_patches()
    b2.apply_patches(patches)
    r = b2.save(target_filepath)

    if not r:
        print "Compiler says:"
        print b2._compiler_stdout
        print b2._compiler_stderr

    nose.tools.assert_true(r, 'Optimization fails on binary %s' % filename)
Пример #2
0
def run_adversarial(filename):
    filepath = os.path.join(bin_location, filename)

    p = ReassemblerBackend(filepath, debugging=True)

    patch = Adversarial(filepath, p)
    patches = patch.get_patches()

    p.apply_patches(patches)

    r = p.save(os.path.join('/', 'tmp', 'adversarial', os.path.basename(filename)))

    if not r:
        print("Compiler says:")
        print(p._compiler_stdout)
        print(p._compiler_stderr)

    nose.tools.assert_true(r, 'Adversarial patching with reassembler fails on binary %s' % filename)
Пример #3
0
def run_shiftstack(filename):
    filepath = os.path.join(bin_location, filename)

    p = ReassemblerBackend(filepath, debugging=True)

    patch = ShiftStack(filepath, p)
    patches = patch.get_patches()

    p.apply_patches(patches)

    r = p.save(
        os.path.join('/', 'tmp', 'shiftstack', os.path.basename(filename)))

    if not r:
        print "Compiler says:"
        print p._compiler_stdout
        print p._compiler_stderr

    nose.tools.assert_true(
        r,
        'ShiftStack patching with reassembler fails on binary %s' % filename)