예제 #1
0
def broken_ccall():
    s = SimState(arch="AMD64")

    l.debug("Testing amd64_actions_ADD")
    l.debug("(8-bit) 1 + 1...")
    arg_l = s.se.BitVecVal(1, 8)
    arg_r = s.se.BitVecVal(1, 8)
    ret = s_ccall.pc_actions_ADD(s, 8, arg_l, arg_r, 0, platform='AMD64')
    nose.tools.assert_equal(ret, 0)

    l.debug("(32-bit) (-1) + (-2)...")
    arg_l = s.se.BitVecVal(-1, 32)
    arg_r = s.se.BitVecVal(-1, 32)
    ret = s_ccall.pc_actions_ADD(s, 32, arg_l, arg_r, 0, platform='AMD64')
    nose.tools.assert_equal(ret, 0b101010)

    l.debug("Testing pc_actions_SUB")
    l.debug("(8-bit) 1 - 1...", )
    arg_l = s.se.BitVecVal(1, 8)
    arg_r = s.se.BitVecVal(1, 8)
    ret = s_ccall.pc_actions_SUB(s, 8, arg_l, arg_r, 0, platform='AMD64')
    nose.tools.assert_equal(ret, 0b010100)

    l.debug("(32-bit) (-1) - (-2)...")
    arg_l = s.se.BitVecVal(-1, 32)
    arg_r = s.se.BitVecVal(-1, 32)
    ret = s_ccall.pc_actions_SUB(s, 32, arg_l, arg_r, 0, platform='AMD64')
    nose.tools.assert_equal(ret, 0)
예제 #2
0
def broken_ccall():
    s = SimState(arch="AMD64")

    l.debug("Testing amd64_actions_ADD")
    l.debug("(8-bit) 1 + 1...")
    arg_l = s.se.BitVecVal(1, 8)
    arg_r = s.se.BitVecVal(1, 8)
    ret = s_ccall.pc_actions_ADD(s, 8, arg_l, arg_r, 0, platform='AMD64')
    nose.tools.assert_equal(ret, 0)

    l.debug("(32-bit) (-1) + (-2)...")
    arg_l = s.se.BitVecVal(-1, 32)
    arg_r = s.se.BitVecVal(-1, 32)
    ret = s_ccall.pc_actions_ADD(s, 32, arg_l, arg_r, 0, platform='AMD64')
    nose.tools.assert_equal(ret, 0b101010)

    l.debug("Testing pc_actions_SUB")
    l.debug("(8-bit) 1 - 1...",)
    arg_l = s.se.BitVecVal(1, 8)
    arg_r = s.se.BitVecVal(1, 8)
    ret = s_ccall.pc_actions_SUB(s, 8, arg_l, arg_r, 0, platform='AMD64')
    nose.tools.assert_equal(ret, 0b010100)

    l.debug("(32-bit) (-1) - (-2)...")
    arg_l = s.se.BitVecVal(-1, 32)
    arg_r = s.se.BitVecVal(-1, 32)
    ret = s_ccall.pc_actions_SUB(s, 32, arg_l, arg_r, 0, platform='AMD64')
    nose.tools.assert_equal(ret, 0)
예제 #3
0
파일: test_vex.py 프로젝트: shadown/simuvex
def test_ccall():
    s = SimState(arch="AMD64")

    l.debug("Testing amd64_actions_ADD")
    l.debug("(8-bit) 1 + 1...")
    arg_l = s.se.BVV(1, 8)
    arg_r = s.se.BVV(1, 8)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_ADD(s, 8, arg_l, arg_r, 0, platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 0))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 0))

    l.debug("(32-bit) (-1) + (-2)...")
    arg_l = s.se.BVV(-1, 32)
    arg_r = s.se.BVV(-1, 32)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_ADD(s, 32, arg_l, arg_r, 0, platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 1))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 1))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 1))
    nose.tools.assert_true(s.se.is_true(of == 0))

    l.debug("Testing pc_actions_SUB")
    l.debug("(8-bit) 1 - 1...",)
    arg_l = s.se.BVV(1, 8)
    arg_r = s.se.BVV(1, 8)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_SUB(s, 8, arg_l, arg_r, 0, platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 0))
    nose.tools.assert_true(s.se.is_true(pf == 1))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 1))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 0))

    l.debug("(32-bit) (-1) - (-2)...")
    arg_l = s.se.BVV(-1, 32)
    arg_r = s.se.BVV(-2, 32)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_SUB(s, 32, arg_l, arg_r, 0, platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 0))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 0))
