Пример #1
0
    def _create_nondet_method(self, method_name, method_type, param_types):
        if not (method_type == 'void' or self.is_supported_type(method_type)):
            logging.warning('Crest can\'t handle symbolic values of type %s',
                            method_type)
            internal_type = 'unsigned long long'
            logging.warning('Continuing with type %s for method %s',
                            internal_type, method_name)
        elif method_type == '_Bool':
            internal_type = 'char'
        else:
            internal_type = method_type
        var_name = utils.get_sym_var_name(method_name)
        marker_method_call = 'CREST_' + '_'.join(internal_type.split())
        method_head = utils.get_method_head(method_name, method_type,
                                            param_types)
        method_body = ['{']
        if method_type != 'void':
            method_body += [
                '{0} {1};'.format(internal_type, var_name), '{0}({1});'.format(
                    marker_method_call, var_name)
            ]

            if method_type == internal_type:
                method_body.append('return {0};'.format(var_name))
            else:
                method_body.append('return ({0}) {1};'.format(
                    method_type, var_name))

        method_body = '\n    '.join(method_body)
        method_body += '\n}\n'

        return method_head + method_body
Пример #2
0
    def _get_nondet_method_definition(method_name, method_type, param_types):
        method_head = utils.get_method_head(method_name, method_type,
                                            param_types)
        method_body = ['{']
        if method_type != 'void':
            method_body += ['return *(({}*) 0);'.format(method_type)]
        method_body = '\n    '.join(method_body)
        method_body += '\n}\n'

        return method_head + method_body
Пример #3
0
    def _create_nondet_method(self, method_name, method_type, param_types):
        method_head = utils.get_method_head(method_name, 'int', param_types)
        method_body = ['{']
        if method_type != 'void':
            method_body += [
                'return ({0}) {1}();'.format(method_type, input_method)
            ]
        method_body = '\n    '.join(method_body)
        method_body += '\n}\n'

        return method_head + method_body
Пример #4
0
    def _get_nondet_method_definition(method_name, method_type, method_param):
        definition = ""
        definition += utils.get_method_head(method_name, method_type,
                                            method_param)
        definition += ' {\n'
        if method_type != 'void':
            definition += "    unsigned int inp_size = 3000;\n"
            definition += "    char * inp_var = malloc(inp_size);\n"
            definition += "    fgets(inp_var, inp_size, stdin);\n"

            definition += "    return *((" + method_type + "*) parse_inp(inp_var));\n"
        definition += ' }\n'
        return definition
Пример #5
0
    def _get_nondet_method_definition(method_name, method_type, param_types):
        var_name = utils.get_sym_var_name(method_name)
        method_head = utils.get_method_head(method_name, method_type,
                                            param_types)
        method_body = ['{']
        if method_type != 'void':
            method_body += [
                '{0} {1};'.format(method_type, var_name),
                'input(&{0}, sizeof({0}), \"{0}\");'.format(var_name),
                'return {0};'.format(var_name)
            ]
        method_body = '\n    '.join(method_body)
        method_body += '\n}\n'

        return method_head + method_body
Пример #6
0
    def _create_nondet_method(self, method_name, method_type, param_types):
        var_name = utils.get_sym_var_name(method_name)
        method_head = utils.get_method_head(method_name, method_type,
                                            param_types)
        method_body = ['{']
        if method_type != 'void':
            method_body += [
                '{0} {1};'.format(method_type, var_name),
                'klee_make_symbolic(&{0}, sizeof({0}), \"{0}\");'.format(
                    var_name), 'return {0};'.format(var_name)
            ]
        method_body = '\n    '.join(method_body)
        method_body += '\n}\n'

        return method_head + method_body
Пример #7
0
    def _get_nondet_method_definitions(self, nondet_methods, test_vector):
        definitions = b''
        if test_vector is not None:
            definitions += b'unsigned int access_counter = 0;\n\n'
        for method in nondet_methods:
            definitions += utils.get_method_head(method['name'],
                                                 method['type'],
                                                 method['params']).encode()
            definitions += b' {\n'
            if method['type'] != 'void':
                definitions += "    unsigned int inp_size = 3000;\n".encode()
                definitions += "    char * inp_var = malloc(inp_size);\n".encode(
                )
                if test_vector is None:  # Build generic harness
                    definitions += "    fgets(inp_var, inp_size, stdin);\n".encode(
                    )
                else:
                    definitions += "    switch(access_counter) {\n".encode()
                    for idx, item in enumerate(test_vector.vector):
                        if type(item['value']) is bytes:
                            value = item['value']
                        else:
                            value = item['value'].encode()
                        # yapf: disable
                        definitions += b''.join([
                            b'case ', str(idx).encode(),
                            b': strcpy(inp_var, "', value, b'"); break;\n'
                        ])
                        # yapf: enable
                    definitions += b"        default: abort();\n"
                    definitions += b"    }\n"
                    definitions += b"    access_counter++;\n"

                definitions += b''.join([
                    b'    return *((', method['type'].encode(),
                    b' *) parse_inp(inp_var));\n'
                ])
            definitions += b'}\n\n'
        return definitions
Пример #8
0
    def _create_nondet_method(self, method_name, method_type, param_types):
        var_name = utils.get_sym_var_name(method_name)
        method_head = utils.get_method_head(method_name, method_type,
                                            param_types)
        method_body = ['{']
        if method_type != 'void':
            if 'float' in method_type or 'double' in method_type:
                conversion_cmd = 'strtold({0}, 0);'.format(var_name)
            elif 'unsigned' in method_type and 'long long' in method_type:
                conversion_cmd = 'strtoull({0}, 0, 10);'.format(var_name)
            else:
                conversion_cmd = 'strtoll({0}, 0, 10);'.format(var_name)
            return_statement = 'return ({0}) {1}'.format(
                method_type, conversion_cmd)
            method_body += [
                'char * {0} = malloc(1000);'.format(var_name),
                'fgets({0}, 1000, stdin);'.format(var_name), return_statement
            ]
        method_body = '\n    '.join(method_body)
        method_body += '\n}\n'

        return method_head + method_body