How to use the urh.util.util function in urh

To help you get started, we’ve selected a few urh examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jopohl / urh / tests / awre / test_address_engine.py View on Github external
source, destination = self.alice, self.bob
                data_length = 8
            else:
                source, destination = self.bob, self.alice
                data_length = 16
            pg.generate_message(data=pg.decimal_to_bits(4 * i, data_length), source=source, destination=destination)

        self.save_protocol("address_two_participants", pg)

        self.clear_message_types(pg.protocol.messages)
        ff = FormatFinder(pg.protocol.messages)

        address_engine = AddressEngine(ff.hexvectors, ff.participant_indices)
        address_dict = address_engine.find_addresses()
        self.assertEqual(len(address_dict), 2)
        addresses_1 = list(map(util.convert_numbers_to_hex_string, address_dict[0]))
        addresses_2 = list(map(util.convert_numbers_to_hex_string, address_dict[1]))
        self.assertIn(self.alice.address_hex, addresses_1)
        self.assertIn(self.alice.address_hex, addresses_2)
        self.assertIn(self.bob.address_hex, addresses_1)
        self.assertIn(self.bob.address_hex, addresses_2)

        ff.known_participant_addresses.clear()
        self.assertEqual(len(ff.known_participant_addresses), 0)

        ff.perform_iteration()

        self.assertEqual(len(ff.known_participant_addresses), 2)
        self.assertIn(bytes([int(h, 16) for h in self.alice.address_hex]),
                      map(bytes, ff.known_participant_addresses.values()))
        self.assertIn(bytes([int(h, 16) for h in self.bob.address_hex]),
                      map(bytes, ff.known_participant_addresses.values()))
github jopohl / urh / src / urh / controller / widgets / ChecksumWidget.py View on Github external
def on_line_edit_final_xor_editing_finished(self):
        crc = self.checksum_label.checksum
        final_xor = util.hex2bit(self.ui.lineEditFinalXOR.text())
        final_xor = array.array("B", [0] * (crc.poly_order - 1 - len(final_xor))) + final_xor
        crc.final_xor = final_xor[0:crc.poly_order-1]
        self.ui.lineEditFinalXOR.setText(util.bit2hex(crc.final_xor))
        self.__set_crc_info_label()
        self.__set_crc_function_index()
github jopohl / urh / src / urh / controller / dialogs / CSVImportDialog.py View on Github external
def update_file(self):
        filename = self.ui.lineEditFilename.text()
        self.filename = filename

        enable = util.file_can_be_opened(filename)
        if enable:
            with open(self.filename, encoding="utf-8-sig") as f:
                lines = []
                for i, line in enumerate(f):
                    if i >= self.PREVIEW_ROWS:
                        break
                    lines.append(line.strip())
                self.ui.plainTextEditFilePreview.setPlainText("\n".join(lines))
        else:
            self.ui.plainTextEditFilePreview.clear()

        self.ui.plainTextEditFilePreview.setEnabled(enable)
        self.ui.comboBoxCSVSeparator.setEnabled(enable)
        self.ui.spinBoxIDataColumn.setEnabled(enable)
        self.ui.spinBoxQDataColumn.setEnabled(enable)
        self.ui.spinBoxTimestampColumn.setEnabled(enable)
github jopohl / urh / src / urh / controller / CompareFrameController.py View on Github external
def __init__(self, plugin_manager: PluginManager, project_manager: ProjectManager, parent):

        super().__init__(parent)

        self.proto_analyzer = ProtocolAnalyzer(None)
        self.project_manager = project_manager

        self.ui = Ui_TabAnalysis()
        self.ui.setupUi(self)
        util.set_splitter_stylesheet(self.ui.splitter)
        util.set_splitter_stylesheet(self.ui.splitter_2)

        self.ui.lBitsSelection.setText("")
        self.ui.lDecimalSelection.setText("")
        self.ui.lHexSelection.setText("")
        self.plugin_manager = plugin_manager
        self.decimal_point = QLocale().decimalPoint()

        self.__selected_message_type = self.proto_analyzer.default_message_type

        self.participant_list_model = ParticipantListModel(project_manager.participants)
        self.ui.listViewParticipants.setModel(self.participant_list_model)

        self.__active_group_ids = [0]
        self.selected_protocols = set()