예제 #4
0
파일: test_vex.py 프로젝트: ocean1/simuvex
def test_ccall():
    s = SimState(arch="AMD64")

    l.debug("Testing amd64_actions_ADD")
    l.debug("(8-bit) 1 + 1...")
    arg_l = s.se.BVV(1, 8)
    arg_r = s.se.BVV(1, 8)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_ADD(s,
                                                    8,
                                                    arg_l,
                                                    arg_r,
                                                    0,
                                                    platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 0))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 0))

    l.debug("(32-bit) (-1) + (-2)...")
    arg_l = s.se.BVV(-1, 32)
    arg_r = s.se.BVV(-1, 32)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_ADD(s,
                                                    32,
                                                    arg_l,
                                                    arg_r,
                                                    0,
                                                    platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 1))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 1))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 1))
    nose.tools.assert_true(s.se.is_true(of == 0))

    l.debug("Testing pc_actions_SUB")
    l.debug("(8-bit) 1 - 1...", )
    arg_l = s.se.BVV(1, 8)
    arg_r = s.se.BVV(1, 8)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_SUB(s,
                                                    8,
                                                    arg_l,
                                                    arg_r,
                                                    0,
                                                    platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 0))
    nose.tools.assert_true(s.se.is_true(pf == 1))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 1))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 0))

    l.debug("(32-bit) (-1) - (-2)...")
    arg_l = s.se.BVV(-1, 32)
    arg_r = s.se.BVV(-2, 32)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_SUB(s,
                                                    32,
                                                    arg_l,
                                                    arg_r,
                                                    0,
                                                    platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 0))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 0))

    l.debug("Testing pc_actions_ROL")
    l.debug("(8-bit) ROL 1 1...")
    result = s.se.BVV(2, 8)  # the result of rol(1, 1)
    oldflags = s.se.BVV(0, 8)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_ROL(s,
                                                    8,
                                                    result,
                                                    None,
                                                    oldflags,
                                                    platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 0))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 0))

    l.debug("(32-bit) ROL (-1) (-2)... (shift out of range)")
    result = s.se.BVV(-1, 32)  # the result of rol(-1, 0xfe)
    oldflags = s.se.BVV(0, 32)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_ROL(s,
                                                    32,
                                                    result,
                                                    None,
                                                    oldflags,
                                                    platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 1))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 0))

    l.debug("Testing pc_actions_ROR")
    l.debug("(32-bit) ROR 2 1...")
    result = s.se.BVV(1, 32)  # the result of ror(2, 1)
    oldflags = s.se.BVV(0, 8)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_ROR(s,
                                                    32,
                                                    result,
                                                    None,
                                                    oldflags,
                                                    platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 0))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 0))

    l.debug("Testing pc_actions_ROR")
    l.debug("(32-bit) ROR 1 1...")
    result = s.se.BVV(0x80000000, 32)  # the result of ror(1, 1)
    oldflags = s.se.BVV(0, 8)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_ROR(s,
                                                    32,
                                                    result,
                                                    None,
                                                    oldflags,
                                                    platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 1))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 1))

    l.debug("Testing pc_actions_ROR")
    l.debug("(32-bit) ROR -1 1...")
    result = s.se.BVV(-1, 32)  # the result of ror(0xffffffff, 1)
    oldflags = s.se.BVV(0, 32)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_ROR(s,
                                                    32,
                                                    result,
                                                    None,
                                                    oldflags,
                                                    platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 1))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 0))

    l.debug("(32-bit) ROR (-1) (-2)... (shift out of range)")
    result = s.se.BVV(-1, 32)  # the result of ror(0xffffffff, 0xfe)
    oldflags = s.se.BVV(0, 32)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_ROR(s,
                                                    32,
                                                    result,
                                                    None,
                                                    oldflags,
                                                    platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 1))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 0))
