pypcapkit 1.3.5.post6__cp313-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- pcapkit/__init__.py +124 -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 +298 -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 +69 -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 +32728 -0
- pcapkit/const/reg/ethertype.py +714 -0
- pcapkit/const/reg/linktype.py +890 -0
- pcapkit/const/reg/transtype.py +526 -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 +249 -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 +412 -0
- pcapkit/protocols/internet/ipv6_frag.py +258 -0
- pcapkit/protocols/internet/ipv6_opts.py +1890 -0
- pcapkit/protocols/internet/ipv6_route.py +708 -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 +197 -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 +197 -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.5.post6.dist-info/LICENSE +29 -0
- pypcapkit-1.3.5.post6.dist-info/METADATA +238 -0
- pypcapkit-1.3.5.post6.dist-info/RECORD +466 -0
- pypcapkit-1.3.5.post6.dist-info/WHEEL +5 -0
- pypcapkit-1.3.5.post6.dist-info/entry_points.txt +3 -0
- pypcapkit-1.3.5.post6.dist-info/top_level.txt +1 -0
@@ -0,0 +1,375 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""numerical field class"""
|
3
|
+
|
4
|
+
import enum
|
5
|
+
import math
|
6
|
+
from typing import TYPE_CHECKING, Generic, TypeVar, Union, cast
|
7
|
+
|
8
|
+
import aenum
|
9
|
+
|
10
|
+
from pcapkit.corekit.fields.field import Field, NoValue
|
11
|
+
from pcapkit.utilities.exceptions import IntError
|
12
|
+
|
13
|
+
__all__ = [
|
14
|
+
'NumberField',
|
15
|
+
'Int32Field', 'UInt32Field',
|
16
|
+
'Int16Field', 'UInt16Field',
|
17
|
+
'Int64Field', 'UInt64Field',
|
18
|
+
'Int8Field', 'UInt8Field',
|
19
|
+
'EnumField',
|
20
|
+
]
|
21
|
+
|
22
|
+
if TYPE_CHECKING:
|
23
|
+
from enum import IntEnum as StdlibEnum
|
24
|
+
from typing import Any, Callable, Optional, Type
|
25
|
+
|
26
|
+
from aenum import IntEnum as AenumEnum
|
27
|
+
from typing_extensions import Literal, Self
|
28
|
+
|
29
|
+
from pcapkit.corekit.fields.field import NoValueType
|
30
|
+
|
31
|
+
_T = TypeVar('_T', bound='int')
|
32
|
+
|
33
|
+
|
34
|
+
class NumberField(Field[int], Generic[_T]):
|
35
|
+
"""Numerical value for protocol fields.
|
36
|
+
|
37
|
+
Args:
|
38
|
+
length: Field size (in bytes); if a callable is given, it should return
|
39
|
+
an integer value and accept the current packet as its only argument.
|
40
|
+
default: Field default value, if any.
|
41
|
+
signed: Whether the field is signed.
|
42
|
+
byteorder: Field byte order.
|
43
|
+
bit_length: Field bit length.
|
44
|
+
callback: Callback function to be called upon
|
45
|
+
:meth:`self.__call__ <pcapkit.corekit.fields.field.FieldBase.__call__>`.
|
46
|
+
|
47
|
+
"""
|
48
|
+
|
49
|
+
__length__ = None # type: Optional[int]
|
50
|
+
__template__ = None # type: Optional[str]
|
51
|
+
__signed__ = None # type: Optional[bool]
|
52
|
+
|
53
|
+
@property
|
54
|
+
def bit_length(self) -> 'int':
|
55
|
+
"""Field bit length."""
|
56
|
+
return self._bit_length
|
57
|
+
|
58
|
+
def __init__(self, length: 'Optional[int | Callable[[dict[str, Any]], int]]' = None,
|
59
|
+
default: 'int | NoValueType' = NoValue, signed: 'bool' = False,
|
60
|
+
byteorder: 'Literal["little", "big"]' = 'big',
|
61
|
+
bit_length: 'Optional[int]' = None,
|
62
|
+
callback: 'Callable[[Self, dict[str, Any]], None]' = lambda *_: None) -> 'None':
|
63
|
+
if length is None:
|
64
|
+
if self.__length__ is None:
|
65
|
+
raise IntError(f'Field has no length.')
|
66
|
+
length = self.__length__
|
67
|
+
super().__init__(length, default, callback)
|
68
|
+
|
69
|
+
if bit_length is not None:
|
70
|
+
self._bit_length = bit_length
|
71
|
+
self._bit_mask = (1 << bit_length) - 1
|
72
|
+
else:
|
73
|
+
self._bit_length, self._bit_mask = -1, -1
|
74
|
+
|
75
|
+
self._signed = signed if self.__signed__ is None else self.__signed__
|
76
|
+
self._byteorder = byteorder
|
77
|
+
self._need_process = False
|
78
|
+
|
79
|
+
endian = '>' if byteorder == 'big' else '<'
|
80
|
+
if self.__template__ is not None:
|
81
|
+
struct_fmt = self.__template__
|
82
|
+
else:
|
83
|
+
struct_fmt = self.build_template(self._length, signed)
|
84
|
+
self._template = f'{endian}{struct_fmt}'
|
85
|
+
|
86
|
+
def __call__(self, packet: 'dict[str, Any]') -> 'Self':
|
87
|
+
"""Update field attributes.
|
88
|
+
|
89
|
+
Args:
|
90
|
+
packet: Packet data.
|
91
|
+
|
92
|
+
Returns:
|
93
|
+
New instance of :class:`NumberField`.
|
94
|
+
|
95
|
+
This method will return a new instance of :class:`NumberField` instead of
|
96
|
+
updating the current instance.
|
97
|
+
|
98
|
+
"""
|
99
|
+
new_self = super().__call__(packet)
|
100
|
+
|
101
|
+
if new_self._bit_length < 0:
|
102
|
+
new_self._bit_length = new_self._length * 8
|
103
|
+
new_self._bit_mask = (1 << new_self._bit_length) - 1
|
104
|
+
|
105
|
+
endian = '>' if new_self._byteorder == 'big' else '<'
|
106
|
+
struct_fmt = new_self.build_template(new_self._length, new_self._signed)
|
107
|
+
|
108
|
+
new_self._template = f'{endian}{struct_fmt}'
|
109
|
+
return new_self
|
110
|
+
|
111
|
+
def build_template(self, length: 'int', signed: 'bool') -> 'str':
|
112
|
+
"""Build template for field.
|
113
|
+
|
114
|
+
Arguments:
|
115
|
+
length: Field size (in bytes)
|
116
|
+
signed: Whether the field is signed
|
117
|
+
|
118
|
+
Returns:
|
119
|
+
Template for field.
|
120
|
+
|
121
|
+
"""
|
122
|
+
if length == 8: # unpack to 8-byte integer (long long)
|
123
|
+
struct_fmt = 'q' if signed else 'Q'
|
124
|
+
elif length == 4: # unpack to 4-byte integer (int / long)
|
125
|
+
struct_fmt = 'i' if signed else 'I'
|
126
|
+
elif length == 2: # unpack to 2-byte integer (short)
|
127
|
+
struct_fmt = 'h' if signed else 'H'
|
128
|
+
elif length == 1: # unpack to 1-byte integer (char)
|
129
|
+
struct_fmt = 'b' if signed else 'B'
|
130
|
+
else: # do not unpack
|
131
|
+
struct_fmt = f'{length}s'
|
132
|
+
self._need_process = True
|
133
|
+
return struct_fmt
|
134
|
+
|
135
|
+
def pre_process(self, value: 'int', packet: 'dict[str, Any]') -> 'int | bytes': # pylint: disable=unused-argument
|
136
|
+
"""Process field value before construction (packing).
|
137
|
+
|
138
|
+
Arguments:
|
139
|
+
value: Field value.
|
140
|
+
packet: Packet data.
|
141
|
+
|
142
|
+
Returns:
|
143
|
+
Processed field value.
|
144
|
+
|
145
|
+
"""
|
146
|
+
value = value & self._bit_mask
|
147
|
+
if not self._need_process:
|
148
|
+
return value
|
149
|
+
|
150
|
+
if self._length < 0:
|
151
|
+
self._length = math.ceil(value.bit_length() // 8)
|
152
|
+
|
153
|
+
endian = '>' if self._byteorder == 'big' else '<'
|
154
|
+
struct_fmt = self.build_template(self._length, self._signed)
|
155
|
+
|
156
|
+
self._template = f'{endian}{struct_fmt}'
|
157
|
+
|
158
|
+
return value.to_bytes(
|
159
|
+
self._length, self._byteorder, signed=self._signed
|
160
|
+
)
|
161
|
+
|
162
|
+
def post_process(self, value: 'int | bytes', packet: 'dict[str, Any]') -> 'int': # pylint: disable=unused-argument
|
163
|
+
"""Process field value after parsing (unpacked).
|
164
|
+
|
165
|
+
Args:
|
166
|
+
value: Field value.
|
167
|
+
packet: Packet data.
|
168
|
+
|
169
|
+
Returns:
|
170
|
+
Processed field value.
|
171
|
+
|
172
|
+
"""
|
173
|
+
if not self._need_process:
|
174
|
+
return cast('int', value) & self._bit_mask
|
175
|
+
return int.from_bytes(
|
176
|
+
cast('bytes', value), self._byteorder, signed=self._signed
|
177
|
+
) & self._bit_mask
|
178
|
+
|
179
|
+
|
180
|
+
class Int32Field(NumberField):
|
181
|
+
"""Integer value for protocol fields.
|
182
|
+
|
183
|
+
Args:
|
184
|
+
length: Field size (in bytes).
|
185
|
+
default: Field default value, if any.
|
186
|
+
signed: Whether the field is signed.
|
187
|
+
byteorder: Field byte order.
|
188
|
+
bit_length: Field bit length.
|
189
|
+
callback: Callback function to be called upon
|
190
|
+
:meth:`self.__call__ <pcapkit.corekit.fields.field.FieldBase.__call__>`.
|
191
|
+
|
192
|
+
"""
|
193
|
+
|
194
|
+
__length__ = 4
|
195
|
+
__template__ = 'i'
|
196
|
+
__signed__ = True
|
197
|
+
|
198
|
+
|
199
|
+
class UInt32Field(NumberField):
|
200
|
+
"""Unsigned integer value for protocol fields.
|
201
|
+
|
202
|
+
Args:
|
203
|
+
length: Field size (in bytes).
|
204
|
+
default: Field default value, if any.
|
205
|
+
signed: Whether the field is signed.
|
206
|
+
byteorder: Field byte order.
|
207
|
+
bit_length: Field bit length.
|
208
|
+
callback: Callback function to be called upon
|
209
|
+
:meth:`self.__call__ <pcapkit.corekit.fields.field.FieldBase.__call__>`.
|
210
|
+
|
211
|
+
"""
|
212
|
+
|
213
|
+
__length__ = 4
|
214
|
+
__template__ = 'I'
|
215
|
+
__signed__ = False
|
216
|
+
|
217
|
+
|
218
|
+
class Int16Field(NumberField):
|
219
|
+
"""Short integer value for protocol fields.
|
220
|
+
|
221
|
+
Args:
|
222
|
+
length: Field size (in bytes).
|
223
|
+
default: Field default value, if any.
|
224
|
+
signed: Whether the field is signed.
|
225
|
+
byteorder: Field byte order.
|
226
|
+
bit_length: Field bit length.
|
227
|
+
callback: Callback function to be called upon
|
228
|
+
:meth:`self.__call__ <pcapkit.corekit.fields.field.FieldBase.__call__>`.
|
229
|
+
|
230
|
+
"""
|
231
|
+
|
232
|
+
__length__ = 2
|
233
|
+
__template__ = 'h'
|
234
|
+
__signed__ = True
|
235
|
+
|
236
|
+
|
237
|
+
class UInt16Field(NumberField):
|
238
|
+
"""Unsigned short integer value for protocol fields.
|
239
|
+
|
240
|
+
Args:
|
241
|
+
length: Field size (in bytes).
|
242
|
+
default: Field default value, if any.
|
243
|
+
signed: Whether the field is signed.
|
244
|
+
byteorder: Field byte order.
|
245
|
+
bit_length: Field bit length.
|
246
|
+
callback: Callback function to be called upon
|
247
|
+
:meth:`self.__call__ <pcapkit.corekit.fields.field.FieldBase.__call__>`.
|
248
|
+
|
249
|
+
"""
|
250
|
+
|
251
|
+
__length__ = 2
|
252
|
+
__template__ = 'H'
|
253
|
+
__signed__ = False
|
254
|
+
|
255
|
+
|
256
|
+
class Int64Field(NumberField):
|
257
|
+
"""Long integer value for protocol fields.
|
258
|
+
|
259
|
+
Args:
|
260
|
+
length: Field size (in bytes).
|
261
|
+
default: Field default value, if any.
|
262
|
+
signed: Whether the field is signed.
|
263
|
+
byteorder: Field byte order.
|
264
|
+
bit_length: Field bit length.
|
265
|
+
callback: Callback function to be called upon
|
266
|
+
:meth:`self.__call__ <pcapkit.corekit.fields.field.FieldBase.__call__>`.
|
267
|
+
|
268
|
+
"""
|
269
|
+
|
270
|
+
__length__ = 8
|
271
|
+
__template__ = 'q'
|
272
|
+
__signed__ = True
|
273
|
+
|
274
|
+
|
275
|
+
class UInt64Field(NumberField):
|
276
|
+
"""Unsigned long integer value for protocol fields.
|
277
|
+
|
278
|
+
Args:
|
279
|
+
length: Field size (in bytes).
|
280
|
+
default: Field default value, if any.
|
281
|
+
signed: Whether the field is signed.
|
282
|
+
byteorder: Field byte order.
|
283
|
+
bit_length: Field bit length.
|
284
|
+
callback: Callback function to be called upon
|
285
|
+
:meth:`self.__call__ <pcapkit.corekit.fields.field.FieldBase.__call__>`.
|
286
|
+
|
287
|
+
"""
|
288
|
+
|
289
|
+
__length__ = 8
|
290
|
+
__template__ = 'Q'
|
291
|
+
__signed__ = False
|
292
|
+
|
293
|
+
|
294
|
+
class Int8Field(NumberField):
|
295
|
+
"""Byte value for protocol fields.
|
296
|
+
|
297
|
+
Args:
|
298
|
+
length: Field size (in bytes).
|
299
|
+
default: Field default value, if any.
|
300
|
+
signed: Whether the field is signed.
|
301
|
+
byteorder: Field byte order.
|
302
|
+
bit_length: Field bit length.
|
303
|
+
callback: Callback function to be called upon
|
304
|
+
:meth:`self.__call__ <pcapkit.corekit.fields.field.FieldBase.__call__>`.
|
305
|
+
|
306
|
+
"""
|
307
|
+
|
308
|
+
__length__ = 1
|
309
|
+
__template__ = 'b'
|
310
|
+
__signed__ = True
|
311
|
+
|
312
|
+
|
313
|
+
class UInt8Field(NumberField):
|
314
|
+
"""Unsigned byte value for protocol fields.
|
315
|
+
|
316
|
+
Args:
|
317
|
+
length: Field size (in bytes).
|
318
|
+
default: Field default value, if any.
|
319
|
+
signed: Whether the field is signed.
|
320
|
+
byteorder: Field byte order.
|
321
|
+
bit_length: Field bit length.
|
322
|
+
callback: Callback function to be called upon
|
323
|
+
:meth:`self.__call__ <pcapkit.corekit.fields.field.FieldBase.__call__>`.
|
324
|
+
|
325
|
+
"""
|
326
|
+
|
327
|
+
__length__ = 1
|
328
|
+
__template__ = 'B'
|
329
|
+
__signed__ = False
|
330
|
+
|
331
|
+
|
332
|
+
class EnumField(NumberField[Union[enum.IntEnum, aenum.IntEnum]]):
|
333
|
+
"""Enumerated value for protocol fields.
|
334
|
+
|
335
|
+
Args:
|
336
|
+
length: Field size (in bytes); if a callable is given, it should return
|
337
|
+
an integer value and accept the current packet as its only argument.
|
338
|
+
default: Field default value, if any.
|
339
|
+
signed: Whether the field is signed.
|
340
|
+
byteorder: Field byte order.
|
341
|
+
bit_length: Field bit length.
|
342
|
+
namespace: Field namespace (a :class:`enum.IntEnum` class).
|
343
|
+
callback: Callback function to be called upon
|
344
|
+
:meth:`self.__call__ <pcapkit.corekit.fields.field.FieldBase.__call__>`.
|
345
|
+
|
346
|
+
"""
|
347
|
+
|
348
|
+
def __init__(self, length: 'int | Callable[[dict[str, Any]], int]',
|
349
|
+
default: 'StdlibEnum | AenumEnum | NoValueType' = NoValue, signed: 'bool' = False,
|
350
|
+
byteorder: 'Literal["little", "big"]' = 'big',
|
351
|
+
bit_length: 'Optional[int]' = None,
|
352
|
+
namespace: 'Optional[Type[StdlibEnum] | Type[AenumEnum]]' = None,
|
353
|
+
callback: 'Callable[[Self, dict[str, Any]], None]' = lambda *_: None) -> 'None':
|
354
|
+
super().__init__(length, default, signed, byteorder, bit_length, callback)
|
355
|
+
|
356
|
+
self._namespace = namespace
|
357
|
+
|
358
|
+
def post_process(self, value: 'int | bytes', packet: 'dict[str, Any]') -> 'StdlibEnum | AenumEnum':
|
359
|
+
"""Process field value after parsing (unpacked).
|
360
|
+
|
361
|
+
Args:
|
362
|
+
value: Field value.
|
363
|
+
packet: Packet data.
|
364
|
+
|
365
|
+
Returns:
|
366
|
+
Processed field value.
|
367
|
+
|
368
|
+
"""
|
369
|
+
value = super().post_process(value, packet)
|
370
|
+
if self._namespace is None:
|
371
|
+
unknown = enum.IntEnum('<unknown>', {
|
372
|
+
'<unassigned>': value,
|
373
|
+
}, module='pcapkit.const', qualname='pcapkit.const.<unknown>')
|
374
|
+
return getattr(unknown, '<unassigned>')
|
375
|
+
return self._namespace(value)
|
@@ -0,0 +1,245 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""text field class"""
|
3
|
+
|
4
|
+
import urllib.parse as urllib_parse
|
5
|
+
from typing import TYPE_CHECKING, Any, Generic, TypeVar
|
6
|
+
|
7
|
+
import chardet
|
8
|
+
|
9
|
+
from pcapkit.corekit.fields.field import Field, NoValue
|
10
|
+
from pcapkit.utilities.compat import Dict
|
11
|
+
|
12
|
+
__all__ = [
|
13
|
+
'_TextField',
|
14
|
+
'StringField',
|
15
|
+
'BitField',
|
16
|
+
'PaddingField',
|
17
|
+
]
|
18
|
+
|
19
|
+
if TYPE_CHECKING:
|
20
|
+
from typing import Callable, Optional, Tuple
|
21
|
+
|
22
|
+
from typing_extensions import Literal, Self
|
23
|
+
|
24
|
+
from pcapkit.corekit.fields.field import NoValueType
|
25
|
+
|
26
|
+
NamespaceEntry = Tuple[int, int]
|
27
|
+
|
28
|
+
_T = TypeVar('_T', 'str', 'bytes', 'dict[str, Any]')
|
29
|
+
|
30
|
+
|
31
|
+
class _TextField(Field[_T], Generic[_T]):
|
32
|
+
"""Internal text value for protocol fields.
|
33
|
+
|
34
|
+
Args:
|
35
|
+
length: Field size (in bytes); if a callable is given, it should return
|
36
|
+
an integer value and accept the current packet as its only argument.
|
37
|
+
default: Field default value, if any.
|
38
|
+
callback: Callback function to be called upon
|
39
|
+
:meth:`self.__call__ <pcapkit.corekit.fields.field.FieldBase.__call__>`.
|
40
|
+
|
41
|
+
"""
|
42
|
+
|
43
|
+
def __init__(self, length: 'int | Callable[[dict[str, Any]], int]',
|
44
|
+
default: '_T | NoValueType' = NoValue,
|
45
|
+
callback: 'Callable[[Self, dict[str, Any]], None]' = lambda *_: None) -> 'None':
|
46
|
+
super().__init__(length, default, callback) # type: ignore[arg-type]
|
47
|
+
|
48
|
+
self._template = f'{self._length}s' if self._length >= 0 else '1024s' # reasonable default
|
49
|
+
|
50
|
+
def __call__(self, packet: 'dict[str, Any]') -> 'Self':
|
51
|
+
"""Update field attributes.
|
52
|
+
|
53
|
+
Args:
|
54
|
+
packet: Packet data.
|
55
|
+
|
56
|
+
Returns:
|
57
|
+
New instance of :class:`_TextField`.
|
58
|
+
|
59
|
+
This method will return a new instance of :class:`_TextField` instead of
|
60
|
+
updating the current instance.
|
61
|
+
|
62
|
+
"""
|
63
|
+
new_self = super().__call__(packet)
|
64
|
+
new_self._template = f'{new_self._length}s'
|
65
|
+
return new_self
|
66
|
+
|
67
|
+
|
68
|
+
class BytesField(_TextField[bytes]):
|
69
|
+
"""Bytes value for protocol fields.
|
70
|
+
|
71
|
+
Args:
|
72
|
+
length: Field size (in bytes); if a callable is given, it should return
|
73
|
+
an integer value and accept the current packet as its only argument.
|
74
|
+
default: Field default value, if any.
|
75
|
+
callback: Callback function to be called upon
|
76
|
+
:meth:`self.__call__ <pcapkit.corekit.fields.field.FieldBase.__call__>`.
|
77
|
+
|
78
|
+
"""
|
79
|
+
|
80
|
+
def pre_process(self, value: 'bytes', packet: 'dict[str, Any]') -> 'bytes': # pylint: disable=unused-argument
|
81
|
+
"""Process field value before construction (packing).
|
82
|
+
|
83
|
+
Arguments:
|
84
|
+
value: Field value.
|
85
|
+
packet: Packet data.
|
86
|
+
|
87
|
+
Returns:
|
88
|
+
Processed field value.
|
89
|
+
|
90
|
+
"""
|
91
|
+
if self._length < 0:
|
92
|
+
self._length = len(value)
|
93
|
+
self._template = f'{self._length}s'
|
94
|
+
return value
|
95
|
+
|
96
|
+
|
97
|
+
class StringField(_TextField[str]):
|
98
|
+
r"""String value for protocol fields.
|
99
|
+
|
100
|
+
Args:
|
101
|
+
length: Field size (in bytes); if a callable is given, it should return
|
102
|
+
an integer value and accept the current packet as its only argument.
|
103
|
+
default: Field default value, if any.
|
104
|
+
encoding: The encoding with which to decode the :obj:`bytes`.
|
105
|
+
If not provided, :mod:`pcapkit` will first try detecting its encoding
|
106
|
+
using |chardet|_. The fallback encoding would is **UTF-8**.
|
107
|
+
errors: The error handling scheme to use for the handling of decoding errors.
|
108
|
+
The default is ``'strict'`` meaning that decoding errors raise a
|
109
|
+
:exc:`UnicodeDecodeError`. Other possible values are ``'ignore'`` and ``'replace'``
|
110
|
+
as well as any other name registered with :func:`codecs.register_error` that
|
111
|
+
can handle :exc:`UnicodeDecodeError`.
|
112
|
+
unquote: Whether to unquote the decoded string as a URL. Should decoding failed ,
|
113
|
+
the method will try again replacing ``'%'`` with ``'\x'`` then decoding the
|
114
|
+
``url`` as ``'utf-8'`` with ``'replace'`` for error handling.
|
115
|
+
callback: Callback function to be called upon
|
116
|
+
:meth:`self.__call__ <pcapkit.corekit.fields.field.FieldBase.__call__>`.
|
117
|
+
|
118
|
+
.. |chardet| replace:: ``chardet``
|
119
|
+
.. _chardet: https://chardet.readthedocs.io
|
120
|
+
|
121
|
+
"""
|
122
|
+
|
123
|
+
def __init__(self, length: 'int | Callable[[dict[str, Any]], int]',
|
124
|
+
default: 'str | NoValueType' = NoValue, encoding: 'Optional[str]' = None,
|
125
|
+
errors: 'Literal["strict", "ignore", "replace"]' = 'strict',
|
126
|
+
unquote: 'bool' = False,
|
127
|
+
callback: 'Callable[[Self, dict[str, Any]], None]' = lambda *_: None) -> 'None':
|
128
|
+
super().__init__(length, default, callback)
|
129
|
+
|
130
|
+
self._encoding = encoding
|
131
|
+
self._errors = errors
|
132
|
+
self._unquote = unquote
|
133
|
+
|
134
|
+
def pre_process(self, value: 'str', packet: 'dict[str, Any]') -> 'bytes': # pylint: disable=unused-argument
|
135
|
+
"""Process field value before construction (packing).
|
136
|
+
|
137
|
+
Arguments:
|
138
|
+
value: Field value.
|
139
|
+
packet: Packet data.
|
140
|
+
|
141
|
+
Returns:
|
142
|
+
Processed field value.
|
143
|
+
|
144
|
+
"""
|
145
|
+
if self._unquote:
|
146
|
+
value = urllib_parse.quote(value, encoding=self._encoding or 'utf-8', errors=self._errors)
|
147
|
+
|
148
|
+
if self._length < 0:
|
149
|
+
self._length = len(value)
|
150
|
+
self._template = f'{self._length}s'
|
151
|
+
return value.encode(self._encoding or 'utf-8', self._errors)
|
152
|
+
|
153
|
+
def post_process(self, value: 'bytes', packet: 'dict[str, Any]') -> 'str': # pylint: disable=unused-argument
|
154
|
+
"""Process field value after parsing (unpacked).
|
155
|
+
|
156
|
+
Arguments:
|
157
|
+
value: Field value.
|
158
|
+
packet: Packet data.
|
159
|
+
|
160
|
+
Returns:
|
161
|
+
Processed field value.
|
162
|
+
|
163
|
+
"""
|
164
|
+
if self._unquote:
|
165
|
+
try:
|
166
|
+
ret = urllib_parse.unquote(value, encoding=self._encoding or 'utf-8', errors=self._errors)
|
167
|
+
except UnicodeError:
|
168
|
+
ret = urllib_parse.unquote(value.replace(b'%', rb'\x'), encoding='utf-8', errors='replace')
|
169
|
+
else:
|
170
|
+
charset = self._encoding or chardet.detect(value)['encoding'] or 'utf-8'
|
171
|
+
try:
|
172
|
+
ret = value.decode(charset, self._errors)
|
173
|
+
except UnicodeError:
|
174
|
+
ret = value.decode(charset, 'replace')
|
175
|
+
return ret
|
176
|
+
|
177
|
+
|
178
|
+
class BitField(_TextField[Dict[str, Any]]):
|
179
|
+
"""Bit value for protocol fields.
|
180
|
+
|
181
|
+
Args:
|
182
|
+
length: Field size (in bytes).
|
183
|
+
default: Field default value, if any.
|
184
|
+
namespace: Field namespace (a dict mapping field name to a tuple of start index,
|
185
|
+
and length of the subfield).
|
186
|
+
callback: Callback function to be called upon
|
187
|
+
:meth:`self.__call__ <pcapkit.corekit.fields.field.FieldBase.__call__>`.
|
188
|
+
|
189
|
+
"""
|
190
|
+
|
191
|
+
def __init__(self, length: 'int',
|
192
|
+
default: 'dict[str, Any] | NoValueType' = NoValue,
|
193
|
+
namespace: 'Optional[dict[str, NamespaceEntry]]' = None,
|
194
|
+
callback: 'Callable[[Self, dict[str, Any]], None]' = lambda *_: None) -> 'None':
|
195
|
+
super().__init__(length, default, callback)
|
196
|
+
|
197
|
+
self._namespace = namespace or {}
|
198
|
+
|
199
|
+
def pre_process(self, value: 'dict[str, Any]', packet: 'dict[str, Any]') -> 'bytes': # pylint: disable=unused-argument
|
200
|
+
"""Process field value before construction (packing).
|
201
|
+
|
202
|
+
Arguments:
|
203
|
+
value: Field value.
|
204
|
+
packet: Packet data.
|
205
|
+
|
206
|
+
Returns:
|
207
|
+
Processed field value.
|
208
|
+
|
209
|
+
"""
|
210
|
+
buffer = bytearray(self.length * 8)
|
211
|
+
for name, (start, len) in self._namespace.items():
|
212
|
+
end = start + len
|
213
|
+
buffer[start:end] = f'{value[name]:0{end - start}b}'.encode()
|
214
|
+
return int(b''.join(map(lambda x: b'1' if x else b'0', buffer)), 2).to_bytes(self.length, 'big')
|
215
|
+
|
216
|
+
def post_process(self, value: 'bytes', packet: 'dict[str, Any]') -> 'dict[str, Any]': # pylint: disable=unused-argument
|
217
|
+
"""Process field value after parsing (unpacked).
|
218
|
+
|
219
|
+
Arguments:
|
220
|
+
value: Field value.
|
221
|
+
packet: Packet data.
|
222
|
+
|
223
|
+
Returns:
|
224
|
+
Processed field value.
|
225
|
+
|
226
|
+
"""
|
227
|
+
buffer = {}
|
228
|
+
binary = ''.join(f'{byte:08b}' for byte in value)
|
229
|
+
for name, (start, len) in self._namespace.items():
|
230
|
+
end = start + len
|
231
|
+
buffer[name] = int(binary[start:end], 2)
|
232
|
+
return buffer
|
233
|
+
|
234
|
+
|
235
|
+
class PaddingField(BytesField):
|
236
|
+
"""Bytes value for protocol fields.
|
237
|
+
|
238
|
+
Args:
|
239
|
+
length: Field size (in bytes); if a callable is given, it should return
|
240
|
+
an integer value and accept the current packet as its only argument.
|
241
|
+
default: Field default value, if any.
|
242
|
+
callback: Callback function to be called upon
|
243
|
+
:meth:`self.__call__ <pcapkit.corekit.fields.field.FieldBase.__call__>`.
|
244
|
+
|
245
|
+
"""
|