Exemplo n.º 1
0
    def loadFromXML(xmlRoot, namespace, version, automata, vocabulary):
        if version == "0.1":

            id = xmlRoot.get('id')
            name = xmlRoot.get('name')
            initiator = TypeConvertor.str2bool(xmlRoot.get('initiator'))

            abstractionLayer = None
            if xmlRoot.find("{" + namespace + "}abstractionLayer") is not None:
                abstractionLayer = AbstractionLayer.loadFromXML(xmlRoot.find("{" + namespace + "}abstractionLayer"), namespace, version, vocabulary)

            return MMSTDVisitor(id, name, automata, initiator, abstractionLayer)

        return None
Exemplo n.º 2
0
    def loadFromXML(xmlRoot, namespace, version, automata, vocabulary):
        if version == "0.1":

            id = xmlRoot.get('id')
            name = xmlRoot.get('name')
            initiator = TypeConvertor.str2bool(xmlRoot.get('initiator'))

            abstractionLayer = None
            if xmlRoot.find("{" + namespace + "}abstractionLayer") is not None:
                abstractionLayer = AbstractionLayer.loadFromXML(
                    xmlRoot.find("{" + namespace + "}abstractionLayer"),
                    namespace, version, vocabulary)

            return MMSTDVisitor(id, name, automata, initiator,
                                abstractionLayer)

        return None
Exemplo n.º 3
0
    def loadProperties(rootElement, namespace):
        # Retrieves the direction
        msg_direction = rootElement.find("{" + namespace + "}direction").text

        # Retrieves the major
        msg_major = rootElement.find("{" + namespace + "}major").text

        # Retrieves the minor
        msg_minor = int(rootElement.find("{" + namespace + "}minor").text)

        # Retrieves the requestMode
        msg_requestMode = rootElement.find("{" + namespace + "}requestMode").text

        # Retrieves the pid
        msg_pid = int(rootElement.find("{" + namespace + "}pid").text)

        # Retrieves the status
        msg_status = int(rootElement.find("{" + namespace + "}status").text)

        # Retrieves the information
        msg_information = long(rootElement.find("{" + namespace + "}information").text)

        # Retrieves the cancel
        msg_cancel = TypeConvertor.str2bool(rootElement.find("{" + namespace + "}cancel").text)

        # Retrieves the sizeIn
        msg_sizeIn = int(rootElement.find("{" + namespace + "}sizeIn").text)

        # Retrieves the sizeOut
        msg_sizeOut = int(rootElement.find("{" + namespace + "}sizeOut").text)

        return (
            msg_direction,
            msg_major,
            msg_minor,
            msg_requestMode,
            msg_pid,
            msg_status,
            msg_information,
            msg_cancel,
            msg_sizeIn,
            msg_sizeOut,
        )
Exemplo n.º 4
0
    def loadProperties(rootElement, namespace):
        # Retrieves the direction
        msg_direction = rootElement.find("{" + namespace + "}direction").text

        # Retrieves the major
        msg_major = rootElement.find("{" + namespace + "}major").text

        # Retrieves the minor
        msg_minor = int(rootElement.find("{" + namespace + "}minor").text)

        # Retrieves the requestMode
        msg_requestMode = rootElement.find("{" + namespace +
                                           "}requestMode").text

        # Retrieves the pid
        msg_pid = int(rootElement.find("{" + namespace + "}pid").text)

        # Retrieves the status
        msg_status = int(rootElement.find("{" + namespace + "}status").text)

        # Retrieves the information
        msg_information = long(
            rootElement.find("{" + namespace + "}information").text)

        # Retrieves the cancel
        msg_cancel = TypeConvertor.str2bool(
            rootElement.find("{" + namespace + "}cancel").text)

        # Retrieves the sizeIn
        msg_sizeIn = int(rootElement.find("{" + namespace + "}sizeIn").text)

        # Retrieves the sizeOut
        msg_sizeOut = int(rootElement.find("{" + namespace + "}sizeOut").text)

        return (msg_direction, msg_major, msg_minor, msg_requestMode, msg_pid,
                msg_status, msg_information, msg_cancel, msg_sizeIn,
                msg_sizeOut)