github jopohl / urh / src / urh / simulator / Simulator.py View on Github external
elif isinstance(self.current_item, SimulatorMessage):
                self.process_message()
                next_item = self.current_item.next()

            elif isinstance(self.current_item, SimulatorGotoAction):
                next_item = self.current_item.target
                self.log_message("GOTO item " + next_item.index())

            elif isinstance(self.current_item, SimulatorTriggerCommandAction):
                next_item = self.current_item.next()
                command = self.__fill_counter_values(self.current_item.command)
                self.log_message("Calling {}".format(command))
                if self.current_item.pass_transcript:
                    transcript = "\n".join(self.transcript.get_for_all_participants(all_rounds=False))
                    result, rc = util.run_command(command, transcript, use_stdin=True, return_rc=True)
                else:
                    result, rc = util.run_command(command, param=None, detailed_output=True, return_rc=True)
                self.current_item.return_code = rc
                self.log_message(result)

            elif isinstance(self.current_item, SimulatorRule):
                condition = self.current_item.get_first_applying_condition()

                if condition is not None and condition.logging_active and condition.type != ConditionType.ELSE:
                    self.log_message("Rule condition " + condition.index() + " (" + condition.condition + ") applied")

                if condition is not None and condition.child_count() > 0:
                    next_item = condition.children[0]
                else:
                    next_item = self.current_item.next_sibling()
github jopohl / urh / src / urh / controller / SignalTabController.py View on Github external
def __init__(self, project_manager, parent=None):
        super().__init__(parent)
        self.ui = Ui_Interpretation()
        self.ui.setupUi(self)

        util.set_splitter_stylesheet(self.ui.splitter)

        self.ui.placeholderLabel.setVisible(False)
        self.getting_started_status = None
        self.__set_getting_started_status(True)

        self.undo_stack = QUndoStack()
        self.project_manager = project_manager

        self.drag_pos = None
github jopohl / urh / src / urh / controller / GeneratorTabController.py View on Github external
def __init__(self, compare_frame_controller: CompareFrameController, project_manager: ProjectManager, parent=None):
        super().__init__(parent)
        self.ui = Ui_GeneratorTab()
        self.ui.setupUi(self)
        util.set_splitter_stylesheet(self.ui.splitter)

        self.project_manager = project_manager

        self.ui.treeProtocols.setHeaderHidden(True)
        self.tree_model = GeneratorTreeModel(compare_frame_controller)
        self.tree_model.set_root_item(compare_frame_controller.proto_tree_model.rootItem)
        self.tree_model.controller = self
        self.ui.treeProtocols.setModel(self.tree_model)

        self.table_model = GeneratorTableModel(compare_frame_controller.proto_tree_model.rootItem,
                                               compare_frame_controller.decodings)
        self.table_model.controller = self
        self.ui.tableMessages.setModel(self.table_model)

        self.label_list_model = GeneratorListModel(None)
        self.ui.listViewProtoLabels.setModel(self.label_list_model)
github jopohl / urh / src / urh / models / TableModel.py View on Github external
def get_tooltip(self, row: int, column: int) -> str:
        msg = self.protocol.messages[row]
        try:
            lbl = next(lbl for lbl in msg.message_type
                       if column in range(*msg.get_label_range(lbl, self.proto_view, self.decode)))
        except StopIteration:
            return ""

        result = lbl.name
        if isinstance(lbl, ChecksumLabel):
            calculated_crc = lbl.calculate_checksum_for_message(msg, use_decoded_bits=self.decode)
            start, end = msg.get_label_range(lbl=lbl, view=0, decode=self.decode)
            bits = msg.decoded_bits if self.decode else msg.plain_bits
            color = "green" if bits[start:end] == calculated_crc else "red"
            expected = util.convert_bits_to_string(calculated_crc, self.proto_view)
            result += '<br><font color="{}">Expected <b>{}</b></font>'.format(color, expected)

        return result
github jopohl / urh / src / urh / controller / ProtocolSniffDialogController.py View on Github external
self.ui.lineEdit_sniff_OutputFile.setCompleter(completer)

        self.setWindowTitle(self.tr("Sniff Protocol"))
        self.setWindowIcon(QIcon.fromTheme(":/icons/icons/sniffer.svg"))

        self.encodings = encodings
        for encoding in self.encodings:
            self.ui.comboBox_sniff_encoding.addItem(encoding.name)

        self.create_connects()

        if encoding_index > -1:
            self.ui.comboBox_sniff_encoding.setCurrentIndex(encoding_index)

        self.ui.comboBox_sniff_viewtype.setCurrentIndex(constants.SETTINGS.value('default_view', 0, int))
        self.ui.txtEd_sniff_Preview.setFont(util.get_monospace_font())