예제 #1
0
    def _import_next_layer(self, proto, length):
        """Import next layer extractor.

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

        Returns:
            * bool -- flag if extraction of next layer succeeded
            * Info -- info of next layer
            * ProtoChain -- protocol chain of next layer
            * str -- alias of next layer

        """
        if self._exproto == 'null' and self._exlayer == 'None':
            from pcapkit.protocols.raw import Raw as NextLayer
        else:
            from pcapkit.foundation.analysis import analyse as NextLayer
        # from pcapkit.foundation.analysis import analyse as NextLayer
        if length == 0:
            next_ = NoPayload()
        elif self._onerror:
            next_ = beholder_ng(NextLayer)(self._file, length, _termination=self._sigterm)
        else:
            next_ = NextLayer(self._file, length, _termination=self._sigterm)
        return next_
예제 #2
0
    def _import_next_layer(self, proto, length=None):
        """Import next layer extractor.

        Arguments:
            proto (str): next layer protocol name
            length (int): valid (*non-padding*) length

        Returns:
            pcapkit.protocols.protocol.Protocol: instance of next layer

        """
        if self._exproto == 'null' and self._exlayer == 'None':
            from pcapkit.protocols.raw import \
                Raw as protocol  # pylint: disable=import-outside-toplevel
        else:
            from pcapkit.foundation.analysis import \
                analyse as protocol  # pylint: disable=import-outside-toplevel

        if length == 0:
            next_ = NoPayload()
        elif self._onerror:
            next_ = beholder_ng(protocol)(self._file,
                                          length,
                                          termination=self._sigterm)
        else:
            next_ = protocol(self._file, length, termination=self._sigterm)
        return next_
예제 #3
0
    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
파일: 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)
예제 #5
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)
예제 #6
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)
예제 #7
0
    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)
예제 #8
0
    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)