本文整理汇总了Python中claripy.Or方法的典型用法代码示例。如果您正苦于以下问题:Python claripy.Or方法的具体用法?Python claripy.Or怎么用?Python claripy.Or使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类claripy
的用法示例。
在下文中一共展示了claripy.Or方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_circumstantial_constraints
# 需要导入模块: import claripy [as 别名]
# 或者: from claripy import Or [as 别名]
def _get_circumstantial_constraints(self, state, rop_uncontrolled):
# for those registers which are uncontrolled by rop, can we control it
# circumstantially?
constraints = [ ]
for register in rop_uncontrolled:
# if it's eax we can't control with rop, make sure it can be 2
if register == "eax":
constraints.append(state.regs.eax == 2)
# if it's ebx we need to make sure it can stdout
if register == "ebx":
constraints.append(state.regs.ebx == 1)
if register == "ecx":
constraints.append(state.regs.ecx >= 0x4347c000)
constraints.append(state.regs.ecx <= (0x4347d000 - 4))
# if it's edx, we need to be able to set it to just above 4 bytes
if register == "edx":
constraints.append(state.regs.edx > 0x4)
# if it's esi, we need to point to NULL or a writable page
# TODO support setting to a writable page
if register == "esi":
or_cons = [ ]
for page_start, page_end in self._get_writable_pages(state):
or_cons.append(claripy.And(state.regs.esi >= page_start, state.regs.esi <= (page_end - 4)))
combine_cons = or_cons[0]
for con in or_cons[1:]:
combine_cons = claripy.Or(combine_cons, con)
constraints.append(combine_cons)
return constraints
示例2: constrain_control
# 需要导入模块: import claripy [as 别名]
# 或者: from claripy import Or [as 别名]
def constrain_control(self,
state,
symbolic_variable,
start_loc,
select_string="`ls`"):
for i in range(len(select_string)):
current_byte = state.memory.load(start_loc + i).get_byte(0)
state.add_constraints(
claripy.Or(claripy.And(select_string[i] == current_byte)))
示例3: strtol_inner
# 需要导入模块: import claripy [as 别名]
# 或者: from claripy import Or [as 别名]
def strtol_inner(s, state, region, base, signed, read_length=None):
"""
:param s: the string address/offset
:param state: SimState
:param region: memory, file, etc
:param base: the base to use to interpret the number
note: all numbers may start with +/- and base 16 may start with 0x
:param signed: boolean, true means the result will be signed, otherwise unsigned
:param read_length: int, the number of bytes parsed in strtol
:return: expression, value, num_bytes
the returned expression is a symbolic boolean indicating success, value will be set to 0 on failure
value is the returned value (set to min/max on overflow)
num_bytes is the number of bytes read in the string
"""
# sanity check
if base < 2 or base > 36:
raise SimProcedureError("base should be in the range [2,36]")
# order matters here since we will use an if then else tree, and -0x will have precedence over -
prefixes = [b"-", b"+", b""]
if base == 16:
prefixes = [b"0x", b"-0x", b"+0x"] + prefixes
cases = []
conditions = []
possible_num_bytes = []
for prefix in prefixes:
if read_length and read_length < len(prefix):
continue
condition, value, num_bytes = strtol._load_num_with_prefix(prefix, s, region, state, base, signed, read_length)
conditions.append(condition)
cases.append((condition, value))
possible_num_bytes.append(num_bytes)
# only one of the cases needed to match
result = state.solver.ite_cases(cases[:-1], cases[-1][1])
expression = state.solver.Or(*conditions)
num_bytes = state.solver.ite_cases(zip(conditions, possible_num_bytes), 0)
return expression, result, num_bytes
示例4: _char_to_val
# 需要导入模块: import claripy [as 别名]
# 或者: from claripy import Or [as 别名]
def _char_to_val(char, base):
"""
converts a symbolic char to a number in the given base
returns expression, result
expression is a symbolic boolean indicating whether or not it was a valid number
result is the value
"""
cases = []
# 0-9
max_digit = claripy.BVV(b"9")
min_digit = claripy.BVV(b"0")
if base < 10:
max_digit = claripy.BVV(ord("0") + base, 8)
is_digit = claripy.And(char >= min_digit, char <= max_digit)
# return early here so we don't add unnecessary statements
if base <= 10:
return is_digit, char - min_digit
# handle alphabetic chars
max_char_lower = claripy.BVV(ord("a") + base-10 - 1, 8)
max_char_upper = claripy.BVV(ord("A") + base-10 - 1, 8)
min_char_lower = claripy.BVV(ord("a"), 8)
min_char_upper = claripy.BVV(ord("A"), 8)
cases.append((is_digit, char - min_digit))
is_alpha_lower = claripy.And(char >= min_char_lower, char <= max_char_lower)
cases.append((is_alpha_lower, char - min_char_lower + 10))
is_alpha_upper = claripy.And(char >= min_char_upper, char <= max_char_upper)
cases.append((is_alpha_upper, char - min_char_upper + 10))
expression = claripy.Or(is_digit, is_alpha_lower, is_alpha_upper)
# use the last case as the default, the expression will encode whether or not it's satisfiable
result = claripy.ite_cases(cases[:-1], cases[-1][1])
return expression, result
示例5: _fold_double_negations
# 需要导入模块: import claripy [as 别名]
# 或者: from claripy import Or [as 别名]
def _fold_double_negations(cond):
# !(!A) ==> A
# !((!A) && (!B)) ==> A || B
# !((!A) && B) ==> A || !B
# !(A || B) ==> (!A && !B)
if cond.op != "Not":
return None
if cond.args[0].op == "Not":
return cond.args[0]
if cond.args[0].op == "And" and len(cond.args[0].args) == 2:
and_0, and_1 = cond.args[0].args
if and_0.op == "Not" and and_1.op == "Not":
expr = claripy.Or(and_0.args[0], and_1.args[0])
return expr
if and_0.op == "Not": # and_1.op != "Not"
expr = claripy.Or(
and_0.args[0],
ConditionProcessor.simplify_condition(
claripy.Not(and_1)
)
)
return expr
if cond.args[0].op == "Or" and len(cond.args[0].args) == 2:
or_0, or_1 = cond.args[0].args
expr = claripy.And(
ConditionProcessor.simplify_condition(claripy.Not(or_0)),
ConditionProcessor.simplify_condition(claripy.Not(or_1)),
)
return expr
return None
# delayed import
示例6: test_or
# 需要导入模块: import claripy [as 别名]
# 或者: from claripy import Or [as 别名]
def test_or(self):
str_symb = claripy.StringS("Symb_or", 4, explicit_name=True)
solver = self.get_solver()
res = claripy.Or((str_symb == claripy.StringV("abc")),
(str_symb == claripy.StringV("ciao")))
solver.add(res)
self.assertTrue(solver.satisfiable())
result = solver.eval(str_symb, 3 if KEEP_TEST_PERFORMANT else 100)
self.assertEqual({'ciao', 'abc'}, set(result))
示例7: test_bool
# 需要导入模块: import claripy [as 别名]
# 或者: from claripy import Or [as 别名]
def test_bool():
bc = claripy.backends.concrete
a = claripy.And(*[False, False, True])
nose.tools.assert_equal(bc.convert(a), False)
a = claripy.And(*[True, True, True])
nose.tools.assert_equal(bc.convert(a), True)
o = claripy.Or(*[False, False, True])
nose.tools.assert_equal(bc.convert(o), True)
o = claripy.Or(*[False, False, False])
nose.tools.assert_equal(bc.convert(o), False)
示例8: test_bool_simplification
# 需要导入模块: import claripy [as 别名]
# 或者: from claripy import Or [as 别名]
def test_bool_simplification():
def assert_correct(a, b):
nose.tools.assert_true(claripy.backends.z3.identical(claripy.simplify(a), b))
a, b, c = (claripy.BoolS(name) for name in ('a', 'b', 'c'))
assert_correct(claripy.And(a, claripy.Not(a)), claripy.false)
assert_correct(claripy.Or(a, claripy.Not(a)), claripy.true)
complex_true_expression = claripy.Or(
claripy.And(a,b),
claripy.Or(claripy.And(a, claripy.Not(b)), claripy.And(claripy.Not(a), c)),
claripy.Or(claripy.And(a, claripy.Not(b)), claripy.And(claripy.Not(a), claripy.Not(c))))
assert_correct(complex_true_expression, claripy.true)
示例9: test_or
# 需要导入模块: import claripy [as 别名]
# 或者: from claripy import Or [as 别名]
def test_or(self):
correct_script = '''(set-logic ALL)
(declare-fun {0}Symb_or () String)
(assert (let ((.def_0 (= {0}Symb_or "ciao"))) (let ((.def_1 (= {0}Symb_or "abc"))) (let ((.def_2 (or .def_1 .def_0))) .def_2))))
(check-sat)
'''.format(String.STRING_TYPE_IDENTIFIER)
str_symb = claripy.StringS("Symb_or", 4, explicit_name=True)
solver = self.get_solver()
res = claripy.Or((str_symb == claripy.StringV("abc")),
(str_symb == claripy.StringV("ciao")))
solver.add(res)
script = solver.get_smtlib_script_satisfiability()
# with open("dump_or.smt2", "w") as dump_f:
# dump_f.write(script)
self.assertEqual(correct_script, script)
示例10: _can_point_to_secret
# 需要导入模块: import claripy [as 别名]
# 或者: from claripy import Or [as 别名]
def _can_point_to_secret(state, ast):
if not isinstance(state.spectre, SpectreExplicitState): return False
in_each_interval = [claripy.And(ast >= mn, ast < mx) for (mn,mx) in state.spectre.secretIntervals]
if state.solver.satisfiable(extra_constraints=[claripy.Or(*in_each_interval)]): return True # there is a solution to current constraints such that the ast points to secret
return False # ast cannot point to secret
示例11: concretize
# 需要导入模块: import claripy [as 别名]
# 或者: from claripy import Or [as 别名]
def concretize(self, memory, addr):
"""
Attempts to resolve the address to a value in the targeted interval(s)
if possible. Else, defers to fallback strategies.
"""
if not self.targetedIntervals: return None
try:
constraint = claripy.Or(*[claripy.And(addr >= mn, addr < mx) for (mn,mx) in self.targetedIntervals])
return [ self._any(memory, addr, extra_constraints=[constraint]) ]
except angr.errors.SimUnsatError:
# no solution
return None
示例12: can_be_oob
# 需要导入模块: import claripy [as 别名]
# 或者: from claripy import Or [as 别名]
def can_be_oob(state, addr, length):
l.debug("checking if {} can be oob".format(addr))
inbounds_intervals = state.oob.inbounds_intervals + [get_stack_interval(state)]
oob_constraints = [claripy.Or(addr < mn, addr+length > mx) for (mn,mx) in inbounds_intervals]
if state.solver.satisfiable(extra_constraints=oob_constraints): return True # there is a solution to current constraints such that the access is OOB
return False # operation must be inbounds
示例13: _concretize
# 需要导入模块: import claripy [as 别名]
# 或者: from claripy import Or [as 别名]
def _concretize(self, memory, addr):
"""
Attempts to resolve the address to a value *outside* all of the in-bounds
intervals if possible.
Else, defers to fallback strategies.
"""
try:
constraints = [memory.state.solver.Or(addr < mn, addr >= mx) for (mn, mx) in memory.state.oob.inbounds_intervals]
return [ self._any(memory, addr, extra_constraints=constraints) ]
except angr.errors.SimUnsatError:
# no solution
return None
示例14: run
# 需要导入模块: import claripy [as 别名]
# 或者: from claripy import Or [as 别名]
def run(self, idx): # pylint: disable=W0221
cidxlist = self.state.solver.eval_upto(idx, 256)
if len(cidxlist) == 1:
cidx = cidxlist[0]
ii = int(self.tstr.split(" ")[cidx], 10)
return claripy.BVV(ii, 32)
else:
bvs = claripy.BVS("gsn", 32)
contraint_list = [claripy.And(bvs == int(self.tstr.split(" ")[cidx], 10), idx==cidx) for cidx in cidxlist]
fc = claripy.Or(*contraint_list)
print(repr(fc)[:200]+" ... "+repr(fc)[-200:])
self.state.add_constraints(fc)
return bvs
示例15: run
# 需要导入模块: import claripy [as 别名]
# 或者: from claripy import Or [as 别名]
def run(self, nptr, endptr, base): # pylint: disable=arguments-differ
if self.state.solver.symbolic(base):
l.warning("Concretizing symbolic base in strtol")
base_concrete = self.state.solver.eval(base)
self.state.add_constraints(base == base_concrete)
base = self.state.solver.eval(base)
if base == 0:
# in this case the base is 16 if it starts with 0x, 8 if it starts with 0, 10 otherwise
# here's the possibilities
base_16_pred = self.state.solver.Or(
self.state.memory.load(nptr, 2) == self.state.solver.BVV(b"0x"),
self.state.memory.load(nptr, 3) == self.state.solver.BVV(b"+0x"),
self.state.memory.load(nptr, 3) == self.state.solver.BVV(b"-0x"))
base_8_pred = self.state.solver.And(
self.state.solver.Or(
self.state.memory.load(nptr, 1) == self.state.solver.BVV(b"0"),
self.state.memory.load(nptr, 2) == self.state.solver.BVV(b"+0"),
self.state.memory.load(nptr, 2) == self.state.solver.BVV(b"-0")),
self.state.solver.Not(base_16_pred))
base_10_pred = self.state.solver.And(
self.state.solver.Not(base_16_pred),
self.state.solver.Not(base_8_pred)
)
expressions = []
values = []
num_bytes_arr = []
# read a string to long for each possibility
pred_base = zip([base_16_pred, base_10_pred, base_8_pred], [16, 10, 8])
for pred, sub_base in pred_base:
expression, value, num_bytes = self.strtol_inner(nptr, self.state, self.state.memory, sub_base, True)
expressions.append(self.state.solver.And(expression, pred))
values.append(value)
num_bytes_arr.append(num_bytes)
# we would return the Or(expressions) as the indicator whether or not it succeeded, but it's not needed
# for strtol
# expression = self.state.solver.Or(expressions)
value = self.state.solver.ite_cases(zip(expressions, values), 0)
num_bytes = self.state.solver.ite_cases(zip(expressions, num_bytes_arr), 0)
self.state.memory.store(endptr, nptr+num_bytes,
condition=(endptr != 0), endness=self.state.arch.memory_endness)
return value
else:
expression, value, num_bytes = self.strtol_inner(nptr, self.state, self.state.memory, base, True)
self.state.memory.store(endptr, nptr+num_bytes, condition=(endptr != 0), endness=self.state.arch.memory_endness)
return self.state.solver.If(expression, value, 0)