コード例 #1
0
ファイル: crest.py プロジェクト: FArian/tbf
    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_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()
                        definitions += b''.join([b'case ', str(idx).encode(), b': strcpy(inp_var, "', value, b'"); break;\n'])
                    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
コード例 #3
0
ファイル: crest.py プロジェクト: FArian/tbf
    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
コード例 #4
0
ファイル: cpatiger.py プロジェクト: FArian/tbf
    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
コード例 #5
0
ファイル: cpatiger.py プロジェクト: FArian/tbf
    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
コード例 #6
0
ファイル: klee.py プロジェクト: FArian/tbf
    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 _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),
                            '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
コード例 #8
0
ファイル: fshell.py プロジェクト: FArian/tbf
    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
コード例 #9
0
ファイル: fshell.py プロジェクト: FArian/tbf
    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