예제 #5
0
파일: test_vex.py 프로젝트: Owlz/simuvex
def test_ccall():
    s = SimState(arch="AMD64")

    l.debug("Testing amd64_actions_ADD")
    l.debug("(8-bit) 1 + 1...")
    arg_l = s.se.BVV(1, 8)
    arg_r = s.se.BVV(1, 8)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_ADD(s, 8, arg_l, arg_r, 0, platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 0))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 0))

    l.debug("(32-bit) (-1) + (-2)...")
    arg_l = s.se.BVV(-1, 32)
    arg_r = s.se.BVV(-1, 32)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_ADD(s, 32, arg_l, arg_r, 0, platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 1))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 1))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 1))
    nose.tools.assert_true(s.se.is_true(of == 0))

    l.debug("Testing pc_actions_SUB")
    l.debug("(8-bit) 1 - 1...",)
    arg_l = s.se.BVV(1, 8)
    arg_r = s.se.BVV(1, 8)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_SUB(s, 8, arg_l, arg_r, 0, platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 0))
    nose.tools.assert_true(s.se.is_true(pf == 1))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 1))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 0))

    l.debug("(32-bit) (-1) - (-2)...")
    arg_l = s.se.BVV(-1, 32)
    arg_r = s.se.BVV(-2, 32)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_SUB(s, 32, arg_l, arg_r, 0, platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 0))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 0))

    l.debug("Testing pc_actions_ROL")
    l.debug("(8-bit) ROL 1 1...")
    result = s.se.BVV(2, 8) # the result of rol(1, 1)
    oldflags = s.se.BVV(0, 8)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_ROL(s, 8, result, None, oldflags, platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 0))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 0))

    l.debug("(32-bit) ROL (-1) (-2)... (shift out of range)")
    result = s.se.BVV(-1, 32) # the result of rol(-1, 0xfe)
    oldflags = s.se.BVV(0, 32)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_ROL(s, 32, result, None, oldflags, platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 1))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 0))

    l.debug("Testing pc_actions_ROR")
    l.debug("(32-bit) ROR 2 1...")
    result = s.se.BVV(1, 32) # the result of ror(2, 1)
    oldflags = s.se.BVV(0, 8)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_ROR(s, 32, result, None, oldflags, platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 0))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 0))

    l.debug("Testing pc_actions_ROR")
    l.debug("(32-bit) ROR 1 1...")
    result = s.se.BVV(0x80000000, 32) # the result of ror(1, 1)
    oldflags = s.se.BVV(0, 8)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_ROR(s, 32, result, None, oldflags, platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 1))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 1))

    l.debug("Testing pc_actions_ROR")
    l.debug("(32-bit) ROR -1 1...")
    result = s.se.BVV(-1, 32) # the result of ror(0xffffffff, 1)
    oldflags = s.se.BVV(0, 32)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_ROR(s, 32, result, None, oldflags, platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 1))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 0))

    l.debug("(32-bit) ROR (-1) (-2)... (shift out of range)")
    result = s.se.BVV(-1, 32) # the result of ror(0xffffffff, 0xfe)
    oldflags = s.se.BVV(0, 32)
    cf, pf, af, zf, sf, of = s_ccall.pc_actions_ROR(s, 32, result, None, oldflags, platform='AMD64')
    nose.tools.assert_true(s.se.is_true(cf == 1))
    nose.tools.assert_true(s.se.is_true(pf == 0))
    nose.tools.assert_true(s.se.is_true(af == 0))
    nose.tools.assert_true(s.se.is_true(zf == 0))
    nose.tools.assert_true(s.se.is_true(sf == 0))
    nose.tools.assert_true(s.se.is_true(of == 0))