• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python TypeConvertor.TypeConvertor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: read

    def read(self, timeout):
        self.log.debug("Reading from the socket some data (timeout = " + str(timeout))
        result = bitarray(endian='big')

        chars = []
        try:
            if timeout > 0:
                ready = select.select([self.socket], [], [], timeout)
                if ready[0]:
                    chars = self.socket.recv(4096)
            else:
                ready = select.select([self.socket], [], [])
                self.log.debug("ready = " + str(ready[0]))
                if ready[0]:
                    chars = self.socket.recv(4096)
        except:
            self.log.debug("Impossible to read from the network socket")
            return None

        if (len(chars) == 0):
            return result
        result = TypeConvertor.stringB2bin(chars)

        self.log.debug("Received : {0}".format(TypeConvertor.bin2strhex(result)))
        return result
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:25,代码来源:InstanciatedNetworkServer.py


示例2: displayMessage

 def displayMessage(self, message):
     # Clean the hexdump view
     self.textview.get_buffer().delete(self.textview.get_buffer().get_start_iter(), self.textview.get_buffer().get_end_iter())
     # Fecth the content of the message to display
     hexContent = TypeConvertor.hexdump(TypeConvertor.netzobRawToPythonRaw(message.getData()))
     # Update the hexdump
     self.textview.get_buffer().insert_with_tags_by_name(self.textview.get_buffer().get_start_iter(), hexContent, "normalTag")
开发者ID:KurSh,项目名称:netzob,代码行数:7,代码来源:ThirdPartyImport.py


示例3: save

    def save(message, xmlMessages, namespace_project, namespace_common):
        root = etree.SubElement(xmlMessages, "{" + namespace_common + "}message")
        root.set("id", str(message.getID()))
        root.set("timestamp", str(message.getTimestamp()))
        root.set("{http://www.w3.org/2001/XMLSchema-instance}type", "netzob-common:FileMessage")
        # data
        subData = etree.SubElement(root, "{" + namespace_common + "}data")
        subData.text = str(message.getData())
        # line number
        subLineNumber = etree.SubElement(root, "{" + namespace_common + "}lineNumber")
        subLineNumber.text = str(message.getLineNumber())
        # filename
        subFilename = etree.SubElement(root, "{" + namespace_common + "}filename")
        subFilename.text = message.getFilename()
        # creationDate
        subCreationDate = etree.SubElement(root, "{" + namespace_common + "}creationDate")
        subCreationDate.text = TypeConvertor.pythonDatetime2XSDDatetime(message.getCreationDate())
        # creationDate
        subModificationDate = etree.SubElement(root, "{" + namespace_common + "}modificationDate")
        subModificationDate.text = TypeConvertor.pythonDatetime2XSDDatetime(message.getModificationDate())

        # owner
        subOwner = etree.SubElement(root, "{" + namespace_common + "}owner")
        subOwner.text = message.getOwner()
        # size
        subSize = etree.SubElement(root, "{" + namespace_common + "}size")
        subSize.text = str(message.getSize())
开发者ID:KurSh,项目名称:netzob,代码行数:27,代码来源:FileMessageFactory.py


示例4: loadFromXML

    def loadFromXML(rootElement, namespace, version, id, timestamp, data):

        # Retrieves the lineNumber (default -1)
        msg_lineNumber = int(rootElement.find("{" + namespace + "}lineNumber").text)

        # Retrieves the filename
        msg_filename = rootElement.find("{" + namespace + "}filename").text.encode("utf-8")

        # Retrieves the creation date
        msg_creationDate = TypeConvertor.xsdDatetime2PythonDatetime(rootElement.find("{" + namespace + "}creationDate").text)

        # Retrieves the modification date
        if rootElement.find("{" + namespace + "}modificationDate").text is not None:
            msg_modificationDate = TypeConvertor.xsdDatetime2PythonDatetime(rootElement.find("{" + namespace + "}modificationDate").text)
        else:
            msg_modificationDate = msg_creationDate

        # Retrieves the owner
        msg_owner = rootElement.find("{" + namespace + "}owner").text

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

        # TODO : verify this ! Circular imports in python !
        # WARNING : verify this ! Circular imports in python !
        from netzob.Common.Models.FileMessage import FileMessage
        result = FileMessage(id, timestamp, data, msg_filename, msg_creationDate, msg_modificationDate, msg_owner, msg_size, msg_lineNumber)

        return result
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:29,代码来源:FileMessageFactory.py


