Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _store_symbolic_addr(self, address, addresses, size, data, endness, condition):
size = self.state.solver.eval(size)
segments = self._get_segments(addresses, size)
if condition is None:
condition = claripy.BoolV(True)
original_values = [ self._read_from(segment['start'], segment['size']) for segment in segments ]
if endness == "Iend_LE" or (endness is None and self.endness == "Iend_LE"):
original_values = [ ov.reversed for ov in original_values ]
stored_values = []
for segment, original_value in zip(segments, original_values):
conditional_value = original_value
for opt in segment['options']:
if endness == "Iend_LE" or (endness is None and self.endness == "Iend_LE"):
high = ((opt['idx']+segment['size']) * self.state.arch.byte_width)-1
low = opt['idx']*self.state.arch.byte_width
else:
high = len(data) - 1 - (opt['idx']*self.state.arch.byte_width)
log.debug('Called SimProcedure java.util.List.add with args: {} {}'.format(this_ref, obj_ref))
if this_ref.symbolic:
return claripy.BoolS('list.append')
try:
array_ref = this_ref.load_field(self.state, ELEMS, 'java.lang.Object[]')
array_len = this_ref.load_field(self.state, SIZE, 'int')
self.state.javavm_memory.store_array_element(array_ref, array_len, obj_ref)
# Update size
new_array_len = claripy.BVV(self.state.solver.eval(array_len) + 1, 32)
this_ref.store_field(self.state, SIZE, 'int', new_array_len)
except KeyError:
log.warning('Could not add element to list {}'.format(this_ref))
return claripy.BoolV(1)
def _store_fully_symbolic(self, address, addresses, size, data, endness, condition):
stored_values = [ ]
byte_dict = defaultdict(list)
max_bytes = data.length//self.state.arch.byte_width
if condition is None:
condition = claripy.BoolV(True)
# chop data into byte-chunks
original_values = [self._read_from(a, max_bytes) for a in addresses]
if endness == "Iend_LE" or (endness is None and self.endness == "Iend_LE"):
original_values = [ ov.reversed for ov in original_values ]
data_bytes = data.chop(bits=self.state.arch.byte_width)
for a, fv in zip(addresses, original_values):
original_bytes = fv.chop(self.state.arch.byte_width)
for index, (d_byte, o_byte) in enumerate(zip(data_bytes, original_bytes)):
# create a dict of all all possible values for a certain address
byte_dict[a+index].append((a, index, d_byte, o_byte))
for byte_addr in sorted(byte_dict.keys()):
write_list = byte_dict[byte_addr]
# If this assertion fails something is really wrong!
def _store_symbolic_addr(self, address, addresses, size, data, endness, condition):
size = self.state.solver.eval(size)
segments = self._get_segments(addresses, size)
if condition is None:
condition = claripy.BoolV(True)
original_values = [ self._read_from(segment['start'], segment['size']) for segment in segments ]
if endness == "Iend_LE" or (endness is None and self.endness == "Iend_LE"):
original_values = [ ov.reversed for ov in original_values ]
stored_values = []
for segment, original_value in zip(segments, original_values):
conditional_value = original_value
for opt in segment['options']:
data_slice = data[((opt['idx']+segment['size'])*self.state.arch.byte_width)-1:opt['idx']*self.state.arch.byte_width]
conditional_value = self.state.solver.If(self.state.solver.And(address == segment['start']-opt['idx'], condition), data_slice, conditional_value)
stored_values.append(dict(value=conditional_value, addr=segment['start'], size=segment['size']))
return stored_values
def _store_symbolic_addr(self, address, addresses, size, data, endness, condition):
size = self.state.solver.eval(size)
segments = self._get_segments(addresses, size)
if condition is None:
condition = claripy.BoolV(True)
original_values = [ self._read_from(segment['start'], segment['size']) for segment in segments ]
if endness == "Iend_LE" or (endness is None and self.endness == "Iend_LE"):
original_values = [ ov.reversed for ov in original_values ]
stored_values = []
for segment, original_value in zip(segments, original_values):
conditional_value = original_value
for opt in segment['options']:
if endness == "Iend_LE" or (endness is None and self.endness == "Iend_LE"):
high = ((opt['idx']+segment['size']) * self.state.arch.byte_width)-1
low = opt['idx']*self.state.arch.byte_width
else:
high = len(data) - 1 - (opt['idx']*self.state.arch.byte_width)
def run(self, this_ref, key_ref):
log.debug('Called SimProcedure java.util.Map.containsKey with args: {} {}'.format(this_ref, key_ref))
if this_ref.symbolic:
return claripy.BoolS('contains_key')
try:
this_ref.load_field(self.state, get_map_key(self.state, key_ref), 'java.lang.Object')
return claripy.BoolV(1)
except (KeyError, AttributeError):
return claripy.BoolV(0)
def _store_fully_symbolic(self, address, addresses, size, data, endness, condition):
stored_values = [ ]
byte_dict = defaultdict(list)
max_bytes = data.length//self.state.arch.byte_width
if condition is None:
condition = claripy.BoolV(True)
# chop data into byte-chunks
original_values = [self._read_from(a, max_bytes) for a in addresses]
if endness == "Iend_LE" or (endness is None and self.endness == "Iend_LE"):
original_values = [ ov.reversed for ov in original_values ]
data_bytes = data.chop(bits=self.state.arch.byte_width)
for a, fv in zip(addresses, original_values):
original_bytes = fv.chop(self.state.arch.byte_width)
for index, (d_byte, o_byte) in enumerate(zip(data_bytes, original_bytes)):
# create a dict of all all possible values for a certain address
byte_dict[a+index].append((a, index, d_byte, o_byte))
for byte_addr in sorted(byte_dict.keys()):
write_list = byte_dict[byte_addr]
# If this assertion fails something is really wrong!
def run(self, this_ref):
log.debug('Called SimProcedure java.util.Iterator.hasNext with args: {}'.format(this_ref))
if this_ref.symbolic:
return claripy.BoolS('iterator.hasNext')
iterator_size = this_ref.load_field(self.state, SIZE, 'int')
iterator_index = this_ref.load_field(self.state, INDEX, 'int')
has_next = self.state.solver.eval(iterator_index) < self.state.solver.eval(iterator_size)
return claripy.BoolV(has_next)