示例#1
0
class NetworkOracle(threading.Thread):

    def __init__(self, communicationChannel, isMaster):
        threading.Thread.__init__(self)
        # create logger with the given configuration
        self.log = logging.getLogger('netzob.Inference.Grammar.Oracle.NetworkOracle.py')
        self.communicationChannel = communicationChannel
        self.isMaster = isMaster

    def setMMSTD(self, mmstd):
        self.mmstd = mmstd

    def run(self):
        self.log.info("Start the network oracle based on given MMSTD")

        # Create a new and clean memory
        memory = Memory(self.mmstd.getVocabulary().getVariables())
        memory.createMemory()
        # Create the abstraction layer for this connection
        abstractionLayer = AbstractionLayer(self.communicationChannel, self.mmstd.getVocabulary(), memory)

        # And we create an MMSTD visitor for this
        self.oracle = MMSTDVisitor("MMSTD-NetworkOracle", self.mmstd, self.isMaster, abstractionLayer)
        self.oracle.start()

        while (self.oracle.isAlive()):
            time.sleep(0.01)

        self.log.warn("The network ORACLE has finished")

    def stop(self):
        self.log.info("Stop the network oracle")
        self.oracle.stop()

    def hasFinish(self):
        return not self.oracle.isActive()

    def getGeneratedInputSymbols(self):
        symbols = []
        abstractionLayer = self.oracle.getAbstractionLayer()
        for i in abstractionLayer.getGeneratedInputSymbols():
            symbols.append(DictionarySymbol(i))
        return symbols

    def getGeneratedOutputSymbols(self):
        symbols = []
        abstractionLayer = self.oracle.getAbstractionLayer()
        for o in abstractionLayer.getGeneratedOutputSymbols():
            symbols.append(DictionarySymbol(o))
        return symbols

    def getResults(self):
        symbols = []
        # Retrieve all the IO from the abstraction layer
        abstractionLayer = self.oracle.getAbstractionLayer()
        print "Abstraction layer = " + str(abstractionLayer)
        for io in abstractionLayer.getGeneratedInputAndOutputsSymbols():
            symbols.append(DictionarySymbol(io))
        return symbols
示例#2
0
class NetworkOracle(threading.Thread):
    def __init__(self, communicationChannel, isMaster):
        threading.Thread.__init__(self)
        # create logger with the given configuration
        self.log = logging.getLogger(
            'netzob.Inference.Grammar.Oracle.NetworkOracle.py')
        self.communicationChannel = communicationChannel
        self.isMaster = isMaster

    def setMMSTD(self, mmstd):
        self.mmstd = mmstd

    def run(self):
        self.log.info("Start the network oracle based on given MMSTD")

        # Create a new and clean memory
        memory = Memory()
        # memory = Memory(self.mmstd.getVocabulary().getVariables())
        memory.createMemory()
        # Create the abstraction layer for this connection
        abstractionLayer = AbstractionLayer(self.communicationChannel,
                                            self.mmstd.getVocabulary(), memory)

        # And we create an MMSTD visitor for this
        anID = str(uuid.uuid4())
        self.oracle = MMSTDVisitor(anID, "MMSTD-NetworkOracle", self.mmstd,
                                   self.isMaster, abstractionLayer)
        self.oracle.start()

        while (self.oracle.isAlive()):
            time.sleep(0.01)

        self.log.warn("The network ORACLE has finished")

    def stop(self):
        self.log.info("Stop the network oracle")
        self.oracle.stop()

    def hasFinish(self):
        return not self.oracle.isActive()

    def getGeneratedInputSymbols(self):
        symbols = []
        abstractionLayer = self.oracle.getAbstractionLayer()
        for i in abstractionLayer.getGeneratedInputSymbols():
            symbols.append(DictionarySymbol(i))
        return symbols

    def getGeneratedOutputSymbols(self):
        symbols = []
        abstractionLayer = self.oracle.getAbstractionLayer()
        for o in abstractionLayer.getGeneratedOutputSymbols():
            symbols.append(DictionarySymbol(o))
        return symbols

    def getResults(self):
        symbols = []
        # Retrieve all the IO from the abstraction layer
        abstractionLayer = self.oracle.getAbstractionLayer()
        print "Abstraction layer = " + str(abstractionLayer)
        for io in abstractionLayer.getGeneratedInputAndOutputsSymbols():
            symbols.append(DictionarySymbol(io))
        return symbols