当前位置: 首页>>代码示例>>Python>>正文


Python TypeConvertor.string2bin方法代码示例

本文整理汇总了Python中netzob.Common.Type.TypeConvertor.TypeConvertor.string2bin方法的典型用法代码示例。如果您正苦于以下问题:Python TypeConvertor.string2bin方法的具体用法?Python TypeConvertor.string2bin怎么用?Python TypeConvertor.string2bin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在netzob.Common.Type.TypeConvertor.TypeConvertor的用法示例。


在下文中一共展示了TypeConvertor.string2bin方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: learn

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import string2bin [as 别名]
    def learn(self, value, indice, negative, vocabulary, memory):
        if self.format == Format.ASCII:
            currentContent = TypeConvertor.bin2string(value[indice:])
            IPRegex = re.compile("(((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))")
            hasMatched = False
            for t in range(min(len(currentContent), 15), 7, -1):
                currentPossibleIP = currentContent[:t]
                result = IPRegex.match(currentPossibleIP)
                if result != None:
                    hasMatched = True
                elif hasMatched:
                    break

            if hasMatched:
                result = currentContent[:t + 2]
                self.log.debug("Learn from received message : " + str(result))

                strCurrentValue = str(result)
                binCurrentValue = TypeConvertor.string2bin(result, 'big')
                memory.memorize(self, (binCurrentValue, strCurrentValue))

                return len(TypeConvertor.string2bin(result, 'big'))
            else:
                self.log.debug("Compare on format was not successfull")
                return -1
        else:
            raise NotImplementedError("Error, the current variable (IPv4Variable) doesn't support function compareFormat in this case")
开发者ID:KurSh,项目名称:netzob,代码行数:29,代码来源:IPv4Variable.py

示例2: __init__

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import string2bin [as 别名]
    def __init__(self, text):
        AbstractValue.__init__(self, "TextValue")
        # create logger with the given configuration
        self.log = logging.getLogger('netzob.Common.MMSTD.Dictionary.Values.TextValue.py')

        self.strtext = text
        self.bintext = TypeConvertor.string2bin(self.strtext, 'big')
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:9,代码来源:TextValue.py

示例3: computeCurrentValue

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import string2bin [as 别名]
 def computeCurrentValue(self, strValue):
     if strValue != None:
         strCurrentValue = strValue
         binCurrentValue = TypeConvertor.string2bin(strValue)
         self.currentValue = (binCurrentValue, strCurrentValue)
     else:
         self.currentValue = None
开发者ID:KurSh,项目名称:netzob,代码行数:9,代码来源:WordVariable.py

示例4: generateValue

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import string2bin [as 别名]
    def generateValue(self, negative, dictionary):

        variable = dictionary.getVariableByID(self.idVar)
        (binValue, strValue) = variable.getValue(negative, dictionary)

        self.log.debug("GENERATE VALUE of size : " + str(binValue))
        nb_letter = TypeConvertor.bin2int(binValue)
        self.strVal = ''.join(random.choice(string.ascii_letters) for x in range(nb_letter))
        self.binVal = TypeConvertor.string2bin(self.strVal, 'big')
        self.log.debug("Generated value = " + self.strVal)
        self.log.debug("Generated value = " + str(self.binVal))
开发者ID:KurSh,项目名称:netzob,代码行数:13,代码来源:_DynLenStringVariable.py

示例5: computeCurrentValue

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import string2bin [as 别名]
    def computeCurrentValue(self, strValue):
        """computeCurrentValue:
                Compute a couple of binary and string values for the current variable.

                @type strValue: string
                @param strValue: a string value proposed as default value for this variable.
        """
        if strValue is not None:
            strCurrentValue = strValue
            binCurrentValue = TypeConvertor.string2bin(strValue)
            self.currentValue = (binCurrentValue, strCurrentValue)
        else:
            self.currentValue = None
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:15,代码来源:_WordVariable.py

