コード例 #1
0
ファイル: protocol.py プロジェクト: jeetbhatt-sys/PyPCAPKit
    def _decode_next_layer(self, dict_, proto=None, length=None):
        """Decode next layer protocol.

        Arguments:
            dict_ (dict): info buffer
            proto (int): next layer protocol index
            length (int): valid (*non-padding*) length

        Returns:
            dict: current protocol with next layer extracted

        """
        if self._onerror:
            next_ = beholder(self._import_next_layer)(self, proto, length)
        else:
            next_ = self._import_next_layer(proto, length)
        info, chain = next_.info, next_.protochain

        # make next layer protocol name
        layer = next_.alias.lower()
        # proto = next_.__class__.__name__

        # write info and protocol chain into dict
        dict_[layer] = info
        self._next = next_  # pylint: disable=attribute-defined-outside-init
        self._protos = ProtoChain(self.__class__, self.alias, basis=chain)  # pylint: disable=attribute-defined-outside-init
        return dict_
コード例 #2
0
ファイル: protocol.py プロジェクト: ekoziol/PyPCAPKit
    def _decode_next_layer(self, dict_, proto=None, length=None):
        """Decode next layer protocol.

        Positional arguments:
            * dict_ -- dict, info buffer
            * proto -- str, next layer protocol name
            * length -- int, valid (not padding) length

        Returns:
            * dict -- current protocol with next layer extracted

        """
        if self._onerror:
            next_ = beholder(self._import_next_layer)(self, proto, length)
        else:
            next_ = self._import_next_layer(proto, length)
        info, chain = next_.info, next_.protochain

        # make next layer protocol name
        layer = next_.alias.lower()
        # proto = next_.__class__.__name__

        # write info and protocol chain into dict
        dict_[layer] = info
        self._next = next_
        self._protos = ProtoChain(self.__class__, self.alias, basis=chain)
        return dict_
コード例 #3
0
ファイル: raw.py プロジェクト: jeetbhatt-sys/PyPCAPKit
    def __post_init__(self, file, length=None, *, error=None, **kwargs):  # pylint: disable=arguments-differ
        """Post initialisation hook.

        Args:
            file (io.BytesIO): Source packet stream.
            length (Optional[int]): Length of packet data.

        Keyword Args:
            error (Optional[str]): Parsing errors if any (for parsing).
            **kwargs: Arbitrary keyword arguments.

        Would :mod:`pcapkit` encounter malformed packets, the original parsing
        error message will be provided as in ``error``.

        See Also:
            For construction argument, please refer to :meth:`make`.

        """
        if file is None:
            _data = self.make(**kwargs)
        else:
            _data = file.read(length)

        #: bytes: Raw packet data.
        self._data = _data
        #: io.BytesIO: Source packet stream.
        self._file = io.BytesIO(self._data)
        #: pcapkit.corekit.infoclass.Info: Parsed packet data.
        self._info = Info(self.read(length, error=error, **kwargs))

        #: pcapkit.protocols.null.NoPayload: Next layer (no payload).
        self._next = NoPayload()
        #: pcapkit.corekit.protochain.ProtoChain: Protocol chain from current layer.
        self._protos = ProtoChain(self.__class__, self.alias)
コード例 #4
0
    def _decode_next_layer(self,
                           dict_,
                           proto=None,
                           length=None,
                           *,
                           version=4,
                           ipv6_exthdr=None):  # pylint: disable=arguments-differ
        """Decode next layer extractor.

        Arguments:
            dict_ (dict): info buffer
            proto (int): next layer protocol index
            length (int): valid (*non-padding*) length

        Keyword Arguments:
            version (Literal[4, 6]): IP version
            ipv6_exthdr (pcapkit.corekit.protochain.ProtoChain): protocol chain of IPv6 extension headers

        Returns:
            dict: current protocol with next layer extracted

        """
        if self._onerror:
            next_ = beholder(self._import_next_layer)(self,
                                                      proto,
                                                      length,
                                                      version=version)
        else:
            next_ = self._import_next_layer(proto, length, version=version)
        info, chain = next_.info, next_.protochain

        # make next layer protocol name
        layer = next_.alias.lower()
        # proto = next_.__class__.__name__

        # write info and protocol chain into dict
        dict_[layer] = info
        self._next = next_  # pylint: disable=attribute-defined-outside-init
        if ipv6_exthdr is not None:
            for proto_cls in reversed(ipv6_exthdr):
                chain = ProtoChain(proto_cls.__class__,
                                   proto_cls.alias,
                                   basis=chain)
        self._protos = ProtoChain(self.__class__, self.alias, basis=chain)  # pylint: disable=attribute-defined-outside-init
        return dict_
コード例 #5
0
ファイル: null.py プロジェクト: ljouans/PyPCAPKit
 def __init__(self, *args, **kwargs):  # pylint: disable=super-init-not-called
     #: NoPayload: Payload of current instance.
     self._next = self
     #: Info: Info dict of current instance.
     self._info = Info()
     #: io.BytesIO: Source data stream.
     self._file = io.BytesIO()
     #: ProtoChain: Protocol chain of current instance.
     self._protos = ProtoChain()
