Example #1
0
    def updateMessageList(self):
        # We read each file and create one message for each file
        fileNumber = 0

        # We split the content of each message and retrieve new messages
        self.retrieveMessagesFromFiles()
        new_messages = []
        for message in self.messages:
            lineNumber = 0
            if len(self.lineSeparator) > 0:
                splittedStrHexData = message.getData().split(self.lineSeparator)
            else:
                splittedStrHexData = [message.getData()]
            for s in splittedStrHexData:
                if len(s) > 0:
                    message = FileMessage(uuid.uuid4(), 0, s, message.getFilename(), message.getCreationDate(), message.getModificationDate(), message.getOwner(), message.getSize(), lineNumber)
                    new_messages.append(message)
                    lineNumber += 1

        # We save the new messages
        self.messages = []
        self.messages.extend(new_messages)
        self.lineView.get_model().clear()
        for message in self.messages:
            self.lineView.get_model().append(None, [message.getID(), message.getData()])
        # We clean the display
        self.textview.get_buffer().delete(self.textview.get_buffer().get_start_iter(), self.textview.get_buffer().get_end_iter())
Example #2
0
    def updateMessageList(self):
        # We read each file and create one message for each file
        fileNumber = 0

        # We split the content of each message and retrieve new messages
        self.retrieveMessagesFromFiles()
        new_messages = []
        for message in self.messages:
            lineNumber = 0
            if len(self.lineSeparator) > 0:
                splittedStrHexData = message.getData().split(self.lineSeparator)
            else:
                splittedStrHexData = [message.getData()]
            for s in splittedStrHexData:
                if len(s) > 0:
                    message = FileMessage(str(uuid.uuid4()), 0, s, message.getFilename(), message.getCreationDate(), message.getModificationDate(), message.getOwner(), message.getSize(), lineNumber)
                    new_messages.append(message)
                    lineNumber += 1

        # We save the new messages
        self.messages = []
        self.messages.extend(new_messages)
        self.lineView.get_model().clear()
        for message in self.messages:
            self.lineView.get_model().append(None, [message.getID(), message.getData()])
        # We clean the display
        self.textview.get_buffer().delete(self.textview.get_buffer().get_start_iter(), self.textview.get_buffer().get_end_iter())
Example #3
0
    def retrieveMessagesFromFiles(self):
        # We capture the current environment
        self.envDeps.captureEnvData()

        # We read each file and create one message for each file
        fileNumber = 0
        self.messages = []
        self.lineView.get_model().clear()

        for file in self.filesToBeImported:
            # Extraction of the metadata
            fileName = file.strip()
            size = os.path.getsize(file)
            creationDate = datetime.datetime.fromtimestamp(os.path.getctime(file))
            modificationDate = datetime.datetime.fromtimestamp(os.path.getmtime(file))
            owner = "none"

            # Retrieve the binary content of the file
            content = self.getNetzobRawContentOfFile(file)
            if not len(content) > 0:
                continue

            # Create a message
            message = FileMessage(uuid.uuid4(), 0, content, fileName, creationDate, modificationDate, owner, size, 0)
            self.messages.append(message)
            self.lineView.get_model().append(None, [message.getID(), content])
            fileNumber += 1

        # We clean the display
        self.textview.get_buffer().insert_with_tags_by_name(self.textview.get_buffer().get_start_iter(), "", "normalTag")
Example #4
0
    def retrieveMessagesFromFiles(self):
        # We capture the current environment
        self.envDeps.captureEnvData()

        # We read each file and create one message for each file
        fileNumber = 0
        self.messages = []
        self.lineView.get_model().clear()

        for file in self.filesToBeImported:
            # Extraction of the metadata
            fileName = file.strip()
            size = os.path.getsize(file)
            creationDate = datetime.datetime.fromtimestamp(os.path.getctime(file))
            modificationDate = datetime.datetime.fromtimestamp(os.path.getmtime(file))
            owner = "none"

            # Retrieve the binary content of the file
            content = self.getNetzobRawContentOfFile(file)
            if not len(content) > 0:
                continue

            # Create a message
            message = FileMessage(str(uuid.uuid4()), 0, content, fileName, creationDate, modificationDate, owner, size, 0)
            self.messages.append(message)
            self.lineView.get_model().append(None, [message.getID(), content])
            fileNumber += 1

        # We clean the display
        self.textview.get_buffer().insert_with_tags_by_name(self.textview.get_buffer().get_start_iter(), "", "normalTag")