Exemplo n.º 5
0
    def loadFromXML(rootElement, namespace, version):

        # Then we verify its an IPC Message
        if rootElement.get("{http://www.w3.org/2001/XMLSchema-instance}type", "abstract") != "netzob-common:IRPMessage":
            raise NameError("The parsed xml doesn't represent a IRP message.")

        # Verifies the data field
        if rootElement.find("{" + namespace + "}data") == None or rootElement.find("{" + namespace + "}data").text == None or not rootElement.find("{" + namespace + "}data").text:
            raise NameError("The parsed message has no data specified")

        # Parse the data field and transform it into a byte array
        msg_data = bytearray(rootElement.find("{" + namespace + "}data").text)

        # Retrieve the id
        msg_id = rootElement.get("id")

        # Retrieve the timestamp
        msg_timestamp = int(rootElement.get("timestamp"))

        # Retrieves the direction
        msg_direction = rootElement.find("{" + namespace + "}direction").text

        # Retrieves the major
        msg_major = rootElement.find("{" + namespace + "}major").text

        # Retrieves the minor
        msg_minor = int(rootElement.find("{" + namespace + "}minor").text)

        # Retrieves the requestMode
        msg_requestMode = rootElement.find("{" + namespace + "}requestMode").text

        # Retrieves the pid
        msg_pid = int(rootElement.find("{" + namespace + "}pid").text)

        # Retrieves the status
        msg_status = int(rootElement.find("{" + namespace + "}status").text)

        # Retrieves the information
        msg_information = long(rootElement.find("{" + namespace + "}information").text)

        # Retrieves the cancel
        msg_cancel = TypeConvertor.str2bool(rootElement.find("{" + namespace + "}cancel").text)

        # Retrieves the sizeIn
        msg_sizeIn = int(rootElement.find("{" + namespace + "}sizeIn").text)

        # Retrieves the sizeOut
        msg_sizeOut = int(rootElement.find("{" + namespace + "}sizeOut").text)

        #Retrieve pattern

        pattern = []
        try:
            patTemp = rootElement.find("{" + namespace + "}pattern")
            pattern.append(patTemp.find("{" + namespace + "}direction").text)
            tokens = patTemp.findall("{" + namespace + "}token")
            #print "find "+str(tokens)
            tokenList = []
            for t in tokens:
                t_format = t.get("format")
                t_length = t.get("length")
                t_type = t.get("type")
                t_value = t.get("value").decode("base-64")
                tokenList.append(Token(t_format, t_length, t_type, t_value))
            pattern.append(tokenList)
        except:
            pattern = []

        #print "FACTORY "+rootElement.find("{" + namespace + "}pattern").text+" give "+str(pattern[0])+";"+str([str(i) for i in pattern[1]])
        # TODO : verify this ! Circular imports in python !
        # WARNING : verify this ! Circular imports in python !
        from netzob.Common.Models.IRPMessage import IRPMessage

        result = IRPMessage(msg_id, msg_timestamp, msg_data, "IRP", msg_direction, msg_major, msg_minor, msg_requestMode, msg_pid, msg_status, msg_information, msg_cancel, msg_sizeIn, msg_sizeOut, pattern)

        return result
