# Path: sibyl/commons.py
# class HeaderFile(object):
#     """Abstract representation of a Header file"""
# 
#     def __init__(self, header_data, ctype_manager):
#         """Parse @header_data to fill @ctype_manager
#         @header_data: str of a C-like header file
#         @ctype_manager: miasm2.core.objc.CTypesManager instance"""
#         self.data = header_data
#         self.ctype_manager = ctype_manager
# 
#         self.ast = self.parse_header(header_data)
#         self.ctype_manager.types_ast.add_c_decl(header_data)
#         self.functions = {} # function name -> FuncPrototype
# 
#         if pycparser is None:
#             raise ImportError("pycparser module is needed to parse header file")
#         self.parse_functions()
# 
#     @staticmethod
#     def parse_header(header_data):
#         """Return the AST corresponding to @header_data
#         @header_data: str of a C-like header file
#         """
#         # We can't use add_c_decl, because we need the AST to get back
#         # function's arguments name
#         parser = pycparser.c_parser.CParser()
#         return c_to_ast(parser, header_data)
# 
#     def parse_functions(self):
#         """Search for function declarations"""
# 
#         for ext in self.ast.ext:
#             if not (isinstance(ext, pycparser.c_ast.Decl) and
#                     isinstance(ext.type, (pycparser.c_ast.FuncDecl,
#                                           pycparser.c_ast.FuncDef))):
#                 continue
#             func_name = ext.name
#             objc_func = self.ctype_manager.get_objc(CTypeFunc(func_name))
# 
#             args_order = []
#             args = {}
#             for i, param in enumerate(ext.type.args.params):
#                 args_order.append(param.name)
#                 args[param.name] = objc_func.args[i][1]
# 
#             self.functions[func_name] = FuncPrototype(func_name,
#                                                       objc_func.type_ret,
#                                                       *args_order, **args)


import random
    import pycparser
from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE
from miasm2.expression.modint import mod_size2int
from miasm2.expression.simplifications import expr_simp
    from miasm2.core.objc import CTypesManagerNotPacked, CHandler
    from miasm2.core.ctypesmngr import CAstTypes
    from miasm2.arch.x86.ctype import CTypeAMD64_unk
from sibyl.commons import HeaderFile

class TestSetGenerator(TestSet):
    """TestSet based using a generator to retrieve tests"""

    def __init__(self, generator):
        self._generator = generator

    def execute(self, callback):
        for (init, check) in self._generator:
            if not callback(init, check):
                return False
        return True


class TestHeader(Test):
    """Test extension with support for header parsing, and handling of struct
    offset, size, ...
    """

    header = None

    def __init__(self, *args, **kwargs):
        super(TestHeader, self).__init__(*args, **kwargs)
        # Requirement check
        if pycparser is None:
            raise ImportError("pycparser module is needed to launch tests based"
                              "on header files")

        ctype_manager = CTypesManagerNotPacked(CAstTypes(), CTypeAMD64_unk())


# Path: sibyl/commons.py
# class HeaderFile(object):
#     """Abstract representation of a Header file"""
# 
#     def __init__(self, header_data, ctype_manager):
#         """Parse @header_data to fill @ctype_manager
#         @header_data: str of a C-like header file
#         @ctype_manager: miasm2.core.objc.CTypesManager instance"""
#         self.data = header_data
#         self.ctype_manager = ctype_manager
# 
#         self.ast = self.parse_header(header_data)
#         self.ctype_manager.types_ast.add_c_decl(header_data)
#         self.functions = {} # function name -> FuncPrototype
# 
#         if pycparser is None:
#             raise ImportError("pycparser module is needed to parse header file")
#         self.parse_functions()
# 
#     @staticmethod
#     def parse_header(header_data):
#         """Return the AST corresponding to @header_data
#         @header_data: str of a C-like header file
#         """
#         # We can't use add_c_decl, because we need the AST to get back
#         # function's arguments name
#         parser = pycparser.c_parser.CParser()
#         return c_to_ast(parser, header_data)
# 
#     def parse_functions(self):
#         """Search for function declarations"""
# 
#         for ext in self.ast.ext:
#             if not (isinstance(ext, pycparser.c_ast.Decl) and
#                     isinstance(ext.type, (pycparser.c_ast.FuncDecl,
#                                           pycparser.c_ast.FuncDef))):
#                 continue
#             func_name = ext.name
#             objc_func = self.ctype_manager.get_objc(CTypeFunc(func_name))
# 
#             args_order = []
#             args = {}
#             for i, param in enumerate(ext.type.args.params):
#                 args_order.append(param.name)
#                 args[param.name] = objc_func.args[i][1]
# 
#             self.functions[func_name] = FuncPrototype(func_name,
#                                                       objc_func.type_ret,
#                                                       *args_order, **args)


# Path: sibyl/test/test.py
import random
    import pycparser
from miasm2.jitter.csts import PAGE_READ, PAGE_WRITE
from miasm2.expression.modint import mod_size2int
from miasm2.expression.simplifications import expr_simp
    from miasm2.core.objc import CTypesManagerNotPacked, CHandler
    from miasm2.core.ctypesmngr import CAstTypes
    from miasm2.arch.x86.ctype import CTypeAMD64_unk
from sibyl.commons import HeaderFile


class TestSetGenerator(TestSet):
    """TestSet based using a generator to retrieve tests"""

    def __init__(self, generator):
        self._generator = generator

    def execute(self, callback):
        for (init, check) in self._generator:
            if not callback(init, check):
                return False
        return True


class TestHeader(Test):
    """Test extension with support for header parsing, and handling of struct
    offset, size, ...
    """

    header = None

    def __init__(self, *args, **kwargs):
        super(TestHeader, self).__init__(*args, **kwargs)
        # Requirement check
        if pycparser is None:
            raise ImportError("pycparser module is needed to launch tests based"
                              "on header files")

        ctype_manager = CTypesManagerNotPacked(CAstTypes(), CTypeAMD64_unk())


        hdr = HeaderFile(self.header, ctype_manager)