Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if size.symbolic:
raise NotImplementedError()
elif real_fd is None:
for i in xrange(0, size.value):
b = bv.Symbol(8, 'file_{}_{:x}'.format(fd.value, offset))
output.append(b)
file['bytes'][offset] = b
offset += 1
else:
real_fd.seek(offset, 0)
for i in range(0, size.value):
byte = real_fd.read(1)
if len(byte) == 1:
if byte == '#':
b = bv.Symbol(8, 'file_{}_{:x}'.format(fd.value, offset))
else:
b = bv.Constant(8, ord(byte))
output.append(b)
file['bytes'][offset] = b
offset += 1
else:
break
file['offset'] = offset
if real_fd is not None:
real_fd.close()
return f.ret(value=size)
def concretise(state, value, count=8):
values = set()
constraint = None
if not value.symbolic:
return [value]
elif not isinstance(value, bv.Symbol):
new_value = bv.Symbol(value.size, unique_name('concretise'))
constraint = (new_value == value)
state.solver.add(constraint)
value = new_value
# we now know that value is a symbol
# TODO: this really hurts performance, but it will probably also help
# with finding bugs... add in again once I have better path culling
# heuristics again
#values.add(maximum(state, value))
#values.add(minimum(state, value))
#if len(values) == 1:
# max == min, our work here is done...
# return list(values)
bv.if_then_else(
byte1 == byte2,
prev_result,
bv.if_then_else(
byte1 < byte2,
first_smaller,
first_larger)),
prev_result)
# this reduces the memory footprint_ of the resulting expression
# significantly
prev_result = bv.Symbol(ptr1.size, unique_name('tmp'))
s.solver.add(prev_result == result)
if result.symbolic:
result_symbol = bv.Symbol(result.size, unique_name('memcmp'))
s.solver.add(result_symbol == result)
result = result_symbol
return f.ret(value=result)
bv.if_then_else(
char1 == char2,
prev_result,
bv.if_then_else(
char1 < char2,
first_smaller,
first_larger)),
prev_result)
# this reduces the memory footprint_ of the resulting expression
# significantly
prev_result = bv.Symbol(32, unique_name('tmp'))
s.solver.add(prev_result == result)
if result.symbolic:
result_symbol = bv.Symbol(32, unique_name('strcmp'))
s.solver.add(result_symbol == result)
result = result_symbol
return f.ret(value=result)
first_larger))
else:
result = bv.if_then_else(
not_already_terminated,
bv.if_then_else(
char1 == char2,
prev_result,
bv.if_then_else(
char1 < char2,
first_smaller,
first_larger)),
prev_result)
# this reduces the memory footprint_ of the resulting expression
# significantly
prev_result = bv.Symbol(32, unique_name('tmp'))
s.solver.add(prev_result == result)
if result.symbolic:
result_symbol = bv.Symbol(32, unique_name('strcmp'))
s.solver.add(result_symbol == result)
result = result_symbol
return f.ret(value=result)
first_larger))
else:
result = bv.if_then_else(
not_already_terminated,
bv.if_then_else(
byte1 == byte2,
prev_result,
bv.if_then_else(
byte1 < byte2,
first_smaller,
first_larger)),
prev_result)
# this reduces the memory footprint_ of the resulting expression
# significantly
prev_result = bv.Symbol(ptr1.size, unique_name('tmp'))
s.solver.add(prev_result == result)
if result.symbolic:
result_symbol = bv.Symbol(result.size, unique_name('memcmp'))
s.solver.add(result_symbol == result)
result = result_symbol
return f.ret(value=result)