コード例 #6
0
    def _decode_next_layer(self,
                           dict_,
                           proto=None,
                           length=None,
                           *,
                           version=4,
                           ipv6_exthdr=None):
        """Decode next layer extractor.

        Positional arguments:
            * dict_ -- dict, info buffer
            * proto -- str, next layer protocol name
            * length -- int, valid (not padding) length

        Keyword Arguments:
            * version -- int, IP version (4 in default)
                            <keyword> 4 / 6
            * ext_proto -- ProtoChain, ProtoChain of IPv6 extension headers

        Returns:
            * dict -- current protocol with next layer extracted

        """
        if self._onerror:
            next_ = beholder(self._import_next_layer)(self,
                                                      proto,
                                                      length,
                                                      version=version)
        else:
            next_ = self._import_next_layer(proto, length, version=version)
        info, chain = next_.info, next_.protochain

        # make next layer protocol name
        layer = next_.alias.lower()
        # proto = next_.__class__.__name__

        # write info and protocol chain into dict
        dict_[layer] = info
        self._next = next_
        if ipv6_exthdr is not None:
            for proto in reversed(ipv6_exthdr):
                chain = ProtoChain(proto.__class__, proto.alias, basis=chain)
        self._protos = ProtoChain(self.__class__, self.alias, basis=chain)
        return dict_
コード例 #7
0
ファイル: ftp.py プロジェクト: 5l1v3r1/PyPCAPKit
    def __init__(self, _file, length=None, **kwargs):  # pylint: disable=super-init-not-called
        """Initialisation.

        Args:
            file (io.BytesIO): Source packet stream.
            length (Optional[int]): Length of packet data.

        Keyword Args:
            **kwargs: Arbitrary keyword arguments.

        """
        self._file = _file
        self._info = Info(self.read_ftp(length))

        self._next = NoPayload()
        self._protos = ProtoChain(self.__class__, self.alias)
コード例 #8
0
ファイル: null.py プロジェクト: 5l1v3r1/PyPCAPKit
    def __init__(self, *args, **kwargs):  # pylint: disable=super-init-not-called
        """Initialisation.

        Args:
            *args: Arbitrary positional arguments.

        Keyword Args:
            **kwargs: Arbitrary keyword arguments.

        """
        #: pcapkit.protocols.null.NoPayload: Payload of current instance.
        self._next = self
        #: pcapkit.corekit.infoclass.Info: Info dict of current instance.
        self._info = Info()
        #: io.BytesIO: Source data stream.
        self._file = io.BytesIO()
        #: pcapkit.corekit.protochain.ProtoChain: Protocol chain of current instance.
        self._protos = ProtoChain()
コード例 #9
0
    def __post_init__(self, file=None, length=None, **kwargs):
        """Post initialisation hook.

        Args:
            file (Optional[io.BytesIO]): Source packet stream.
            length (Optional[int]): Length of packet data.

        Keyword Args:
            **kwargs: Arbitrary keyword arguments.

        See Also:
            For construction argument, please refer to :meth:`make`.

        """
        # call super post-init
        super().__post_init__(file, length, **kwargs)

        #: pcapkit.protocols.null.NoPayload: Payload of current instance.
        self._next = NoPayload()
        #: pcapkit.corekit.protochain.ProtoChain: Protocol chain of current instance.
        self._protos = ProtoChain(self.__class__, self.alias)
コード例 #10
0
ファイル: null.py プロジェクト: jeetbhatt-sys/PyPCAPKit
    def __post_init__(self, file=None, length=None, **kwargs):  # pylint: disable=unused-argument
        """Post initialisation hook.

        Args:
            file (Optional[io.BytesIO]): Source packet stream.
            length (Optional[int]): Length of packet data.

        Keyword Args:
            **kwargs: Arbitrary keyword arguments.

        """
        #: bytes: Raw packet data.
        self._data = bytes()
        #: io.BytesIO: Source data stream.
        self._file = io.BytesIO()
        #: pcapkit.corekit.infoclass.Info: Info dict of current instance.
        self._info = Info()

        #: pcapkit.protocols.null.NoPayload: Payload of current instance.
        self._next = self
        #: pcapkit.corekit.protochain.ProtoChain: Protocol chain of current instance.
        self._protos = ProtoChain()
コード例 #11
0
ファイル: raw.py プロジェクト: 5l1v3r1/PyPCAPKit
    def __init__(self, file, length=None, *, error=None, **kwargs):  # pylint: disable=super-init-not-called
        """Initialisation.

        Args:
            file (io.BytesIO): Source packet stream.
            length (Optional[int]): Length of packet data.

        Keyword Args:
            error (Optional[str]): Parsing errors if any.
            **kwargs: Arbitrary keyword arguments.

        Would :mod:`pcapkit` encounter malformed packets, the original parsing
        error message will be provided as in ``error``.

        """
        #: io.BytesIO: Source packet stream.
        self._file = file
        #: pcapkit.corekit.infoclass.Info: Parsed packet data.
        self._info = Info(self.read_raw(length, error=error))

        #: pcapkit.protocols.null.NoPayload: Next layer (no payload).
        self._next = NoPayload()
        #: pcapkit.corekit.protochain.ProtoChain: Protocol chain from current layer.
        self._protos = ProtoChain(self.__class__, self.alias)
コード例 #12
0
ファイル: raw.py プロジェクト: lorenzatoandrea/PyPCAPKit
    def __init__(self, file, length=None, *, error=None, **kwargs):
        self._file = file
        self._info = Info(self.read_raw(length, error=error))

        self._next = NoPayload()
        self._protos = ProtoChain(self.__class__, self.alias)
コード例 #13
0
ファイル: http.py プロジェクト: lorenzatoandrea/PyPCAPKit
    def __init__(self, _file, length=None, **kwargs):
        self._file = _file
        self._info = Info(self.read_http(length))

        self._next = NoPayload()
        self._protos = ProtoChain(self.__class__, self.alias)
コード例 #14
0
ファイル: null.py プロジェクト: xuacker/PyPCAPKit
 def __init__(self, *args, **kwargs):
     self._next = self
     self._info = Info()
     self._file = io.BytesIO()
     self._protos = ProtoChain()