def __init__(self, vocabularyController, layers): self.vocabularyController = vocabularyController self.layers = layers multipleLayers = False if len(layers) > 1: multipleLayers = True self._view = ContextualMenuOnLayerView(self, multipleLayers) self.log = logging.getLogger(__name__)
class ContextualMenuOnLayerController(object): """Contextual menu on layer (visualization, etc.)""" def __init__(self, vocabularyController, layers): self.vocabularyController = vocabularyController self.layers = layers multipleLayers = False if len(layers) > 1: multipleLayers = True self._view = ContextualMenuOnLayerView(self, multipleLayers) self.log = logging.getLogger(__name__) @property def view(self): return self._view def run(self, event): self._view.run(event) #+---------------------------------------------- #| rightClickToChangeFormat: #| Callback to change the field/symbol format #| by doing a right click on it. #+---------------------------------------------- def changeFormat_cb(self, event, aFormat): for layer in self.layers: layer.setFormat(aFormat) self.vocabularyController.view.updateSelectedMessageTable() #+---------------------------------------------- #| rightClickToChangeUnitSize: #| Callback to change the field/symbol unitsize #| by doing a right click on it. #+---------------------------------------------- def changeUnitSize_cb(self, event, unitSize): for layer in self.layers: layer.setUnitSize(unitSize) self.vocabularyController.view.updateSelectedMessageTable() #+---------------------------------------------- #| rightClickToChangeSign: #| Callback to change the field/symbol sign #| by doing a right click on it. #+---------------------------------------------- def changeSign_cb(self, event, sign): for layer in self.layers: layer.setSign(sign) self.vocabularyController.view.updateSelectedMessageTable() #+---------------------------------------------- #| rightClickToChangeEndianess: #| Callback to change the field/symbol endianess #| by doing a right click on it. #+---------------------------------------------- def changeEndianess_cb(self, event, endianess): for layer in self.layers: layer.setEndianess(endianess) self.vocabularyController.view.updateSelectedMessageTable() def applyTransformationFunction_cb(self, event, transformationFunction): """Add the selected transformation function""" # Computes if the current included messages are already functioned allTransformed = True for message in self.layers[0].getMessages(): found = False for function in message.getTransformationFunctions(): if function.getName() == transformationFunction.getName(): found = True if not found: allTransformed = False break if not allTransformed: #Activate function for message in self.layers[0].getMessages(): found = False for function in message.getTransformationFunctions(): if function.getName() == transformationFunction.getName(): found = True if not found: message.addTransformationFunction(transformationFunction) else: # Deactivate function for message in self.layers[0].getMessages(): message.removeTransformationFunction(transformationFunction) self.layers[0].resetPartitioning() self.vocabularyController.view.updateSelectedMessageTable() def createCustomFunction_cb(self, event): """Callback executed when the user clicks on menu entry to create a custom function""" customFunctionController = CustomTransformationFunctionController(self.vocabularyController, self.layers[0]) customFunctionController.run() def renameLayer_cb(self, widget): builder2 = Gtk.Builder() builder2.add_from_file(os.path.join( ResourcesConfiguration.getStaticResources(), "ui", "dialogbox.glade")) dialog = builder2.get_object("renamelayer") dialog.set_title(_("Rename the layer {0}").format(self.layers[0].getName())) applybutton = builder2.get_object("button10") entry = builder2.get_object("entry3") entry.connect("changed", self.entry_disableButtonIfEmpty_cb, applybutton) result = dialog.run() if (result == 0): newLayerName = entry.get_text() self.log.debug("Renamed layer {0} to {1}".format(self.layers[0].getName(), newLayerName)) currentProject = self.vocabularyController.netzob.getCurrentProject() currentProject.getVocabulary().getFieldByID(self.layers[0].getID()).setName(newLayerName) self.vocabularyController.view.updateLeftPanel() self.vocabularyController.view.updateSelectedMessageTable() dialog.destroy() dialog.destroy() def entry_disableButtonIfEmpty_cb(self, widget, button): if(len(widget.get_text()) > 0): button.set_sensitive(True) else: button.set_sensitive(False) def deleteLayer_cb(self, widget): for layer in self.layers: # Verify if selected layer is the top layer (i.e. the symbol) if layer == layer.getSymbol().getField(): # If so, delete the symbol and its messages currentProject = self.vocabularyController.netzob.getCurrentProject() currentVocabulary = currentProject.getVocabulary() for mess in layer.getSymbol().getMessages(): currentVocabulary.removeMessage(mess) currentVocabulary.removeSymbol(layer.getSymbol()) self.vocabularyController.view.emptyMessageTableDisplayingSymbols([layer.getSymbol()]) else: layer.flattenLocalFields() self.vocabularyController.view.updateLeftPanel() self.vocabularyController.view.updateSelectedMessageTable() def sequenceAlignment_cb(self, action): sequence_controller = SequenceAlignmentController(self.vocabularyController, [self.layers[0]]) sequence_controller.run() def forcePartitionment_cb(self, action): force_controller = ForcePartitioningController(self.vocabularyController, [self.layers[0]]) force_controller.run() def simplePartitionment_cb(self, action): simple_controller = SimplePartitioningController(self.vocabularyController, [self.layers[0]]) simple_controller.run() def smoothPartitionment_cb(self, action): smooth_controller = SmoothPartitioningController(self.vocabularyController, [self.layers[0]]) smooth_controller.run() def resetPartitionment_cb(self, action): reset_controller = ResetPartitioningController(self.vocabularyController, [self.layers[0]]) reset_controller.run()
class ContextualMenuOnLayerController(object): """Contextual menu on layer (visualization, etc.)""" def __init__(self, vocabularyController, layers): self.vocabularyController = vocabularyController self.layers = layers multipleLayers = False if len(layers) > 1: multipleLayers = True self._view = ContextualMenuOnLayerView(self, multipleLayers) self.log = logging.getLogger(__name__) @property def view(self): return self._view def run(self, event): self._view.run(event) #+---------------------------------------------- #| rightClickToChangeFormat: #| Callback to change the field/symbol format #| by doing a right click on it. #+---------------------------------------------- def changeFormat_cb(self, event, aFormat): for layer in self.layers: layer.setFormat(aFormat) self.vocabularyController.view.updateSelectedMessageTable() #+---------------------------------------------- #| rightClickToChangeUnitSize: #| Callback to change the field/symbol unitsize #| by doing a right click on it. #+---------------------------------------------- def changeUnitSize_cb(self, event, unitSize): for layer in self.layers: layer.setUnitSize(unitSize) self.vocabularyController.view.updateSelectedMessageTable() #+---------------------------------------------- #| rightClickToChangeSign: #| Callback to change the field/symbol sign #| by doing a right click on it. #+---------------------------------------------- def changeSign_cb(self, event, sign): for layer in self.layers: layer.setSign(sign) self.vocabularyController.view.updateSelectedMessageTable() #+---------------------------------------------- #| rightClickToChangeEndianess: #| Callback to change the field/symbol endianess #| by doing a right click on it. #+---------------------------------------------- def changeEndianess_cb(self, event, endianess): for layer in self.layers: layer.setEndianess(endianess) self.vocabularyController.view.updateSelectedMessageTable() def applyTransformationFunction_cb(self, event, transformationFunction): """Add the selected transformation function""" # Computes if the current included messages are already functioned allTransformed = True for message in self.layers[0].getMessages(): found = False for function in message.getTransformationFunctions(): if function.getName() == transformationFunction.getName(): found = True if not found: allTransformed = False break if not allTransformed: #Activate function for message in self.layers[0].getMessages(): found = False for function in message.getTransformationFunctions(): if function.getName() == transformationFunction.getName(): found = True if not found: message.addTransformationFunction(transformationFunction) else: # Deactivate function for message in self.layers[0].getMessages(): message.removeTransformationFunction(transformationFunction) self.layers[0].resetPartitioning() self.vocabularyController.view.updateSelectedMessageTable() def createCustomFunction_cb(self, event): """Callback executed when the user clicks on menu entry to create a custom function""" customFunctionController = CustomTransformationFunctionController( self.vocabularyController, self.layers[0]) customFunctionController.run() def renameLayer_cb(self, widget): builder2 = Gtk.Builder() builder2.add_from_file( os.path.join(ResourcesConfiguration.getStaticResources(), "ui", "dialogbox.glade")) dialog = builder2.get_object("renamelayer") dialog.set_title( _("Rename the layer {0}").format(self.layers[0].getName())) applybutton = builder2.get_object("button10") entry = builder2.get_object("entry3") entry.connect("changed", self.entry_disableButtonIfEmpty_cb, applybutton) result = dialog.run() if (result == 0): newLayerName = entry.get_text() self.log.debug("Renamed layer {0} to {1}".format( self.layers[0].getName(), newLayerName)) currentProject = self.vocabularyController.netzob.getCurrentProject( ) currentProject.getVocabulary().getFieldByID( self.layers[0].getID()).setName(newLayerName) self.vocabularyController.view.updateLeftPanel() self.vocabularyController.view.updateSelectedMessageTable() dialog.destroy() dialog.destroy() def entry_disableButtonIfEmpty_cb(self, widget, button): if (len(widget.get_text()) > 0): button.set_sensitive(True) else: button.set_sensitive(False) def deleteLayer_cb(self, widget): for layer in self.layers: # Verify if selected layer is the top layer (i.e. the symbol) if layer == layer.getSymbol().getField(): # If so, delete the symbol and its messages currentProject = self.vocabularyController.netzob.getCurrentProject( ) currentVocabulary = currentProject.getVocabulary() for mess in layer.getSymbol().getMessages(): currentVocabulary.removeMessage(mess) currentVocabulary.removeSymbol(layer.getSymbol()) self.vocabularyController.view.emptyMessageTableDisplayingSymbols( [layer.getSymbol()]) else: layer.flattenLocalFields() self.vocabularyController.view.updateLeftPanel() self.vocabularyController.view.updateSelectedMessageTable() def sequenceAlignment_cb(self, action): sequence_controller = SequenceAlignmentController( self.vocabularyController, [self.layers[0]]) sequence_controller.run() def forcePartitionment_cb(self, action): force_controller = ForcePartitioningController( self.vocabularyController, [self.layers[0]]) force_controller.run() def simplePartitionment_cb(self, action): simple_controller = SimplePartitioningController( self.vocabularyController, [self.layers[0]]) simple_controller.run() def smoothPartitionment_cb(self, action): smooth_controller = SmoothPartitioningController( self.vocabularyController, [self.layers[0]]) smooth_controller.run() def resetPartitionment_cb(self, action): reset_controller = ResetPartitioningController( self.vocabularyController, [self.layers[0]]) reset_controller.run()