示例5: getSearchedDataForString

 def getSearchedDataForString(self, value):
     # Creation of a SearchTask
     task = SearchTask(value, value, Format.STRING)
     task.registerVariation(TypeConvertor.stringToNetzobRaw(value), "String representation of '%s'" % value)
     task.registerVariation(TypeConvertor.stringToNetzobRaw(value[::-1]), "Inverted string representation of '%s'" % value[::-1])
     task.registerVariation(TypeConvertor.stringToNetzobRaw(value.decode('utf-8')), "String representation of '%s' encoded in UTF-8" % value)
     return [task]
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:7,代码来源:Searcher.py


示例6: learn

    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,代码行数:27,代码来源:IPv4Variable.py


示例7: compareFormat

    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.
        """
        tmp = value[indice:]
        size = len(tmp)
        if size <= 16:
            self.log.debug("Too small, not even 16 bits available (2 letters)")
            return -1
        for i in range(size, 16, -1):
            subValue = value[indice:indice + i - 1]
            if (i - 1) % 8 == 0:
                strVal = TypeConvertor.bin2string(TypeConvertor.strBitarray2Bitarray(subValue))
                typeIdentifier = TypeIdentifier()
                if typeIdentifier.isAscii(strVal):
                    self.log.debug("Its an ascii : (" + str(strVal) + ")")
                    if (not ' ' in strVal and not '\n' in strVal and not '\r' in strVal):
                        self.log.debug("Its an ascii without space : (" + str(strVal) + ")")
                        self.log.debug("Binary value of the ascii  : %s" % str(TypeConvertor.strBitarray2Bitarray(subValue)))
                        return indice + i - 1

        return -1
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:35,代码来源:_WordVariable.py


示例8: processUPGMA

    def processUPGMA(self):
        self.log.debug("Computing the associated matrix")

        # Serialize the symbols
        (serialSymbols, formatSymbols) = TypeConvertor.serializeSymbols(self.symbols, self.unitSize, self.scores)
        self.log.debug("Clustering input format " + formatSymbols)

        # Execute the Clustering part in C
        debug = False
        logging.debug("Execute the clustering part in C ...")
        (i_max, j_max, maxScore, scores) = _libNeedleman.getHighestEquivalentGroup(self.doInternalSlick, len(self.symbols), formatSymbols, serialSymbols, self.cb_executionStatus, debug)
        listScores = TypeConvertor.deserializeScores(self.symbols, scores)

        # Retrieve the scores for each association of symbols
        self.scores = {}
        for (iuid, juid, score) in listScores:
            if iuid not in self.scores.keys():
                self.scores[iuid] = {}
            if juid not in self.scores.keys():
                self.scores[juid] = {}
            self.scores[iuid][juid] = score
            if iuid not in self.scores[juid].keys():
                self.scores[juid][iuid] = score

        # Reduce the UPGMA matrix (merge symbols by similarity)
        self.computePhylogenicTree()
        return (i_max, j_max, maxScore)
开发者ID:KurSh,项目名称:netzob,代码行数:27,代码来源:UPGMA.py


示例9: receiveSymbolWithTimeout

    def receiveSymbolWithTimeout(self, timeout):
        # First we read from the input the message
        receivedData = self.communicationChannel.read(timeout)

        nbMaxAttempts = 5

        if receivedData is None:
            self.log.warn("The communication channel seems to be closed !")
#            return (EmptySymbol(), None)
            return (None, None)

        if len(receivedData) > 0:
            now = datetime.datetime.now()
            receptionTime = now.strftime("%H:%M:%S")
            self.log.info("Received following message : " + TypeConvertor.bin2strhex(receivedData))

            # Now we abstract the message
            symbol = self.abstract(receivedData)

            # We store the received messages its time and its abstract representation
            self.inputMessages.append([receptionTime, TypeConvertor.bin2strhex(receivedData), symbol.getName()])
            self.registerInputSymbol(receptionTime, TypeConvertor.bin2strhex(receivedData), symbol)

            return (symbol, receivedData)
        else:
            if len(self.manipulatedSymbols) > nbMaxAttempts:
                if self.manipulatedSymbols[len(self.manipulatedSymbols) - 1].getType() == EmptySymbol.TYPE or self.manipulatedSymbols[len(self.manipulatedSymbols) - 1].getType() == UnknownSymbol.TYPE:
                    self.log.warn("Consider client has disconnected since no valid symbol received after " + str(nbMaxAttempts) + " attempts")
                    return (None, None)
            now = datetime.datetime.now()
            receptionTime = now.strftime("%H:%M:%S")
            symbol = EmptySymbol()
            self.registerInputSymbol(receptionTime, "", symbol)
            return (symbol, None)
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:34,代码来源:AbstractionLayer.py


示例10: generateXMLConfigFile

    def generateXMLConfigFile(self):
        # Register the namespace
        etree.register_namespace("netzob", PROJECT_NAMESPACE)
        etree.register_namespace("netzob-common", COMMON_NAMESPACE)

        # Dump the file
        root = etree.Element("{" + PROJECT_NAMESPACE + "}project")
        root.set("id", str(self.getID()))
        root.set("path", str(self.getPath()))
        # Warning, changed because of project = Project.createProject(self.netzob.getCurrentWorkspace(), projectName)
        if isinstance(self.getCreationDate(), types.TupleType):
            root.set("creation_date", TypeConvertor.pythonDatetime2XSDDatetime(self.getCreationDate()[0]))
        else:
            root.set("creation_date", TypeConvertor.pythonDatetime2XSDDatetime(self.getCreationDate()))
        root.set("name", str(self.getName()))

        if self.description:
            root.set("description", str(self.description))

        # Save the configuration in it
        self.getConfiguration().save(root, PROJECT_NAMESPACE)

        # Save the vocabulary in it
        self.getVocabulary().save(root, PROJECT_NAMESPACE, COMMON_NAMESPACE)

        # Save the grammar in it
        if self.getGrammar() is not None:
            self.getGrammar().save(root, PROJECT_NAMESPACE)

        # Save the simulator in it
        self.getSimulator().save(root, PROJECT_NAMESPACE)

        return root
开发者ID:otetard,项目名称:netzob,代码行数:33,代码来源:Project.py


示例11: getSearchedDataForDecimal

 def getSearchedDataForDecimal(self, value):
     if not value.isdigit():
         return []
     # Creation of a SearchTask
     task = SearchTask(value, value, Format.DECIMAL)
     task.registerVariation(TypeConvertor.decimalToNetzobRaw(value), "Decimal representation of '{0}'".format(TypeConvertor.decimalToNetzobRaw(value)))
     task.registerVariation(TypeConvertor.decimalToNetzobRaw(value[::-1]), "Inverted decimal representation of '{0}'".format(TypeConvertor.decimalToNetzobRaw(value[::-1])))
     return [task]
开发者ID:lindi2,项目名称:netzob,代码行数:8,代码来源:Searcher.py


示例12: generateValue

 def generateValue(self, negative, dictionary):
     self.log.debug("Generate value of hex")
     if self.min != -1 and self.max != -1:
         # generate a value in int
         r = random.randint(self.min, self.max)
         self.log.debug("Generating hex of value : " + str(r))
         self.binValue = TypeConvertor.int2bin(r, self.size)
         self.strValue = TypeConvertor.int2string(r)
开发者ID:KurSh,项目名称:netzob,代码行数:8,代码来源:_IntVariable.py


示例13: getMessageDetails

 def getMessageDetails(self, messageID):
     if not messageID in self._payloadDict:
         errorMessage = _("Message ID: {0} not found in importer " +
                          "message list").format(messageID)
         logging.error(errorMessage)
         raise NetzobImportException("IPC", errorMessage, ERROR)
     payload = self._payloadDict[messageID]
     return TypeConvertor.hexdump(TypeConvertor.netzobRawToPythonRaw(payload))
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:8,代码来源:IpcCapturer.py


示例14: doGetMessageDetails

    def doGetMessageDetails(self, messageID):
        message = self.model.getMessageByID(str(messageID))

        properties = [(props.getName(), props.getCurrentValue()) for props in message.getProperties()
                      if props.getName() != 'Data']
        messageDetails = "\n".join(["{0}: {1}".format(*prop)
                                    for prop in properties])
        messageDetails += "\n\n" + TypeConvertor.hexdump(TypeConvertor.netzobRawToPythonRaw(message.getStringData()))
        return messageDetails
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:9,代码来源:XMLImporterController.py


示例15: learn

 def learn(self, value, indice, negative, vocabulary, memory):
     # First we retrieve the size of the value to memorize
     size = self.compare(value, indice, negative, vocabulary, memory)
     if size > 0:
         # memorize
         self.log.debug("Memorize : " + str(value[indice:size]))
         memory.memorize(self, (value[indice:size], TypeConvertor.bin2string(TypeConvertor.strBitarray2Bitarray(value[indice:size]))))
         return size
     else:
         self.log.debug("Incompatible for learning")
         return -1
开发者ID:KurSh,项目名称:netzob,代码行数:11,代码来源:WordVariable.py


示例16: generateValue

    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,代码行数:11,代码来源:_DynLenStringVariable.py


示例17: write

    def write(self, message):
        self.log.debug("Writing to the socket")
        self.outputMessages.append(message)
        # This work only for values between 0x00 and 0x7f
        # self.socket.send(message.tostring())
        if self.protocol == "UDP":
            self.socket.sendto(TypeConvertor.bin2string(message), (self.getTargetIP(), self.getTargetPort()))
        else:  # TCP
            self.socket.send(TypeConvertor.bin2string(message))

        self.log.debug("Write down !")
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:11,代码来源:InstanciatedNetworkServer.py


示例18: reverse

 def reverse(self, message):
     """reverse:
     Encode in B64 the provided message"""
     result = message
     try:
         rawContent = TypeConvertor.netzobRawToPythonRaw(message)
         b64Content = base64.b64encode(rawContent)
         result = TypeConvertor.pythonRawToNetzobRaw(b64Content)
     except TypeError as error:
         logging.warning("Impossible to compute the base64 value of message (error={0})".format(str(error)))
         result = ""
     return result
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:12,代码来源:Base64Function.py


示例19: reverse

 def reverse(self, message):
     """reverse:
     This compress the provided message in bz2 format"""
     result = message
     rawData = TypeConvertor.netzobRawToPythonRaw(message)
     try:
         rawResult = bz2.compress(rawData)
         result = TypeConvertor.pythonRawToNetzobRaw(rawResult)
     except Exception as e:
         logging.info("Impossible to reverse BZ2 function (compress) on provided message (error= {0})".format(str(e)))
         result = ""
     return result
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:12,代码来源:BZ2Function.py


示例20: apply

 def apply(self, message):
     result = message
     rawData = TypeConvertor.netzobRawToPythonRaw(message)
     compressedstream = StringIO.StringIO(rawData)
     try:
         gzipper = gzip.GzipFile(fileobj=compressedstream)
         data = gzipper.read()
         result = TypeConvertor.pythonRawToNetzobRaw(data)
     except Exception as e:
         logging.info("Impossible to apply GZip function on provided message (error= {0})".format(str(e)))
         result = ""
     return result
开发者ID:EnjoyHacking,项目名称:netzob,代码行数:12,代码来源:GZipFunction.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python json.dumps函数代码示例发布时间:2022-05-27
下一篇:
Python ResourcesConfiguration.ResourcesConfiguration类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap