本文整理汇总了Python中simuvex.SimState类的典型用法代码示例。如果您正苦于以下问题:Python SimState类的具体用法?Python SimState怎么用?Python SimState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_memset
def test_memset():
l.info("concrete src, concrete dst, concrete len")
s = SimState(arch="PPC32", mode="symbolic")
dst = s.se.BitVecVal(0, 128)
dst_addr = s.se.BitVecVal(0x1000, 32)
char = s.se.BitVecVal(0x00000041, 32)
char2 = s.se.BitVecVal(0x50505050, 32)
length = s.BV("some_length", 32)
s.memory.store(dst_addr, dst)
memset(s, inline=True, arguments=[dst_addr, char, s.se.BitVecVal(3, 32)])
nose.tools.assert_equals(s.se.any_int(s.memory.load(dst_addr, 4)), 0x41414100)
l.debug("Symbolic length")
s = SimState(arch="PPC32", mode="symbolic")
s.memory.store(dst_addr, dst)
length = s.BV("some_length", 32)
memset(s, inline=True, arguments=[dst_addr, char2, length])
l.debug("Trying 2")
s_two = s.copy()
s_two.add_constraints(length == 2)
nose.tools.assert_equals(s_two.se.any_int(s_two.memory.load(dst_addr, 4)), 0x50500000)
l.debug("Trying 0")
s_zero = s.copy()
s_zero.add_constraints(length == 0)
nose.tools.assert_equals(s_zero.se.any_int(s_zero.memory.load(dst_addr, 4)), 0x00000000)
l.debug("Trying 5")
s_five = s.copy()
s_five.add_constraints(length == 5)
nose.tools.assert_equals(s_five.se.any_int(s_five.memory.load(dst_addr, 6)), 0x505050505000)
示例2: test_inline_strlen
def test_inline_strlen():
s = SimState(arch="AMD64", mode="symbolic")
l.info("fully concrete string")
a_str = s.se.BitVecVal(0x41414100, 32)
a_addr = s.se.BitVecVal(0x10, 64)
s.memory.store(a_addr, a_str, endness="Iend_BE")
a_len = SimProcedures["libc.so.6"]["strlen"](s, inline=True, arguments=[a_addr]).ret_expr
nose.tools.assert_true(s.se.unique(a_len))
nose.tools.assert_equal(s.se.any_int(a_len), 3)
l.info("concrete-terminated string")
b_str = s.se.Concat(s.BV("mystring", 24), s.se.BitVecVal(0, 8))
b_addr = s.se.BitVecVal(0x20, 64)
s.memory.store(b_addr, b_str, endness="Iend_BE")
b_len = SimProcedures["libc.so.6"]["strlen"](s, inline=True, arguments=[b_addr]).ret_expr
nose.tools.assert_equal(s.se.max_int(b_len), 3)
nose.tools.assert_items_equal(s.se.any_n_int(b_len, 10), (0, 1, 2, 3))
l.info("fully unconstrained")
u_addr = s.se.BitVecVal(0x50, 64)
u_len_sp = SimProcedures["libc.so.6"]["strlen"](s, inline=True, arguments=[u_addr])
u_len = u_len_sp.ret_expr
nose.tools.assert_equal(len(s.se.any_n_int(u_len, 100)), s.libc.buf_symbolic_bytes)
nose.tools.assert_equal(s.se.max_int(u_len), s.libc.buf_symbolic_bytes - 1)
# print u_len_sp.se.maximum_null
# s.add_constraints(u_len < 16)
nose.tools.assert_equal(s.se.any_n_int(s.memory.load(0x50 + u_len, 1), 300), [0])
#
# This tests if a strlen can influence a symbolic str.
#
l.info("Trying to influence length.")
s = SimState(arch="AMD64", mode="symbolic")
str_c = s.BV("some_string", 8 * 16)
c_addr = s.se.BitVecVal(0x10, 64)
s.memory.store(c_addr, str_c, endness="Iend_BE")
c_len = SimProcedures["libc.so.6"]["strlen"](s, inline=True, arguments=[c_addr]).ret_expr
nose.tools.assert_equal(len(s.se.any_n_int(c_len, 100)), s.libc.buf_symbolic_bytes)
nose.tools.assert_equal(s.se.max_int(c_len), s.libc.buf_symbolic_bytes - 1)
one_s = s.copy()
one_s.add_constraints(c_len == 1)
nose.tools.assert_equal(one_s.se.any_str(str_c).index("\x00"), 1)
str_test = one_s.memory.load(c_addr, 2, endness="Iend_BE")
nose.tools.assert_equal(len(one_s.se.any_n_str(str_test, 300)), 255)
for i in range(16):
test_s = s.copy()
test_s.add_constraints(c_len == i)
str_test = test_s.memory.load(c_addr, i + 1, endness="Iend_BE")
nose.tools.assert_equal(test_s.se.any_str(str_test).index("\x00"), i)
for j in range(i):
nose.tools.assert_false(test_s.se.unique(test_s.memory.load(c_addr + j, 1)))
示例3: test_unsat_core
def test_unsat_core():
s = SimState(arch='AMD64', mode='symbolic', add_options={ simuvex.options.CONSTRAINT_TRACKING_IN_SOLVER })
x = s.se.BVS('x', 32)
s.add_constraints(s.se.BVV(0, 32) == x)
s.add_constraints(s.se.BVV(1, 32) == x)
nose.tools.assert_false(s.satisfiable())
unsat_core = s.se.unsat_core()
nose.tools.assert_equal(len(unsat_core), 2)
示例4: test_state_merge_static
def test_state_merge_static():
# With abstract memory
# Aligned memory merging
a = SimState(mode='static')
se = a.se
addr = a.se.ValueSet(region='global', bits=32, val=8)
a.memory.store(addr, a.se.BitVecVal(42, 32))
b = a.copy()
c = a.copy()
a.memory.store(addr, a.se.BitVecVal(50, 32), endness='Iend_LE')
b.memory.store(addr, a.se.BitVecVal(60, 32), endness='Iend_LE')
c.memory.store(addr, a.se.BitVecVal(70, 32), endness='Iend_LE')
merged, _, _ = a.merge(b, c)
nose.tools.assert_true(merged.memory.load(addr, 4).identical(a.se.SI(bits=32, stride=10, lower_bound=50, upper_bound=70)))
示例5: test_concretization_strategies
def test_concretization_strategies():
initial_memory = {0: 'A', 1: 'B', 2: 'C', 3: 'D'}
s = SimState(memory_backer=initial_memory)
# sanity check
nose.tools.assert_equal(s.se.any_n_str(s.memory.load(3, 1), 2), ['D'])
x = s.se.BVS('x', s.arch.bits)
s.add_constraints(x >= 1)
ss = s.copy()
nose.tools.assert_equal(ss.se.any_n_str(ss.memory.load(x, 1), 2), ['B'])
ss = s.copy()
ss.options.add(simuvex.o.CONSERVATIVE_READ_STRATEGY)
nose.tools.assert_true('symbolic' in next(iter(ss.memory.load(x, 1).variables)))
示例6: test_strchr
def test_strchr():
l.info("concrete haystack and needle")
s = SimState(arch="AMD64", mode="symbolic")
str_haystack = s.se.BitVecVal(0x41424300, 32)
str_needle = s.se.BitVecVal(0x42, 64)
addr_haystack = s.se.BitVecVal(0x10, 64)
s.memory.store(addr_haystack, str_haystack, endness="Iend_BE")
ss_res = strchr(s, inline=True, arguments=[addr_haystack, str_needle]).ret_expr
nose.tools.assert_true(s.se.unique(ss_res))
nose.tools.assert_equal(s.se.any_int(ss_res), 0x11)
l.info("concrete haystack, symbolic needle")
s = SimState(arch="AMD64", mode="symbolic")
str_haystack = s.se.BitVecVal(0x41424300, 32)
str_needle = s.BV("wtf", 64)
chr_needle = str_needle[7:0]
addr_haystack = s.se.BitVecVal(0x10, 64)
s.memory.store(addr_haystack, str_haystack, endness="Iend_BE")
ss_res = strchr(s, inline=True, arguments=[addr_haystack, str_needle]).ret_expr
nose.tools.assert_false(s.se.unique(ss_res))
nose.tools.assert_equal(len(s.se.any_n_int(ss_res, 10)), 4)
s_match = s.copy()
s_nomatch = s.copy()
s_match.add_constraints(ss_res != 0)
s_nomatch.add_constraints(ss_res == 0)
nose.tools.assert_true(s_match.satisfiable())
nose.tools.assert_true(s_nomatch.satisfiable())
nose.tools.assert_equal(len(s_match.se.any_n_int(chr_needle, 300)), 3)
nose.tools.assert_equal(len(s_nomatch.se.any_n_int(chr_needle, 300)), 253)
nose.tools.assert_items_equal(s_match.se.any_n_int(ss_res, 300), [0x10, 0x11, 0x12])
nose.tools.assert_items_equal(s_match.se.any_n_int(chr_needle, 300), [0x41, 0x42, 0x43])
s_match.memory.store(ss_res, s_match.BVV(0x44, 8))
nose.tools.assert_items_equal(s_match.se.any_n_int(s_match.memory.load(0x10, 1), 300), [0x41, 0x44])
nose.tools.assert_items_equal(s_match.se.any_n_int(s_match.memory.load(0x11, 1), 300), [0x42, 0x44])
nose.tools.assert_items_equal(s_match.se.any_n_int(s_match.memory.load(0x12, 1), 300), [0x43, 0x44])
return
示例7: test_state_merge_static
def test_state_merge_static():
# With abstract memory
# Aligned memory merging
a = SimState(mode='static')
addr = a.se.ValueSet(region='global', bits=32, val=8)
a.memory.store(addr, a.se.BVV(42, 32))
# Clear a_locs, so further writes will not try to merge with value 42
a.memory.regions['global']._alocs = { }
b = a.copy()
c = a.copy()
a.memory.store(addr, a.se.BVV(50, 32), endness='Iend_LE')
b.memory.store(addr, a.se.BVV(60, 32), endness='Iend_LE')
c.memory.store(addr, a.se.BVV(70, 32), endness='Iend_LE')
merged, _, _ = a.merge(b, c)
actual = claripy.backends.vsa.convert(merged.memory.load(addr, 4))
expected = claripy.backends.vsa.convert(a.se.SI(bits=32, stride=10, lower_bound=50, upper_bound=70))
nose.tools.assert_true(actual.identical(expected))
示例8: test_state_merge_static
def test_state_merge_static():
# With abstract memory
# Aligned memory merging
a = SimState(mode="static")
se = a.se
addr = a.se.ValueSet(region="global", bits=32, val=8)
a.memory.store(addr, a.se.BitVecVal(42, 32))
# Clear a_locs, so further writes will not try to merge with value 42
a.memory.regions["global"]._alocs = {}
b = a.copy()
c = a.copy()
a.memory.store(addr, a.se.BitVecVal(50, 32), endness="Iend_LE")
b.memory.store(addr, a.se.BitVecVal(60, 32), endness="Iend_LE")
c.memory.store(addr, a.se.BitVecVal(70, 32), endness="Iend_LE")
merged, _, _ = a.merge(b, c)
nose.tools.assert_true(
merged.memory.load(addr, 4).identical(a.se.SI(bits=32, stride=10, lower_bound=50, upper_bound=70))
)
示例9: test_strcpy
def test_strcpy():
l.info("concrete src, concrete dst")
l.debug("... full copy")
s = SimState(arch="AMD64", mode="symbolic")
dst = s.se.BitVecVal(0x41414100, 32)
dst_addr = s.se.BitVecVal(0x1000, 64)
src = s.se.BitVecVal(0x42420000, 32)
src_addr = s.se.BitVecVal(0x2000, 64)
s.memory.store(dst_addr, dst)
s.memory.store(src_addr, src)
strcpy(s, inline=True, arguments=[dst_addr, src_addr])
new_dst = s.memory.load(dst_addr, 4, endness="Iend_BE")
nose.tools.assert_equal(s.se.any_str(new_dst), "BB\x00\x00")
l.info("symbolic src, concrete dst")
dst = s.se.BitVecVal(0x41414100, 32)
dst_addr = s.se.BitVecVal(0x1000, 64)
src = s.BV("src", 32)
src_addr = s.se.BitVecVal(0x2000, 64)
s = SimState(arch="AMD64", mode="symbolic")
s.memory.store(dst_addr, dst)
s.memory.store(src_addr, src)
ln = strlen(s, inline=True, arguments=[src_addr]).ret_expr
strcpy(s, inline=True, arguments=[dst_addr, src_addr])
cm = strcmp(s, inline=True, arguments=[dst_addr, src_addr]).ret_expr
s.add_constraints(cm == 0)
s.add_constraints(ln == 15)
示例10: broken_sprintf
def broken_sprintf():
l.info("concrete src, concrete dst, concrete len")
s = SimState(mode="symbolic", arch="PPC32")
format_str = s.se.BitVecVal(0x25640000, 32)
format_addr = s.se.BitVecVal(0x2000, 32)
# dst = s.se.BitVecVal("destination", 128)
dst_addr = s.se.BitVecVal(0x1000, 32)
arg = s.BV("some_number", 32)
s.memory.store(format_addr, format_str)
sprintf(s, inline=True, arguments=[dst_addr, format_addr, arg])
for i in range(9):
j = random.randint(10 ** i, 10 ** (i + 1))
s2 = s.copy()
s2.add_constraints(arg == j)
# print s2.se.any_n_str(s2.memory.load(dst_addr, i+2), 2), repr("%d\x00" % j)
nose.tools.assert_equal(s2.se.any_n_str(s2.memory.load(dst_addr, i + 2), 2), ["%d\x00" % j])
s2 = s.copy()
s2.add_constraints(arg == 0)
# print s2.se.any_n_str(s2.memory.load(dst_addr, 2), 2), repr("%d\x00" % 0)
nose.tools.assert_equal(s2.se.any_n_str(s2.memory.load(dst_addr, 2), 2), ["%d\x00" % 0])
示例11: test_copy
def test_copy():
s = SimState()
s.memory.store(0x100, "ABCDEFGHIJKLMNOP")
s.memory.store(0x200, "XXXXXXXXXXXXXXXX")
x = s.se.BV('size', s.arch.bits)
s.add_constraints(s.se.ULT(x, 10))
s.memory.copy_contents(0x200, 0x100, x)
nose.tools.assert_equals(sorted(s.se.any_n_int(x, 100)), range(10))
result = s.memory.load(0x200, 5)
nose.tools.assert_equals(sorted(s.se.any_n_str(result, 100)), [ "ABCDE", "ABCDX", "ABCXX", "ABXXX", "AXXXX", "XXXXX" ])
nose.tools.assert_equals(sorted(s.se.any_n_str(result, 100, extra_constraints=[x==3])), [ "ABCXX" ])
s = SimState()
s.posix.write(0, "ABCDEFGHIJKLMNOP", len("ABCDEFGHIJKLMNOP"))
s.posix.seek(0, 0)
s.memory.store(0x200, "XXXXXXXXXXXXXXXX")
x = s.se.BV('size', s.arch.bits)
s.add_constraints(s.se.ULT(x, 10))
s.posix.read(0, x, dst_addr=0x200)
nose.tools.assert_equals(sorted(s.se.any_n_int(x, 100)), range(10))
result = s.memory.load(0x200, 5)
nose.tools.assert_equals(sorted(s.se.any_n_str(result, 100)), [ "ABCDE", "ABCDX", "ABCXX", "ABXXX", "AXXXX", "XXXXX" ])
nose.tools.assert_equals(sorted(s.se.any_n_str(result, 100, extra_constraints=[x==3])), [ "ABCXX" ])
s = SimState()
s.posix.write(0, "ABCDEFGHIJKLMNOP", len("ABCDEFGHIJKLMNOP"))
s.posix.seek(0, 0)
s.memory.store(0x200, "XXXXXXXXXXXXXXXX")
x = s.se.BV('size', s.arch.bits)
s.add_constraints(s.se.ULT(x, 10))
ret_x = SimProcedures['libc.so.6']['read'](s, inline=True, arguments=[0, 0x200, x]).ret_expr
nose.tools.assert_equals(sorted(s.se.any_n_int(x, 100)), range(10))
result = s.memory.load(0x200, 5)
nose.tools.assert_equals(sorted(s.se.any_n_str(result, 100)), [ "ABCDE", "ABCDX", "ABCXX", "ABXXX", "AXXXX", "XXXXX" ])
nose.tools.assert_equals(sorted(s.se.any_n_str(result, 100, extra_constraints=[x==3])), [ "ABCXX" ])
nose.tools.assert_equals(sorted(s.se.any_n_int(ret_x, 100)), range(10))
nose.tools.assert_equals(sorted(s.se.any_n_str(result, 100, extra_constraints=[ret_x==3])), [ "ABCXX" ])
示例12: test_strstr_inconsistency
def test_strstr_inconsistency(n=2):
l.info("symbolic haystack, symbolic needle")
s = SimState(arch="AMD64", mode="symbolic")
s.libc.buf_symbolic_bytes = n
addr_haystack = s.se.BitVecVal(0x10, 64)
addr_needle = s.se.BitVecVal(0xB0, 64)
# len_needle = strlen(s, inline=True, arguments=[addr_needle])
ss_res = strstr(s, inline=True, arguments=[addr_haystack, addr_needle]).ret_expr
# slh_res = strlen(s, inline=True, arguments=[addr_haystack]).ret_expr
# sln_res = strlen(s, inline=True, arguments=[addr_needle]).ret_expr
# print "LENH:", s.se.any_n_int(slh_res, 100)
# print "LENN:", s.se.any_n_int(sln_res, 100)
nose.tools.assert_false(s.se.unique(ss_res))
nose.tools.assert_items_equal(s.se.any_n_int(ss_res, 100), [0] + range(0x10, 0x10 + s.libc.buf_symbolic_bytes - 1))
s.add_constraints(ss_res != 0)
ss2 = strstr(s, inline=True, arguments=[addr_haystack, addr_needle]).ret_expr
s.add_constraints(ss2 == 0)
nose.tools.assert_false(s.satisfiable())
示例13: test_memcpy
def test_memcpy():
l.info("concrete src, concrete dst, concrete len")
l.debug("... full copy")
s = SimState(arch="AMD64", mode="symbolic")
dst = s.se.BitVecVal(0x41414141, 32)
dst_addr = s.se.BitVecVal(0x1000, 64)
src = s.se.BitVecVal(0x42424242, 32)
src_addr = s.se.BitVecVal(0x2000, 64)
s.memory.store(dst_addr, dst)
s.memory.store(src_addr, src)
memcpy(s, inline=True, arguments=[dst_addr, src_addr, s.se.BitVecVal(4, 64)])
new_dst = s.memory.load(dst_addr, 4, endness="Iend_BE")
nose.tools.assert_equal(s.se.any_n_str(new_dst, 2), ["BBBB"])
l.debug("... partial copy")
s = SimState(arch="AMD64", mode="symbolic")
s.memory.store(dst_addr, dst)
s.memory.store(src_addr, src)
memcpy(s, inline=True, arguments=[dst_addr, src_addr, s.se.BitVecVal(2, 64)])
new_dst = s.memory.load(dst_addr, 4, endness="Iend_BE")
nose.tools.assert_equal(s.se.any_n_str(new_dst, 2), ["BBAA"])
l.info("symbolic src, concrete dst, concrete len")
s = SimState(arch="AMD64", mode="symbolic")
dst = s.se.BitVecVal(0x41414141, 32)
dst_addr = s.se.BitVecVal(0x1000, 64)
src = s.BV("src", 32)
src_addr = s.se.BitVecVal(0x2000, 64)
s.memory.store(dst_addr, dst)
s.memory.store(src_addr, src)
# make sure it copies it all
memcpy(s, inline=True, arguments=[dst_addr, src_addr, s.se.BitVecVal(4, 64)])
nose.tools.assert_true(s.satisfiable())
s.add_constraints(src != s.memory.load(dst_addr, 4))
nose.tools.assert_false(s.satisfiable())
l.info("symbolic src, concrete dst, symbolic len")
s = SimState(arch="AMD64", mode="symbolic")
dst = s.se.BitVecVal(0x41414141, 32)
dst_addr = s.se.BitVecVal(0x1000, 64)
src = s.BV("src", 32)
src_addr = s.se.BitVecVal(0x2000, 64)
cpylen = s.BV("len", 64)
s.memory.store(dst_addr, dst)
s.memory.store(src_addr, src)
memcpy(s, inline=True, arguments=[dst_addr, src_addr, cpylen])
result = s.memory.load(dst_addr, 4, endness="Iend_BE")
# make sure it copies it all
s1 = s.copy()
s1.add_constraints(cpylen == 1)
nose.tools.assert_true(s1.se.unique(s1.memory.load(dst_addr + 1, 3)))
nose.tools.assert_equals(len(s1.se.any_n_int(s1.memory.load(dst_addr, 1), 300)), 256)
s2 = s.copy()
s2.add_constraints(cpylen == 2)
nose.tools.assert_equals(len(s2.se.any_n_int(result[31:24], 300)), 256)
nose.tools.assert_equals(len(s2.se.any_n_int(result[23:16], 300)), 256)
nose.tools.assert_equals(s2.se.any_n_str(result[15:0], 300), ["AA"])
l.info("concrete src, concrete dst, symbolic len")
dst = s2.se.BitVecVal(0x41414141, 32)
dst_addr = s2.se.BitVecVal(0x1000, 64)
src = s2.se.BitVecVal(0x42424242, 32)
src_addr = s2.se.BitVecVal(0x2000, 64)
s = SimState(arch="AMD64", mode="symbolic")
s.memory.store(dst_addr, dst)
s.memory.store(src_addr, src)
cpylen = s.BV("len", 64)
s.add_constraints(s.se.ULE(cpylen, 4))
memcpy(s, inline=True, arguments=[dst_addr, src_addr, cpylen])
new_dst = s.memory.load(dst_addr, 4, endness="Iend_BE")
nose.tools.assert_items_equal(s.se.any_n_str(new_dst, 300), ["AAAA", "BAAA", "BBAA", "BBBA", "BBBB"])
示例14: test_inline_strcmp
def test_inline_strcmp():
s = SimState(arch="AMD64", mode="symbolic")
str_a = s.se.BitVecVal(0x41414100, 32)
str_b = s.BV("mystring", 32)
a_addr = s.se.BitVecVal(0x10, 64)
b_addr = s.se.BitVecVal(0xB0, 64)
s.memory.store(a_addr, str_a, endness="Iend_BE")
s.memory.store(b_addr, str_b, endness="Iend_BE")
s_cmp = s.copy()
cmpres = SimProcedures["libc.so.6"]["strcmp"](s_cmp, inline=True, arguments=[a_addr, b_addr]).ret_expr
s_match = s_cmp.copy()
s_nomatch = s_cmp.copy()
s_match.add_constraints(cmpres == 0)
s_nomatch.add_constraints(cmpres != 0)
nose.tools.assert_true(s_match.se.unique(str_b))
nose.tools.assert_false(s_nomatch.se.unique(str_b))
nose.tools.assert_equal(s_match.se.any_str(str_b), "AAA\x00")
s_ncmp = s.copy()
ncmpres = SimProcedures["libc.so.6"]["strncmp"](
s_ncmp, inline=True, arguments=[a_addr, b_addr, s.se.BitVecVal(2, s.arch.bits)]
).ret_expr
s_match = s_ncmp.copy()
s_nomatch = s_ncmp.copy()
s_match.add_constraints(ncmpres == 0)
s_nomatch.add_constraints(ncmpres != 0)
nose.tools.assert_false(s_match.se.unique(str_b))
nose.tools.assert_true(s_match.se.unique(s_match.memory.load(b_addr, 2)))
nose.tools.assert_equal(len(s_match.se.any_n_int(s_match.memory.load(b_addr, 3), 300)), 256)
nose.tools.assert_false(s_nomatch.se.unique(str_b))
l.info("concrete a, symbolic b")
s = SimState(arch="AMD64", mode="symbolic")
str_a = s.se.BitVecVal(0x41424300, 32)
str_b = s.BV("mystring", 32)
a_addr = s.se.BitVecVal(0x10, 64)
b_addr = s.se.BitVecVal(0xB0, 64)
s.memory.store(a_addr, str_a, endness="Iend_BE")
s.memory.store(b_addr, str_b, endness="Iend_BE")
s_cmp = s.copy()
cmpres = strncmp(s_cmp, inline=True, arguments=[a_addr, b_addr, s.se.BitVecVal(2, s_cmp.arch.bits)]).ret_expr
s_match = s_cmp.copy()
s_nomatch = s_cmp.copy()
s_match.add_constraints(cmpres == 0)
s_nomatch.add_constraints(cmpres != 0)
nose.tools.assert_true(s_match.se.solution(str_b, 0x41420000))
nose.tools.assert_true(s_match.se.solution(str_b, 0x41421234))
nose.tools.assert_true(s_match.se.solution(str_b, 0x41424300))
nose.tools.assert_false(s_nomatch.se.solution(str_b, 0x41420000))
nose.tools.assert_false(s_nomatch.se.solution(str_b, 0x41421234))
nose.tools.assert_false(s_nomatch.se.solution(str_b, 0x41424300))
l.info("symbolic a, symbolic b")
s = SimState(arch="AMD64", mode="symbolic")
a_addr = s.se.BitVecVal(0x10, 64)
b_addr = s.se.BitVecVal(0xB0, 64)
s_cmp = s.copy()
cmpres = strcmp(s_cmp, inline=True, arguments=[a_addr, b_addr]).ret_expr
s_match = s_cmp.copy()
s_nomatch = s_cmp.copy()
s_match.add_constraints(cmpres == 0)
s_nomatch.add_constraints(cmpres != 0)
m_res = strcmp(s_match, inline=True, arguments=[a_addr, b_addr]).ret_expr
s_match.add_constraints(m_res != 0)
nm_res = strcmp(s_nomatch, inline=True, arguments=[a_addr, b_addr]).ret_expr
s_nomatch.add_constraints(nm_res == 0)
nose.tools.assert_false(s_match.satisfiable())
nose.tools.assert_false(s_match.satisfiable())
示例15: broken_strtok_r
def broken_strtok_r():
l.debug("CONCRETE MODE")
s = SimState(arch="AMD64", mode="symbolic")
s.memory.store(100, s.se.BitVecVal(0x4141414241414241424300, 88), endness="Iend_BE")
s.memory.store(200, s.se.BitVecVal(0x4200, 16), endness="Iend_BE")
str_ptr = s.se.BitVecVal(100, s.arch.bits)
delim_ptr = s.se.BitVecVal(200, s.arch.bits)
state_ptr = s.se.BitVecVal(300, s.arch.bits)
st1 = strtok_r(s, inline=True, arguments=[str_ptr, delim_ptr, state_ptr])
nose.tools.assert_equal(s.se.any_n_int(st1.ret_expr, 10), [104])
nose.tools.assert_equal(s.se.any_n_int(s.memory.load(st1.ret_expr - 1, 1), 10), [0])
nose.tools.assert_equal(s.se.any_n_int(s.memory.load(200, 2), 10), [0x4200])
st2 = strtok_r(s, inline=True, arguments=[s.se.BitVecVal(0, s.arch.bits), delim_ptr, state_ptr])
nose.tools.assert_equal(s.se.any_n_int(st2.ret_expr, 10), [107])
nose.tools.assert_equal(s.se.any_n_int(s.memory.load(st2.ret_expr - 1, 1), 10), [0])
st3 = strtok_r(s, inline=True, arguments=[s.se.BitVecVal(0, s.arch.bits), delim_ptr, state_ptr])
nose.tools.assert_equal(s.se.any_n_int(st3.ret_expr, 10), [109])
nose.tools.assert_equal(s.se.any_n_int(s.memory.load(st3.ret_expr - 1, 1), 10), [0])
st4 = strtok_r(s, inline=True, arguments=[s.se.BitVecVal(0, s.arch.bits), delim_ptr, state_ptr])
nose.tools.assert_equal(s.se.any_n_int(st4.ret_expr, 10), [0])
nose.tools.assert_equal(s.se.any_n_int(s.memory.load(300, s.arch.bytes, endness=s.arch.memory_endness), 10), [109])
st5 = strtok_r(s, inline=True, arguments=[s.se.BitVecVal(0, s.arch.bits), delim_ptr, state_ptr])
nose.tools.assert_equal(s.se.any_n_int(st5.ret_expr, 10), [0])
nose.tools.assert_equal(s.se.any_n_int(s.memory.load(300, s.arch.bytes, endness=s.arch.memory_endness), 10), [109])
s.memory.store(1000, s.se.BitVecVal(0x4141414241414241424300, 88), endness="Iend_BE")
s.memory.store(2000, s.se.BitVecVal(0x4200, 16), endness="Iend_BE")
str_ptr = s.se.BitVecVal(1000, s.arch.bits)
delim_ptr = s.se.BitVecVal(2000, s.arch.bits)
state_ptr = s.se.BitVecVal(3000, s.arch.bits)
st1 = strtok_r(s, inline=True, arguments=[str_ptr, delim_ptr, state_ptr])
nose.tools.assert_equal(s.se.any_n_int(st1.ret_expr, 10), [1004])
nose.tools.assert_equal(s.se.any_n_int(s.memory.load(st1.ret_expr - 1, 1), 10), [0])
nose.tools.assert_equal(s.se.any_n_int(s.memory.load(2000, 2), 10), [0x4200])
st2 = strtok_r(s, inline=True, arguments=[s.se.BitVecVal(0, s.arch.bits), delim_ptr, state_ptr])
nose.tools.assert_equal(s.se.any_n_int(st2.ret_expr, 10), [1007])
nose.tools.assert_equal(s.se.any_n_int(s.memory.load(st2.ret_expr - 1, 1), 10), [0])
st3 = strtok_r(s, inline=True, arguments=[s.se.BitVecVal(0, s.arch.bits), delim_ptr, state_ptr])
nose.tools.assert_equal(s.se.any_n_int(st3.ret_expr, 10), [1009])
nose.tools.assert_equal(s.se.any_n_int(s.memory.load(st3.ret_expr - 1, 1), 10), [0])
st4 = strtok_r(s, inline=True, arguments=[s.se.BitVecVal(0, s.arch.bits), delim_ptr, state_ptr])
nose.tools.assert_equal(s.se.any_n_int(st4.ret_expr, 10), [0])
nose.tools.assert_equal(
s.se.any_n_int(s.memory.load(3000, s.arch.bytes, endness=s.arch.memory_endness), 10), [1009]
)
st5 = strtok_r(s, inline=True, arguments=[s.se.BitVecVal(0, s.arch.bits), delim_ptr, state_ptr])
nose.tools.assert_equal(s.se.any_n_int(st5.ret_expr, 10), [0])
nose.tools.assert_equal(
s.se.any_n_int(s.memory.load(3000, s.arch.bytes, endness=s.arch.memory_endness), 10), [1009]
)
print "LIGHT FULLY SYMBOLIC TEST"
s = SimState(arch="AMD64", mode="symbolic")
str_ptr = s.se.BitVecVal(100, s.arch.bits)
delim_ptr = s.se.BitVecVal(200, s.arch.bits)
state_ptr = s.se.BitVecVal(300, s.arch.bits)
s.add_constraints(s.memory.load(delim_ptr, 1) != 0)
st1 = strtok_r(s, inline=True, arguments=[str_ptr, delim_ptr, state_ptr])
s.add_constraints(st1.ret_expr != 0)
nose.tools.assert_equal(s.se.any_n_int(s.memory.load(st1.ret_expr - 1, 1), 10), [0])