code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
@functools.wraps(func)
def behold(file, length, *args, **kwargs):
seek_cur = file.tell()
try:
return func(file, length, *args, **kwargs)
except Exception:
# from pcapkit.foundation.analysis import analyse
from pcapkit.protocols.raw import Raw
... | def beholder_ng(func) | Behold analysis procedure. | 3.947007 | 4.017052 | 0.982563 |
if length is None:
length = len(self)
_flag = self._read_binary(1)
_vers = self._read_fileng(1).hex()[1]
_hlen = self._read_unpack(2) if int(_flag[1]) else None
_tnnl = self._read_unpack(2)
_sssn = self._read_unpack(2)
_nseq = self._read_unpa... | def read_l2tp(self, length) | Read Layer Two Tunnelling Protocol.
Structure of L2TP header [RFC 2661]:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
... | 3.370874 | 2.776688 | 1.213991 |
if isinstance(key, int):
return ECDSA_LOW_Curve(key)
if key not in ECDSA_LOW_Curve._member_map_:
extend_enum(ECDSA_LOW_Curve, key, default)
return ECDSA_LOW_Curve[key] | def get(key, default=-1) | Backport support for original codes. | 5.136911 | 4.680596 | 1.097491 |
if isinstance(key, int):
return Hardware(key)
if key not in Hardware._member_map_:
extend_enum(Hardware, key, default)
return Hardware[key] | def get(key, default=-1) | Backport support for original codes. | 6.366552 | 5.520733 | 1.153208 |
if length is None:
length = len(self)
_tcif = self._read_binary(2)
_type = self._read_protos(2)
vlan = dict(
tci=dict(
pcp=_PCP.get(int(_tcif[:3], base=2)),
dei=True if _tcif[3] else False,
vid=int(_tcif[4... | def read_vlan(self, length) | Read 802.1Q Customer VLAN Tag Type.
Structure of 802.1Q Customer VLAN Tag Type [RFC 7042]:
Octets Bits Name Description
1 0 vlan.tci Tag Control Information
1 0 vlan.tci.pcp Priority Cod... | 5.319366 | 4.286148 | 1.24106 |
if isinstance(key, int):
return TaggerId(key)
if key not in TaggerId._member_map_:
extend_enum(TaggerId, key, default)
return TaggerId[key] | def get(key, default=-1) | Backport support for original codes. | 5.11918 | 4.479421 | 1.142822 |
counter = 0 # length of read option list
optkind = list() # option kind list
options = dict() # dict of option data
while counter < size:
# get option kind
kind = self._read_unpack(1)
# fetch corresponding option tuple
... | def _read_tcp_options(self, size) | Read TCP option list.
Positional arguments:
* size -- int, length of option list
Returns:
* tuple -- TCP option list
* dict -- extracted TCP option | 4.618124 | 4.505614 | 1.024971 |
data = dict(
kind=kind,
length=size,
data=self._read_fileng(size),
)
return data | def _read_mode_donone(self, size, kind) | Read options request no process.
Positional arguments:
* size - int, length of option
* kind - int, option kind value
Returns:
* dict -- extracted option with no operation
Structure of TCP options:
Octets Bits Name ... | 6.404864 | 6.898539 | 0.928438 |
data = dict(
kind=kind,
length=size,
data=self._read_unpack(size),
)
return data | def _read_mode_unpack(self, size, kind) | Read options request unpack process.
Keyword arguments:
size - int, length of option
kind - int, option kind value
Returns:
* dict -- extracted option which unpacked
Structure of TCP options:
Octets Bits Name Descr... | 4.963257 | 5.06686 | 0.979553 |
temp = struct.unpack('>II', self._read_fileng(size))
data = dict(
kind=kind,
length=size,
val=temp[0],
ecr=temp[1],
)
return data | def _read_mode_tsopt(self, size, kind) | Read Timestamps option.
Positional arguments:
* size - int, length of option
* kind - int, 8 (Timestamps)
Returns:
* dict -- extracted Timestamps (TS) option
Structure of TCP TSopt [RFC 7323]:
+-------+-------+---------------------+-------------... | 6.648014 | 4.858887 | 1.368217 |
temp = self._read_binary(size)
data = dict(
kind=kind,
length=size,
start=True if int(temp[0]) else False,
end=True if int(temp[1]) else False,
filler=bytes(chr(int(temp[2:], base=2)), encoding='utf-8'),
)
return data | def _read_mode_pocsp(self, size, kind) | Read Partial Order Connection Service Profile option.
Positional arguments:
* size - int, length of option
* kind - int, 10 (POC-Serv Profile)
Returns:
* dict -- extracted Partial Order Connection Service Profile (POC-SP) option
Structure of TCP POC-SP Opti... | 4.752055 | 3.414111 | 1.391887 |
temp = self._read_unpack(size)
algo = chksum_opt.get(temp)
data = dict(
kind=kind,
length=size,
ac=algo,
)
return data | def _read_mode_acopt(self, size, kind) | Read Alternate Checksum Request option.
Positional arguments:
size - int, length of option
kind - int, 14 (Alt-Chksum Request)
Returns:
* dict -- extracted Alternate Checksum Request (CHKSUM-REQ) option
Structure of TCP CHKSUM-REQ [RFC 1146][RFC 6247]:
... | 12.127742 | 8.542841 | 1.419638 |
rvrr = self._read_binary(1)
ttld = self._read_unpack(1)
noun = self._read_fileng(4)
data = dict(
kind=kind,
length=size,
req_rate=int(rvrr[4:], base=2),
ttl_diff=ttld,
nounce=noun[:-2],
)
return data | def _read_mode_qsopt(self, size, kind) | Read Quick-Start Response option.
Positional arguments:
* size - int, length of option
* kind - int, 27 (Quick-Start Response)
Returns:
* dict -- extracted Quick-Start Response (QS) option
Structure of TCP QSopt [RFC 4782]:
0 ... | 9.897898 | 5.870749 | 1.685969 |
temp = self._read_fileng(size)
data = dict(
kind=kind,
length=size,
granularity='minutes' if int(temp[0]) else 'seconds',
timeout=bytes(chr(int(temp[0:], base=2)), encoding='utf-8'),
)
return data | def _read_mode_utopt(self, size, kind) | Read User Timeout option.
Positional arguments:
* size - int, length of option
* kind - int, 28 (User Timeout Option)
Returns:
* dict -- extracted User Timeout (TIMEOUT) option
Structure of TCP TIMEOUT [RFC 5482]:
0 1 ... | 10.700179 | 6.951555 | 1.53925 |
key_ = self._read_unpack(1)
rkey = self._read_unpack(1)
mac_ = self._read_fileng(size - 2)
data = dict(
kind=kind,
length=size,
keyid=key_,
rnextkeyid=rkey,
mac=mac_,
)
return data | def _read_mode_tcpao(self, size, kind) | Read Authentication option.
Positional arguments:
* size - int, length of option
* kind - int, 29 (TCP Authentication Option)
Returns:
* dict -- extracted Authentication (AO) option
Structure of TCP AOopt [RFC 5925]:
+------------+------------+-... | 5.85088 | 3.745511 | 1.562105 |
bins = self._read_binary(1)
subt = int(bins[:4], base=2) # subtype number
bits = bins[4:] # 4-bit data
dlen = size - 1 # length of remaining data
# fetch subtype-specific data
func = mptcp_opt.get(subt)
if func is None:... | def _read_mode_mptcp(self, size, kind) | Read Multipath TCP option.
Positional arguments:
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Multipath TCP (MP-TCP) option
Structure of MP-TCP [RFC 6824]:
1 ... | 6.885952 | 6.112065 | 1.126616 |
vers = int(bits, base=2)
bins = self._read_binary(1)
skey = self._read_fileng(8)
rkey = self._read_fileng(8) if size == 17 else None
data = dict(
kind=kind,
length=size + 1,
subtype='MP_CAPABLE',
capable=dict(
... | def _read_mptcp_capable(self, bits, size, kind) | Read Multipath Capable option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Multipath Capable (MP_CAPABLE) option
Structure of MP_CAPABLE [RFC 6824]:
... | 4.417034 | 3.031093 | 1.457241 |
if self._syn and self._ack: # MP_JOIN-SYN/ACK
return self._read_join_synack(bits, size, kind)
elif self._syn: # MP_JOIN-SYN
return self._read_join_syn(bits, size, kind)
elif self._ack: # MP_JOIN-ACK
return self._rea... | def _read_mptcp_join(self, bits, size, kind) | Read Join Connection option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Join Connection (MP_JOIN) option
Structure of MP_JOIN [RFC 6824]:
... | 3.819258 | 3.428034 | 1.114125 |
adid = self._read_unpack(1)
rtkn = self._read_fileng(4)
srno = self._read_unpack(4)
data = dict(
kind=kind,
length=size + 1,
subtype='MP_JOIN-SYN',
join=dict(
syn=dict(
backup=True if int(bits[3... | def _read_join_syn(self, bits, size, kind) | Read Join Connection option for Initial SYN.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Join Connection (MP_JOIN-SYN) option for Initial SYN
Structu... | 7.569702 | 4.15241 | 1.822966 |
adid = self._read_unpack(1)
hmac = self._read_fileng(8)
srno = self._read_unpack(4)
data = dict(
kind=kind,
length=size + 1,
subtype='MP_JOIN-SYN/ACK',
join=dict(
synack=dict(
backup=True if int... | def _read_join_synack(self, bits, size, kind) | Read Join Connection option for Responding SYN/ACK.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Join Connection (MP_JOIN-SYN/ACK) option for Responding SYN/AC... | 7.392351 | 3.85339 | 1.918402 |
temp = self._read_fileng(20)
data = dict(
kind=kind,
length=size + 1,
subtype='MP_JOIN-ACK',
join=dict(
ack=dict(
hmac=temp,
),
),
)
return data | def _read_join_ack(self, bits, size, kind) | Read Join Connection option for Third ACK.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Join Connection (MP_JOIN-ACK) option for Third ACK
Structure o... | 9.750667 | 5.353796 | 1.821262 |
vers = int(bits, base=2)
adid = self._read_unpack(1)
ipad = self._read_fileng(4) if vers == 4 else self._read_fileng(16)
ip_l = 4 if vers == 4 else 16
pt_l = size - 1 - ip_l
port = self._read_unpack(2) if pt_l else None
data = dict(
kind=kind... | def _read_mptcp_add(self, bits, size, kind) | Read Add Address option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
* kind - int, 30 (Multipath TCP)
Returns:
* dict -- extracted Add Address (ADD_ADDR) option
Structure of ADD_ADDR [RFC 6824]:
... | 5.202873 | 3.489494 | 1.491011 |
adid = []
for _ in size:
adid.append(self._read_unpack(1))
data = dict(
subtype='REMOVE_ADDR',
removeaddr=dict(
addrid=adid or None,
),
)
return data | def _read_mptcp_remove(self, bits, size) | Read Remove Address option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
Returns:
* dict -- extracted Remove Address (REMOVE_ADDR) option
Structure of REMOVE_ADDR [RFC 6824]:
1 ... | 9.528572 | 6.707854 | 1.42051 |
temp = self._read_unpack(1) if size else None
data = dict(
subtype='MP_PRIO',
prio=dict(
res=b'\x00' * 3,
backup=True if int(bits[3]) else False,
addrid=temp,
),
)
return data | def _read_mptcp_prio(self, bits, size) | Read Change Subflow Priority option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
Returns:
* dict -- extracted Change Subflow Priority (MP_PRIO) option
Structure of MP_PRIO [RFC 6824]:
1 ... | 10.681952 | 8.06461 | 1.324546 |
____ = self._read_fileng(1)
dsn_ = self._read_unpack(8)
data = dict(
subtype='MP_FAIL',
fail=dict(
dsn=dsn_,
),
)
return data | def _read_mptcp_fail(self, bits, size) | Read Fallback option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
Returns:
* dict -- extracted Fallback (MP_FAIL) option
Structure of MP_FAIL [RFC 6824]:
1 2 ... | 12.952744 | 9.346292 | 1.38587 |
____ = self._read_fileng(1)
rkey = self._read_fileng(8)
data = dict(
subtype='MP_FASTCLOSE',
fastclose=dict(
rkey=rkey,
),
)
return data | def _read_mptcp_fastclose(self, bits, size) | Read Fast Close option.
Positional arguments:
* bits - str, 4-bit data
* size - int, length of option
Returns:
* dict -- extracted Fast Close (MP_FASTCLOSE) option
Structure of MP_FASTCLOSE [RFC 6824]:
1 2 ... | 9.071062 | 6.326001 | 1.433933 |
if isinstance(key, int):
return ESP_TransformSuite(key)
if key not in ESP_TransformSuite._member_map_:
extend_enum(ESP_TransformSuite, key, default)
return ESP_TransformSuite[key] | def get(key, default=-1) | Backport support for original codes. | 6.838775 | 6.260192 | 1.092422 |
if isinstance(key, int):
return ClassificationLevel(key)
if key not in ClassificationLevel._member_map_:
extend_enum(ClassificationLevel, key, default)
return ClassificationLevel[key] | def get(key, default=-1) | Backport support for original codes. | 4.65897 | 4.154204 | 1.121507 |
layer = layer.__layer__
if isinstance(protocol, type) and issubclass(protocol, Protocol):
protocol = protocol.__index__()
str_check(fin or '', fout or '', format or '',
trace_fout or '', trace_format or '',
engine or '', layer or '', *(protocol or ''))
bool_check... | def extract(fin=None, fout=None, format=None, # basic settings
auto=True, extension=True, store=True, # internal settings
files=False, nofile=False, verbose=False, # output settings
engine=None, layer=None, protocol=Non... | Extract a PCAP file.
Keyword arguments:
* fin -- str, file name to be read; if file not exist, raise an error
* fout -- str, file name to be written
* format -- str, file format of output
<keyword> 'plist' / 'json' / 'tree' / 'html'
* auto -- bool, if auto... | 2.329496 | 2.653699 | 0.87783 |
if isinstance(file, bytes):
file = io.BytesIO(file)
io_check(file)
int_check(length or sys.maxsize)
return analyse2(file, length) | def analyse(file, length=None) | Analyse application layer packets.
Keyword arguments:
* file -- bytes or file-like object, packet to be analysed
* length -- int, length of the analysing packet
Returns:
* Analysis -- an Analysis object from `pcapkit.analyser` | 5.860556 | 7.191654 | 0.814911 |
if isinstance(protocol, type) and issubclass(protocol, Protocol):
protocol = protocol.__index__()
str_check(protocol)
bool_check(strict)
if protocol == 'IPv4':
return IPv4_Reassembly(strict=strict)
elif protocol == 'IPv6':
return IPv6_Reassembly(strict=strict)
elif... | def reassemble(protocol, strict=False) | Reassemble fragmented datagrams.
Keyword arguments:
* protocol -- str, protocol to be reassembled
* strict -- bool, if return all datagrams (including those not implemented) when submit (default is False)
<keyword> True / False
Returns:
* [if protocol is IPv4] I... | 3.009725 | 2.914644 | 1.032622 |
str_check(fout or '', format or '')
return TraceFlow(fout=fout, format=format, byteorder=byteorder, nanosecond=nanosecond) | def trace(fout=None, format=None, byteorder=sys.byteorder, nanosecond=False) | Trace TCP flows.
Keyword arguments:
* fout -- str, output path
* format -- str, output format
* byteorder -- str, output file byte order
* nanosecond -- bool, output nanosecond-resolution file flag | 6.017859 | 6.400039 | 0.940285 |
if isinstance(key, int):
return TransType(key)
if key not in TransType._member_map_:
extend_enum(TransType, key, default)
return TransType[key] | def get(key, default=-1) | Backport support for original codes. | 5.371754 | 4.687888 | 1.145879 |
if length is None:
length = len(self)
_next = self._read_protos(1)
_temp = self._read_fileng(1)
_offm = self._read_binary(2)
_ipid = self._read_unpack(4)
ipv6_frag = dict(
next=_next,
length=8,
offset=int(_offm[:1... | def read_ipv6_frag(self, length, extension) | Read Fragment Header for IPv6.
Structure of IPv6-Frag header [RFC 8200]:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Header | Reserved | Fragment Offset |Res|M|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
... | 5.251358 | 4.785701 | 1.097302 |
if isinstance(key, int):
return HI_Algorithm(key)
if key not in HI_Algorithm._member_map_:
extend_enum(HI_Algorithm, key, default)
return HI_Algorithm[key] | def get(key, default=-1) | Backport support for original codes. | 5.864199 | 5.282129 | 1.110196 |
if isinstance(key, int):
return Parameter(key)
if key not in Parameter._member_map_:
extend_enum(Parameter, key, default)
return Parameter[key] | def get(key, default=-1) | Backport support for original codes. | 6.334703 | 5.840917 | 1.084539 |
bin_ = bin(kind)[2:].zfill(8)
type_ = {
'copy': bool(int(bin_[0], base=2)),
'class': opt_class.get(int(bin_[1:3], base=2)),
'number': int(bin_[3:], base=2),
}
return type_ | def _read_opt_type(self, kind) | Read option type field.
Positional arguments:
* kind -- int, option kind value
Returns:
* dict -- extracted IPv4 option
Structure of option type field [RFC 791]:
Octets Bits Name Descriptions
0 0 i... | 4.670385 | 3.261973 | 1.431767 |
counter = 0 # length of read option list
optkind = list() # option kind list
options = dict() # dict of option data
while counter < size:
# get option kind
kind = self._read_unpack(1)
# fetch corresponding option tuple
... | def _read_ipv4_options(self, size=None) | Read IPv4 option list.
Positional arguments:
* size -- int, buffer size
Returns:
* tuple -- IPv4 option list
* dict -- extracted IPv4 option | 4.976868 | 4.85779 | 1.024513 |
if size < 3:
raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format')
data = dict(
kind=kind,
type=self._read_opt_type(kind),
length=size,
data=self._read_fileng(size),
)
return data | def _read_mode_donone(self, size, kind) | Read options request no process.
Positional arguments:
* size - int, length of option
* kind - int, option kind value
Returns:
* dict -- extracted option
Structure of IPv4 options:
Octets Bits Name Description
... | 8.148832 | 6.44046 | 1.265256 |
if size < 3:
raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format')
data = dict(
kind=kind,
type=self._read_opt_type(kind),
length=size,
data=self._read_unpack(size),
)
return data | def _read_mode_unpack(self, size, kind) | Read options request unpack process.
Positional arguments:
* size - int, length of option
* kind - int, option kind value
Returns:
* dict -- extracted option
Structure of IPv4 options:
Octets Bits Name Description
... | 7.446871 | 6.077784 | 1.225261 |
if size < 3 or (size - 3) % 4 != 0:
raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format')
_rptr = self._read_unpack(1)
if _rptr < 4:
raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format')
data = dict(
kind=kind,
... | def _read_mode_route(self, size, kind) | Read options with route data.
Positional arguments:
* size - int, length of option
* kind - int, 7/131/137 (RR/LSR/SSR)
Returns:
* dict -- extracted option with route data
Structure of these options:
* [RFC 791] Loose Source Route
... | 4.989148 | 4.717987 | 1.057474 |
if size != 8:
raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format')
_type = self._read_opt_type(kind)
_fcrr = self._read_binary(1)
_func = int(_fcrr[:4], base=2)
_rate = int(_fcrr[4:], base=2)
_ttlv = self._read_unpack(1)
_nonr ... | def _read_mode_qs(self, size, kind) | Read Quick Start option.
Positional arguments:
* size - int, length of option
* kind - int, 25 (QS)
Returns:
* dict -- extracted Quick Start (QS) option
Structure of Quick-Start (QS) option [RFC 4782]:
* A Quick-Start Request.
0... | 5.037504 | 3.863711 | 1.303799 |
if size > 40 or size < 4:
raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format')
_tptr = self._read_unpack(1)
_oflg = self._read_binary(1)
_oflw = int(_oflg[:4], base=2)
_flag = int(_oflg[4:], base=2)
if _tptr < 5:
raise Pro... | def _read_mode_ts(self, size, kind) | Read Time Stamp option.
Positional arguments:
* size - int, length of option
* kind - int, 68 (TS)
Returns:
* dict -- extracted Time Stamp (TS) option
Structure of Timestamp (TS) option [RFC 791]:
+--------+--------+--------+--------+
... | 2.900059 | 2.592212 | 1.118758 |
if size != 12:
raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format')
_idnm = self._read_unpack(2)
_ohcn = self._read_unpack(2)
_rhcn = self._read_unpack(2)
_ipad = self._read_ipv4_addr()
data = dict(
kind=kind,
... | def _read_mode_tr(self, size, kind) | Read Traceroute option.
Positional arguments:
size - int, length of option
kind - int, 82 (TR)
Returns:
* dict -- extracted Traceroute (TR) option
Structure of Traceroute (TR) option [RFC 1393][RFC 6814]:
0 8 16 ... | 5.395495 | 3.575799 | 1.508892 |
if size < 3:
raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format')
_clvl = self._read_unpack(1)
data = dict(
kind=kind,
type=self._read_opt_type(kind),
length=size,
level=_CLASSIFICATION_LEVEL.get(_clvl, _clvl),... | def _read_mode_sec(self, size, kind) | Read options with security info.
Positional arguments:
size - int, length of option
kind - int, 130 (SEC )/ 133 (ESEC)
Returns:
* dict -- extracted option with security info (E/SEC)
Structure of these options:
* [RFC 1108] Security (SEC)
... | 4.618284 | 4.186683 | 1.103089 |
if size != 4:
raise ProtocolError(f'{self.alias}: [Optno {kind}] invalid format')
_code = self._read_unpack(2)
data = dict(
kind=kind,
type=self._read_opt_type(kind),
length=size,
alert=_ROUTER_ALERT.get(_code, 'Reserved'),
... | def _read_mode_rsralt(self, size, kind) | Read Router Alert option.
Positional arguments:
size - int, length of option
kind - int, 148 (RTRALT)
Returns:
* dict -- extracted Router Alert (RTRALT) option
Structure of Router Alert (RTRALT) option [RFC 2113]:
+--------+--------+--------+---... | 9.271261 | 6.222826 | 1.489879 |
_magn = self._read_fileng(4)
if _magn == b'\xd4\xc3\xb2\xa1':
lilendian = True
self._nsec = False
self._byte = 'little'
elif _magn == b'\xa1\xb2\xc3\xd4':
lilendian = False
self._nsec = False
self._byte = 'big'
... | def read_header(self) | Read global header of PCAP file.
Structure of global header (C):
typedef struct pcap_hdr_s {
guint32 magic_number; /* magic number */
guint16 version_major; /* major version number */
guint16 version_minor; /* minor version number */
... | 2.898687 | 2.534845 | 1.143536 |
_byte = self._read_unpack(4, lilendian=True)
_prot = LINKTYPE.get(_byte)
return _prot | def _read_protos(self, size) | Read next layer protocol type.
Positional arguments:
* size -- int, buffer size
Returns:
* str -- link layer protocol name | 18.71612 | 15.696155 | 1.192402 |
# _scur = self._file.tell()
_temp = self._read_unpack(4, lilendian=True, quiet=True)
if _temp is None:
raise EOFError
_tsss = _temp
_tsus = self._read_unpack(4, lilendian=True)
_ilen = self._read_unpack(4, lilendian=True)
_olen = self._read_u... | def read_frame(self) | Read each block after global header.
Structure of record/package header (C):
typedef struct pcaprec_hdr_s {
guint32 ts_sec; /* timestamp seconds */
guint32 ts_usec; /* timestamp microseconds */
guint32 incl_len; /* number of octets of packet ... | 4.758013 | 3.98676 | 1.193454 |
seek_cur = self._file.tell()
try:
next_ = self._import_next_layer(self._prot, length)
except Exception:
dict_['error'] = traceback.format_exc(limit=1).strip().split(os.linesep)[-1]
self._file.seek(seek_cur, os.SEEK_SET)
next_ = beholder(se... | def _decode_next_layer(self, dict_, 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 packet extracted | 6.17547 | 5.998305 | 1.029536 |
if proto == 1:
from pcapkit.protocols.link import Ethernet as Protocol
elif proto == 228:
from pcapkit.protocols.internet import IPv4 as Protocol
elif proto == 229:
from pcapkit.protocols.internet import IPv6 as Protocol
else:
from... | def _import_next_layer(self, proto, length, error=False) | Import next layer extractor.
Positional arguments:
* proto -- str, next layer protocol name
* length -- int, valid (not padding) length
Keyword arguments:
* error -- bool, if function call on error
Returns:
* bool -- flag if extraction of next l... | 3.989238 | 4.216916 | 0.946008 |
if isinstance(key, int):
return RegistrationFailure(key)
if key not in RegistrationFailure._member_map_:
extend_enum(RegistrationFailure, key, default)
return RegistrationFailure[key] | def get(key, default=-1) | Backport support for original codes. | 6.054811 | 5.269236 | 1.149087 |
if isinstance(key, int):
return TOS_PRE(key)
if key not in TOS_PRE._member_map_:
extend_enum(TOS_PRE, key, default)
return TOS_PRE[key] | def get(key, default=-1) | Backport support for original codes. | 6.498904 | 6.03659 | 1.076585 |
if length is None:
length = len(self)
raw = dict(
packet=self._read_fileng(length),
error=error or None,
)
return raw | def read_raw(self, length, *, error=None) | Read raw packet data. | 7.912155 | 6.705297 | 1.179986 |
if isinstance(key, int):
return NotifyMessage(key)
if key not in NotifyMessage._member_map_:
extend_enum(NotifyMessage, key, default)
return NotifyMessage[key] | def get(key, default=-1) | Backport support for original codes. | 5.86947 | 5.442376 | 1.078476 |
if not (isinstance(value, int) and 0 <= value <= 65535):
raise ValueError('%r is not a valid %s' % (value, cls.__name__))
if 2 <= value <= 6:
extend_enum(cls, 'Unassigned [%d]' % value, value)
return cls(value)
if 8 <= value <= 13:
extend_... | def _missing_(cls, value) | Lookup function used when value is not found. | 1.615774 | 1.629554 | 0.991544 |
hdr_len = ipv6.__hdr_len__
for code in (0, 60, 43):
ext_hdr = ipv6.extension_hdrs.get(code)
if ext_hdr is not None:
hdr_len += ext_hdr.length
return hdr_len | def ipv6_hdr_len(ipv6) | Calculate length of headers before IPv6-Frag | 4.197482 | 4.312931 | 0.973232 |
chain = [type(packet).__name__]
payload = packet.data
while not isinstance(payload, bytes):
chain.append(type(payload).__name__)
payload = payload.data
return ':'.join(chain) | def packet2chain(packet) | Fetch DPKT packet protocol chain. | 3.221842 | 2.926384 | 1.100963 |
def wrapper(packet):
dict_ = dict()
for field in packet.__hdr_fields__:
dict_[field] = getattr(packet, field, None)
payload = packet.data
if not isinstance(payload, bytes):
dict_[type(payload).__name__] = wrapper(payload)
return dict_
return {... | def packet2dict(packet, timestamp, *, data_link) | Convert DPKT packet into dict. | 4.593914 | 4.258426 | 1.078782 |
ipv4 = getattr(packet, 'ip', None)
if ipv4 is not None:
if ipv4.df: # dismiss not fragmented packet
return False, None
data = dict(
bufid=(
ipaddress.ip_address(ipv4.src), # source IP address
ipaddress.ip_address(ip... | def ipv4_reassembly(packet, *, count=NotImplemented) | Make data for IPv4 reassembly. | 4.963302 | 4.793608 | 1.0354 |
ipv6 = getattr(packet, 'ip6', None)
if ipv6 is not None:
ipv6_frag = ipv6.extension_hdrs.get(44)
if ipv6_frag is None: # dismiss not fragmented packet
return False, None
hdr_len = ipv6_hdr_len(ipv6)
data = dict(
bufid=(
ipaddress... | def ipv6_reassembly(packet, *, count=NotImplemented) | Make data for IPv6 reassembly. | 5.347534 | 5.222095 | 1.024021 |
if getattr(packet, 'ip', None):
ip = packet['ip']
elif getattr(packet, 'ip6', None):
ip = packet['ip6']
else:
return False, None
tcp = getattr(ip, 'tcp', None)
if tcp is not None:
flags = bin(tcp.flags)[2:].zfill(8)
data = dict(
bufid=(
... | def tcp_reassembly(packet, *, count=NotImplemented) | Make data for TCP reassembly. | 3.656744 | 3.575151 | 1.022822 |
if getattr(packet, 'ip', None):
ip = packet['ip']
elif getattr(packet, 'ip6', None):
ip = packet['ip6']
else:
return False, None
tcp = getattr(ip, 'tcp', None)
if tcp is not None:
flags = bin(tcp.flags)[2:].zfill(8)
data = dict(
protocol=data_... | def tcp_traceflow(packet, timestamp, *, data_link, count=NotImplemented) | Trace packet flow for TCP. | 3.035797 | 3.008343 | 1.009126 |
if length is None:
length = len(self)
if length < 9:
raise ProtocolError(f'HTTP/2: invalid format', quiet=True)
_tlen = self._read_unpack(3)
_type = self._read_unpack(1)
_flag = self._read_binary(1)
_rsid = self._read_binary(4)
... | def read_http(self, length) | Read Hypertext Transfer Protocol (HTTP/2).
Structure of HTTP/2 packet [RFC 7540]:
+-----------------------------------------------+
| Length (24) |
+---------------+---------------+---------------+
| Type (8) | Flags (8) ... | 3.031287 | 2.972972 | 1.019615 |
if any((int(bit, base=2) for bit in flag)):
raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True)
data = dict(
flags=None,
payload=self._read_fileng(size - 9) or None,
)
return data | def _read_http_none(self, size, kind, flag) | Read HTTP packet with unsigned type. | 11.013122 | 10.458527 | 1.053028 |
_plen = 0
_flag = dict(
END_STREAM=False, # bit 0
PADDED=False, # bit 3
)
for index, bit in enumerate(flag):
if index == 0 and bit:
_flag['END_STREAM'] = True
elif index == 3 and bit:
_flag['... | def _read_http_data(self, size, kind, flag) | Read HTTP/2 DATA frames.
Structure of HTTP/2 DATA frame [RFC 7540]:
+-----------------------------------------------+
| Length (24) |
+---------------+---------------+---------------+
| Type (8) | Flags (8) |
... | 2.989314 | 2.948784 | 1.013745 |
_plen = 0
_elen = 0
_flag = dict(
END_STREAM=False, # bit 0
END_HEADERS=False, # bit 2
PADDED=False, # bit 3
PRIORITY=False, # bit 5
)
for index, bit in enumerate(flag):
if index == ... | def _read_http_headers(self, size, kind, flag) | Read HTTP/2 HEADERS frames.
Structure of HTTP/2 HEADERS frame [RFC 7540]:
+-----------------------------------------------+
| Length (24) |
+---------------+---------------+---------------+
| Type (8) | Flags (8) |
... | 2.915247 | 2.747008 | 1.061244 |
if size != 9:
raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True)
if any((int(bit, base=2) for bit in flag)):
raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True)
_edep = self._read_binary(4)
_wght = self._read_un... | def _read_http_priority(self, size, kind, flag) | Read HTTP/2 PRIORITY frames.
Structure of HTTP/2 PRIORITY frame [RFC 7540]:
+-----------------------------------------------+
| Length (24) |
+---------------+---------------+---------------+
| Type (8) | Flags (8) |
... | 5.049827 | 4.798385 | 1.052401 |
if size != 8:
raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True)
if any((int(bit, base=2) for bit in flag)):
raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True)
_code = self._read_unpack(4)
data = dict(
... | def _read_http_rst_stream(self, size, kind, flag) | Read HTTP/2 RST_STREAM frames.
Structure of HTTP/2 RST_STREAM frame [RFC 7540]:
+-----------------------------------------------+
| Length (24) |
+---------------+---------------+---------------+
| Type (8) | Flags (8) |... | 6.25097 | 5.823199 | 1.07346 |
if size % 5 != 0:
raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True)
_flag = dict(
ACK=False, # bit 0
)
for index, bit in enumerate(flag):
if index == 0 and bit:
_flag['ACK'] = True
elif ... | def _read_http_settings(self, size, kind, flag) | Read HTTP/2 SETTINGS frames.
Structure of HTTP/2 SETTINGS frame [RFC 7540]:
+-----------------------------------------------+
| Length (24) |
+---------------+---------------+---------------+
| Type (8) | Flags (8) |
... | 3.248635 | 3.362789 | 0.966054 |
if size < 4:
raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True)
_plen = 0
_flag = dict(
END_HEADERS=False, # bit 2
PADDED=False, # bit 3
)
for index, bit in enumerate(flag):
if index ==... | def _read_http_push_promise(self, size, kind, flag) | Read HTTP/2 PUSH_PROMISE frames.
Structure of HTTP/2 PUSH_PROMISE frame [RFC 7540]:
+-----------------------------------------------+
| Length (24) |
+---------------+---------------+---------------+
| Type (8) | Flags (8)... | 2.84857 | 2.818524 | 1.01066 |
if size != 8:
raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True)
_flag = dict(
ACK=False, # bit 0
)
for index, bit in enumerate(flag):
if index == 0 and bit:
_flag['ACK'] = True
elif bit:... | def _read_http_ping(self, size, kind, flag) | Read HTTP/2 PING frames.
Structure of HTTP/2 PING frame [RFC 7540]:
+-----------------------------------------------+
| Length (24) |
+---------------+---------------+---------------+
| Type (8) | Flags (8) |
... | 4.415834 | 4.412245 | 1.000814 |
_dlen = size - 8
if _dlen < 0:
raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True)
if any((int(bit, base=2) for bit in flag)):
raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True)
_rsid = self._read_binary(4)
... | def _read_http_goaway(self, size, kind, flag) | Read HTTP/2 GOAWAY frames.
Structure of HTTP/2 GOAWAY frame [RFC 7540]:
+-----------------------------------------------+
| Length (24) |
+---------------+---------------+---------------+
| Type (8) | Flags (8) |
... | 4.145393 | 3.964737 | 1.045566 |
if size != 4:
raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True)
if any((int(bit, base=2) for bit in flag)):
raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True)
_size = self._read_binary(4)
if int(_size[0], bas... | def _read_http_window_update(self, size, kind, flag) | Read HTTP/2 WINDOW_UPDATE frames.
Structure of HTTP/2 WINDOW_UPDATE frame [RFC 7540]:
+-----------------------------------------------+
| Length (24) |
+---------------+---------------+---------------+
| Type (8) | Flags (... | 3.938935 | 4.139278 | 0.9516 |
_flag = dict(
END_HEADERS=False, # bit 2
)
for index, bit in enumerate(flag):
if index == 2 and bit:
_flag['END_HEADERS'] = True
elif bit:
raise ProtocolError(f'HTTP/2: [Type {kind}] invalid format', quiet=True)
... | def _read_http_continuation(self, size, kind, flag) | Read HTTP/2 WINDOW_UPDATE frames.
Structure of HTTP/2 WINDOW_UPDATE frame [RFC 7540]:
+-----------------------------------------------+
| Length (24) |
+---------------+---------------+---------------+
| Type (8) | Flags (... | 7.497866 | 7.467378 | 1.004083 |
if isinstance(key, int):
return OptionNumber(key)
if key not in OptionNumber._member_map_:
extend_enum(OptionNumber, key, default)
return OptionNumber[key] | def get(key, default=-1) | Backport support for original codes. | 6.175589 | 5.442229 | 1.134753 |
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:
... | 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 --... | 6.633732 | 7.211515 | 0.919881 |
if isinstance(key, int):
return ProtectionAuthority(key)
if key not in ProtectionAuthority._member_map_:
extend_enum(ProtectionAuthority, key, default)
return ProtectionAuthority[key] | def get(key, default=-1) | Backport support for original codes. | 6.993734 | 6.199914 | 1.128037 |
if isinstance(key, int):
return RouterAlert(key)
if key not in RouterAlert._member_map_:
extend_enum(RouterAlert, key, default)
return RouterAlert[key] | def get(key, default=-1) | Backport support for original codes. | 6.849123 | 5.986969 | 1.144005 |
if isinstance(key, int):
return QS_Function(key)
if key not in QS_Function._member_map_:
extend_enum(QS_Function, key, default)
return QS_Function[key] | def get(key, default=-1) | Backport support for original codes. | 5.726119 | 5.413719 | 1.057705 |
flag = True
if self._exeng == 'dpkt':
flag, engine = self.import_test('dpkt', name='DPKT')
if flag:
return self._run_dpkt(engine)
elif self._exeng == 'scapy':
flag, engine = self.import_test('scapy.all', name='Scapy')
if fl... | def run(self) | Start extraction. | 2.972876 | 2.923377 | 1.016932 |
self._gbhdr = Header(self._ifile)
self._vinfo = self._gbhdr.version
self._dlink = self._gbhdr.protocol
self._nnsec = self._gbhdr.nanosecond
if self._trace is not NotImplemented:
self._trace._endian = self._gbhdr.byteorder
self._trace._nnsecd = se... | def record_header(self) | Read global header.
- Extract global header.
- Make Info object out of header properties.
- Append Info.
- Write plist file. | 6.289486 | 6.008272 | 1.046804 |
self._expkg = None
self._extmp = None
self._flag_e = True
self._ifile.close() | def _cleanup(self) | Cleanup after extraction & analysis. | 21.759422 | 17.185051 | 1.266183 |
if not self._flag_e and self._flag_m:
# join processes
[proc.join() for proc in self._mpprc]
if self._exeng == 'server':
self._mpsvc.join()
# restore attributes
if self._exeng == 'server':
self._frame = list(se... | def _aftermathmp(self) | Aftermath for multiprocessing. | 5.427045 | 5.142561 | 1.055319 |
self._aftermathmp()
self._ifile.close()
self._flag_e = True | def _update_eof(self) | Update EOF flag. | 52.073692 | 37.5261 | 1.387666 |
if self._exeng == 'scapy':
return self._scapy_read_frame()
elif self._exeng == 'dpkt':
return self._dpkt_read_frame()
elif self._exeng == 'pyshark':
return self._pyshark_read_frame()
else:
return self._default_read_frame() | def _read_frame(self) | Headquarters for frame reader. | 2.873419 | 2.626183 | 1.094143 |
from pcapkit.toolkit.default import (ipv4_reassembly, ipv6_reassembly,
tcp_reassembly, tcp_traceflow)
# read frame header
if not self._flag_m:
frame = Frame(self._ifile, num=self._frnum+1, proto=self._dlink,
... | def _default_read_frame(self, *, frame=None, mpkit=None) | Read frames with default engine.
- Extract frames and each layer of packets.
- Make Info object out of frame properties.
- Append Info.
- Write plist & append Info. | 3.764595 | 3.768539 | 0.998954 |
# if not self._flag_a:
# self._flag_a = True
# warnings.warn(f"'Extractor(engine=scapy)' object is not iterable; "
# "so 'auto=False' will be ignored", AttributeWarning, stacklevel=stacklevel())
if self._exlyr != 'None' or self._exptl != 'nul... | def _run_scapy(self, scapy_all) | Call scapy.all.sniff to extract PCAP files. | 9.224078 | 8.885402 | 1.038116 |
from pcapkit.toolkit.scapy import (ipv4_reassembly, ipv6_reassembly,
packet2chain, packet2dict, tcp_reassembly,
tcp_traceflow)
# fetch Scapy packet
packet = next(self._extmp)
# verbose output... | def _scapy_read_frame(self) | Read frames with Scapy. | 3.112827 | 3.061014 | 1.016927 |
# if not self._flag_a:
# self._flag_a = True
# warnings.warn(f"'Extractor(engine=dpkt)' object is not iterable; "
# "so 'auto=False' will be ignored", AttributeWarning, stacklevel=stacklevel())
if self._exlyr != 'None' or self._exptl != 'null... | def _run_dpkt(self, dpkt) | Call dpkt.pcap.Reader to extract PCAP files. | 8.363746 | 7.834589 | 1.067541 |
from pcapkit.toolkit.dpkt import (ipv4_reassembly, ipv6_reassembly,
packet2chain, packet2dict, tcp_reassembly,
tcp_traceflow)
# fetch DPKT packet
timestamp, packet = next(self._extmp)
# extract... | def _dpkt_read_frame(self) | Read frames. | 3.339005 | 3.306936 | 1.009697 |
# if not self._flag_a:
# self._flag_a = True
# warnings.warn(f"'Extractor(engine=pyshark)' object is not iterable; "
# "so 'auto=False' will be ignored", AttributeWarning, stacklevel=stacklevel())
if self._exlyr != 'None' or self._exptl != 'n... | def _run_pyshark(self, pyshark) | Call pyshark.FileCapture to extract PCAP files. | 5.656137 | 5.50624 | 1.027223 |
from pcapkit.toolkit.pyshark import packet2dict, tcp_traceflow
# fetch PyShark packet
packet = next(self._extmp)
# def _pyshark_packet2chain(packet):
#
# return ':'.join(map(lambda layer: layer.layer_name.upper(), packet.layers))
# verbose out... | def _pyshark_read_frame(self) | Read frames. | 5.507267 | 5.430785 | 1.014083 |
if not self._flag_m:
raise UnsupportedCall(f"Extractor(engine={self._exeng})' has no attribute '_run_pipline'")
if not self._flag_q:
self._flag_q = True
warnings.warn("'Extractor(engine=pipeline)' does not support output; "
f"'fout=... | def _run_pipeline(self, multiprocessing) | Use pipeline multiprocessing to extract PCAP files. | 5.348894 | 5.18903 | 1.030808 |
# check EOF
if self._flag_e:
raise EOFError
def _analyse_frame(*, frame, mpkit):
# wait until ready
while mpkit.current != self._frnum:
time.sleep(random.randint(0, datetime.datetime.now().second) // 600)
# a... | def _pipeline_read_frame(self, *, mpfdp, mpkit) | Extract frame. | 5.354683 | 5.215911 | 1.026606 |
if not self._flag_m:
raise UnsupportedCall(f"Extractor(engine={self._exeng})' has no attribute '_run_server'")
if not self._flag_q:
self._flag_q = True
warnings.warn("'Extractor(engine=pipeline)' does not support output; "
f"'fout={... | def _run_server(self, multiprocessing) | Use server multiprocessing to extract PCAP files. | 4.696997 | 4.557739 | 1.030554 |
# check EOF
if self._flag_e:
raise EOFError
# extract frame
try:
frame = Frame(self._ifile, num=self._frnum, proto=self._dlink, layer=self._exlyr,
protocol=self._exptl, nanosecond=self._nnsec, mpkit=mpkit, mpfdp=mpfdp)
... | def _server_extract_frame(self, *, mpfdp, mpkit, mpbuf) | Extract frame. | 7.591558 | 7.337444 | 1.034633 |
while True:
# fetch frame
# print(self._frnum, 'trying')
frame = mpbuf.pop(self._frnum, None)
if frame is EOFError:
break
if frame is None:
continue
# print(self._frnum, 'get')
self._def... | def _server_analyse_frame(self, *, mpkit, mpfrm, mprsm, mpbuf) | Analyse frame. | 7.207861 | 6.945131 | 1.037829 |
if isinstance(key, int):
return Checksum(key)
if key not in Checksum._member_map_:
extend_enum(Checksum, key, default)
return Checksum[key] | def get(key, default=-1) | Backport support for original codes. | 5.865596 | 5.381733 | 1.089908 |
if isinstance(key, int):
return Operation(key)
if key not in Operation._member_map_:
extend_enum(Operation, key, default)
return Operation[key] | def get(key, default=-1) | Backport support for original codes. | 5.437543 | 4.820097 | 1.128098 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.