def test_int_to_str_simplification(self):
        correct_script = '''(set-logic ALL)


(check-sat)
'''
        int_concrete = claripy.BVV(0xc, 32)
        res = claripy.IntToStr(int_concrete)
        solver = self.get_solver()
        solver.add(res == claripy.StringV("12"))
        script = solver.get_smtlib_script_satisfiability()
        self.assertEqual(correct_script, script)
    def test_int_to_str(self):
        correct_script = '''(set-logic ALL)
(declare-fun symb_int () Int)
(assert (let ((.def_0 (= ( int.to.str symb_int ) "12"))) .def_0))
(check-sat)
'''
        int_symb = claripy.BVS("symb_int", 32, explicit_name=True)
        res = claripy.IntToStr(int_symb)
        solver = self.get_solver()
        solver.add(res == claripy.StringV("12"))
        script = solver.get_smtlib_script_satisfiability()
        self.assertEqual(correct_script, script)
Exemple #3
0
    def run(self, this_ref, thing):
        log.debug(
            'Called SimProcedure java.lang.StringBuilder.append with args: {} {}'
            .format(this_ref, thing))
        field = this_ref.get_field(self.state, 'str', 'java.lang.String')
        field_str = self.state.memory.load(field)

        if isinstance(thing, SimSootValue_StringRef):
            thing_str = self.state.memory.load(thing)

        elif isinstance(thing, claripy.ast.BV):
            thing_str = claripy.IntToStr(thing)

        else:
            log.error(
                'NotImplemented, unsupported type for StringBuilder.append')
            return this_ref

        result = claripy.StrConcat(field_str, thing_str)
        new_str_ref = SimSootValue_StringRef.new_string(self.state, result)
        this_ref.store_field(self.state, 'str', 'java.lang.String',
                             new_str_ref)

        return this_ref
Exemple #4
0
 def run(self, int_val):
     log.debug(
         'Called SimProcedure java.lang.Integer.toString with args: {}'.
         format(int_val))
     return SimSootValue_StringRef.new_string(self.state,
                                              claripy.IntToStr(int_val))
                subNode = convertAst(ast.args[0]).node_Bits.node_BV
                FP = ast_pb2.FP()
                FP.fromBv.CopyFrom(subNode)
                return FP

            else:
                raise ValueError("Serialization not implemented for ast: " +
                                 str(ast))
    elif isinstance(ast, SimActionObject):
        return _convertAst(ast.ast)
    else:
        return ast


if __name__ == "__main__":
    s = claripy.IntToStr(
        (claripy.BVS("x", 64) *
         (claripy.BVV(9, 64) + claripy.BVS("x", 64)))[32:0]) + (
             claripy.StringV("toto") + claripy.StringS("toto", 32))

    b = convertAst(s)

    print(str(b))

    print(b.IsInitialized())

    # Parsing and Serialization
    # Finally, each protocol buffer class has methods for writing and reading messages of your chosen type using the protocol buffer binary format. These include:
    #     SerializeToString(): serializes the message and returns it as a string. Note that the bytes are binary, not text; we only use the str type as a convenient container.
    #     ParseFromString(data): parses a message from the given string.