コード例 #1
0
        def add_to_tree(model, path, iter, tree):
            obj = SequencePacket(model.get_value(iter, 0))
            parent = model.iter_parent(iter)

            if not parent:
                tree.append_node(Node(obj))
            else:
                path = model.get_path(parent)
                parent = tree.get_from_path(path)
                parent.append_node(Node(obj))
コード例 #2
0
            def add_to_tree(model, path, iter, tree):
                obj = copy.deepcopy(model.get_value(iter, 0))
                parent = model.iter_parent(iter)

                if not parent:
                    tree.append_node(Node(obj))
                else:
                    path = tree.find(model.get_value(parent, 0))

                    if not path:
                        tree.append_node(Node(obj))
                    else:
                        node = tree.get_from_path(path)
                        node.append_node(Node(obj))
コード例 #3
0
    def __on_run(self, action):
        # We have to construct a sequence and run our operation :D

        tree = Node()

        def complete_sequence(model, path, iter, tree):
            path = list(path)[:-1]
            node = Node(SequencePacket(model.get_value(iter, 0)))

            if path:
                tree = tree.get_from_path(path)

            tree.append_node(node)

        self.store.foreach(complete_sequence, tree)

        count = self.packet_count.get_value_as_int()
        inter = self.packet_interval.get_value_as_int()

        operation = SequenceOperation(tree, count, inter,
                                      self.intf_combo.get_interface(),
                                      self.check_strict.get_active(),
                                      self.check_received.get_active(),
                                      self.check_sent.get_active())

        tab = PMApp().main_window.get_tab("OperationsTab")
        tab.tree.append_operation(operation)
コード例 #4
0
    def __init__(self, fname):
        self.fname = fname

        self.in_node = False
        self.in_packet = False

        # Various attributes
        self.packet_interval = None
        self.packet_filter = None

        self.attr_strict = None
        self.attr_sent = None
        self.attr_recv = None
        self.attr_loopcnt = None
        self.attr_inter = None

        # Variables used to track document
        self.in_proto = False
        self.protocol = None
        self.current_protocol = None
        self.in_field = False
        self.field_id = False
        self.field_value = None

        self.tree = Node()
        self.current_node = self.tree
        self.tree_len = 0

        handler.ContentHandler.__init__(self)
コード例 #5
0
        def complete_sequence(model, path, iter, tree):
            path = list(path)[:-1]
            node = Node(SequencePacket(model.get_value(iter, 0)))

            if path:
                tree = tree.get_from_path(path)

            tree.append_node(node)
コード例 #6
0
ファイル: maintab.py プロジェクト: Paulxia/PacketManipulator
    def __impl_create_sequence_session(self, packets):
        """
        Create a sequence from packets

        @param packets a Node object or a list of packets or a single packet
        """

        if isinstance(packets, Node):
            ctx = backend.SequenceContext(packets)
        else:
            seq = Node()

            for packet in packets:
                seq.append_node(Node(backend.SequencePacket(packet)))

            ctx = backend.SequenceContext(seq)

        session = SequenceSession(ctx)
        return self.__append_session(session)
コード例 #7
0
    def get_current_tree(self):
        tree = Node()

        def add_to_tree(model, path, iter, tree):
            obj = SequencePacket(model.get_value(iter, 0))
            parent = model.iter_parent(iter)

            if not parent:
                tree.append_node(Node(obj))
            else:
                path = model.get_path(parent)
                parent = tree.get_from_path(path)
                parent.append_node(Node(obj))

        self.store.foreach(add_to_tree, tree)

        return tree
コード例 #8
0
    def startElement(self, name, attrs):
        if name == 'PMScapySequence':
            self.in_sequence = True

            try:
                self.attr_loopcnt = int(attrs['loopcnt'])
                self.attr_inter = float(attrs['inter'])

                self.attr_recv = int(attrs['report_recv']) != 0
                self.attr_sent = int(attrs['report_sent']) != 0
                self.attr_strict = int(attrs['strict']) != 0
            except Exception:
                if not isinstance(self.attr_loopcnt, int):
                    self.attr_loopcnt = 1
                if not isinstance(self.attr_inter, (float, int)):
                    self.attr_inter = 500
                if not isinstance(self.attr_recv, bool):
                    self.attr_recv = False
                if not isinstance(self.attr_sent, bool):
                    self.attr_sent = True
                if not isinstance(self.attr_strict, bool):
                    self.attr_strict = True

        elif self.in_sequence and name == 'SequencePacket':

            self.add_pending()

            try:
                self.packet_interval = eval(attrs['interval']) or 0
                self.packet_filter = attrs['filter']

                node = Node(
                    SequencePacket(None, self.packet_interval,
                                   self.packet_filter))

                self.current_node.append_node(node)
                self.current_node = node

                self.tree_len += 1

            except Exception, err:
                log.debug(generate_traceback())
            else:
                self.in_packet = True
コード例 #9
0
    def get_selected_packets(self, tree=False):
        """
        @return a list or a Tree contanining the selected packets
        """

        if tree:
            node = Node()

            def add_to_tree(model, path, iter, tree):
                obj = copy.deepcopy(model.get_value(iter, 0))
                parent = model.iter_parent(iter)

                if not parent:
                    tree.append_node(Node(obj))
                else:
                    path = tree.find(model.get_value(parent, 0))

                    if not path:
                        tree.append_node(Node(obj))
                    else:
                        node = tree.get_from_path(path)
                        node.append_node(Node(obj))

            self.tree.get_selection().selected_foreach(add_to_tree, node)

            for child in node:
                child.data = backend.SequencePacket(child.data)

            return node
        else:
            ret = []
            model, lst = self.tree.get_selection().get_selected_rows()

            for path in lst:
                ret.append(model.get_value(model.get_iter(path), 0))

            return ret
コード例 #10
0
        log.error(generate_traceback())
        raise err


def load_sequence(fname):
    try:
        return SequenceLoader(fname)
    except Exception, err:
        log.error("Error while loading sequence from %s" % fname)
        log.error(generate_traceback())

        raise err


if __name__ == "__main__":
    tree = Node()
    first = Node(SequencePacket(MetaPacket(Ether() / IP() / TCP())))
    first.append_node(Node(SequencePacket(MetaPacket(IP()))))

    tree.append_node(first)
    SequenceWriter("test.xml", tree)

    for child in tree:
        print child.get_data().packet.get_time()

    import time
    time.sleep(2)

    new_tree = SequenceLoader("test.xml").parse()

    print "Checking validity %s" % ((new_tree == tree) and ("ok") or ("wrong"))
コード例 #11
0
    except Exception, err:
        log.error("Cannot while saving sequence to %s" % fname)
        log.error(generate_traceback())
        raise err

def load_sequence(fname):
    try:
        return SequenceLoader(fname)
    except Exception, err:
        log.error("Error while loading sequence from %s" % fname)
        log.error(generate_traceback())

        raise err

if __name__ == "__main__":
    tree = Node()
    first = Node(SequencePacket(MetaPacket(Ether() / IP() /  TCP())))
    first.append_node(Node(SequencePacket(MetaPacket(IP()))))

    tree.append_node(first)
    SequenceWriter("test.xml", tree)

    for child in tree:
        print child.get_data().packet.get_time()

    import time
    time.sleep(2)

    new_tree = SequenceLoader("test.xml").parse()

    print "Checking validity %s" % ((new_tree == tree) and ("ok") or ("wrong"))