How to use the urh.signalprocessing.ProtocoLabel.ProtocolLabel 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 / src / urh / signalprocessing / LabelAssigner.py View on Github external
The sync is chosen by comparing all constant ranges that lay right behind the preamble and chose the most frequent one.

        :return:
        """
        if not self.is_initialized:
            self.__search_constant_intervals()

        possible_sync_pos = defaultdict(int)
        for const_range in (cr for const_interval in self.common_intervals.values() for cr in const_interval):
            const_range = Interval(4 * ((const_range.start + 1) // 4) - 1, 4 * ((const_range.end + 1) // 4) - 1) # align to nibbles
            possible_sync_pos[const_range] += int(const_range.start == self.preamble_end)

        sync_interval = max(possible_sync_pos, key=possible_sync_pos.__getitem__)

        self.sync_end = sync_interval.end
        return ProtocolLabel(start=sync_interval.start + 1, end=sync_interval.end - 1, name="Sync", color_index=None)
github jopohl / urh / tests / test_messagetype.py View on Github external
def test_find_unlabeled_range(self):
        lbl11 = ProtocolLabel(name="Label 1.1", start=2, end=10, color_index=0)
        lbl12 = ProtocolLabel(name="Label 1.2", start=15, end=20, color_index=0)
        lbl13 = ProtocolLabel(name="Label 1.3", start=40, end=60, color_index=0)

        mt1 = MessageType(name="MT1", iterable=[lbl11, lbl12, lbl13])

        self.assertEqual([(0, 2), (11, 15), (21, 40), (61, None)], mt1.unlabeled_ranges)
        self.assertEqual([(0, 2), (11, 15), (21, 40), (61, None)], mt1.unlabeled_ranges_with_other_mt(mt1))

        lbl21 = ProtocolLabel(name="Label 2.1", start=1, end=11, color_index=0)
        lbl22 = ProtocolLabel(name="Label 2.2", start=14, end=18, color_index=0)
        lbl23 = ProtocolLabel(name="Label 2.3", start=50, end=70, color_index=0)

        mt2 = MessageType(name="MT2", iterable=[lbl21, lbl22, lbl23])

        self.assertEqual(mt1.unlabeled_ranges_with_other_mt(mt2), mt2.unlabeled_ranges_with_other_mt(mt1))
        self.assertEqual(mt1.unlabeled_ranges_with_other_mt(mt2), [(0, 1), (11, 14), (21, 40), (71, None)])
github jopohl / urh / tests / test_awre.py View on Github external
sync_start, sync_end = 32, 63
        length_start, length_end = 64, 71
        ack_address_start, ack_address_end = 72, 95
        dst_address_start, dst_address_end = 88, 111
        src_address_start, src_address_end = 112, 135

        preamble_label = ProtocolLabel(name=self.preamble_field_type.caption, field_type=self.preamble_field_type,
                                       start=preamble_start, end=preamble_end, color_index=0)
        sync_label = ProtocolLabel(name=self.sync_field_type.caption, field_type=self.sync_field_type,
                                   start=sync_start, end=sync_end, color_index=1)
        length_label = ProtocolLabel(name=self.length_field_type.caption, field_type=self.length_field_type,
                                     start=length_start, end=length_end, color_index=2)
        ack_address_label = ProtocolLabel(name=self.dst_address_field_type.caption,
                                          field_type=self.dst_address_field_type,
                                          start=ack_address_start, end=ack_address_end, color_index=3)
        dst_address_label = ProtocolLabel(name=self.dst_address_field_type.caption,
                                          field_type=self.dst_address_field_type,
                                          start=dst_address_start, end=dst_address_end, color_index=4)
        src_address_label = ProtocolLabel(name=self.src_address_field_type.caption,
                                          field_type=self.src_address_field_type,
                                          start=src_address_start, end=src_address_end, color_index=5)

        ff = FormatFinder(protocol=self.protocol, participants=self.participants, field_types=self.field_types)
        ff.perform_iteration()

        self.assertIn(preamble_label, self.protocol.default_message_type)
        self.assertIn(sync_label, self.protocol.default_message_type)
        self.assertIn(length_label, self.protocol.default_message_type)
        self.assertIn(dst_address_label, self.protocol.default_message_type)
        self.assertIn(src_address_label, self.protocol.default_message_type)

        self.assertEqual(len(self.protocol.message_types), 2)
github jopohl / urh / src / urh / ui / views / LabelValueTableView.py View on Github external
def __init__(self, parent=None):
        super().__init__(parent)
        self.setItemDelegateForColumn(1, ComboBoxDelegate(ProtocolLabel.DISPLAY_FORMATS, parent=self))

        orders = OrderedDict([("Big Endian (BE)", [bo + "/BE" for bo in ProtocolLabel.DISPLAY_BIT_ORDERS]),
                              ("Little Endian (LE)", [bo + "/LE" for bo in ProtocolLabel.DISPLAY_BIT_ORDERS])])

        self.setItemDelegateForColumn(2, SectionComboBoxDelegate(orders, parent=self))
        self.setEditTriggers(QTableView.AllEditTriggers)
github jopohl / urh / src / urh / models / GeneratorListModel.py View on Github external
from PyQt5.QtCore import QAbstractListModel, Qt, QModelIndex, pyqtSignal
from PyQt5.QtGui import QColor

from urh import constants
from urh.signalprocessing.ProtocoLabel import ProtocolLabel
from urh.signalprocessing.ProtocolAnalyzerContainer import ProtocolAnalyzerContainer
from urh.signalprocessing.Message import Message


class GeneratorListModel(QAbstractListModel):
    protolabel_fuzzing_status_changed = pyqtSignal(ProtocolLabel)
    protolabel_removed = pyqtSignal(ProtocolLabel)

    def __init__(self, message: Message, parent=None):
        super().__init__(parent)
        self.__message = message
    
    @property
    def labels(self):
        if self.message:
            return self.message.message_type
        else:
            return []
    
    @property
    def message(self):
        return self.__message
github jopohl / urh / src / urh / controller / dialogs / ProtocolLabelDialog.py View on Github external
from urh.signalprocessing.ChecksumLabel import ChecksumLabel
from urh.signalprocessing.FieldType import FieldType
from urh.signalprocessing.Message import Message
from urh.signalprocessing.MessageType import MessageType
from urh.signalprocessing.ProtocoLabel import ProtocolLabel
from urh.simulator.SimulatorProtocolLabel import SimulatorProtocolLabel
from urh.ui.delegates.CheckBoxDelegate import CheckBoxDelegate
from urh.ui.delegates.ComboBoxDelegate import ComboBoxDelegate
from urh.ui.delegates.SpinBoxDelegate import SpinBoxDelegate
from urh.ui.ui_properties_dialog import Ui_DialogLabels
from urh.util import util
from urh.util.Logger import logger


class ProtocolLabelDialog(QDialog):
    apply_decoding_changed = pyqtSignal(ProtocolLabel, MessageType)

    SPECIAL_CONFIG_TYPES = [FieldType.Function.CHECKSUM]

    def __init__(self, message: Message, viewtype: int, selected_index=None, parent=None):
        super().__init__(parent)
        self.ui = Ui_DialogLabels()
        self.ui.setupUi(self)
        util.set_splitter_stylesheet(self.ui.splitter)

        field_types = FieldType.load_from_xml()
        self.model = PLabelTableModel(message, field_types)

        self.ui.tblViewProtoLabels.setItemDelegateForColumn(0, ComboBoxDelegate([ft.caption for ft in field_types],
                                                                                is_editable=True,
                                                                                return_index=False, parent=self))
        self.ui.tblViewProtoLabels.setItemDelegateForColumn(1, SpinBoxDelegate(1, len(message), self))
github jopohl / urh / src / urh / models / FieldTypeTableModel.py View on Github external
def data(self, index: QModelIndex, role=Qt.DisplayRole):
        if not index.isValid():
            return None

        if role == Qt.DisplayRole or role == Qt.EditRole:
            i = index.row()
            j = index.column()
            fieldtype = self.field_types[i]

            if j == 0:
                return fieldtype.caption
            elif j == 1:
                return fieldtype.function.name
            elif j == 2:
                return ProtocolLabel.DISPLAY_FORMATS[fieldtype.display_format_index]
github jopohl / urh / src / urh / models / PLabelTableModel.py View on Github external
from PyQt5.QtCore import QAbstractTableModel, pyqtSignal, Qt, QModelIndex
from PyQt5.QtGui import QFont

from urh.signalprocessing.Message import Message
from urh.signalprocessing.MessageType import MessageType
from urh.signalprocessing.ProtocoLabel import ProtocolLabel


class PLabelTableModel(QAbstractTableModel):
    header_labels = ["Name", "Start", "End", 'Color', 'Apply decoding']

    label_removed = pyqtSignal(ProtocolLabel)
    special_status_label_changed = pyqtSignal(ProtocolLabel)
    apply_decoding_changed = pyqtSignal(ProtocolLabel)

    def __init__(self, message: Message, field_types, parent=None):
        """

        :param message:
        :type field_types: list of FieldType
        :param parent:
        """
        super().__init__(parent)
        self.row_count = len(message.message_type)
        self.proto_view = 0
        self.__message = None
        self.message = message
github jopohl / urh / src / urh / signalprocessing / ChecksumLabel.py View on Github external
def to_label(self, field_type: FieldType) -> ProtocolLabel:
        result = ProtocolLabel(name=self.name, start=self.start, end=self.end - 1, color_index=self.color_index, field_type=field_type,
                               auto_created=self.auto_created, fuzz_created=self.fuzz_created)
        result.apply_decoding = self.apply_decoding
        result.show = self.show
        result.fuzz_me = self.fuzz_me
        result.fuzz_values = self.fuzz_values
        result.display_format_index = self.display_format_index
        return result
github jopohl / urh / src / urh / signalprocessing / LabelAssigner.py View on Github external
break
                else:
                    candidate = max(overlapping_intervals)

            if candidate is None:
                continue

            overlapping_candidate = next((c for c in common_constant_intervals if c.overlaps_with(candidate)), None)

            if overlapping_candidate is None:
                common_constant_intervals.add(candidate)
            else:
                common_constant_intervals.remove(overlapping_candidate)
                common_constant_intervals.add(candidate.find_common_interval(overlapping_candidate))

        return [ProtocolLabel(start=interval.start, end=interval.end, name="Constant #{0}".format(i+1),
                              color_index=None) for i, interval in enumerate(common_constant_intervals)]