def addDecimalWord(self, event, rootVariable, rootEntry): # Display the form for the creation of a word variable dialog = Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.QUESTION, Gtk.ButtonsType.OK, None) dialog.set_markup(_("Definition of the Decimal WORD")) # Create the ID of the new variable variableID = str(uuid.uuid4()) mainTable = Gtk.Table(rows=3, columns=2, homogeneous=False) # parent id of the variable variablePIDLabel = Gtk.Label(label=_("Parent ID:")) variablePIDLabel.show() variablePIDValueLabel = Gtk.Label(label=str(rootVariable.getID())) variablePIDValueLabel.set_sensitive(False) variablePIDValueLabel.show() mainTable.attach(variablePIDLabel, 0, 1, 0, 1, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) mainTable.attach(variablePIDValueLabel, 1, 2, 0, 1, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) # id of the variable variableIDLabel = Gtk.Label(label=_("ID:")) variableIDLabel.show() variableIDValueLabel = Gtk.Label(label=variableID) variableIDValueLabel.set_sensitive(False) variableIDValueLabel.show() mainTable.attach(variableIDLabel, 0, 1, 1, 2, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) mainTable.attach(variableIDValueLabel, 1, 2, 1, 2, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) # value of the variable variableValueLabel = Gtk.Label(label=_("Value:")) variableValueLabel.show() variableValueEntry = Gtk.Entry() variableValueEntry.show() mainTable.attach(variableValueLabel, 0, 1, 2, 3, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) mainTable.attach(variableValueEntry, 1, 2, 2, 3, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) dialog.vbox.pack_end(mainTable, True, True, 0) dialog.show_all() result = dialog.run() if result != Gtk.ResponseType.OK: dialog.destroy() return # We retrieve the value of the variable varValue = variableValueEntry.get_text() # Creation of the word id, name, mutable, value): decimalwordVariable = DataVariable(variableID, "decimal word", True, False, DecimalWordType(), varValue, len(varValue), len(varValue)) rootVariable.addChild(decimalwordVariable) self.datas[str(decimalwordVariable.getID())] = decimalwordVariable self.treestore.append(rootEntry, [str(decimalwordVariable.getID()), decimalwordVariable.getUncontextualizedDescription()]) # We close the current dialog dialog.destroy()
def addIPv4(self, event, rootVariable, rootEntry): # Display the form for the creation of an IPv4 variable dialog = Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.QUESTION, Gtk.ButtonsType.OK, None) dialog.set_markup(_("Definition of the IPv4 Variable")) # Create the ID of the new variable varID = str(uuid.uuid4()) variableID = str(varID) mainTable = Gtk.Table(rows=3, columns=2, homogeneous=False) # parent id of the variable variablePIDLabel = Gtk.Label(label=_("Parent ID:")) variablePIDLabel.show() variablePIDValueLabel = Gtk.Label(label=str(rootVariable.getID())) variablePIDValueLabel.set_sensitive(False) variablePIDValueLabel.show() mainTable.attach(variablePIDLabel, 0, 1, 0, 1, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) mainTable.attach(variablePIDValueLabel, 1, 2, 0, 1, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) # id of the variable variableIDLabel = Gtk.Label(label=_("ID:")) variableIDLabel.show() variableIDValueLabel = Gtk.Label(label=variableID) variableIDValueLabel.set_sensitive(False) variableIDValueLabel.show() mainTable.attach(variableIDLabel, 0, 1, 1, 2, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) mainTable.attach(variableIDValueLabel, 1, 2, 1, 2, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) # Original Value originalValueLabel = Gtk.Label(label=_("Original value:")) originalValueLabel.show() originalValueEntry = Gtk.Entry() originalValueEntry.show() mainTable.attach(originalValueLabel, 0, 1, 2, 3, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) mainTable.attach(originalValueEntry, 1, 2, 2, 3, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) # Constraints label constraintsLabel = Gtk.Label(label=_("Constraints when parsing / generating")) constraintsLabel.show() mainTable.attach(constraintsLabel, 0, 2, 3, 4, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) # start Value startValueLabel = Gtk.Label(label=_("Start:")) startValueLabel.show() startValueEntry = Gtk.Entry() startValueEntry.show() mainTable.attach(startValueLabel, 0, 1, 4, 5, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) mainTable.attach(startValueEntry, 1, 2, 4, 5, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) # end Value endValueLabel = Gtk.Label(label=_("End:")) endValueLabel.show() endValueEntry = Gtk.Entry() endValueEntry.show() mainTable.attach(endValueLabel, 0, 1, 5, 6, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) mainTable.attach(endValueEntry, 1, 2, 5, 6, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) # Format label hdrFormatLabel = Gtk.Label(label=_("Representation")) hdrFormatLabel.show() mainTable.attach(hdrFormatLabel, 0, 2, 7, 8, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) # Format Value formatValueLabel = Gtk.Label(label=_("Format:")) formatValueLabel.show() formatValueCombo = Gtk.ComboBoxText.new_with_entry() formatValueCombo.show() formatValueComboStore = Gtk.ListStore(str) # format name formatValueCombo.set_model(formatValueComboStore) # We retrieve all the existing variables in the project formatValueCombo.get_model().append([Format.HEX]) formatValueCombo.get_model().append([Format.ASCII]) mainTable.attach(formatValueLabel, 0, 1, 8, 9, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) mainTable.attach(formatValueCombo, 1, 2, 8, 9, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) dialog.vbox.pack_end(mainTable, True, True, 0) dialog.show_all() result = dialog.run() if result != Gtk.ResponseType.OK: dialog.destroy() return # Creation of the variable (ipv4) # original value : originalValue = originalValueEntry.get_text() if len(originalValue) == 0: originalValue = None # constraints startValue = startValueEntry.get_text() if len(startValue) == 0: startValue = None endValue = endValueEntry.get_text() if len(endValue) == 0: endValue = None # format format = formatValueCombo.get_model().get_value(formatValueCombo.get_active_iter(), 0) ipVariable = DataVariable(varID, "ipv4", True, False, IPv4WordType(), originalValue, startValue, endValue, format) rootVariable.addChild(ipVariable) self.datas[str(ipVariable.getID())] = ipVariable self.treestore.append(rootEntry, [str(ipVariable.getID()), ipVariable.getUncontextualizedDescription()]) # We close the current dialog dialog.destroy()
def addHexadecimal(self, event, rootVariable, rootEntry): # Display the form for the creation of an Hexadecimal variable dialog = Gtk.MessageDialog(None, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.QUESTION, Gtk.ButtonsType.OK, None) dialog.set_markup(_("Definition of the Hexadecimal Variable")) # Create the ID of the new variable varID = str(uuid.uuid4()) variableID = str(varID) mainTable = Gtk.Table(rows=3, columns=2, homogeneous=False) # parent id of the variable variablePIDLabel = Gtk.Label(label=_("Parent ID:")) variablePIDLabel.show() variablePIDValueLabel = Gtk.Label(label=str(rootVariable.getID())) variablePIDValueLabel.set_sensitive(False) variablePIDValueLabel.show() mainTable.attach(variablePIDLabel, 0, 1, 0, 1, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) mainTable.attach(variablePIDValueLabel, 1, 2, 0, 1, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) # id of the variable variableIDLabel = Gtk.Label(label=_("ID:")) variableIDLabel.show() variableIDValueLabel = Gtk.Label(label=variableID) variableIDValueLabel.set_sensitive(False) variableIDValueLabel.show() mainTable.attach(variableIDLabel, 0, 1, 1, 2, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) mainTable.attach(variableIDValueLabel, 1, 2, 1, 2, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) # Original Value originalValueLabel = Gtk.Label(label=_("Original value:")) originalValueLabel.show() originalValueEntry = Gtk.Entry() originalValueEntry.show() mainTable.attach(originalValueLabel, 0, 1, 2, 3, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) mainTable.attach(originalValueEntry, 1, 2, 2, 3, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) # Constraints label constraintsLabel = Gtk.Label(label=_("Constraints when parsing / generating")) constraintsLabel.show() mainTable.attach(constraintsLabel, 0, 2, 3, 4, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) # start Value minBitsLabel = Gtk.Label(label=_("Minimum number of hex (0xf=1):")) minBitsLabel.show() minBitsEntry = Gtk.Entry() minBitsEntry.show() mainTable.attach(minBitsLabel, 0, 1, 4, 5, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) mainTable.attach(minBitsEntry, 1, 2, 4, 5, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) # end Value maxBitsLabel = Gtk.Label(label=_("Maximum number of hex:")) maxBitsLabel.show() maxBitsEntry = Gtk.Entry() maxBitsEntry.show() mainTable.attach(maxBitsLabel, 0, 1, 5, 6, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) mainTable.attach(maxBitsEntry, 1, 2, 5, 6, xoptions=Gtk.AttachOptions.FILL, yoptions=0, xpadding=5, ypadding=5) dialog.vbox.pack_end(mainTable, True, True, 0) dialog.show_all() result = dialog.run() if result != Gtk.ResponseType.OK: dialog.destroy() return # Creation of the variable (binary) # original value : originalValue = originalValueEntry.get_text() if len(originalValue) == 0: originalValue = None # constraints minSize = int(minBitsEntry.get_text()) maxSize = int(maxBitsEntry.get_text()) hexVariable = DataVariable(varID, "hexadecimal", True, False, HexWordType(), originalValue, minSize, maxSize) rootVariable.addChild(hexVariable) self.datas[str(hexVariable.getID())] = hexVariable self.treestore.append(rootEntry, [str(hexVariable.getID()), hexVariable.getUncontextualizedDescription()]) # We close the current dialog dialog.destroy()