def test_str_to_int_simplification(self): target_num = 12 if not KEEP_TEST_PERFORMANT else 1000000 str_concrete = claripy.StringV(str(target_num)) solver = self.get_solver() res = claripy.StrToInt(str_concrete, 32) solver.add(res == target_num) self.assertTrue(solver.satisfiable()) self.assertEqual(tuple(), tuple(solver.constraints)) self.assertEqual((target_num, ), solver.eval(res, 2))
def test_str_to_int(self): str_symb = claripy.StringS("symb_strtoint", 4, explicit_name=True) res = claripy.StrToInt(str_symb, 32) solver = self.get_solver() target_num = 12 if KEEP_TEST_PERFORMANT else 100000 solver.add(res == target_num) self.assertTrue(solver.satisfiable()) solutions = solver.eval(str_symb, 2 if KEEP_TEST_PERFORMANT else 1000000) for sol in solutions: self.assertTrue(int(sol) == target_num)
def test_str_to_int_simplification(self): correct_script = '''(set-logic ALL) (check-sat) ''' str_concrete = claripy.StringV("12") solver = self.get_solver() res = claripy.StrToInt(str_concrete, 32) solver.add(res == 12) script = solver.get_smtlib_script_satisfiability() self.assertEqual(correct_script, script)
def test_str_to_int(self): correct_script = '''(set-logic ALL) (declare-fun {0}symb_strtoint () String) (assert (let ((.def_0 (= ( str.to.int {0}symb_strtoint ) 12))) .def_0)) (check-sat) '''.format(String.STRING_TYPE_IDENTIFIER) str_symb = claripy.StringS("symb_strtoint", 4, explicit_name=True) res = claripy.StrToInt(str_symb, 32) solver = self.get_solver() solver.add(res == 12) script = solver.get_smtlib_script_satisfiability() # with open("dump_strtoint.smt2", "w") as dump_f: # dump_f.write(script) self.assertEqual(correct_script, script)
def run(self, str_ref): log.debug( 'Called SimProcedure java.lang.Double.parseDouble with args: {}'. format(str_ref)) str_ = self.state.memory.load(str_ref) if str_.concrete: str_value = self.state.solver.eval(str_) # this can raise a ValueError if str_value is not convertible to float double_val = float(str_value) return claripy.FPV(double_val, claripy.FSORT_DOUBLE) else: return claripy.StrToInt(str_, self.arch.bits)