Exemplo n.º 6
0
    def loadProjectConfiguration(xmlRoot, namespace, version):

        projectConfiguration = ProjectConfiguration()

        if version == "0.1":
            # Load the configuration of the vocabulary inference
            if xmlRoot.find("{" + namespace + "}vocabulary_inference") is not None:

                xmlVocabularyInference = xmlRoot.find("{" + namespace + "}vocabulary_inference")

                # Equivalence threshold
                xmlEquivalence = xmlVocabularyInference.find("{" + namespace + "}" + ProjectConfiguration.VOCABULARY_EQUIVALENCE_THRESHOLD)
                if xmlEquivalence is not None and xmlEquivalence.text is not None and len(xmlEquivalence.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_EQUIVALENCE_THRESHOLD, int(xmlEquivalence.text))

                # Orphan reduction
                xmlOrphanReduction = xmlVocabularyInference.find("{" + namespace + "}" + ProjectConfiguration.VOCABULARY_ORPHAN_REDUCTION)
                if xmlOrphanReduction is not None and xmlOrphanReduction.text is not None and len(xmlOrphanReduction.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_ORPHAN_REDUCTION, TypeConvertor.str2bool(xmlOrphanReduction.text))

                # Nb iteration
                xmlNbIteration = xmlVocabularyInference.find("{" + namespace + "}" + ProjectConfiguration.VOCABULARY_NB_ITERATION)
                if xmlNbIteration is not None and xmlNbIteration.text is not None and len(xmlNbIteration.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_NB_ITERATION, int(xmlNbIteration.text))

                # Do Internal Slick
                xmlDoInternalSlick = xmlVocabularyInference.find("{" + namespace + "}" + ProjectConfiguration.VOCABULARY_DO_INTERNAL_SLICK)
                if xmlDoInternalSlick is not None and xmlDoInternalSlick.text is not None and len(xmlDoInternalSlick.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_DO_INTERNAL_SLICK, TypeConvertor.str2bool(xmlDoInternalSlick.text))

                # Display Messages
                xmlDisplayMessages = xmlVocabularyInference.find("{" + namespace + "}" + ProjectConfiguration.VOCABULARY_DISPLAY_MESSAGES)
                if xmlDisplayMessages is not None and xmlDisplayMessages.text is not None and len(xmlDisplayMessages.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_DISPLAY_MESSAGES, TypeConvertor.str2bool(xmlDisplayMessages.text))

                # Display Symbol Structure
                xmlDisplaySymbolStructure = xmlVocabularyInference.find("{" + namespace + "}" + ProjectConfiguration.VOCABULARY_DISPLAY_SYMBOL_STRUCTURE)
                if xmlDisplaySymbolStructure is not None and xmlDisplaySymbolStructure.text is not None and len(xmlDisplaySymbolStructure.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_DISPLAY_SYMBOL_STRUCTURE, TypeConvertor.str2bool(xmlDisplaySymbolStructure.text))

                # Display Console
                xmlDisplayConsole = xmlVocabularyInference.find("{" + namespace + "}" + ProjectConfiguration.VOCABULARY_DISPLAY_CONSOLE)
                if xmlDisplayConsole is not None and xmlDisplayConsole.text is not None and len(xmlDisplayConsole.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_DISPLAY_CONSOLE, TypeConvertor.str2bool(xmlDisplayConsole.text))

                # Display Search
                xmlDisplaySearch = xmlVocabularyInference.find("{" + namespace + "}" + ProjectConfiguration.VOCABULARY_DISPLAY_SEARCH)
                if xmlDisplaySearch is not None and xmlDisplaySearch.text is not None and len(xmlDisplaySearch.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_DISPLAY_SEARCH, TypeConvertor.str2bool(xmlDisplaySearch.text))

                # Display Properties
                xmlDisplayProperties = xmlVocabularyInference.find("{" + namespace + "}" + ProjectConfiguration.VOCABULARY_DISPLAY_PROPERTIES)
                if xmlDisplayProperties is not None and xmlDisplayProperties.text is not None and len(xmlDisplayProperties.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_DISPLAY_PROPERTIES, TypeConvertor.str2bool(xmlDisplayProperties.text))

                # Global format
                xmlGlobalFormat = xmlVocabularyInference.find("{" + namespace + "}" + ProjectConfiguration.VOCABULARY_GLOBAL_FORMAT)
                if xmlGlobalFormat is not None and xmlGlobalFormat.text is not None and len(xmlGlobalFormat.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_GLOBAL_FORMAT, xmlGlobalFormat.text)

                # Global unitsize
                xmlGlobalUnitSize = xmlVocabularyInference.find("{" + namespace + "}" + ProjectConfiguration.VOCABULARY_GLOBAL_UNITSIZE)
                if xmlGlobalUnitSize is not None and xmlGlobalUnitSize.text is not None and len(xmlGlobalUnitSize.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_GLOBAL_UNITSIZE, xmlGlobalUnitSize.text)

                # Global sign
                xmlGlobalSign = xmlVocabularyInference.find("{" + namespace + "}" + ProjectConfiguration.VOCABULARY_GLOBAL_SIGN)
                if xmlGlobalSign is not None and xmlGlobalSign.text is not None and len(xmlGlobalSign.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_GLOBAL_SIGN, xmlGlobalSign.text)

                # Global endianess
                xmlGlobalEndianess = xmlVocabularyInference.find("{" + namespace + "}" + ProjectConfiguration.VOCABULARY_GLOBAL_ENDIANESS)
                if xmlGlobalEndianess is not None and xmlGlobalEndianess.text is not None and len(xmlGlobalEndianess.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_GLOBAL_ENDIANESS, xmlGlobalEndianess.text)

                # Environmental dependencies
                xmlEnvDependencies = xmlVocabularyInference.find("{" + namespace + "}" + ProjectConfiguration.VOCABULARY_ENVIRONMENTAL_DEPENDENCIES)
                if xmlEnvDependencies is not None:
                    envDependencies = projectConfiguration.getVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_ENVIRONMENTAL_DEPENDENCIES)
                    for xmlEnvDependency in xmlEnvDependencies.findall("{" + namespace + "}" + ProjectConfiguration.VOCABULARY_ENVIRONMENTAL_DEPENDENCY):
                        envDependencyName = xmlEnvDependency.get("name", "none")
                        envDependencyType = xmlEnvDependency.get("type", "none")
                        envDependencyValue = xmlEnvDependency.text
                        if envDependencyValue is None:
                            envDependencyValue = ""
                        envDependencies.append(EnvironmentalDependency(envDependencyName, envDependencyType, envDependencyValue))

            # Load the configuration of the grammar inference

            # Load the configuration of the simulation

        return projectConfiguration