Example #5
0
    def applySeparatorOnFiles(self, lineSeparator):
        # We read each file and create one message for each file
        fileNumber = 0

        # We split the content of each message and retrieve new messages
        self.retrieveMessagesFromFiles()
        new_messages = []
        for message in self.messages:
            lineNumber = 0
            if len(lineSeparator) > 0:
                splittedStrHexData = message.getData().split(lineSeparator)
            else:
                splittedStrHexData = [message.getData()]
            for s in splittedStrHexData:
                if len(s) > 0:
                    message = FileMessage(uuid.uuid4(), 0, s, message.getFilename(), message.getCreationDate(), message.getModificationDate(), message.getOwner(), message.getSize(), lineNumber)
                    new_messages.append(message)
                    lineNumber += 1

        # We save the new messages
        self.messages = []
        self.messages.extend(new_messages)
    def readMessages(self):
        # Iterate over all imported files and split them
        # according to the set separator
        self.messages = []
        for fileMessage in self.importedFiles:
            lineNumber = 0
            if len(self.messageSeparator) > 0:
                splittedStrHexData = fileMessage.getData().split(
                    self.messageSeparator)
                if self.messageSeparatorStrategy != DelimiterSeparatedImporter.SEPARATOR_STRATEGY_DELETE:
                    i_s = 0
                    l_s = len(splittedStrHexData)
                    for s in splittedStrHexData:
                        if self.messageSeparatorStrategy == DelimiterSeparatedImporter.SEPARATOR_STRATEGY_KEEP_END:
                            if fileMessage.getData().endswith(
                                    self.messageSeparator):
                                limit = l_s
                            else:
                                limit = l_s - 1
                            if i_s < limit:
                                splittedStrHexData[
                                    i_s] = s + self.messageSeparator

                        if self.messageSeparatorStrategy == DelimiterSeparatedImporter.SEPARATOR_STRATEGY_KEEP_START:
                            if fileMessage.getData().startswith(
                                    self.messageSeparator):
                                limit = 0
                            else:
                                limit = 1
                            if i_s >= limit:
                                splittedStrHexData[
                                    i_s] = self.messageSeparator + s

                        i_s += 1

            else:
                splittedStrHexData = [fileMessage.getData()]
            i_s = 0
            for s in splittedStrHexData:
                if len(s) > 0:
                    message = FileMessage(str(uuid.uuid4()), 0, s,
                                          fileMessage.getFilename(),
                                          fileMessage.getCreationDate(),
                                          fileMessage.getModificationDate(),
                                          fileMessage.getOwner(),
                                          fileMessage.getSize(), lineNumber)
                    self.messages.append(message)
                i_s += 1
 def setSourceFiles(self, filePathList):
     self.importedFiles = []
     for filePath in filePathList:
         size = os.path.getsize(filePath)
         creationDate = datetime.datetime.fromtimestamp(
             os.path.getctime(filePath))
         modificationDate = datetime.datetime.fromtimestamp(
             os.path.getmtime(filePath))
         owner = "none"
         # Retrieve the binary content of the file
         content = self._getNetzobRawContentOfFile(filePath)
         if not len(content) > 0:
             continue
         # Create a message
         message = FileMessage(str(uuid.uuid4()), 0, content, filePath,
                               creationDate, modificationDate, owner, size,
                               0)
         self.importedFiles.append(message)
Example #8
0
    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
Example #9
0
 def test_loadFromXml(self):
     id = str(uuid.uuid4())
     filename = "fichierDeTest.txt"
     lineNumber = 1
     creationDate = "2011-12-01 18:01"
     modificationDate = "2011-12-01 18:02"
     owner = "netzob"
     size = "1000ko"
     strData = "NETwork protocol modeliZatiOn By reverse engineering"
     data = str(bytearray(strData)).encode('hex')
     
     message = FileMessage()
     message.setID(id)
     message.setLineNumber(lineNumber)
     message.setFilename(filename)
     message.setCreationDate(creationDate)
     message.setModificationDate(modificationDate)
     message.setOwner(owner)
     message.setSize(size)
     message.setData(data)
     
     outputXml = message.getFactory().saveInXML(message)
     
     rootElement2 = ElementTree.XML(outputXml)
     self.message2 = FileMessageFactory.loadFromXML(rootElement2)       
     
     self.assertEqual(id, self.message2.getID())
     self.assertEqual(lineNumber, self.message2.getLineNumber())
     self.assertEqual(filename, self.message2.getFilename())
     self.assertEqual(creationDate, self.message2.getCreationDate())
     self.assertEqual(modificationDate, self.message2.getModificationDate())
     self.assertEqual(owner, self.message2.getOwner())        
     self.assertEqual(size, self.message2.getSize())
     self.assertEqual(bytearray(strData.encode('hex')), self.message2.getData())