示例6: learn

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import string2bin [as 别名]
    def learn(self, value, indice, negative, vocabulary, memory):
        """learn:
                Compare the current variable to the end (starting at the "indice"-th character) of value.
                Moreover it stores learns from the provided message.
                Return the number of letters that matches, -1 if it does not match.
        """
        if self.format == Format.ASCII:
            currentContent = TypeConvertor.bin2string(value[indice:])
            IPRegex = re.compile(
                "(((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))"
            )
            hasMatched = False
            for t in range(min(len(currentContent), 15), 7, -1):
                currentPossibleIP = currentContent[:t]
                result = IPRegex.match(currentPossibleIP)
                if result is not None:
                    hasMatched = True
                elif hasMatched:
                    break

            if hasMatched:
                result = currentContent[: t + 2]
                self.log.debug("Learn from received message : " + str(result))

                strCurrentValue = str(result)
                binCurrentValue = TypeConvertor.string2bin(result, "big")
                memory.memorize(self, (binCurrentValue, strCurrentValue))

                return len(TypeConvertor.string2bin(result, "big"))
            else:
                self.log.debug("Compare on format was not successfull")
                return -1
        else:
            raise NotImplementedError(
                "Error, the current variable (IPv4Variable) doesn't support function compareFormat in this case"
            )
开发者ID:sangyf,项目名称:netzob,代码行数:38,代码来源:_IPv4Variable.py

示例7: getValueToSend

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import string2bin [as 别名]
    def getValueToSend(self, negative, vocabulary, memory):
        if self.getCurrentValue() != None:
            return self.getCurrentValue()

        if memory.hasMemorized(self):
            return memory.recall(self)

        # We generate a new value
        strValue = self.generateValue()
        binValue = TypeConvertor.string2bin(strValue)

        # We save in memory the current value
        memory.memorize(self, (binValue, strValue))

        # We return the newly generated and memorized value
        return (binValue, strValue)
开发者ID:KurSh,项目名称:netzob,代码行数:18,代码来源:WordVariable.py

示例8: computeCurrentValue

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import string2bin [as 别名]
 def computeCurrentValue(self, strValue):
     if strValue != None:
         if self.format == Format.ASCII:
             strCurrentValue = str(strValue)
             binCurrentValue = TypeConvertor.string2bin(strValue, 'big')
         elif self.format == Format.HEX:
             hexVal = TypeConvertor.ipToNetzobRaw(strValue)
             if hexVal != None:
                 strCurrentValue = str(strValue)
                 binCurrentValue = TypeConvertor.netzobRawToBitArray(hexVal)
             else:
                 strCurrentValue = str("None:Error")
                 binCurrentValue = None
         self.currentValue = (binCurrentValue, strCurrentValue)
     else:
         self.currentValue = None
开发者ID:KurSh,项目名称:netzob,代码行数:18,代码来源:IPv4Variable.py

示例9: getValueToSend

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import string2bin [as 别名]
    def getValueToSend(self, negative, vocabulary, memory):
        """getValueToSend:
                Get the current value of the variable it can be the original value if its set and not forget or the value in memory if it has one or it generates one and save its value in memory.
        """
        if self.getCurrentValue() is not None:
            return self.getCurrentValue()

        if memory.hasMemorized(self):
            return memory.recall(self)

        # We generate a new value
        strValue = self.generateValue()
        binValue = TypeConvertor.string2bin(strValue)

        # We save in memory the current value
        memory.memorize(self, (binValue, strValue))

        # We return the newly generated and memorized value
        return (binValue, strValue)
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:21,代码来源:_WordVariable.py

