pypcapkit 1.3.3.post1__cp313-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pcapkit/__init__.py +126 -0
- pcapkit/__main__.py +138 -0
- pcapkit/all.py +136 -0
- pcapkit/const/__init__.py +81 -0
- pcapkit/const/arp/__init__.py +25 -0
- pcapkit/const/arp/hardware.py +181 -0
- pcapkit/const/arp/operation.py +131 -0
- pcapkit/const/ftp/__init__.py +25 -0
- pcapkit/const/ftp/command.py +309 -0
- pcapkit/const/ftp/return_code.py +304 -0
- pcapkit/const/hip/__init__.py +94 -0
- pcapkit/const/hip/certificate.py +77 -0
- pcapkit/const/hip/cipher.py +65 -0
- pcapkit/const/hip/di.py +59 -0
- pcapkit/const/hip/ecdsa_curve.py +59 -0
- pcapkit/const/hip/ecdsa_low_curve.py +56 -0
- pcapkit/const/hip/eddsa_curve.py +65 -0
- pcapkit/const/hip/esp_transform_suite.py +98 -0
- pcapkit/const/hip/group.py +86 -0
- pcapkit/const/hip/hi_algorithm.py +86 -0
- pcapkit/const/hip/hit_suite.py +68 -0
- pcapkit/const/hip/nat_traversal.py +62 -0
- pcapkit/const/hip/notify_message.py +200 -0
- pcapkit/const/hip/packet.py +89 -0
- pcapkit/const/hip/parameter.py +377 -0
- pcapkit/const/hip/registration.py +68 -0
- pcapkit/const/hip/registration_failure.py +84 -0
- pcapkit/const/hip/suite.py +71 -0
- pcapkit/const/hip/transport.py +59 -0
- pcapkit/const/http/__init__.py +39 -0
- pcapkit/const/http/error_code.py +95 -0
- pcapkit/const/http/frame.py +95 -0
- pcapkit/const/http/method.py +184 -0
- pcapkit/const/http/setting.py +96 -0
- pcapkit/const/http/status_code.py +294 -0
- pcapkit/const/ipv4/__init__.py +57 -0
- pcapkit/const/ipv4/classification_level.py +64 -0
- pcapkit/const/ipv4/option_class.py +55 -0
- pcapkit/const/ipv4/option_number.py +137 -0
- pcapkit/const/ipv4/protection_authority.py +63 -0
- pcapkit/const/ipv4/qs_function.py +51 -0
- pcapkit/const/ipv4/router_alert.py +251 -0
- pcapkit/const/ipv4/tos_del.py +51 -0
- pcapkit/const/ipv4/tos_ecn.py +55 -0
- pcapkit/const/ipv4/tos_pre.py +63 -0
- pcapkit/const/ipv4/tos_rel.py +51 -0
- pcapkit/const/ipv4/tos_thr.py +51 -0
- pcapkit/const/ipv4/ts_flag.py +53 -0
- pcapkit/const/ipv6/__init__.py +53 -0
- pcapkit/const/ipv6/extension_header.py +66 -0
- pcapkit/const/ipv6/option.py +137 -0
- pcapkit/const/ipv6/option_action.py +55 -0
- pcapkit/const/ipv6/qs_function.py +51 -0
- pcapkit/const/ipv6/router_alert.py +266 -0
- pcapkit/const/ipv6/routing.py +80 -0
- pcapkit/const/ipv6/seed_id.py +55 -0
- pcapkit/const/ipv6/smf_dpd_mode.py +51 -0
- pcapkit/const/ipv6/tagger_id.py +62 -0
- pcapkit/const/ipx/__init__.py +27 -0
- pcapkit/const/ipx/packet.py +72 -0
- pcapkit/const/ipx/socket.py +104 -0
- pcapkit/const/l2tp/__init__.py +21 -0
- pcapkit/const/l2tp/type.py +51 -0
- pcapkit/const/mh/__init__.py +204 -0
- pcapkit/const/mh/access_type.py +92 -0
- pcapkit/const/mh/ack_status_code.py +71 -0
- pcapkit/const/mh/ani_suboption.py +74 -0
- pcapkit/const/mh/auth_subtype.py +53 -0
- pcapkit/const/mh/binding_ack_flag.py +66 -0
- pcapkit/const/mh/binding_error.py +51 -0
- pcapkit/const/mh/binding_revocation.py +59 -0
- pcapkit/const/mh/binding_update_flag.py +81 -0
- pcapkit/const/mh/cga_extension.py +66 -0
- pcapkit/const/mh/cga_sec.py +57 -0
- pcapkit/const/mh/cga_type.py +68 -0
- pcapkit/const/mh/dhcp_support_mode.py +53 -0
- pcapkit/const/mh/dns_status_code.py +65 -0
- pcapkit/const/mh/dsmip6_tls_packet.py +62 -0
- pcapkit/const/mh/dsmipv6_home_address.py +74 -0
- pcapkit/const/mh/enumerating_algorithm.py +56 -0
- pcapkit/const/mh/fb_ack_status.py +62 -0
- pcapkit/const/mh/fb_action.py +71 -0
- pcapkit/const/mh/fb_indication_trigger.py +65 -0
- pcapkit/const/mh/fb_type.py +59 -0
- pcapkit/const/mh/flow_id_status.py +77 -0
- pcapkit/const/mh/flow_id_suboption.py +71 -0
- pcapkit/const/mh/handoff_type.py +71 -0
- pcapkit/const/mh/handover_ack_flag.py +54 -0
- pcapkit/const/mh/handover_ack_status.py +92 -0
- pcapkit/const/mh/handover_initiate_flag.py +57 -0
- pcapkit/const/mh/handover_initiate_status.py +62 -0
- pcapkit/const/mh/home_address_reply.py +71 -0
- pcapkit/const/mh/lla_code.py +63 -0
- pcapkit/const/mh/lma_mag_suboption.py +59 -0
- pcapkit/const/mh/mn_group_id.py +59 -0
- pcapkit/const/mh/mn_id_subtype.py +77 -0
- pcapkit/const/mh/operator_id.py +63 -0
- pcapkit/const/mh/option.py +260 -0
- pcapkit/const/mh/packet.py +119 -0
- pcapkit/const/mh/qos_attribute.py +89 -0
- pcapkit/const/mh/revocation_status_code.py +83 -0
- pcapkit/const/mh/revocation_trigger.py +86 -0
- pcapkit/const/mh/status_code.py +232 -0
- pcapkit/const/mh/traffic_selector.py +62 -0
- pcapkit/const/mh/upa_status.py +71 -0
- pcapkit/const/mh/upn_reason.py +80 -0
- pcapkit/const/ospf/__init__.py +27 -0
- pcapkit/const/ospf/authentication.py +65 -0
- pcapkit/const/ospf/packet.py +71 -0
- pcapkit/const/pcapng/__init__.py +51 -0
- pcapkit/const/pcapng/block_type.py +152 -0
- pcapkit/const/pcapng/filter_type.py +48 -0
- pcapkit/const/pcapng/hash_algorithm.py +59 -0
- pcapkit/const/pcapng/option_type.py +233 -0
- pcapkit/const/pcapng/record_type.py +57 -0
- pcapkit/const/pcapng/secrets_type.py +56 -0
- pcapkit/const/pcapng/verdict_type.py +53 -0
- pcapkit/const/reg/__init__.py +34 -0
- pcapkit/const/reg/apptype.py +32702 -0
- pcapkit/const/reg/ethertype.py +714 -0
- pcapkit/const/reg/linktype.py +902 -0
- pcapkit/const/reg/transtype.py +523 -0
- pcapkit/const/tcp/__init__.py +35 -0
- pcapkit/const/tcp/checksum.py +55 -0
- pcapkit/const/tcp/flags.py +73 -0
- pcapkit/const/tcp/mp_tcp_option.py +80 -0
- pcapkit/const/tcp/option.py +198 -0
- pcapkit/const/vlan/__init__.py +23 -0
- pcapkit/const/vlan/priority_level.py +71 -0
- pcapkit/corekit/__init__.py +59 -0
- pcapkit/corekit/fields/__init__.py +45 -0
- pcapkit/corekit/fields/collections.py +282 -0
- pcapkit/corekit/fields/field.py +269 -0
- pcapkit/corekit/fields/ipaddress.py +274 -0
- pcapkit/corekit/fields/misc.py +722 -0
- pcapkit/corekit/fields/numbers.py +375 -0
- pcapkit/corekit/fields/strings.py +245 -0
- pcapkit/corekit/infoclass.py +394 -0
- pcapkit/corekit/io.py +506 -0
- pcapkit/corekit/module.py +39 -0
- pcapkit/corekit/multidict.py +626 -0
- pcapkit/corekit/protochain.py +263 -0
- pcapkit/corekit/version.py +33 -0
- pcapkit/dumpkit/__init__.py +15 -0
- pcapkit/dumpkit/common.py +199 -0
- pcapkit/dumpkit/null.py +77 -0
- pcapkit/dumpkit/pcap.py +144 -0
- pcapkit/foundation/__init__.py +45 -0
- pcapkit/foundation/engines/__init__.py +36 -0
- pcapkit/foundation/engines/dpkt.py +230 -0
- pcapkit/foundation/engines/engine.py +194 -0
- pcapkit/foundation/engines/pcap.py +188 -0
- pcapkit/foundation/engines/pcapng.py +310 -0
- pcapkit/foundation/engines/pyshark.py +166 -0
- pcapkit/foundation/engines/scapy.py +161 -0
- pcapkit/foundation/extraction.py +915 -0
- pcapkit/foundation/reassembly/__init__.py +49 -0
- pcapkit/foundation/reassembly/data/__init__.py +48 -0
- pcapkit/foundation/reassembly/data/ip.py +117 -0
- pcapkit/foundation/reassembly/data/tcp.py +145 -0
- pcapkit/foundation/reassembly/ip.py +192 -0
- pcapkit/foundation/reassembly/ipv4.py +50 -0
- pcapkit/foundation/reassembly/ipv6.py +50 -0
- pcapkit/foundation/reassembly/reassembly.py +389 -0
- pcapkit/foundation/reassembly/tcp.py +249 -0
- pcapkit/foundation/registry/__init__.py +41 -0
- pcapkit/foundation/registry/foundation.py +327 -0
- pcapkit/foundation/registry/protocols.py +885 -0
- pcapkit/foundation/traceflow/__init__.py +44 -0
- pcapkit/foundation/traceflow/data/__init__.py +30 -0
- pcapkit/foundation/traceflow/data/tcp.py +105 -0
- pcapkit/foundation/traceflow/tcp.py +159 -0
- pcapkit/foundation/traceflow/traceflow.py +390 -0
- pcapkit/interface/__init__.py +22 -0
- pcapkit/interface/core.py +185 -0
- pcapkit/interface/misc.py +120 -0
- pcapkit/protocols/__init__.py +85 -0
- pcapkit/protocols/application/NotImplemented/bgp.py +0 -0
- pcapkit/protocols/application/NotImplemented/dhcp.py +0 -0
- pcapkit/protocols/application/NotImplemented/dhcpv6.py +0 -0
- pcapkit/protocols/application/NotImplemented/dns.py +0 -0
- pcapkit/protocols/application/NotImplemented/imap.py +0 -0
- pcapkit/protocols/application/NotImplemented/ldap.py +0 -0
- pcapkit/protocols/application/NotImplemented/mqtt.py +0 -0
- pcapkit/protocols/application/NotImplemented/nntp.py +0 -0
- pcapkit/protocols/application/NotImplemented/ntp.py +0 -0
- pcapkit/protocols/application/NotImplemented/onc_rpc.py +0 -0
- pcapkit/protocols/application/NotImplemented/pop.py +0 -0
- pcapkit/protocols/application/NotImplemented/rip.py +0 -0
- pcapkit/protocols/application/NotImplemented/rtp.py +0 -0
- pcapkit/protocols/application/NotImplemented/sip.py +0 -0
- pcapkit/protocols/application/NotImplemented/smtp.py +0 -0
- pcapkit/protocols/application/NotImplemented/snmp.py +0 -0
- pcapkit/protocols/application/NotImplemented/ssh.py +0 -0
- pcapkit/protocols/application/NotImplemented/telnet.py +0 -0
- pcapkit/protocols/application/NotImplemented/tls.py +0 -0
- pcapkit/protocols/application/NotImplemented/xmpp.py +0 -0
- pcapkit/protocols/application/__init__.py +34 -0
- pcapkit/protocols/application/application.py +114 -0
- pcapkit/protocols/application/ftp.py +206 -0
- pcapkit/protocols/application/http.py +176 -0
- pcapkit/protocols/application/httpv1.py +320 -0
- pcapkit/protocols/application/httpv2.py +1255 -0
- pcapkit/protocols/data/__init__.py +192 -0
- pcapkit/protocols/data/application/__init__.py +57 -0
- pcapkit/protocols/data/application/ftp.py +59 -0
- pcapkit/protocols/data/application/httpv1.py +79 -0
- pcapkit/protocols/data/application/httpv2.py +293 -0
- pcapkit/protocols/data/data.py +25 -0
- pcapkit/protocols/data/internet/__init__.py +298 -0
- pcapkit/protocols/data/internet/ah.py +31 -0
- pcapkit/protocols/data/internet/hip.py +804 -0
- pcapkit/protocols/data/internet/hopopt.py +351 -0
- pcapkit/protocols/data/internet/ipv4.py +369 -0
- pcapkit/protocols/data/internet/ipv6.py +67 -0
- pcapkit/protocols/data/internet/ipv6_frag.py +29 -0
- pcapkit/protocols/data/internet/ipv6_opts.py +368 -0
- pcapkit/protocols/data/internet/ipv6_route.py +86 -0
- pcapkit/protocols/data/internet/ipx.py +56 -0
- pcapkit/protocols/data/internet/mh.py +509 -0
- pcapkit/protocols/data/link/__init__.py +33 -0
- pcapkit/protocols/data/link/arp.py +74 -0
- pcapkit/protocols/data/link/ethernet.py +28 -0
- pcapkit/protocols/data/link/l2tp.py +63 -0
- pcapkit/protocols/data/link/ospf.py +58 -0
- pcapkit/protocols/data/link/vlan.py +42 -0
- pcapkit/protocols/data/misc/__init__.py +109 -0
- pcapkit/protocols/data/misc/null.py +18 -0
- pcapkit/protocols/data/misc/pcap/__init__.py +18 -0
- pcapkit/protocols/data/misc/pcap/frame.py +56 -0
- pcapkit/protocols/data/misc/pcap/header.py +53 -0
- pcapkit/protocols/data/misc/pcapng.py +925 -0
- pcapkit/protocols/data/misc/raw.py +25 -0
- pcapkit/protocols/data/protocol.py +32 -0
- pcapkit/protocols/data/transport/__init__.py +71 -0
- pcapkit/protocols/data/transport/tcp.py +555 -0
- pcapkit/protocols/data/transport/udp.py +29 -0
- pcapkit/protocols/internet/NotImplemented/ecn.py +0 -0
- pcapkit/protocols/internet/NotImplemented/esp.py +97 -0
- pcapkit/protocols/internet/NotImplemented/icmp.py +0 -0
- pcapkit/protocols/internet/NotImplemented/icmpv6.py +0 -0
- pcapkit/protocols/internet/NotImplemented/igmp.py +0 -0
- pcapkit/protocols/internet/NotImplemented/shim6.py +0 -0
- pcapkit/protocols/internet/__init__.py +43 -0
- pcapkit/protocols/internet/ah.py +275 -0
- pcapkit/protocols/internet/hip.py +4727 -0
- pcapkit/protocols/internet/hopopt.py +1879 -0
- pcapkit/protocols/internet/internet.py +240 -0
- pcapkit/protocols/internet/ip.py +51 -0
- pcapkit/protocols/internet/ipsec.py +50 -0
- pcapkit/protocols/internet/ipv4.py +1782 -0
- pcapkit/protocols/internet/ipv6.py +361 -0
- pcapkit/protocols/internet/ipv6_frag.py +258 -0
- pcapkit/protocols/internet/ipv6_opts.py +1890 -0
- pcapkit/protocols/internet/ipv6_route.py +710 -0
- pcapkit/protocols/internet/ipx.py +230 -0
- pcapkit/protocols/internet/mh.py +2764 -0
- pcapkit/protocols/link/NotImplemented/dsl.py +0 -0
- pcapkit/protocols/link/NotImplemented/eapol.py +1 -0
- pcapkit/protocols/link/NotImplemented/fddi.py +0 -0
- pcapkit/protocols/link/NotImplemented/isdn.py +0 -0
- pcapkit/protocols/link/NotImplemented/ndp.py +0 -0
- pcapkit/protocols/link/NotImplemented/ppp.py +0 -0
- pcapkit/protocols/link/__init__.py +35 -0
- pcapkit/protocols/link/arp.py +421 -0
- pcapkit/protocols/link/ethernet.py +248 -0
- pcapkit/protocols/link/l2tp.py +267 -0
- pcapkit/protocols/link/link.py +140 -0
- pcapkit/protocols/link/ospf.py +342 -0
- pcapkit/protocols/link/rarp.py +82 -0
- pcapkit/protocols/link/vlan.py +225 -0
- pcapkit/protocols/misc/__init__.py +37 -0
- pcapkit/protocols/misc/null.py +129 -0
- pcapkit/protocols/misc/pcap/__init__.py +17 -0
- pcapkit/protocols/misc/pcap/frame.py +478 -0
- pcapkit/protocols/misc/pcap/header.py +358 -0
- pcapkit/protocols/misc/pcapng.py +5520 -0
- pcapkit/protocols/misc/raw.py +180 -0
- pcapkit/protocols/protocol.py +1216 -0
- pcapkit/protocols/schema/__init__.py +140 -0
- pcapkit/protocols/schema/application/__init__.py +40 -0
- pcapkit/protocols/schema/application/ftp.py +21 -0
- pcapkit/protocols/schema/application/httpv1.py +21 -0
- pcapkit/protocols/schema/application/httpv2.py +384 -0
- pcapkit/protocols/schema/internet/__init__.py +294 -0
- pcapkit/protocols/schema/internet/ah.py +40 -0
- pcapkit/protocols/schema/internet/hip.py +1184 -0
- pcapkit/protocols/schema/internet/hopopt.py +679 -0
- pcapkit/protocols/schema/internet/ipv4.py +576 -0
- pcapkit/protocols/schema/internet/ipv6.py +63 -0
- pcapkit/protocols/schema/internet/ipv6_frag.py +48 -0
- pcapkit/protocols/schema/internet/ipv6_opts.py +680 -0
- pcapkit/protocols/schema/internet/ipv6_route.py +198 -0
- pcapkit/protocols/schema/internet/ipx.py +40 -0
- pcapkit/protocols/schema/internet/mh.py +718 -0
- pcapkit/protocols/schema/link/__init__.py +19 -0
- pcapkit/protocols/schema/link/arp.py +39 -0
- pcapkit/protocols/schema/link/ethernet.py +51 -0
- pcapkit/protocols/schema/link/l2tp.py +88 -0
- pcapkit/protocols/schema/link/ospf.py +90 -0
- pcapkit/protocols/schema/link/vlan.py +69 -0
- pcapkit/protocols/schema/misc/__init__.py +108 -0
- pcapkit/protocols/schema/misc/null.py +18 -0
- pcapkit/protocols/schema/misc/pcap/__init__.py +10 -0
- pcapkit/protocols/schema/misc/pcap/frame.py +51 -0
- pcapkit/protocols/schema/misc/pcap/header.py +63 -0
- pcapkit/protocols/schema/misc/pcapng.py +1689 -0
- pcapkit/protocols/schema/misc/raw.py +24 -0
- pcapkit/protocols/schema/schema.py +809 -0
- pcapkit/protocols/schema/transport/__init__.py +69 -0
- pcapkit/protocols/schema/transport/tcp.py +928 -0
- pcapkit/protocols/schema/transport/udp.py +90 -0
- pcapkit/protocols/transport/NotImplemented/dccp.py +0 -0
- pcapkit/protocols/transport/NotImplemented/rsvp.py +0 -0
- pcapkit/protocols/transport/NotImplemented/sctp.py +0 -0
- pcapkit/protocols/transport/__init__.py +27 -0
- pcapkit/protocols/transport/tcp.py +3025 -0
- pcapkit/protocols/transport/transport.py +158 -0
- pcapkit/protocols/transport/udp.py +214 -0
- pcapkit/py.typed +0 -0
- pcapkit/toolkit/__init__.py +57 -0
- pcapkit/toolkit/dpkt.py +306 -0
- pcapkit/toolkit/pcap.py +212 -0
- pcapkit/toolkit/pcapng.py +251 -0
- pcapkit/toolkit/pyshark.py +99 -0
- pcapkit/toolkit/scapy.py +297 -0
- pcapkit/utilities/__init__.py +20 -0
- pcapkit/utilities/compat.py +196 -0
- pcapkit/utilities/decorators.py +192 -0
- pcapkit/utilities/exceptions.py +365 -0
- pcapkit/utilities/logging.py +55 -0
- pcapkit/utilities/warnings.py +185 -0
- pcapkit/vendor/__init__.py +105 -0
- pcapkit/vendor/__main__.py +92 -0
- pcapkit/vendor/arp/__init__.py +27 -0
- pcapkit/vendor/arp/hardware.py +29 -0
- pcapkit/vendor/arp/operation.py +29 -0
- pcapkit/vendor/default.py +474 -0
- pcapkit/vendor/ftp/__init__.py +27 -0
- pcapkit/vendor/ftp/command.py +244 -0
- pcapkit/vendor/ftp/return_code.py +256 -0
- pcapkit/vendor/hip/__init__.py +94 -0
- pcapkit/vendor/hip/certificate.py +29 -0
- pcapkit/vendor/hip/cipher.py +29 -0
- pcapkit/vendor/hip/di.py +29 -0
- pcapkit/vendor/hip/ecdsa_curve.py +29 -0
- pcapkit/vendor/hip/ecdsa_low_curve.py +29 -0
- pcapkit/vendor/hip/eddsa_curve.py +85 -0
- pcapkit/vendor/hip/esp_transform_suite.py +29 -0
- pcapkit/vendor/hip/group.py +87 -0
- pcapkit/vendor/hip/hi_algorithm.py +29 -0
- pcapkit/vendor/hip/hit_suite.py +29 -0
- pcapkit/vendor/hip/nat_traversal.py +29 -0
- pcapkit/vendor/hip/notify_message.py +29 -0
- pcapkit/vendor/hip/packet.py +88 -0
- pcapkit/vendor/hip/parameter.py +88 -0
- pcapkit/vendor/hip/registration.py +29 -0
- pcapkit/vendor/hip/registration_failure.py +29 -0
- pcapkit/vendor/hip/suite.py +29 -0
- pcapkit/vendor/hip/transport.py +29 -0
- pcapkit/vendor/http/__init__.py +39 -0
- pcapkit/vendor/http/error_code.py +95 -0
- pcapkit/vendor/http/frame.py +91 -0
- pcapkit/vendor/http/method.py +167 -0
- pcapkit/vendor/http/setting.py +93 -0
- pcapkit/vendor/http/status_code.py +185 -0
- pcapkit/vendor/ipv4/__init__.py +57 -0
- pcapkit/vendor/ipv4/classification_level.py +91 -0
- pcapkit/vendor/ipv4/option_class.py +80 -0
- pcapkit/vendor/ipv4/option_number.py +105 -0
- pcapkit/vendor/ipv4/protection_authority.py +84 -0
- pcapkit/vendor/ipv4/qs_function.py +78 -0
- pcapkit/vendor/ipv4/router_alert.py +93 -0
- pcapkit/vendor/ipv4/tos_del.py +78 -0
- pcapkit/vendor/ipv4/tos_ecn.py +95 -0
- pcapkit/vendor/ipv4/tos_pre.py +84 -0
- pcapkit/vendor/ipv4/tos_rel.py +78 -0
- pcapkit/vendor/ipv4/tos_thr.py +77 -0
- pcapkit/vendor/ipv4/ts_flag.py +79 -0
- pcapkit/vendor/ipv6/__init__.py +53 -0
- pcapkit/vendor/ipv6/extension_header.py +171 -0
- pcapkit/vendor/ipv6/option.py +104 -0
- pcapkit/vendor/ipv6/option_action.py +90 -0
- pcapkit/vendor/ipv6/qs_function.py +78 -0
- pcapkit/vendor/ipv6/router_alert.py +93 -0
- pcapkit/vendor/ipv6/routing.py +87 -0
- pcapkit/vendor/ipv6/seed_id.py +81 -0
- pcapkit/vendor/ipv6/smf_dpd_mode.py +78 -0
- pcapkit/vendor/ipv6/tagger_id.py +81 -0
- pcapkit/vendor/ipx/__init__.py +37 -0
- pcapkit/vendor/ipx/packet.py +123 -0
- pcapkit/vendor/ipx/socket.py +125 -0
- pcapkit/vendor/l2tp/__init__.py +21 -0
- pcapkit/vendor/l2tp/type.py +78 -0
- pcapkit/vendor/mh/__init__.py +204 -0
- pcapkit/vendor/mh/access_type.py +87 -0
- pcapkit/vendor/mh/ack_status_code.py +88 -0
- pcapkit/vendor/mh/ani_suboption.py +88 -0
- pcapkit/vendor/mh/auth_subtype.py +83 -0
- pcapkit/vendor/mh/binding_ack_flag.py +148 -0
- pcapkit/vendor/mh/binding_error.py +78 -0
- pcapkit/vendor/mh/binding_revocation.py +87 -0
- pcapkit/vendor/mh/binding_update_flag.py +147 -0
- pcapkit/vendor/mh/cga_extension.py +91 -0
- pcapkit/vendor/mh/cga_sec.py +91 -0
- pcapkit/vendor/mh/cga_type.py +74 -0
- pcapkit/vendor/mh/dhcp_support_mode.py +77 -0
- pcapkit/vendor/mh/dns_status_code.py +87 -0
- pcapkit/vendor/mh/dsmip6_tls_packet.py +87 -0
- pcapkit/vendor/mh/dsmipv6_home_address.py +87 -0
- pcapkit/vendor/mh/enumerating_algorithm.py +82 -0
- pcapkit/vendor/mh/fb_ack_status.py +87 -0
- pcapkit/vendor/mh/fb_action.py +88 -0
- pcapkit/vendor/mh/fb_indication_trigger.py +87 -0
- pcapkit/vendor/mh/fb_type.py +88 -0
- pcapkit/vendor/mh/flow_id_status.py +87 -0
- pcapkit/vendor/mh/flow_id_suboption.py +87 -0
- pcapkit/vendor/mh/handoff_type.py +87 -0
- pcapkit/vendor/mh/handover_ack_flag.py +143 -0
- pcapkit/vendor/mh/handover_ack_status.py +87 -0
- pcapkit/vendor/mh/handover_initiate_flag.py +143 -0
- pcapkit/vendor/mh/handover_initiate_status.py +87 -0
- pcapkit/vendor/mh/home_address_reply.py +87 -0
- pcapkit/vendor/mh/lla_code.py +97 -0
- pcapkit/vendor/mh/lma_mag_suboption.py +88 -0
- pcapkit/vendor/mh/mn_group_id.py +87 -0
- pcapkit/vendor/mh/mn_id_subtype.py +87 -0
- pcapkit/vendor/mh/operator_id.py +87 -0
- pcapkit/vendor/mh/option.py +83 -0
- pcapkit/vendor/mh/packet.py +82 -0
- pcapkit/vendor/mh/qos_attribute.py +87 -0
- pcapkit/vendor/mh/revocation_status_code.py +87 -0
- pcapkit/vendor/mh/revocation_trigger.py +87 -0
- pcapkit/vendor/mh/status_code.py +91 -0
- pcapkit/vendor/mh/traffic_selector.py +87 -0
- pcapkit/vendor/mh/upa_status.py +87 -0
- pcapkit/vendor/mh/upn_reason.py +87 -0
- pcapkit/vendor/ospf/__init__.py +27 -0
- pcapkit/vendor/ospf/authentication.py +29 -0
- pcapkit/vendor/ospf/packet.py +29 -0
- pcapkit/vendor/pcapng/__init__.py +51 -0
- pcapkit/vendor/pcapng/block_type.py +94 -0
- pcapkit/vendor/pcapng/filter_type.py +77 -0
- pcapkit/vendor/pcapng/hash_algorithm.py +82 -0
- pcapkit/vendor/pcapng/option_type.py +287 -0
- pcapkit/vendor/pcapng/record_type.py +81 -0
- pcapkit/vendor/pcapng/secrets_type.py +81 -0
- pcapkit/vendor/pcapng/verdict_type.py +79 -0
- pcapkit/vendor/reg/__init__.py +34 -0
- pcapkit/vendor/reg/apptype.py +338 -0
- pcapkit/vendor/reg/ethertype.py +121 -0
- pcapkit/vendor/reg/linktype.py +110 -0
- pcapkit/vendor/reg/transtype.py +111 -0
- pcapkit/vendor/tcp/__init__.py +35 -0
- pcapkit/vendor/tcp/checksum.py +80 -0
- pcapkit/vendor/tcp/flags.py +149 -0
- pcapkit/vendor/tcp/mp_tcp_option.py +90 -0
- pcapkit/vendor/tcp/option.py +103 -0
- pcapkit/vendor/vlan/__init__.py +23 -0
- pcapkit/vendor/vlan/priority_level.py +97 -0
- pypcapkit-1.3.3.post1.dist-info/LICENSE +29 -0
- pypcapkit-1.3.3.post1.dist-info/METADATA +236 -0
- pypcapkit-1.3.3.post1.dist-info/RECORD +466 -0
- pypcapkit-1.3.3.post1.dist-info/WHEEL +5 -0
- pypcapkit-1.3.3.post1.dist-info/entry_points.txt +3 -0
- pypcapkit-1.3.3.post1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,389 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""Base Class
|
3
|
+
================
|
4
|
+
|
5
|
+
.. module:: pcapkit.foundation.reassembly.reassembly
|
6
|
+
|
7
|
+
:mod:`pcapkit.foundation.reassembly.reassembly` contains
|
8
|
+
:class:`~pcapkit.foundation.reassembly.reassembly.Reassembly` only,
|
9
|
+
which is an abstract base class for all reassembly classes,
|
10
|
+
bases on algorithms described in :rfc:`791` and :rfc:`815`,
|
11
|
+
implements datagram reassembly of IP and TCP packets.
|
12
|
+
|
13
|
+
"""
|
14
|
+
import abc
|
15
|
+
from typing import TYPE_CHECKING, Generic, Type, TypeVar, cast
|
16
|
+
|
17
|
+
from pcapkit.protocols import __proto__ as protocol_registry
|
18
|
+
from pcapkit.protocols.misc.raw import Raw
|
19
|
+
from pcapkit.utilities.exceptions import UnsupportedCall
|
20
|
+
|
21
|
+
if TYPE_CHECKING:
|
22
|
+
from typing import Any, Callable, Optional, Type
|
23
|
+
|
24
|
+
from typing_extensions import Self
|
25
|
+
|
26
|
+
from pcapkit.corekit.infoclass import Info
|
27
|
+
from pcapkit.protocols.protocol import ProtocolBase as Protocol
|
28
|
+
|
29
|
+
CallbackFn = Callable[[list['_DT']], None]
|
30
|
+
|
31
|
+
__all__ = ['Reassembly']
|
32
|
+
|
33
|
+
# packet
|
34
|
+
_PT = TypeVar('_PT', bound='Info')
|
35
|
+
# datagram
|
36
|
+
_DT = TypeVar('_DT', bound='Info')
|
37
|
+
# buffer ID
|
38
|
+
_IT = TypeVar('_IT', bound='tuple')
|
39
|
+
# buffer
|
40
|
+
_BT = TypeVar('_BT', bound='Info')
|
41
|
+
|
42
|
+
|
43
|
+
class ReassemblyMeta(abc.ABCMeta):
|
44
|
+
"""Meta class to add dynamic support to :class:`Reassembly`.
|
45
|
+
|
46
|
+
This meta class is used to generate necessary attributes for the
|
47
|
+
:class:`Reassembly` class. It can be useful to reduce unnecessary
|
48
|
+
registry calls and simplify the customisation process.
|
49
|
+
|
50
|
+
"""
|
51
|
+
if TYPE_CHECKING:
|
52
|
+
#: Protocol name of current reassembly object.
|
53
|
+
__protocol_name__: 'str'
|
54
|
+
#: Protocol of current reassembly object.
|
55
|
+
__protocol_type__: 'Type[Protocol]'
|
56
|
+
|
57
|
+
@property
|
58
|
+
def name(cls) -> 'str':
|
59
|
+
"""Protocol name of current reassembly object."""
|
60
|
+
if hasattr(cls, '__protocol_name__'):
|
61
|
+
return cls.__protocol_name__
|
62
|
+
return cls.__name__
|
63
|
+
|
64
|
+
@property
|
65
|
+
def protocol(cls) -> 'Type[Protocol]':
|
66
|
+
"""Protocol of current reassembly object."""
|
67
|
+
if hasattr(cls, '__protocol_type__'):
|
68
|
+
return cls.__protocol_type__
|
69
|
+
return protocol_registry.get(cls.name.upper(), Raw)
|
70
|
+
|
71
|
+
|
72
|
+
class ReassemblyBase(Generic[_PT, _DT, _IT, _BT], metaclass=ReassemblyMeta):
|
73
|
+
"""Base class for reassembly procedure.
|
74
|
+
|
75
|
+
Args:
|
76
|
+
strict: if return all datagrams (including those not
|
77
|
+
implemented) when submit
|
78
|
+
store: if store reassembled datagram in memory, i.e.,
|
79
|
+
:attr:`self._dtgram <_dtgram>` (if not, datagram
|
80
|
+
will be discarded after callback)
|
81
|
+
|
82
|
+
Note:
|
83
|
+
This class is for internal use only. For customisation, please use
|
84
|
+
:class:`TraceFlow` instead.
|
85
|
+
|
86
|
+
"""
|
87
|
+
if TYPE_CHECKING:
|
88
|
+
#: Protocol name of current reassembly object.
|
89
|
+
__protocol_name__: 'str'
|
90
|
+
#: Protocol of current reassembly object.
|
91
|
+
__protocol_type__: 'Type[Protocol]'
|
92
|
+
|
93
|
+
#: List of callback functions upon reassembled datagram.
|
94
|
+
__callback_fn__: 'list[CallbackFn]'
|
95
|
+
|
96
|
+
_flag_s: 'bool'
|
97
|
+
_flag_d: 'bool'
|
98
|
+
_flag_n: 'bool'
|
99
|
+
|
100
|
+
# Internal data storage for cached properties.
|
101
|
+
__cached__: 'dict[str, Any]'
|
102
|
+
|
103
|
+
##########################################################################
|
104
|
+
# Properties.
|
105
|
+
##########################################################################
|
106
|
+
|
107
|
+
@property
|
108
|
+
def name(self) -> 'str':
|
109
|
+
"""Protocol name of current reassembly object.
|
110
|
+
|
111
|
+
Note:
|
112
|
+
This property is not available as a class
|
113
|
+
attribute.
|
114
|
+
|
115
|
+
"""
|
116
|
+
if hasattr(self, '__protocol_name__'):
|
117
|
+
return self.__protocol_name__
|
118
|
+
return type(self).name # type: ignore[return-value]
|
119
|
+
|
120
|
+
@property
|
121
|
+
def protocol(self) -> 'Type[Protocol]':
|
122
|
+
"""Protocol of current reassembly object.
|
123
|
+
|
124
|
+
Note:
|
125
|
+
This property is not available as a class
|
126
|
+
attribute.
|
127
|
+
|
128
|
+
"""
|
129
|
+
if hasattr(self, '__protocol_type__'):
|
130
|
+
return self.__protocol_type__
|
131
|
+
return type(self).protocol # type: ignore[return-value]
|
132
|
+
|
133
|
+
# total number of reassembled packets
|
134
|
+
@property
|
135
|
+
def count(self) -> 'int':
|
136
|
+
"""Total number of reassembled packets."""
|
137
|
+
if self._flag_n:
|
138
|
+
self.__cached__.clear()
|
139
|
+
self._flag_n = False
|
140
|
+
|
141
|
+
if (cached := self.__cached__.get('count')) is not None:
|
142
|
+
return cached
|
143
|
+
|
144
|
+
ret = len(self.datagram)
|
145
|
+
self.__cached__['count'] = ret
|
146
|
+
return ret
|
147
|
+
|
148
|
+
# reassembled datagram
|
149
|
+
@property
|
150
|
+
def datagram(self) -> 'tuple[_DT, ...]':
|
151
|
+
"""Reassembled datagram.
|
152
|
+
|
153
|
+
Raises:
|
154
|
+
UnsupportedCall: If :attr:`self._flag_d <_flag_d>` is
|
155
|
+
set to :data:`False`.
|
156
|
+
|
157
|
+
"""
|
158
|
+
if not self._flag_d:
|
159
|
+
raise UnsupportedCall(f'{self.__class__.__name__}(store=False) has no attribute "datagram"')
|
160
|
+
|
161
|
+
if self._buffer:
|
162
|
+
return self.fetch()
|
163
|
+
return tuple(self._dtgram)
|
164
|
+
|
165
|
+
##########################################################################
|
166
|
+
# Methods.
|
167
|
+
##########################################################################
|
168
|
+
|
169
|
+
# reassembly procedure
|
170
|
+
@abc.abstractmethod
|
171
|
+
def reassembly(self, info: '_PT') -> 'None':
|
172
|
+
"""Reassembly procedure.
|
173
|
+
|
174
|
+
Arguments:
|
175
|
+
info: info dict of packets to be reassembled
|
176
|
+
|
177
|
+
"""
|
178
|
+
# clear cache
|
179
|
+
self._flag_n = False
|
180
|
+
self.__cached__['count'] = None
|
181
|
+
self.__cached__['fetch'] = None
|
182
|
+
|
183
|
+
# submit reassembled payload
|
184
|
+
@abc.abstractmethod
|
185
|
+
def submit(self, buf: '_BT', **kwargs: 'Any') -> 'list[_DT]':
|
186
|
+
"""Submit reassembled payload.
|
187
|
+
|
188
|
+
Arguments:
|
189
|
+
buf: buffer dict of reassembled packets
|
190
|
+
**kwargs: arbitrary keyword arguments
|
191
|
+
|
192
|
+
"""
|
193
|
+
|
194
|
+
# fetch datagram
|
195
|
+
def fetch(self) -> 'tuple[_DT, ...]':
|
196
|
+
"""Fetch datagram.
|
197
|
+
|
198
|
+
Returns:
|
199
|
+
Tuple of reassembled datagrams.
|
200
|
+
|
201
|
+
Fetch reassembled datagrams from
|
202
|
+
:attr:`self._dtgram <pcapkit.foundation.reassembly.reassembly.Reassembly._dtgram>`
|
203
|
+
and returns a *tuple* of such datagrams.
|
204
|
+
|
205
|
+
If no cache found, the method will call
|
206
|
+
:meth:`self.submit <pcapkit.foundation.reassembly.reassembly.Reassembly.submit>`
|
207
|
+
to *forcedly* obtain newly reassembled payload. Otherwise, the
|
208
|
+
already calculated
|
209
|
+
:attr:`self._dtgram <pcapkit.foundation.reassembly.reassembly.Reassembly._dtgram>`
|
210
|
+
will be returned.
|
211
|
+
|
212
|
+
"""
|
213
|
+
if self._flag_n:
|
214
|
+
self.__cached__.clear()
|
215
|
+
self._flag_n = False
|
216
|
+
|
217
|
+
if (cached := self.__cached__.get('fetch')) is not None:
|
218
|
+
return cached
|
219
|
+
|
220
|
+
temp_dtgram = [] # type: list[_DT]
|
221
|
+
for (bufid, buffer) in self._buffer.items():
|
222
|
+
temp_dtgram.extend(
|
223
|
+
self.submit(buffer, bufid=bufid)
|
224
|
+
)
|
225
|
+
temp_dtgram.extend(self._dtgram)
|
226
|
+
ret = tuple(temp_dtgram)
|
227
|
+
|
228
|
+
self.__cached__['fetch'] = ret
|
229
|
+
return ret
|
230
|
+
|
231
|
+
# return datagram index
|
232
|
+
def index(self, pkt_num: 'int') -> 'Optional[int]':
|
233
|
+
"""Return datagram index.
|
234
|
+
|
235
|
+
Arguments:
|
236
|
+
pkt_num: index of packet
|
237
|
+
|
238
|
+
Returns:
|
239
|
+
Reassembled datagram index which was from No. ``pkt_num`` packet;
|
240
|
+
if not found, returns :obj:`None`.
|
241
|
+
|
242
|
+
"""
|
243
|
+
for counter, datagram in enumerate(self.datagram):
|
244
|
+
if pkt_num in datagram.index: # type: ignore[attr-defined]
|
245
|
+
return counter
|
246
|
+
return None
|
247
|
+
|
248
|
+
# run automatically
|
249
|
+
def run(self, packets: 'list[_PT]') -> 'None':
|
250
|
+
"""Run automatically.
|
251
|
+
|
252
|
+
Arguments:
|
253
|
+
packets: list of packet dicts to be reassembled
|
254
|
+
|
255
|
+
"""
|
256
|
+
for packet in packets:
|
257
|
+
self.reassembly(packet)
|
258
|
+
|
259
|
+
# register callback function
|
260
|
+
@classmethod
|
261
|
+
def register(cls, callback: 'CallbackFn', *, index: 'Optional[int]' = None) -> 'None':
|
262
|
+
"""Register callback function.
|
263
|
+
|
264
|
+
Arguments:
|
265
|
+
callback: callback function, which will be called
|
266
|
+
when reassembled datagram is obtained, with the
|
267
|
+
list of reassembled datagrams as its only argument
|
268
|
+
index: index to be inserted in the callback list,; by
|
269
|
+
default, the callback will be appended to the end
|
270
|
+
of the list
|
271
|
+
|
272
|
+
"""
|
273
|
+
if index is not None:
|
274
|
+
cls.__callback_fn__.insert(index, callback)
|
275
|
+
else:
|
276
|
+
cls.__callback_fn__.append(callback)
|
277
|
+
|
278
|
+
##########################################################################
|
279
|
+
# Data models.
|
280
|
+
##########################################################################
|
281
|
+
|
282
|
+
def __new__(cls, *args: 'Any', **kwargs: 'Any') -> 'Self': # pylint: disable=unused-argument
|
283
|
+
self = super().__new__(cls)
|
284
|
+
|
285
|
+
# NOTE: Assign this attribute after ``__new__`` to avoid shared memory
|
286
|
+
# reference between instances.
|
287
|
+
self.__cached__ = {}
|
288
|
+
|
289
|
+
return self
|
290
|
+
|
291
|
+
def __init__(self, *, strict: 'bool' = True, store: 'bool' = True) -> 'None':
|
292
|
+
"""Initialise packet reassembly.
|
293
|
+
|
294
|
+
Args:
|
295
|
+
strict: if return all datagrams (including those not
|
296
|
+
implemented) when submit
|
297
|
+
store: if store reassembled datagram in memory, i.e.,
|
298
|
+
:attr:`self._dtgram <_dtgram>` (if not, datagram
|
299
|
+
will be discarded after callback)
|
300
|
+
|
301
|
+
"""
|
302
|
+
#: bool: Strict mode flag. If set to :data:`True`, all
|
303
|
+
#: data will be returned, including those not completely
|
304
|
+
#: reassembled; otherwise, only completely reassembled
|
305
|
+
#: data will be returned.
|
306
|
+
self._flag_s = strict
|
307
|
+
#: bool: Store mode flag. If set to :data:`True`, all
|
308
|
+
#: reassembled datagram will be stored in memory, i.e.,
|
309
|
+
#: :attr:`self._dtgram <_dtgram>`; otherwise, datagram
|
310
|
+
#: will be discarded after callback.
|
311
|
+
self._flag_d = store
|
312
|
+
#: bool: New datagram flag. If set to :data:`True`, the
|
313
|
+
#: :attr:`self._dtgram <_dtgram>` will be repopulated.
|
314
|
+
self._flag_n = False
|
315
|
+
|
316
|
+
#: dict[_IT, _BT]: Dict buffer field. This field is used to
|
317
|
+
#: store reassembled packets in the form of ``{bufid: buffer}``.
|
318
|
+
self._buffer = {} # type: dict[_IT, _BT]
|
319
|
+
#: list[_DT]: List reassembled datagram. This list is used
|
320
|
+
#: to store reassembled datagrams.
|
321
|
+
self._dtgram = [] # type: list[_DT]
|
322
|
+
|
323
|
+
def __call__(self, packet: '_PT') -> 'None':
|
324
|
+
"""Call packet reassembly.
|
325
|
+
|
326
|
+
Arguments:
|
327
|
+
packet: packet dict to be reassembled
|
328
|
+
(detailed format described in corresponding protocol)
|
329
|
+
|
330
|
+
"""
|
331
|
+
self._flag_n = True
|
332
|
+
self.reassembly(packet)
|
333
|
+
|
334
|
+
def __init_subclass__(cls) -> 'None':
|
335
|
+
"""Initialise subclass.
|
336
|
+
|
337
|
+
This method is to be used for generating necessary attributes
|
338
|
+
for the :class:`Reassembly` class. It can be useful to reduce
|
339
|
+
unnecessary registry calls and simplify the customisation process.
|
340
|
+
|
341
|
+
"""
|
342
|
+
cls.__callback_fn__ = []
|
343
|
+
|
344
|
+
|
345
|
+
class Reassembly(ReassemblyBase[_PT, _DT, _IT, _BT], Generic[_PT, _DT, _IT, _BT]):
|
346
|
+
"""Base flow tracing class.
|
347
|
+
|
348
|
+
Example:
|
349
|
+
|
350
|
+
Use keyword argument ``protocol`` to specify the protocol
|
351
|
+
name at class definition:
|
352
|
+
|
353
|
+
.. code-block:: python
|
354
|
+
|
355
|
+
class MyProtocol(Reassembly, protocol='my_protocol'):
|
356
|
+
...
|
357
|
+
|
358
|
+
Arguments:
|
359
|
+
strict: if return all datagrams (including those not
|
360
|
+
implemented) when submit
|
361
|
+
store: if store reassembled datagram in memory, i.e.,
|
362
|
+
:attr:`self._dtgram <_dtgram>` (if not, datagram
|
363
|
+
will be discarded after callback)
|
364
|
+
|
365
|
+
"""
|
366
|
+
|
367
|
+
def __init_subclass__(cls, /, protocol: 'Optional[str]' = None, *args: 'Any', **kwargs: 'Any') -> 'None':
|
368
|
+
"""Initialise subclass.
|
369
|
+
|
370
|
+
This method is to be used for registering the engine class to
|
371
|
+
:class:`~pcapkit.foundation.extraction.Extractor` class.
|
372
|
+
|
373
|
+
Args:
|
374
|
+
name: Protocol name, default to class name.
|
375
|
+
*args: Arbitrary positional arguments.
|
376
|
+
**kwargs: Arbitrary keyword arguments.
|
377
|
+
|
378
|
+
See Also:
|
379
|
+
For more details, please refer to
|
380
|
+
:meth:`pcapkit.foundation.extraction.Extractor.register_reassembly`.
|
381
|
+
|
382
|
+
"""
|
383
|
+
if protocol is None:
|
384
|
+
protocol = cast('str', cls.name)
|
385
|
+
|
386
|
+
from pcapkit.foundation.extraction import Extractor
|
387
|
+
Extractor.register_reassembly(protocol.lower(), cls)
|
388
|
+
|
389
|
+
return super().__init_subclass__()
|
@@ -0,0 +1,249 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""TCP Datagram Reassembly
|
3
|
+
=============================
|
4
|
+
|
5
|
+
.. module:: pcapkit.foundation.reassembly.tcp
|
6
|
+
|
7
|
+
:mod:`pcapkit.foundation.reassembly.tcp` contains
|
8
|
+
:class:`~pcapkit.foundation.reassembly.reassembly.Reassembly` only,
|
9
|
+
which reconstructs fragmented TCP packets back to origin.
|
10
|
+
|
11
|
+
"""
|
12
|
+
import sys
|
13
|
+
from typing import TYPE_CHECKING
|
14
|
+
|
15
|
+
from pcapkit.foundation.reassembly.data.tcp import (Buffer, BufferID, Datagram, DatagramID,
|
16
|
+
Fragment, HoleDiscriptor, Packet)
|
17
|
+
from pcapkit.foundation.reassembly.reassembly import ReassemblyBase as Reassembly
|
18
|
+
from pcapkit.protocols.transport.tcp import TCP as TCP_Protocol
|
19
|
+
|
20
|
+
if TYPE_CHECKING:
|
21
|
+
from typing import Type
|
22
|
+
|
23
|
+
__all__ = ['TCP']
|
24
|
+
|
25
|
+
|
26
|
+
class TCP(Reassembly[Packet, Datagram, BufferID, Buffer]):
|
27
|
+
"""Reassembly for TCP payload.
|
28
|
+
|
29
|
+
Args:
|
30
|
+
strict: if return all datagrams (including those not
|
31
|
+
implemented) when submit
|
32
|
+
store: if store reassembled datagram in memory, i.e.,
|
33
|
+
:attr:`self._dtgram <pcapkit.foundation.reassembly.reassembly.Reassembly._dtgram>`
|
34
|
+
(if not, datagram will be discarded after callback)
|
35
|
+
|
36
|
+
Example:
|
37
|
+
>>> from pcapkit.foundation.reassembly import TCP
|
38
|
+
# Initialise instance:
|
39
|
+
>>> tcp_reassembly = TCP()
|
40
|
+
# Call reassembly:
|
41
|
+
>>> tcp_reassembly(packet_dict)
|
42
|
+
# Fetch result:
|
43
|
+
>>> result = tcp_reassembly.datagram
|
44
|
+
|
45
|
+
"""
|
46
|
+
if TYPE_CHECKING:
|
47
|
+
protocol: 'Type[TCP_Protocol]'
|
48
|
+
|
49
|
+
##########################################################################
|
50
|
+
# Defaults.
|
51
|
+
##########################################################################
|
52
|
+
|
53
|
+
#: Protocol name of current reassembly object.
|
54
|
+
__protocol_name__ = 'TCP'
|
55
|
+
#: Protocol of current reassembly object.
|
56
|
+
__protocol_type__ = TCP_Protocol
|
57
|
+
|
58
|
+
##########################################################################
|
59
|
+
# Methods.
|
60
|
+
##########################################################################
|
61
|
+
|
62
|
+
def reassembly(self, info: 'Packet') -> 'None':
|
63
|
+
"""Reassembly procedure.
|
64
|
+
|
65
|
+
Arguments:
|
66
|
+
info: :term:`info <reasm.tcp.packet>` dict of packets to be reassembled
|
67
|
+
|
68
|
+
"""
|
69
|
+
# clear cache
|
70
|
+
self._flag_n = False
|
71
|
+
self.__cached__.clear()
|
72
|
+
|
73
|
+
BUFID = info.bufid # Buffer Identifier
|
74
|
+
DSN = info.dsn # Data Sequence Number
|
75
|
+
ACK = info.ack # Acknowledgement Number
|
76
|
+
FIN = info.fin # Finish Flag (Termination)
|
77
|
+
RST = info.rst # Reset Connection Flag (Termination)
|
78
|
+
SYN = info.syn # Synchronise Flag (Establishment)
|
79
|
+
|
80
|
+
# when SYN is set, reset buffer of existing session
|
81
|
+
if SYN and BUFID in self._buffer:
|
82
|
+
self._dtgram.extend(
|
83
|
+
self.submit(self._buffer.pop(BUFID), bufid=BUFID)
|
84
|
+
)
|
85
|
+
|
86
|
+
# initialise buffer with BUFID & ACK
|
87
|
+
if BUFID not in self._buffer:
|
88
|
+
self._buffer[BUFID] = Buffer(
|
89
|
+
hdl=[
|
90
|
+
HoleDiscriptor(
|
91
|
+
first=info.len,
|
92
|
+
last=sys.maxsize,
|
93
|
+
),
|
94
|
+
],
|
95
|
+
hdr=info.header if SYN else b'',
|
96
|
+
ack={
|
97
|
+
ACK: Fragment(
|
98
|
+
ind=[
|
99
|
+
info.num,
|
100
|
+
],
|
101
|
+
isn=info.dsn,
|
102
|
+
len=info.len,
|
103
|
+
raw=info.payload,
|
104
|
+
),
|
105
|
+
},
|
106
|
+
)
|
107
|
+
else:
|
108
|
+
# initialise buffer with ACK
|
109
|
+
if ACK not in self._buffer[BUFID].ack:
|
110
|
+
self._buffer[BUFID].ack[ACK] = Fragment(
|
111
|
+
ind=[
|
112
|
+
info.num,
|
113
|
+
],
|
114
|
+
isn=info.dsn,
|
115
|
+
len=info.len,
|
116
|
+
raw=info.payload,
|
117
|
+
)
|
118
|
+
else:
|
119
|
+
# put header into header buffer
|
120
|
+
if SYN:
|
121
|
+
self._buffer[BUFID].__update__(hdr=info.header)
|
122
|
+
|
123
|
+
# append packet index
|
124
|
+
self._buffer[BUFID].ack[ACK].ind.append(info.num)
|
125
|
+
|
126
|
+
# record fragment payload
|
127
|
+
ISN = self._buffer[BUFID].ack[ACK].isn # Initial Sequence Number
|
128
|
+
RAW = self._buffer[BUFID].ack[ACK].raw # Raw Payload Data
|
129
|
+
if DSN >= ISN: # if fragment goes after existing payload
|
130
|
+
LEN = self._buffer[BUFID].ack[ACK].len
|
131
|
+
GAP = DSN - (ISN + LEN) # gap length between payloads
|
132
|
+
if GAP >= 0: # if fragment goes after existing payload
|
133
|
+
RAW += bytearray(GAP) + info.payload
|
134
|
+
else: # if fragment partially overlaps existing payload
|
135
|
+
RAW[DSN-ISN:] = info.payload
|
136
|
+
else: # if fragment exceeds existing payload
|
137
|
+
LEN = info.len
|
138
|
+
GAP = ISN - (DSN + LEN) # gap length between payloads
|
139
|
+
self._buffer[BUFID].ack[ACK].__update__(
|
140
|
+
isn=DSN,
|
141
|
+
)
|
142
|
+
if GAP >= 0: # if fragment exceeds existing payload
|
143
|
+
RAW = info.payload + bytearray(GAP) + RAW
|
144
|
+
else: # if fragment partially overlaps existing payload
|
145
|
+
RAW = info.payload + RAW[ISN-GAP:]
|
146
|
+
#self._buffer[BUFID].ack[ACK].raw = RAW # update payload datagram
|
147
|
+
#self._buffer[BUFID].ack[ACK].len = len(RAW) # update payload length
|
148
|
+
self._buffer[BUFID].ack[ACK].__update__(
|
149
|
+
raw=RAW, # update payload datagram
|
150
|
+
len=len(RAW), # update payload length
|
151
|
+
)
|
152
|
+
|
153
|
+
# update hole descriptor list
|
154
|
+
HDL = self._buffer[BUFID].hdl # HDL alias
|
155
|
+
for (index, hole) in enumerate(HDL): # step one
|
156
|
+
if info.first > hole.last: # step two
|
157
|
+
continue
|
158
|
+
if info.last < hole.first: # step three
|
159
|
+
continue
|
160
|
+
del HDL[index] # step four
|
161
|
+
if info.first > hole.first: # step five
|
162
|
+
new_hole = HoleDiscriptor(
|
163
|
+
first=hole.first,
|
164
|
+
last=info.first - 1,
|
165
|
+
)
|
166
|
+
HDL.insert(index, new_hole)
|
167
|
+
index += 1
|
168
|
+
if info.last < hole.last and not FIN and not RST: # step six
|
169
|
+
new_hole = HoleDiscriptor(
|
170
|
+
first=info.last + 1,
|
171
|
+
last=hole.last
|
172
|
+
)
|
173
|
+
HDL.insert(index, new_hole)
|
174
|
+
break # step seven
|
175
|
+
#self._buffer[BUFID].hdl = HDL # update HDL
|
176
|
+
|
177
|
+
# when FIN/RST is set, submit buffer of this session
|
178
|
+
if FIN or RST:
|
179
|
+
self._dtgram.extend(
|
180
|
+
self.submit(self._buffer.pop(BUFID), bufid=BUFID)
|
181
|
+
)
|
182
|
+
|
183
|
+
def submit(self, buf: 'Buffer', *, bufid: 'BufferID') -> 'list[Datagram]': # type: ignore[override] # pylint: disable=arguments-differ
|
184
|
+
"""Submit reassembled payload.
|
185
|
+
|
186
|
+
Arguments:
|
187
|
+
buf: :term:`buffer <reasm.tcp.buffer>` dict of reassembled packets
|
188
|
+
bufid: buffer identifier
|
189
|
+
|
190
|
+
Returns:
|
191
|
+
Reassembled :term:`packets <reasm.tcp.datagram>`.
|
192
|
+
|
193
|
+
"""
|
194
|
+
datagram = [] # type: list[Datagram] # reassembled datagram
|
195
|
+
HDL = buf.hdl # hole descriptor list
|
196
|
+
|
197
|
+
# check through every buffer with ACK
|
198
|
+
for (ack, buffer) in buf.ack.items():
|
199
|
+
# if this buffer is not implemented
|
200
|
+
# go through every hole and extract received payload
|
201
|
+
if len(HDL) > 2 and self._flag_s:
|
202
|
+
data = [] # type: list[bytes]
|
203
|
+
start = stop = 0
|
204
|
+
for hole in HDL:
|
205
|
+
stop = hole.first
|
206
|
+
byte = buffer.raw[start:stop]
|
207
|
+
start = hole.last
|
208
|
+
if byte: # strip empty payload
|
209
|
+
data.append(byte)
|
210
|
+
byte = buffer.raw[start:]
|
211
|
+
if byte: # strip empty payload
|
212
|
+
data.append(bytes(byte))
|
213
|
+
if data: # strip empty buffer
|
214
|
+
packet = Datagram(
|
215
|
+
completed=False,
|
216
|
+
id=DatagramID(
|
217
|
+
src=(bufid[0], bufid[1]),
|
218
|
+
dst=(bufid[2], bufid[3]),
|
219
|
+
ack=ack,
|
220
|
+
),
|
221
|
+
index=tuple(buffer.ind),
|
222
|
+
header=buf.hdr,
|
223
|
+
payload=tuple(data),
|
224
|
+
packet=None,
|
225
|
+
)
|
226
|
+
datagram.append(packet)
|
227
|
+
|
228
|
+
# if this buffer is implemented
|
229
|
+
# export payload data & convert into bytes
|
230
|
+
else:
|
231
|
+
payload = buffer.raw
|
232
|
+
if payload: # strip empty buffer
|
233
|
+
packet = Datagram(
|
234
|
+
completed=True,
|
235
|
+
id=DatagramID(
|
236
|
+
src=(bufid[0], bufid[1]),
|
237
|
+
dst=(bufid[2], bufid[3]),
|
238
|
+
ack=ack,
|
239
|
+
),
|
240
|
+
index=tuple(buffer.ind),
|
241
|
+
header=buf.hdr,
|
242
|
+
payload=bytes(payload),
|
243
|
+
packet=self.protocol.analyze((bufid[1], bufid[3]), bytes(payload)),
|
244
|
+
)
|
245
|
+
datagram.append(packet)
|
246
|
+
|
247
|
+
for callback in self.__callback_fn__:
|
248
|
+
callback(datagram)
|
249
|
+
return datagram
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""Registry Management
|
3
|
+
=========================
|
4
|
+
|
5
|
+
.. module:: pcapkit.foundation.registry
|
6
|
+
|
7
|
+
This module provides the registry management for :mod:`pcapkit`, as the module
|
8
|
+
contains various registry points.
|
9
|
+
|
10
|
+
"""
|
11
|
+
|
12
|
+
from pcapkit.foundation.registry.foundation import *
|
13
|
+
from pcapkit.foundation.registry.protocols import *
|
14
|
+
|
15
|
+
__all__ = [
|
16
|
+
'register_extractor_engine',
|
17
|
+
|
18
|
+
'register_dumper',
|
19
|
+
'register_extractor_dumper', 'register_traceflow_dumper',
|
20
|
+
|
21
|
+
'register_protocol',
|
22
|
+
|
23
|
+
'register_linktype',
|
24
|
+
'register_pcap', 'register_pcapng',
|
25
|
+
|
26
|
+
'register_ethertype',
|
27
|
+
|
28
|
+
'register_transtype',
|
29
|
+
'register_ipv4_option', 'register_hip_parameter', 'register_hopopt_option',
|
30
|
+
'register_ipv6_opts_option', 'register_ipv6_route_routing',
|
31
|
+
'register_mh_message', 'register_mh_option', 'register_mh_extension',
|
32
|
+
|
33
|
+
'register_apptype',
|
34
|
+
'register_tcp', 'register_udp',
|
35
|
+
'register_tcp_option', 'register_tcp_mp_option',
|
36
|
+
|
37
|
+
'register_http_frame',
|
38
|
+
|
39
|
+
'register_pcapng_block', 'register_pcapng_option', 'register_pcapng_secrets',
|
40
|
+
'register_pcapng_record',
|
41
|
+
]
|