예제 #1
0
def test_assert_compare():
    proj = pySym.Project(os.path.join(myPath, "scripts", "assert_script_1.py"))
    pg = proj.factory.path_group()
    pg.explore()

    assert len(pg.completed) == 1
    s = pg.completed[0].state.copy()
    i = s.getVar('i')

    # Try some values
    assert all([x%12==4 for x in s.any_n_int(i, 32)])
예제 #2
0
def test_function_ord_symbolic_input():
    proj = pySym.Project(os.path.join(myPath, "scripts", "ord_symbolic_chr.py"))
    pg = proj.factory.path_group()
    pg.explore()

    assert len(pg.completed) == 1

    s = pg.completed[0].state.getVar('s')
    c = pg.completed[0].state.getVar('c')

    # Set the integer value, back prop to the string
    c.setTo(ord('X'))
    assert str(s)[1] == "X"
예제 #3
0
def test_basic_hooking():
    # Temporarily bastardizing the hook dictionary to pass state back to my test. ONLY for this test.
    proj = pySym.Project(os.path.join(myPath, "scripts", "basic_function.py"))

    def my_hook(state):
        state._project._hooks[6969] = True
        assert isinstance(state, pySym.pyState.State)

    proj.hook(6, my_hook)
    proj._hooks[6969] = False
    pg = proj.factory.path_group()
    pg.explore()

    assert proj._hooks[6969]
예제 #4
0
def test_basic_project():
    proj = pySym.Project(os.path.join(myPath, "scripts", "basic_function.py"))
    pg = proj.factory.path_group()
    pg.explore()

    assert len(pg.deadended) == 1
    assert len(pg.completed) == 1
    assert pg.completed[0].state.any_int('x') == 1

    # Make sure we're passing the project through fully
    assert pg._project is proj
    assert pg.deadended[0]._project is proj
    assert pg.deadended[0].state._project is proj
    assert pg.completed[0]._project is proj
    assert pg.completed[0].state._project is proj
예제 #5
0
파일: sym.py 프로젝트: codeezer/ms
import pySym
proj = pySym.Project("./test.py")
pg = proj.factory.path_group()
pg.explore()
pg.completed[0].state.any_int('z')
예제 #6
0
파일: z3_test.py 프로젝트: pbehnke/pySym
#!/usr/bin/env python3

import pySym

proj = pySym.Project("./cipher_mod.py", debug=True)
pg = proj.factory.path_group()
pg.explore()

print(
    "When z3 doesn't freeze, i should make it here in about 30 seconds. Otherwise, it will take infinite amount of time."
)
예제 #7
0
#!/usr/bin/env python
from copy import copy
import z3
import pySym
import IPython

proj = pySym.Project("./bkpctf_crc_mod.py")

def hook_crc(state):
    shift = int(state.getVar('shift'))
    mesg = state.getVar('mesg')
    CRC_POLY = state.getVar('CRC_POLY', ctx=0)
    Then = []
    Else = []
    If = copy(mesg[shift]).getZ3Object() != 0

    print("Hit hook. Shift == " + str(shift))
    print("Len msg == " + str(len(mesg)))

    for i in range(65):
        old_c = copy(mesg[shift+i])
        new_c = mesg[shift+i]
        new_c.increment()
        Then.append(new_c.getZ3Object() == old_c.getZ3Object() ^ CRC_POLY[i].getZ3Object())
        Else.append(new_c.getZ3Object() == old_c.getZ3Object())

    state.addConstraint(z3.If(If, z3.And(Then), z3.And(Else)))
    mesg = state.getVar('mesg')[-64:]
    #print([c.state for c in mesg])
    #print(state)