Exemplo n.º 7
0
    def loadProjectConfiguration(xmlRoot, namespace, version):

        projectConfiguration = ProjectConfiguration()

        if version == "0.1":
            # Load the configuration of the vocabulary inference
            if xmlRoot.find("{" + namespace +
                            "}vocabulary_inference") is not None:

                xmlVocabularyInference = xmlRoot.find("{" + namespace +
                                                      "}vocabulary_inference")

                # Equivalence threshold
                xmlEquivalence = xmlVocabularyInference.find(
                    "{" + namespace + "}" +
                    ProjectConfiguration.VOCABULARY_EQUIVALENCE_THRESHOLD)
                if xmlEquivalence is not None and xmlEquivalence.text is not None and len(
                        xmlEquivalence.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(
                        ProjectConfiguration.VOCABULARY_EQUIVALENCE_THRESHOLD,
                        int(xmlEquivalence.text))

                # Orphan reduction
                xmlOrphanReduction = xmlVocabularyInference.find(
                    "{" + namespace + "}" +
                    ProjectConfiguration.VOCABULARY_ORPHAN_REDUCTION)
                if xmlOrphanReduction is not None and xmlOrphanReduction.text is not None and len(
                        xmlOrphanReduction.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(
                        ProjectConfiguration.VOCABULARY_ORPHAN_REDUCTION,
                        TypeConvertor.str2bool(xmlOrphanReduction.text))

                # Nb iteration
                xmlNbIteration = xmlVocabularyInference.find(
                    "{" + namespace + "}" +
                    ProjectConfiguration.VOCABULARY_NB_ITERATION)
                if xmlNbIteration is not None and xmlNbIteration.text is not None and len(
                        xmlNbIteration.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(
                        ProjectConfiguration.VOCABULARY_NB_ITERATION,
                        int(xmlNbIteration.text))

                # Do Internal Slick
                xmlDoInternalSlick = xmlVocabularyInference.find(
                    "{" + namespace + "}" +
                    ProjectConfiguration.VOCABULARY_DO_INTERNAL_SLICK)
                if xmlDoInternalSlick is not None and xmlDoInternalSlick.text is not None and len(
                        xmlDoInternalSlick.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(
                        ProjectConfiguration.VOCABULARY_DO_INTERNAL_SLICK,
                        TypeConvertor.str2bool(xmlDoInternalSlick.text))

                # Display Messages
                xmlDisplayMessages = xmlVocabularyInference.find(
                    "{" + namespace + "}" +
                    ProjectConfiguration.VOCABULARY_DISPLAY_MESSAGES)
                if xmlDisplayMessages is not None and xmlDisplayMessages.text is not None and len(
                        xmlDisplayMessages.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(
                        ProjectConfiguration.VOCABULARY_DISPLAY_MESSAGES,
                        TypeConvertor.str2bool(xmlDisplayMessages.text))

                # Display Symbol Structure
                xmlDisplaySymbolStructure = xmlVocabularyInference.find(
                    "{" + namespace + "}" +
                    ProjectConfiguration.VOCABULARY_DISPLAY_SYMBOL_STRUCTURE)
                if xmlDisplaySymbolStructure is not None and xmlDisplaySymbolStructure.text is not None and len(
                        xmlDisplaySymbolStructure.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(
                        ProjectConfiguration.
                        VOCABULARY_DISPLAY_SYMBOL_STRUCTURE,
                        TypeConvertor.str2bool(xmlDisplaySymbolStructure.text))

                # Display Console
                xmlDisplayConsole = xmlVocabularyInference.find(
                    "{" + namespace + "}" +
                    ProjectConfiguration.VOCABULARY_DISPLAY_CONSOLE)
                if xmlDisplayConsole is not None and xmlDisplayConsole.text is not None and len(
                        xmlDisplayConsole.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(
                        ProjectConfiguration.VOCABULARY_DISPLAY_CONSOLE,
                        TypeConvertor.str2bool(xmlDisplayConsole.text))

                # Display Search
                xmlDisplaySearch = xmlVocabularyInference.find(
                    "{" + namespace + "}" +
                    ProjectConfiguration.VOCABULARY_DISPLAY_SEARCH)
                if xmlDisplaySearch is not None and xmlDisplaySearch.text is not None and len(
                        xmlDisplaySearch.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(
                        ProjectConfiguration.VOCABULARY_DISPLAY_SEARCH,
                        TypeConvertor.str2bool(xmlDisplaySearch.text))

                # Display Properties
                xmlDisplayProperties = xmlVocabularyInference.find(
                    "{" + namespace + "}" +
                    ProjectConfiguration.VOCABULARY_DISPLAY_PROPERTIES)
                if xmlDisplayProperties is not None and xmlDisplayProperties.text is not None and len(
                        xmlDisplayProperties.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(
                        ProjectConfiguration.VOCABULARY_DISPLAY_PROPERTIES,
                        TypeConvertor.str2bool(xmlDisplayProperties.text))

                # Global format
                xmlGlobalFormat = xmlVocabularyInference.find(
                    "{" + namespace + "}" +
                    ProjectConfiguration.VOCABULARY_GLOBAL_FORMAT)
                if xmlGlobalFormat is not None and xmlGlobalFormat.text is not None and len(
                        xmlGlobalFormat.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(
                        ProjectConfiguration.VOCABULARY_GLOBAL_FORMAT,
                        xmlGlobalFormat.text)

                # Global unitsize
                xmlGlobalUnitSize = xmlVocabularyInference.find(
                    "{" + namespace + "}" +
                    ProjectConfiguration.VOCABULARY_GLOBAL_UNITSIZE)
                if xmlGlobalUnitSize is not None and xmlGlobalUnitSize.text is not None and len(
                        xmlGlobalUnitSize.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(
                        ProjectConfiguration.VOCABULARY_GLOBAL_UNITSIZE,
                        xmlGlobalUnitSize.text)

                # Global sign
                xmlGlobalSign = xmlVocabularyInference.find(
                    "{" + namespace + "}" +
                    ProjectConfiguration.VOCABULARY_GLOBAL_SIGN)
                if xmlGlobalSign is not None and xmlGlobalSign.text is not None and len(
                        xmlGlobalSign.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(
                        ProjectConfiguration.VOCABULARY_GLOBAL_SIGN,
                        xmlGlobalSign.text)

                # Global endianess
                xmlGlobalEndianess = xmlVocabularyInference.find(
                    "{" + namespace + "}" +
                    ProjectConfiguration.VOCABULARY_GLOBAL_ENDIANESS)
                if xmlGlobalEndianess is not None and xmlGlobalEndianess.text is not None and len(
                        xmlGlobalEndianess.text) > 0:
                    projectConfiguration.setVocabularyInferenceParameter(
                        ProjectConfiguration.VOCABULARY_GLOBAL_ENDIANESS,
                        xmlGlobalEndianess.text)

                # Environmental dependencies
                xmlEnvDependencies = xmlVocabularyInference.find(
                    "{" + namespace + "}" +
                    ProjectConfiguration.VOCABULARY_ENVIRONMENTAL_DEPENDENCIES)
                if xmlEnvDependencies is not None:
                    envDependencies = projectConfiguration.getVocabularyInferenceParameter(
                        ProjectConfiguration.
                        VOCABULARY_ENVIRONMENTAL_DEPENDENCIES)
                    for xmlEnvDependency in xmlEnvDependencies.findall(
                            "{" + namespace + "}" + ProjectConfiguration.
                            VOCABULARY_ENVIRONMENTAL_DEPENDENCY):
                        envDependencyName = xmlEnvDependency.get(
                            "name", "none")
                        envDependencyType = xmlEnvDependency.get(
                            "type", "none")
                        envDependencyValue = xmlEnvDependency.text
                        if envDependencyValue is None:
                            envDependencyValue = ""
                        envDependencies.append(
                            EnvironmentalDependency(envDependencyName,
                                                    envDependencyType,
                                                    envDependencyValue))

            # Load the configuration of the grammar inference

            # Load the configuration of the simulation

        return projectConfiguration