Ejemplo n.º 1
0
    def loadFromXML(xmlRoot, namespace, version, symbol):
        """loadFromXML:
                Load a variable from an XML definition.
                Calls its proper heir function for it to create the variable.

                @type xmlRoot: lxml.etree.Element
                @param xmlRoot: the root of the XML definition.
                @type namespace: string
                @param namespace: the namespace (precision) associated to the variable in the XML definition.
                @type version: string
                @param version: the load version.
                @rtype: netzob.Common.MMSTD.Dictionary.Variable.AbstractVariable.AbstractVariable
                @type symbol: netzob.Common.Symbol
                @param symbol: the symbol in which the current variable is placed, used by relation variable.
                @return: a variable constructed from this XML definition.
        """
        if version == "0.1":
            logging.debug("[ AbstractVariable: loadFromXML:")
            # Data Variable
            if xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type", "abstract") == "netzob:DataVariable":
                from netzob.Common.MMSTD.Dictionary.Variables.DataVariable import DataVariable
                return DataVariable.loadFromXML(xmlRoot, namespace, version, symbol)

            # Aggregate Variable
            elif xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type", "abstract") == "netzob:AggregateVariable":
                from netzob.Common.MMSTD.Dictionary.Variables.AggregateVariable import AggregateVariable
                return AggregateVariable.loadFromXML(xmlRoot, namespace, version, symbol)

            # Alternate Variable
            elif xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type", "abstract") == "netzob:AlternateVariable":
                from netzob.Common.MMSTD.Dictionary.Variables.AlternateVariable import AlternateVariable
                return AlternateVariable.loadFromXML(xmlRoot, namespace, version, symbol)

            # Repeat Variable
            elif xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type", "abstract") == "netzob:RepeatVariable":
                from netzob.Common.MMSTD.Dictionary.Variables.RepeatVariable import RepeatVariable
                return RepeatVariable.loadFromXML(xmlRoot, namespace, version, symbol)

            # Direct Relation Variable
            #elif xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type", "abstract") == "netzob:DirectRelationVariable":
            #    from netzob.Common.MMSTD.Dictionary.Variables.DirectRelationVariable import DirectRelationVariable
            #    return DirectRelationVariable.loadFromXML(xmlRoot, namespace, version, symbol)

            # Computed Relation Variable
            elif xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type", "abstract") == "netzob:ComputedRelationVariable":
                from netzob.Common.MMSTD.Dictionary.Variables.ComputedRelationVariable import ComputedRelationVariable
                return ComputedRelationVariable.loadFromXML(xmlRoot, namespace, version, symbol)

            else:
                logging.debug("xmlRoot.get(...) returns {0} which does not correspond to a true variable class.").format(xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type", "abstract"))
            logging.debug("AbstractVariable: loadFromXML ]")
        else:
            logging.debug("Version != 0.1")
Ejemplo n.º 2
0
    def loadFromXML(xmlRoot, namespace, version):
        if version == "0.1":
            # IPv4 Variable
            if xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type", "abstract") == "netzob:IPv4Variable":
                from netzob.Common.MMSTD.Dictionary.Variables.IPv4Variable import IPv4Variable
                return IPv4Variable.loadFromXML(xmlRoot, namespace, version)

            # Word Variable
            if xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type", "abstract") == "netzob:WordVariable":
                from netzob.Common.MMSTD.Dictionary.Variables.WordVariable import WordVariable
                return WordVariable.loadFromXML(xmlRoot, namespace, version)

            # DecimalWord Variable
            if xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type", "abstract") == "netzob:DecimalWordVariable":
                from netzob.Common.MMSTD.Dictionary.Variables.DecimalWordVariable import DecimalWordVariable
                return DecimalWordVariable.loadFromXML(xmlRoot, namespace, version)

            # Binary Variable
            if xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type", "abstract") == "netzob:BinaryVariable":
                from netzob.Common.MMSTD.Dictionary.Variables.BinaryVariable import BinaryVariable
                return BinaryVariable.loadFromXML(xmlRoot, namespace, version)

            # Hex Variable
            if xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type", "abstract") == "netzob:HexVariable":
                from netzob.Common.MMSTD.Dictionary.Variables.HexVariable import HexVariable
                return HexVariable.loadFromXML(xmlRoot, namespace, version)

            # Aggregate Variable
            if xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type", "abstract") == "netzob:AggregateVariable":
                from netzob.Common.MMSTD.Dictionary.Variables.AggregateVariable import AggregateVariable
                return AggregateVariable.loadFromXML(xmlRoot, namespace, version)

            # Alternate Variable
            if xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type", "abstract") == "netzob:AlternateVariable":
                from netzob.Common.MMSTD.Dictionary.Variables.AlternateVariable import AlternateVariable
                return AlternateVariable.loadFromXML(xmlRoot, namespace, version)

            # Referenced Variable
            if xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type", "abstract") == "netzob:ReferencedVariable":
                from netzob.Common.MMSTD.Dictionary.Variables.ReferencedVariable import ReferencedVariable
                return ReferencedVariable.loadFromXML(xmlRoot, namespace, version)
Ejemplo n.º 3
0
    def loadFromXML(xmlRoot, namespace, version, symbol):
        """loadFromXML:
                Load a variable from an XML definition.
                Calls its proper heir function for it to create the variable.

                @type xmlRoot: lxml.etree.Element
                @param xmlRoot: the root of the XML definition.
                @type namespace: string
                @param namespace: the namespace (precision) associated to the variable in the XML definition.
                @type version: string
                @param version: the load version.
                @rtype: netzob.Common.MMSTD.Dictionary.Variable.AbstractVariable.AbstractVariable
                @type symbol: netzob.Common.Symbol
                @param symbol: the symbol in which the current variable is placed, used by relation variable.
                @return: a variable constructed from this XML definition.
        """
        if version == "0.1":
            logging.debug("[ AbstractVariable: loadFromXML:")
            # Data Variable
            if xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type",
                           "abstract") == "netzob:DataVariable":
                from netzob.Common.MMSTD.Dictionary.Variables.DataVariable import DataVariable
                return DataVariable.loadFromXML(xmlRoot, namespace, version,
                                                symbol)

            # Aggregate Variable
            elif xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type",
                             "abstract") == "netzob:AggregateVariable":
                from netzob.Common.MMSTD.Dictionary.Variables.AggregateVariable import AggregateVariable
                return AggregateVariable.loadFromXML(xmlRoot, namespace,
                                                     version, symbol)

            # Alternate Variable
            elif xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type",
                             "abstract") == "netzob:AlternateVariable":
                from netzob.Common.MMSTD.Dictionary.Variables.AlternateVariable import AlternateVariable
                return AlternateVariable.loadFromXML(xmlRoot, namespace,
                                                     version, symbol)

            # Repeat Variable
            elif xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type",
                             "abstract") == "netzob:RepeatVariable":
                from netzob.Common.MMSTD.Dictionary.Variables.RepeatVariable import RepeatVariable
                return RepeatVariable.loadFromXML(xmlRoot, namespace, version,
                                                  symbol)

            # Direct Relation Variable
            #elif xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type", "abstract") == "netzob:DirectRelationVariable":
            #    from netzob.Common.MMSTD.Dictionary.Variables.DirectRelationVariable import DirectRelationVariable
            #    return DirectRelationVariable.loadFromXML(xmlRoot, namespace, version, symbol)

            # Computed Relation Variable
            elif xmlRoot.get("{http://www.w3.org/2001/XMLSchema-instance}type",
                             "abstract") == "netzob:ComputedRelationVariable":
                from netzob.Common.MMSTD.Dictionary.Variables.ComputedRelationVariable import ComputedRelationVariable
                return ComputedRelationVariable.loadFromXML(
                    xmlRoot, namespace, version, symbol)

            else:
                logging.debug(
                    "xmlRoot.get(...) returns {0} which does not correspond to a true variable class."
                ).format(
                    xmlRoot.get(
                        "{http://www.w3.org/2001/XMLSchema-instance}type",
                        "abstract"))
            logging.debug("AbstractVariable: loadFromXML ]")
        else:
            logging.debug("Version != 0.1")