示例10: compareFormat

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import string2bin [as 别名]
    def compareFormat(self, value, indice, negative, vocabulary, memory):
        """compareFormat:
                Compute if the provided data is "format-compliant" and return the size of the biggest compliant data.

                @type value: bitarray.bitarray
                @param value: a bit array a subarray of which we compare to the current variable binray value.
                @type indice: integer
                @param indice: the starting point of comparison in value.
                @type negative: boolean
                @param negative: tells if we use the variable or a logical not of it.
                @type vocabulary: netzob.Common.Vocabulary.Vocabulary
                @param vocabulary: the vocabulary of the current project.
                @type memory: netzob.Common.MMSTD.Memory.Memory
                @param memory: a memory which can contain a former value of the variable.
                @rtype: integer
                @return: the size of the biggest compliant data, -1 if it does not comply.
        """
        if self.format == Format.ASCII:
            currentContent = TypeConvertor.bin2string(value[indice:])
            IPRegex = re.compile(
                "(((?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))"
            )
            hasMatched = False
            for t in range(min(len(currentContent), 15), 7, -1):
                currentPossibleIP = currentContent[:t]
                result = IPRegex.match(currentPossibleIP)
                if result is not None:
                    hasMatched = True
                elif hasMatched:
                    break

            if hasMatched:
                result = currentContent[: t + 2]
                self.log.debug("Compare on format was successfull : " + str(result))
                return len(TypeConvertor.string2bin(result, "big"))
            else:
                self.log.debug("Compare on format was not successfull")
                return -1
        else:
            raise NotImplementedError(
                "Error, the current variable (IPv4Variable) doesn't support function compareFormat in this case"
            )
开发者ID:sangyf,项目名称:netzob,代码行数:44,代码来源:_IPv4Variable.py

示例11: read

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import string2bin [as 别名]
 def read(self, timeout):
     chars = []
     try:
         if timeout > 0:
             self.log.debug("Reading from the socket with a timeout of " + str(timeout))
             ready = select.select([self.socket], [], [], timeout)
             if ready[0]:
                 chars = self.socket.recv(4096)
         else:
             self.log.debug("Reading from the socket without any timeout")
             ready = select.select([self.socket], [], [])
             if ready[0]:
                 chars = self.socket.recv(4096)
     except:
         self.log.debug("Impossible to read from the network socket")
         return None
     result = TypeConvertor.string2bin("".join(chars), "big")
     self.log.debug("Read finished")
     if (len(chars) == 0):
         return result
     self.log.debug("Received : {0}".format(TypeConvertor.bin2strhex(result)))
     return result
开发者ID:lindi2,项目名称:netzob,代码行数:24,代码来源:NetworkClient.py

示例12: computeCurrentValue

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import string2bin [as 别名]
    def computeCurrentValue(self, strValue):
        """computeCurrentValue:
                Compute a couple of binary and string values for the current variable.

                @type strValue: string
                @param strValue: a string value proposed as default value for this variable, must be a "real" ip address declared in ASCII like : "192.168.0.10".
        """
        if strValue is not None:
            if self.format == Format.ASCII:
                strCurrentValue = str(strValue)
                binCurrentValue = TypeConvertor.string2bin(strValue, "big")
            elif self.format == Format.HEX:
                hexVal = TypeConvertor.ipToNetzobRaw(strValue)
                if hexVal is not None:
                    strCurrentValue = str(strValue)
                    binCurrentValue = TypeConvertor.netzobRawToBitArray(hexVal)
                else:
                    strCurrentValue = str("None:Error")
                    binCurrentValue = None
            self.currentValue = (binCurrentValue, strCurrentValue)
        else:
            self.currentValue = None
开发者ID:sangyf,项目名称:netzob,代码行数:24,代码来源:_IPv4Variable.py

示例13: str2bin

# 需要导入模块: from netzob.Common.Type.TypeConvertor import TypeConvertor [as 别名]
# 或者: from netzob.Common.Type.TypeConvertor.TypeConvertor import string2bin [as 别名]
 def str2bin(self, stri):
     return TypeConvertor.string2bin(stri)
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:4,代码来源:AbstractWordType.py


注:本文中的netzob.Common.Type.TypeConvertor.TypeConvertor.string2bin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。