@netkitty/codec 1.0.0
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.
- package/CHANGELOG.md +17 -0
- package/LICENSE +21 -0
- package/README.md +352 -0
- package/README.zh-CN.md +342 -0
- package/dist/Codec.d.ts +133 -0
- package/dist/Codec.js +632 -0
- package/dist/PacketHeaders.d.ts +189 -0
- package/dist/PacketHeaders.js +384 -0
- package/dist/abstracts/BaseHeader.d.ts +325 -0
- package/dist/abstracts/BaseHeader.js +734 -0
- package/dist/errors/CodecSchemaValidateError.d.ts +4 -0
- package/dist/errors/CodecSchemaValidateError.js +11 -0
- package/dist/headers/ADSAMS.d.ts +33 -0
- package/dist/headers/ADSAMS.js +208 -0
- package/dist/headers/AH.d.ts +28 -0
- package/dist/headers/AH.js +137 -0
- package/dist/headers/AMQP.d.ts +31 -0
- package/dist/headers/AMQP.js +316 -0
- package/dist/headers/ARP.d.ts +26 -0
- package/dist/headers/ARP.js +243 -0
- package/dist/headers/BACnetIP.d.ts +27 -0
- package/dist/headers/BACnetIP.js +97 -0
- package/dist/headers/BFD.d.ts +28 -0
- package/dist/headers/BFD.js +155 -0
- package/dist/headers/BGP.d.ts +27 -0
- package/dist/headers/BGP.js +111 -0
- package/dist/headers/BSAPIP.d.ts +33 -0
- package/dist/headers/BSAPIP.js +78 -0
- package/dist/headers/Babel.d.ts +32 -0
- package/dist/headers/Babel.js +224 -0
- package/dist/headers/BitTorrent.d.ts +28 -0
- package/dist/headers/BitTorrent.js +72 -0
- package/dist/headers/C37118.d.ts +26 -0
- package/dist/headers/C37118.js +147 -0
- package/dist/headers/CAPWAP.d.ts +38 -0
- package/dist/headers/CAPWAP.js +275 -0
- package/dist/headers/CDP.d.ts +25 -0
- package/dist/headers/CDP.js +117 -0
- package/dist/headers/CMS.d.ts +33 -0
- package/dist/headers/CMS.js +238 -0
- package/dist/headers/COTP.d.ts +30 -0
- package/dist/headers/COTP.js +193 -0
- package/dist/headers/CassandraCQL.d.ts +28 -0
- package/dist/headers/CassandraCQL.js +117 -0
- package/dist/headers/CoAP.d.ts +29 -0
- package/dist/headers/CoAP.js +140 -0
- package/dist/headers/Codesys.d.ts +32 -0
- package/dist/headers/Codesys.js +119 -0
- package/dist/headers/Collectd.d.ts +29 -0
- package/dist/headers/Collectd.js +154 -0
- package/dist/headers/DCCP.d.ts +30 -0
- package/dist/headers/DCCP.js +204 -0
- package/dist/headers/DHCP.d.ts +26 -0
- package/dist/headers/DHCP.js +148 -0
- package/dist/headers/DHCPFailover.d.ts +30 -0
- package/dist/headers/DHCPFailover.js +104 -0
- package/dist/headers/DHCPv6.d.ts +25 -0
- package/dist/headers/DHCPv6.js +145 -0
- package/dist/headers/DNP3.d.ts +27 -0
- package/dist/headers/DNP3.js +150 -0
- package/dist/headers/DNS.d.ts +55 -0
- package/dist/headers/DNS.js +309 -0
- package/dist/headers/DTLS.d.ts +33 -0
- package/dist/headers/DTLS.js +142 -0
- package/dist/headers/Diameter.d.ts +34 -0
- package/dist/headers/Diameter.js +229 -0
- package/dist/headers/EAPOL.d.ts +32 -0
- package/dist/headers/EAPOL.js +135 -0
- package/dist/headers/EIGRP.d.ts +28 -0
- package/dist/headers/EIGRP.js +165 -0
- package/dist/headers/ENIP.d.ts +31 -0
- package/dist/headers/ENIP.js +164 -0
- package/dist/headers/ESP.d.ts +27 -0
- package/dist/headers/ESP.js +140 -0
- package/dist/headers/Elasticsearch.d.ts +30 -0
- package/dist/headers/Elasticsearch.js +125 -0
- package/dist/headers/EtherCAT.d.ts +35 -0
- package/dist/headers/EtherCAT.js +150 -0
- package/dist/headers/EthernetII.d.ts +28 -0
- package/dist/headers/EthernetII.js +117 -0
- package/dist/headers/FCoE.d.ts +38 -0
- package/dist/headers/FCoE.js +210 -0
- package/dist/headers/FTP.d.ts +34 -0
- package/dist/headers/FTP.js +158 -0
- package/dist/headers/Finger.d.ts +41 -0
- package/dist/headers/Finger.js +135 -0
- package/dist/headers/FoundationFieldbusHSE.d.ts +43 -0
- package/dist/headers/FoundationFieldbusHSE.js +163 -0
- package/dist/headers/GELF.d.ts +35 -0
- package/dist/headers/GELF.js +261 -0
- package/dist/headers/GENEVE.d.ts +26 -0
- package/dist/headers/GENEVE.js +209 -0
- package/dist/headers/GESRTP.d.ts +32 -0
- package/dist/headers/GESRTP.js +141 -0
- package/dist/headers/GLBP.d.ts +29 -0
- package/dist/headers/GLBP.js +159 -0
- package/dist/headers/GRE.d.ts +27 -0
- package/dist/headers/GRE.js +181 -0
- package/dist/headers/GTPU.d.ts +25 -0
- package/dist/headers/GTPU.js +203 -0
- package/dist/headers/GTPv2C.d.ts +30 -0
- package/dist/headers/GTPv2C.js +281 -0
- package/dist/headers/GitProtocol.d.ts +34 -0
- package/dist/headers/GitProtocol.js +141 -0
- package/dist/headers/Goose.d.ts +115 -0
- package/dist/headers/Goose.js +1067 -0
- package/dist/headers/Gopher.d.ts +43 -0
- package/dist/headers/Gopher.js +182 -0
- package/dist/headers/HARTIP.d.ts +30 -0
- package/dist/headers/HARTIP.js +145 -0
- package/dist/headers/HSR.d.ts +27 -0
- package/dist/headers/HSR.js +105 -0
- package/dist/headers/HSRP.d.ts +26 -0
- package/dist/headers/HSRP.js +173 -0
- package/dist/headers/HTTP.d.ts +32 -0
- package/dist/headers/HTTP.js +153 -0
- package/dist/headers/HTTP2.d.ts +34 -0
- package/dist/headers/HTTP2.js +190 -0
- package/dist/headers/IAX2.d.ts +33 -0
- package/dist/headers/IAX2.js +274 -0
- package/dist/headers/ICMP.d.ts +15 -0
- package/dist/headers/ICMP.js +148 -0
- package/dist/headers/ICMPv6.d.ts +15 -0
- package/dist/headers/ICMPv6.js +129 -0
- package/dist/headers/IEC104_I_Frame.d.ts +23 -0
- package/dist/headers/IEC104_I_Frame.js +6489 -0
- package/dist/headers/IEC104_S_Frame.d.ts +26 -0
- package/dist/headers/IEC104_S_Frame.js +135 -0
- package/dist/headers/IEC104_U_Frame.d.ts +27 -0
- package/dist/headers/IEC104_U_Frame.js +176 -0
- package/dist/headers/IEC61850SampledValues.d.ts +20 -0
- package/dist/headers/IEC61850SampledValues.js +420 -0
- package/dist/headers/IGMP.d.ts +31 -0
- package/dist/headers/IGMP.js +274 -0
- package/dist/headers/IMAP.d.ts +32 -0
- package/dist/headers/IMAP.js +185 -0
- package/dist/headers/IPFIX.d.ts +29 -0
- package/dist/headers/IPFIX.js +156 -0
- package/dist/headers/IPv4.d.ts +20 -0
- package/dist/headers/IPv4.js +370 -0
- package/dist/headers/IPv6.d.ts +29 -0
- package/dist/headers/IPv6.js +209 -0
- package/dist/headers/IPv6HopByHopOptions.d.ts +81 -0
- package/dist/headers/IPv6HopByHopOptions.js +495 -0
- package/dist/headers/IRC.d.ts +34 -0
- package/dist/headers/IRC.js +175 -0
- package/dist/headers/ISAKMP.d.ts +29 -0
- package/dist/headers/ISAKMP.js +197 -0
- package/dist/headers/ISCSI.d.ts +39 -0
- package/dist/headers/ISCSI.js +289 -0
- package/dist/headers/ISIS.d.ts +25 -0
- package/dist/headers/ISIS.js +79 -0
- package/dist/headers/ISOSession.d.ts +27 -0
- package/dist/headers/ISOSession.js +343 -0
- package/dist/headers/Ident.d.ts +42 -0
- package/dist/headers/Ident.js +184 -0
- package/dist/headers/KNXnetIP.d.ts +30 -0
- package/dist/headers/KNXnetIP.js +135 -0
- package/dist/headers/Kafka.d.ts +35 -0
- package/dist/headers/Kafka.js +128 -0
- package/dist/headers/Kerberos.d.ts +30 -0
- package/dist/headers/Kerberos.js +217 -0
- package/dist/headers/L2TP.d.ts +26 -0
- package/dist/headers/L2TP.js +297 -0
- package/dist/headers/LACP.d.ts +31 -0
- package/dist/headers/LACP.js +151 -0
- package/dist/headers/LDAP.d.ts +31 -0
- package/dist/headers/LDAP.js +226 -0
- package/dist/headers/LDP.d.ts +31 -0
- package/dist/headers/LDP.js +138 -0
- package/dist/headers/LISP.d.ts +30 -0
- package/dist/headers/LISP.js +103 -0
- package/dist/headers/LLC.d.ts +27 -0
- package/dist/headers/LLC.js +81 -0
- package/dist/headers/LLDP.d.ts +26 -0
- package/dist/headers/LLDP.js +126 -0
- package/dist/headers/LLMNR.d.ts +23 -0
- package/dist/headers/LLMNR.js +40 -0
- package/dist/headers/LPD.d.ts +31 -0
- package/dist/headers/LPD.js +159 -0
- package/dist/headers/MACsec.d.ts +34 -0
- package/dist/headers/MACsec.js +178 -0
- package/dist/headers/MDNS.d.ts +26 -0
- package/dist/headers/MDNS.js +45 -0
- package/dist/headers/MGCP.d.ts +30 -0
- package/dist/headers/MGCP.js +155 -0
- package/dist/headers/MMS.d.ts +29 -0
- package/dist/headers/MMS.js +243 -0
- package/dist/headers/MPLS.d.ts +31 -0
- package/dist/headers/MPLS.js +145 -0
- package/dist/headers/MQTT.d.ts +30 -0
- package/dist/headers/MQTT.js +173 -0
- package/dist/headers/MQTTSN.d.ts +34 -0
- package/dist/headers/MQTTSN.js +177 -0
- package/dist/headers/MarkerProtocol.d.ts +32 -0
- package/dist/headers/MarkerProtocol.js +153 -0
- package/dist/headers/Megaco.d.ts +32 -0
- package/dist/headers/Megaco.js +144 -0
- package/dist/headers/Memcached.d.ts +44 -0
- package/dist/headers/Memcached.js +285 -0
- package/dist/headers/ModbusTCP.d.ts +25 -0
- package/dist/headers/ModbusTCP.js +99 -0
- package/dist/headers/ModbusUDP.d.ts +26 -0
- package/dist/headers/ModbusUDP.js +100 -0
- package/dist/headers/MongoDB.d.ts +33 -0
- package/dist/headers/MongoDB.js +143 -0
- package/dist/headers/MySQL.d.ts +30 -0
- package/dist/headers/MySQL.js +114 -0
- package/dist/headers/NATS.d.ts +29 -0
- package/dist/headers/NATS.js +135 -0
- package/dist/headers/NBDS.d.ts +34 -0
- package/dist/headers/NBDS.js +176 -0
- package/dist/headers/NBNS.d.ts +34 -0
- package/dist/headers/NBNS.js +78 -0
- package/dist/headers/NBSS.d.ts +36 -0
- package/dist/headers/NBSS.js +137 -0
- package/dist/headers/NFS.d.ts +36 -0
- package/dist/headers/NFS.js +273 -0
- package/dist/headers/NHRP.d.ts +32 -0
- package/dist/headers/NHRP.js +154 -0
- package/dist/headers/NNTP.d.ts +35 -0
- package/dist/headers/NNTP.js +162 -0
- package/dist/headers/NTP.d.ts +18 -0
- package/dist/headers/NTP.js +73 -0
- package/dist/headers/NetFlowV5.d.ts +28 -0
- package/dist/headers/NetFlowV5.js +205 -0
- package/dist/headers/OLSR.d.ts +31 -0
- package/dist/headers/OLSR.js +213 -0
- package/dist/headers/OPCUA.d.ts +33 -0
- package/dist/headers/OPCUA.js +165 -0
- package/dist/headers/OPCUAPubSub.d.ts +33 -0
- package/dist/headers/OPCUAPubSub.js +144 -0
- package/dist/headers/OSPF.d.ts +31 -0
- package/dist/headers/OSPF.js +365 -0
- package/dist/headers/OmronFINS.d.ts +31 -0
- package/dist/headers/OmronFINS.js +90 -0
- package/dist/headers/OpenFlow.d.ts +30 -0
- package/dist/headers/OpenFlow.js +113 -0
- package/dist/headers/OpenVPN.d.ts +35 -0
- package/dist/headers/OpenVPN.js +214 -0
- package/dist/headers/PCWorx.d.ts +35 -0
- package/dist/headers/PCWorx.js +115 -0
- package/dist/headers/PIM.d.ts +27 -0
- package/dist/headers/PIM.js +129 -0
- package/dist/headers/POP3.d.ts +31 -0
- package/dist/headers/POP3.js +152 -0
- package/dist/headers/POWERLINK.d.ts +28 -0
- package/dist/headers/POWERLINK.js +116 -0
- package/dist/headers/PPPoEDiscovery.d.ts +29 -0
- package/dist/headers/PPPoEDiscovery.js +198 -0
- package/dist/headers/PPPoESession.d.ts +28 -0
- package/dist/headers/PPPoESession.js +125 -0
- package/dist/headers/PPTP.d.ts +30 -0
- package/dist/headers/PPTP.js +122 -0
- package/dist/headers/PROFINETRT.d.ts +28 -0
- package/dist/headers/PROFINETRT.js +74 -0
- package/dist/headers/PTP.d.ts +34 -0
- package/dist/headers/PTP.js +213 -0
- package/dist/headers/PostgreSQL.d.ts +40 -0
- package/dist/headers/PostgreSQL.js +236 -0
- package/dist/headers/QUIC.d.ts +34 -0
- package/dist/headers/QUIC.js +308 -0
- package/dist/headers/RADIUS.d.ts +24 -0
- package/dist/headers/RADIUS.js +138 -0
- package/dist/headers/RDP.d.ts +27 -0
- package/dist/headers/RDP.js +93 -0
- package/dist/headers/RFB.d.ts +39 -0
- package/dist/headers/RFB.js +151 -0
- package/dist/headers/RGoose.d.ts +72 -0
- package/dist/headers/RGoose.js +340 -0
- package/dist/headers/RIP.d.ts +29 -0
- package/dist/headers/RIP.js +133 -0
- package/dist/headers/RIPng.d.ts +26 -0
- package/dist/headers/RIPng.js +140 -0
- package/dist/headers/RMCP.d.ts +26 -0
- package/dist/headers/RMCP.js +155 -0
- package/dist/headers/RSVP.d.ts +31 -0
- package/dist/headers/RSVP.js +263 -0
- package/dist/headers/RTCP.d.ts +34 -0
- package/dist/headers/RTCP.js +217 -0
- package/dist/headers/RTP.d.ts +33 -0
- package/dist/headers/RTP.js +291 -0
- package/dist/headers/RTPS.d.ts +33 -0
- package/dist/headers/RTPS.js +182 -0
- package/dist/headers/RTSP.d.ts +36 -0
- package/dist/headers/RTSP.js +184 -0
- package/dist/headers/RawData.d.ts +17 -0
- package/dist/headers/RawData.js +43 -0
- package/dist/headers/Redis.d.ts +32 -0
- package/dist/headers/Redis.js +202 -0
- package/dist/headers/Rlogin.d.ts +42 -0
- package/dist/headers/Rlogin.js +139 -0
- package/dist/headers/Rsync.d.ts +28 -0
- package/dist/headers/Rsync.js +117 -0
- package/dist/headers/S7comm.d.ts +36 -0
- package/dist/headers/S7comm.js +244 -0
- package/dist/headers/SCTP.d.ts +35 -0
- package/dist/headers/SCTP.js +174 -0
- package/dist/headers/SFlow.d.ts +29 -0
- package/dist/headers/SFlow.js +242 -0
- package/dist/headers/SIP.d.ts +27 -0
- package/dist/headers/SIP.js +146 -0
- package/dist/headers/SLMP.d.ts +36 -0
- package/dist/headers/SLMP.js +154 -0
- package/dist/headers/SLP.d.ts +30 -0
- package/dist/headers/SLP.js +207 -0
- package/dist/headers/SLPv1.d.ts +32 -0
- package/dist/headers/SLPv1.js +138 -0
- package/dist/headers/SMB1.d.ts +37 -0
- package/dist/headers/SMB1.js +200 -0
- package/dist/headers/SMB2.d.ts +36 -0
- package/dist/headers/SMB2.js +203 -0
- package/dist/headers/SMPP.d.ts +33 -0
- package/dist/headers/SMPP.js +119 -0
- package/dist/headers/SMTP.d.ts +33 -0
- package/dist/headers/SMTP.js +157 -0
- package/dist/headers/SNAP.d.ts +22 -0
- package/dist/headers/SNAP.js +68 -0
- package/dist/headers/SNMP.d.ts +28 -0
- package/dist/headers/SNMP.js +302 -0
- package/dist/headers/SOCKS4.d.ts +42 -0
- package/dist/headers/SOCKS4.js +302 -0
- package/dist/headers/SOCKS5.d.ts +45 -0
- package/dist/headers/SOCKS5.js +223 -0
- package/dist/headers/SSDP.d.ts +27 -0
- package/dist/headers/SSDP.js +161 -0
- package/dist/headers/SSH.d.ts +44 -0
- package/dist/headers/SSH.js +274 -0
- package/dist/headers/STOMP.d.ts +48 -0
- package/dist/headers/STOMP.js +177 -0
- package/dist/headers/STP.d.ts +26 -0
- package/dist/headers/STP.js +150 -0
- package/dist/headers/STUN.d.ts +25 -0
- package/dist/headers/STUN.js +183 -0
- package/dist/headers/SercosIII.d.ts +43 -0
- package/dist/headers/SercosIII.js +199 -0
- package/dist/headers/Skinny.d.ts +32 -0
- package/dist/headers/Skinny.js +139 -0
- package/dist/headers/StatsD.d.ts +27 -0
- package/dist/headers/StatsD.js +134 -0
- package/dist/headers/SunRPC.d.ts +34 -0
- package/dist/headers/SunRPC.js +268 -0
- package/dist/headers/Syslog.d.ts +21 -0
- package/dist/headers/Syslog.js +91 -0
- package/dist/headers/TCP.d.ts +19 -0
- package/dist/headers/TCP.js +905 -0
- package/dist/headers/TFTP.d.ts +28 -0
- package/dist/headers/TFTP.js +224 -0
- package/dist/headers/TLS_Alert.d.ts +24 -0
- package/dist/headers/TLS_Alert.js +639 -0
- package/dist/headers/TLS_ApplicationData.d.ts +24 -0
- package/dist/headers/TLS_ApplicationData.js +170 -0
- package/dist/headers/TLS_ChangeCipherSpec.d.ts +23 -0
- package/dist/headers/TLS_ChangeCipherSpec.js +168 -0
- package/dist/headers/TLS_Handshake.d.ts +65 -0
- package/dist/headers/TLS_Handshake.js +860 -0
- package/dist/headers/TLS_Heartbeat.d.ts +27 -0
- package/dist/headers/TLS_Heartbeat.js +247 -0
- package/dist/headers/TPKT.d.ts +26 -0
- package/dist/headers/TPKT.js +99 -0
- package/dist/headers/TacacsPlus.d.ts +27 -0
- package/dist/headers/TacacsPlus.js +133 -0
- package/dist/headers/Telnet.d.ts +40 -0
- package/dist/headers/Telnet.js +193 -0
- package/dist/headers/Teredo.d.ts +40 -0
- package/dist/headers/Teredo.js +251 -0
- package/dist/headers/TimeProtocol.d.ts +25 -0
- package/dist/headers/TimeProtocol.js +53 -0
- package/dist/headers/UDP.d.ts +19 -0
- package/dist/headers/UDP.js +171 -0
- package/dist/headers/VLAN_802dot1Q.d.ts +24 -0
- package/dist/headers/VLAN_802dot1Q.js +96 -0
- package/dist/headers/VRRP.d.ts +26 -0
- package/dist/headers/VRRP.js +309 -0
- package/dist/headers/VXLAN.d.ts +24 -0
- package/dist/headers/VXLAN.js +75 -0
- package/dist/headers/WCCP.d.ts +29 -0
- package/dist/headers/WCCP.js +117 -0
- package/dist/headers/WHOIS.d.ts +37 -0
- package/dist/headers/WHOIS.js +126 -0
- package/dist/headers/WSDiscovery.d.ts +29 -0
- package/dist/headers/WSDiscovery.js +118 -0
- package/dist/headers/WakeOnLAN.d.ts +30 -0
- package/dist/headers/WakeOnLAN.js +126 -0
- package/dist/headers/WebSocket.d.ts +26 -0
- package/dist/headers/WebSocket.js +173 -0
- package/dist/headers/WireGuard.d.ts +38 -0
- package/dist/headers/WireGuard.js +216 -0
- package/dist/headers/XMPP.d.ts +37 -0
- package/dist/headers/XMPP.js +149 -0
- package/dist/headers/Zabbix.d.ts +35 -0
- package/dist/headers/Zabbix.js +153 -0
- package/dist/headers/cms/AcsiPdu.d.ts +45 -0
- package/dist/headers/cms/AcsiPdu.js +112 -0
- package/dist/headers/cms/PerDecoder.d.ts +68 -0
- package/dist/headers/cms/PerDecoder.js +211 -0
- package/dist/headers/cms/PerReader.d.ts +64 -0
- package/dist/headers/cms/PerReader.js +155 -0
- package/dist/helper/BufferToHex.d.ts +5 -0
- package/dist/helper/BufferToHex.js +10 -0
- package/dist/helper/BufferToIP.d.ts +12 -0
- package/dist/helper/BufferToIP.js +23 -0
- package/dist/helper/BufferToNumber.d.ts +18 -0
- package/dist/helper/BufferToNumber.js +47 -0
- package/dist/helper/HexToBuffer.d.ts +7 -0
- package/dist/helper/HexToBuffer.js +27 -0
- package/dist/helper/HexToNumber.d.ts +18 -0
- package/dist/helper/HexToNumber.js +48 -0
- package/dist/helper/IPToBuffer.d.ts +12 -0
- package/dist/helper/IPToBuffer.js +34 -0
- package/dist/helper/NumberToBERBuffer.d.ts +18 -0
- package/dist/helper/NumberToBERBuffer.js +31 -0
- package/dist/helper/NumberToBERHex.d.ts +18 -0
- package/dist/helper/NumberToBERHex.js +52 -0
- package/dist/helper/NumberToBuffer.d.ts +18 -0
- package/dist/helper/NumberToBuffer.js +38 -0
- package/dist/helper/NumberToHex.d.ts +18 -0
- package/dist/helper/NumberToHex.js +35 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +113 -0
- package/dist/lib/FlexibleObject.d.ts +27 -0
- package/dist/lib/FlexibleObject.js +113 -0
- package/dist/lib/GetBERIntegerLengthFromBuffer.d.ts +6 -0
- package/dist/lib/GetBERIntegerLengthFromBuffer.js +16 -0
- package/dist/lib/ProcessPacketPostHandlers.d.ts +13 -0
- package/dist/lib/ProcessPacketPostHandlers.js +53 -0
- package/dist/lib/SortPostHandlers.d.ts +7 -0
- package/dist/lib/SortPostHandlers.js +11 -0
- package/dist/lib/StringContentEncodingEnum.d.ts +10 -0
- package/dist/lib/StringContentEncodingEnum.js +14 -0
- package/dist/schema/ProtocolFieldJSONSchema.d.ts +35 -0
- package/dist/schema/ProtocolFieldJSONSchema.js +2 -0
- package/dist/schema/ProtocolFieldJSONSchemaDefinition.d.ts +2 -0
- package/dist/schema/ProtocolFieldJSONSchemaDefinition.js +2 -0
- package/dist/schema/ProtocolJSONSchema.d.ts +32 -0
- package/dist/schema/ProtocolJSONSchema.js +2 -0
- package/dist/types/CodecData.d.ts +7 -0
- package/dist/types/CodecData.js +2 -0
- package/dist/types/CodecDecodeResult.d.ts +10 -0
- package/dist/types/CodecDecodeResult.js +2 -0
- package/dist/types/CodecEncodeInput.d.ts +2 -0
- package/dist/types/CodecEncodeInput.js +2 -0
- package/dist/types/CodecEncodeResult.d.ts +5 -0
- package/dist/types/CodecEncodeResult.js +2 -0
- package/dist/types/CodecErrorInfo.d.ts +5 -0
- package/dist/types/CodecErrorInfo.js +2 -0
- package/dist/types/CodecModule.d.ts +2 -0
- package/dist/types/CodecModule.js +2 -0
- package/dist/types/CodecModuleConstructor.d.ts +2 -0
- package/dist/types/CodecModuleConstructor.js +2 -0
- package/dist/types/CodecSchema.d.ts +6 -0
- package/dist/types/CodecSchema.js +2 -0
- package/dist/types/DemuxProducer.d.ts +23 -0
- package/dist/types/DemuxProducer.js +2 -0
- package/dist/types/Dissection.d.ts +23 -0
- package/dist/types/Dissection.js +2 -0
- package/dist/types/HeaderTreeNode.d.ts +4 -0
- package/dist/types/HeaderTreeNode.js +2 -0
- package/dist/types/LayerGraph.d.ts +32 -0
- package/dist/types/LayerGraph.js +2 -0
- package/dist/types/PostHandlerItem.d.ts +4 -0
- package/dist/types/PostHandlerItem.js +2 -0
- package/package.json +141 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Memcached = void 0;
|
|
5
|
+
const BaseHeader_1 = require("../abstracts/BaseHeader");
|
|
6
|
+
const BufferToHex_1 = require("../helper/BufferToHex");
|
|
7
|
+
const HexToBuffer_1 = require("../helper/HexToBuffer");
|
|
8
|
+
const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
|
|
9
|
+
/**
|
|
10
|
+
* Memcached — the cache daemon's wire protocol, carried over TCP well-known port 11211. Memcached speaks
|
|
11
|
+
* TWO protocols on the same port, and this codec handles BOTH by branching on the first payload byte
|
|
12
|
+
* (the exact model of the SSH codec, which branches identification-vs-binary on a signature):
|
|
13
|
+
*
|
|
14
|
+
* 1. TEXT protocol (the classic, default). Line-based US-ASCII commands and replies terminated by CR LF:
|
|
15
|
+
* `get <key>\r\n`, `set <key> <flags> <exptime> <bytes>\r\n<data>\r\n`, and replies such as
|
|
16
|
+
* `VALUE <key> <flags> <bytes>\r\n<data>\r\nEND\r\n`, `STORED\r\n`, `END\r\n`, … Like the other
|
|
17
|
+
* US-ASCII line protocols in this codec (POP3/FTP/SIP/HTTP), the exact bytes a peer sees are richer
|
|
18
|
+
* than any structure a form needs (arbitrary keys, inline data blocks, pipelined commands), so the
|
|
19
|
+
* ENTIRE payload is kept verbatim as the authoritative `message` field (hex) and re-emitted untouched;
|
|
20
|
+
* only the leading token is parsed on decode into the display-only `command` field (get/set/VALUE/
|
|
21
|
+
* STORED/…). Encode never reconstructs the payload from `command` — it writes `message` back
|
|
22
|
+
* byte-for-byte, so any conformant (or malformed) text exchange round-trips exactly.
|
|
23
|
+
*
|
|
24
|
+
* 2. BINARY protocol (RFC-less, memcached's binary framing). A fixed 24-byte header —
|
|
25
|
+
* magic(1: 0x80 request / 0x81 response) · opcode(1) · keyLength(2, BE) · extrasLength(1) ·
|
|
26
|
+
* dataType(1) · vbucket-id/status(2, BE) · totalBodyLength(4, BE) · opaque(4) · cas(8) — followed by
|
|
27
|
+
* `totalBodyLength` bytes of body (extras + key + value). This codec structures the 24-byte header as
|
|
28
|
+
* editable fields and keeps the body verbatim as `body` hex, bounded by totalBodyLength (a trailing /
|
|
29
|
+
* pipelined next message is left to the codec's recursion / RawData). The `cas` field is 8 bytes, so
|
|
30
|
+
* it is kept as a HEX string (never a JS Number — 8 bytes exceeds 2^53 and would lose precision). A
|
|
31
|
+
* well-formed binary message round-trips byte-for-byte.
|
|
32
|
+
*
|
|
33
|
+
* Matching rationale (NO heuristicFallback): Memcached is claimed ONLY on the tcp:11211 bucket. The binary
|
|
34
|
+
* header's magic (0x80/0x81) is a weak one-byte signature and the text protocol shares generic verbs
|
|
35
|
+
* (get/set/…) with countless other line protocols, so neither shape carries a signature strong enough to
|
|
36
|
+
* survive the global content-heuristic chain without mislabeling unrelated TCP traffic. Confining
|
|
37
|
+
* Memcached to its well-known port keeps recognition unambiguous; alt-port memcached is rare and falls
|
|
38
|
+
* losslessly to raw.
|
|
39
|
+
*/
|
|
40
|
+
class Memcached extends BaseHeader_1.BaseHeader {
|
|
41
|
+
constructor() {
|
|
42
|
+
super(...arguments);
|
|
43
|
+
this.id = 'memcached';
|
|
44
|
+
this.name = 'Memcached';
|
|
45
|
+
this.nickname = 'Memcached';
|
|
46
|
+
//Memcached is recognized ONLY on its well-known port bucket (tcp:11211) — deliberately NOT via
|
|
47
|
+
//heuristicFallback. The binary magic (0x80/0x81) is a weak one-byte signature and the text verbs are
|
|
48
|
+
//shared with many US-ASCII line protocols, so neither shape is distinctive enough for the global
|
|
49
|
+
//content-heuristic chain; the well-known port is the signature. See the class doc for the rationale.
|
|
50
|
+
this.matchKeys = ['tcpport:11211'];
|
|
51
|
+
//A leaf header — the memcached session (values, cross-message CAS state) is a higher-layer concern.
|
|
52
|
+
this.demuxProducers = [];
|
|
53
|
+
}
|
|
54
|
+
static #schemaCache;
|
|
55
|
+
get SCHEMA() {
|
|
56
|
+
return (_a.#schemaCache ??= _a.#buildSchema());
|
|
57
|
+
}
|
|
58
|
+
/** Known Memcached text tokens (client commands + server replies) — used to recognize a text line. */
|
|
59
|
+
static #TEXT_TOKENS = [
|
|
60
|
+
//Client commands (RFC-less protocol.txt): retrieval, storage, arithmetic, admin, meta.
|
|
61
|
+
'get', 'gets', 'set', 'add', 'replace', 'append', 'prepend', 'cas', 'delete', 'incr', 'decr',
|
|
62
|
+
'touch', 'gat', 'gats', 'stats', 'flush_all', 'version', 'verbosity', 'quit', 'watch', 'lru',
|
|
63
|
+
'lru_crawler', 'me', 'mg', 'ms', 'md', 'mn', 'ma', 'me',
|
|
64
|
+
//Server replies.
|
|
65
|
+
'VALUE', 'END', 'STORED', 'NOT_STORED', 'EXISTS', 'NOT_FOUND', 'DELETED', 'TOUCHED', 'OK',
|
|
66
|
+
'STAT', 'VERSION', 'ERROR', 'CLIENT_ERROR', 'SERVER_ERROR', 'RESET', 'BUSY', 'BADCLASS'
|
|
67
|
+
];
|
|
68
|
+
/** Bytes available to this header: Memcached rides on TCP, which has no per-message length. */
|
|
69
|
+
#payloadLength() {
|
|
70
|
+
const available = this.packet.length - this.startPos;
|
|
71
|
+
return available < 0 ? 0 : available;
|
|
72
|
+
}
|
|
73
|
+
/** True when the payload begins with the binary magic byte (0x80 request / 0x81 response). */
|
|
74
|
+
#isBinaryMagic() {
|
|
75
|
+
if (this.#payloadLength() < 1)
|
|
76
|
+
return false;
|
|
77
|
+
const first = this.readBytes(0, 1, true).readUInt8(0);
|
|
78
|
+
return first === 0x80 || first === 0x81;
|
|
79
|
+
}
|
|
80
|
+
/** The leading token of the text payload (up to the first space, CR or LF), or '' if empty. */
|
|
81
|
+
static #leadingToken(text) {
|
|
82
|
+
const line = text.split(/[\r\n]/)[0];
|
|
83
|
+
return line.split(' ')[0] || '';
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Parse the text payload's leading token into the display-only `command` field and drive the summary.
|
|
87
|
+
* Populated on decode only — `command` has no encode, so it never affects the re-emitted bytes and
|
|
88
|
+
* never mutates `message`. Never throws: an empty payload yields an empty command.
|
|
89
|
+
*/
|
|
90
|
+
#parseText(text) {
|
|
91
|
+
const token = _a.#leadingToken(text);
|
|
92
|
+
this.instance.command.setValue(token);
|
|
93
|
+
this.instance.summaryInfo.setValue(token);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* A guarded big-endian unsigned integer field of the BINARY header. It decodes only when the payload
|
|
97
|
+
* is binary (else it resets to 0 so the text view is clean) and encodes only for the binary shape
|
|
98
|
+
* (the text shape's `message` owns those bytes). Wraps BaseHeader.fieldUInt so the offset/width live
|
|
99
|
+
* in one place.
|
|
100
|
+
*/
|
|
101
|
+
static #binUInt(name, offset, byteLength, label) {
|
|
102
|
+
const field = this.fieldUInt(name, offset, byteLength, label);
|
|
103
|
+
field.default = 0;
|
|
104
|
+
const rawDecode = field.decode;
|
|
105
|
+
const rawEncode = field.encode;
|
|
106
|
+
field.decode = function () {
|
|
107
|
+
if (!this.instance.isBinary.getValue(false)) {
|
|
108
|
+
this.instance[name].setValue(0);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
rawDecode.call(this);
|
|
112
|
+
};
|
|
113
|
+
field.encode = function () {
|
|
114
|
+
if (this.instance.isBinary.getValue(false))
|
|
115
|
+
rawEncode.call(this);
|
|
116
|
+
};
|
|
117
|
+
return field;
|
|
118
|
+
}
|
|
119
|
+
static #buildSchema() {
|
|
120
|
+
return {
|
|
121
|
+
type: 'object',
|
|
122
|
+
summary: 'Memcached ${summaryInfo}',
|
|
123
|
+
properties: {
|
|
124
|
+
//Discriminator between the two on-wire shapes (see class doc). Decoded from the payload's
|
|
125
|
+
//first byte; on encode it is supplied by the input (default false = the TEXT protocol) and
|
|
126
|
+
//read by every field below to decide which bytes it owns. Mirrors SSH.isIdentification.
|
|
127
|
+
isBinary: {
|
|
128
|
+
type: 'boolean',
|
|
129
|
+
label: 'Is Binary',
|
|
130
|
+
default: false,
|
|
131
|
+
decode: function () {
|
|
132
|
+
this.instance.isBinary.setValue(this.#isBinaryMagic());
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
//BINARY 24-byte header. magic(0x80 req / 0x81 resp), opcode, keyLength(BE), extrasLength,
|
|
136
|
+
//dataType, vbucket-id/status(BE), totalBodyLength(BE), opaque, cas(8 bytes → HEX).
|
|
137
|
+
magic: _a.#binUInt('magic', 0, 1, 'Magic'),
|
|
138
|
+
opcode: _a.#binUInt('opcode', 1, 1, 'Opcode'),
|
|
139
|
+
keyLength: _a.#binUInt('keyLength', 2, 2, 'Key Length'),
|
|
140
|
+
extrasLength: _a.#binUInt('extrasLength', 4, 1, 'Extras Length'),
|
|
141
|
+
dataType: _a.#binUInt('dataType', 5, 1, 'Data Type'),
|
|
142
|
+
status: _a.#binUInt('status', 6, 2, 'VBucket/Status'),
|
|
143
|
+
//totalBodyLength counts the whole body (extras + key + value). Honored on encode when
|
|
144
|
+
//supplied (a crafted message may lie); else derived from the body bytes. No `default` so
|
|
145
|
+
//Ajv leaves it undefined and the derive path can trigger (mirrors ENIP.length).
|
|
146
|
+
totalBodyLength: {
|
|
147
|
+
type: 'integer',
|
|
148
|
+
label: 'Total Body Length',
|
|
149
|
+
minimum: 0,
|
|
150
|
+
maximum: 4294967295,
|
|
151
|
+
decode: function () {
|
|
152
|
+
if (!this.instance.isBinary.getValue(false)) {
|
|
153
|
+
this.instance.totalBodyLength.setValue(0);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
this.instance.totalBodyLength.setValue(this.readBytes(8, 4).readUInt32BE(0));
|
|
157
|
+
},
|
|
158
|
+
encode: function () {
|
|
159
|
+
if (!this.instance.isBinary.getValue(false))
|
|
160
|
+
return;
|
|
161
|
+
const provided = this.instance.totalBodyLength.getValue();
|
|
162
|
+
let value = (provided !== undefined && provided !== null)
|
|
163
|
+
? provided
|
|
164
|
+
: (0, HexToBuffer_1.HexToBuffer)(this.instance.body.getValue('')).length;
|
|
165
|
+
if (value > 4294967295) {
|
|
166
|
+
this.recordError(this.instance.totalBodyLength.getPath(), 'Maximum value is 4294967295');
|
|
167
|
+
value = 4294967295;
|
|
168
|
+
}
|
|
169
|
+
if (value < 0) {
|
|
170
|
+
this.recordError(this.instance.totalBodyLength.getPath(), 'Minimum value is 0');
|
|
171
|
+
value = 0;
|
|
172
|
+
}
|
|
173
|
+
this.instance.totalBodyLength.setValue(value);
|
|
174
|
+
const buffer = Buffer.alloc(4);
|
|
175
|
+
buffer.writeUInt32BE(value, 0);
|
|
176
|
+
this.writeBytes(8, buffer);
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
opaque: _a.#binUInt('opaque', 12, 4, 'Opaque'),
|
|
180
|
+
//cas is 8 bytes — an opaque compare-and-swap token. Kept as HEX (never a JS Number: 8
|
|
181
|
+
//bytes exceeds 2^53 and would lose precision). Guarded like the numeric header fields.
|
|
182
|
+
cas: {
|
|
183
|
+
type: 'string',
|
|
184
|
+
label: 'CAS',
|
|
185
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
|
186
|
+
default: '0000000000000000',
|
|
187
|
+
decode: function () {
|
|
188
|
+
if (!this.instance.isBinary.getValue(false)) {
|
|
189
|
+
this.instance.cas.setValue('0000000000000000');
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
this.instance.cas.setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(16, 8)));
|
|
193
|
+
},
|
|
194
|
+
encode: function () {
|
|
195
|
+
if (!this.instance.isBinary.getValue(false))
|
|
196
|
+
return;
|
|
197
|
+
this.writeBytes(16, (0, HexToBuffer_1.HexToBuffer)(this.instance.cas.getValue('0000000000000000')));
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
//BINARY body (extras + key + value), kept verbatim. Bounded by totalBodyLength (the body
|
|
201
|
+
//ends at offset 24 + totalBodyLength) and the captured bytes, so a trailing / pipelined
|
|
202
|
+
//next message is left to the codec's recursion / RawData. Also sets the binary summary.
|
|
203
|
+
body: {
|
|
204
|
+
type: 'string',
|
|
205
|
+
label: 'Body',
|
|
206
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
|
207
|
+
default: '',
|
|
208
|
+
decode: function () {
|
|
209
|
+
if (!this.instance.isBinary.getValue(false)) {
|
|
210
|
+
this.instance.body.setValue('');
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const remaining = this.#payloadLength();
|
|
214
|
+
const totalBodyLength = this.instance.totalBodyLength.getValue(0);
|
|
215
|
+
let end = 24 + totalBodyLength;
|
|
216
|
+
if (end > remaining)
|
|
217
|
+
end = remaining;
|
|
218
|
+
this.instance.body.setValue(end > 24 ? (0, BufferToHex_1.BufferToHex)(this.readBytes(24, end - 24)) : '');
|
|
219
|
+
this.instance.summaryInfo.setValue(`binary op=${this.instance.opcode.getValue(0)}`);
|
|
220
|
+
},
|
|
221
|
+
encode: function () {
|
|
222
|
+
if (!this.instance.isBinary.getValue(false))
|
|
223
|
+
return;
|
|
224
|
+
const body = this.instance.body.getValue('');
|
|
225
|
+
if (body)
|
|
226
|
+
this.writeBytes(24, (0, HexToBuffer_1.HexToBuffer)(body));
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
//Display-only text metadata: the leading token of the text payload (populated by the
|
|
230
|
+
//`message` decode below; no encode of its own). Empty for a binary message.
|
|
231
|
+
command: { type: 'string', label: 'Command', default: '' },
|
|
232
|
+
//Drives the one-line summary: the text command, or `binary op=<opcode>` for a binary msg.
|
|
233
|
+
summaryInfo: { type: 'string', label: 'Summary', hidden: true, default: '' },
|
|
234
|
+
//TEXT payload: the whole message kept verbatim (byte-perfect) and re-emitted untouched. The
|
|
235
|
+
//leading token is parsed into `command` on decode; encode never reconstructs from it.
|
|
236
|
+
message: {
|
|
237
|
+
type: 'string',
|
|
238
|
+
label: 'Message',
|
|
239
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
|
240
|
+
default: '',
|
|
241
|
+
decode: function () {
|
|
242
|
+
if (this.instance.isBinary.getValue(false)) {
|
|
243
|
+
//Binary shape: no verbatim text; clear the text metadata (summary set by body).
|
|
244
|
+
this.instance.message.setValue('');
|
|
245
|
+
this.instance.command.setValue('');
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const available = this.#payloadLength();
|
|
249
|
+
if (available <= 0) {
|
|
250
|
+
this.instance.message.setValue('');
|
|
251
|
+
this.#parseText('');
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const raw = this.readBytes(0, available);
|
|
255
|
+
this.instance.message.setValue((0, BufferToHex_1.BufferToHex)(raw));
|
|
256
|
+
this.#parseText(raw.toString('latin1'));
|
|
257
|
+
},
|
|
258
|
+
encode: function () {
|
|
259
|
+
//Re-emit the authoritative text payload verbatim — never reconstruct from metadata.
|
|
260
|
+
if (this.instance.isBinary.getValue(false))
|
|
261
|
+
return;
|
|
262
|
+
this.writeBytes(0, (0, HexToBuffer_1.HexToBuffer)(this.instance.message.getValue('')));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
match() {
|
|
269
|
+
//Reached only on the tcp:11211 bucket. Confirm the parent is TCP and the payload is either a
|
|
270
|
+
//binary message (magic 0x80/0x81) or a text line whose leading token is a known Memcached verb —
|
|
271
|
+
//so unrelated binary traffic on 11211 still falls through to raw rather than a bogus layer.
|
|
272
|
+
if (!this.prevCodecModule)
|
|
273
|
+
return false;
|
|
274
|
+
if (this.prevCodecModule.id !== 'tcp')
|
|
275
|
+
return false;
|
|
276
|
+
if (this.#payloadLength() < 1)
|
|
277
|
+
return false;
|
|
278
|
+
if (this.#isBinaryMagic())
|
|
279
|
+
return true;
|
|
280
|
+
const lead = this.readBytes(0, 24, true).toString('latin1');
|
|
281
|
+
return _a.#TEXT_TOKENS.includes(_a.#leadingToken(lead));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
exports.Memcached = Memcached;
|
|
285
|
+
_a = Memcached;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BaseHeader } from '../abstracts/BaseHeader';
|
|
2
|
+
import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
|
|
3
|
+
import { DemuxProducer } from '../types/DemuxProducer';
|
|
4
|
+
/**
|
|
5
|
+
* Modbus/TCP (MODBUS Application Protocol V1.1b3 + Modbus Messaging on TCP/IP V1.0b), TCP port 502. Each
|
|
6
|
+
* message is a 7-byte MBAP header — Transaction Identifier, Protocol Identifier (0 for Modbus), Length,
|
|
7
|
+
* and Unit Identifier — followed by the PDU: a Function Code and its data. The Length field counts the
|
|
8
|
+
* Unit Identifier plus the PDU, so it bounds the message (a second pipelined PDU or trailing bytes are
|
|
9
|
+
* left to the codec's recursion / RawData).
|
|
10
|
+
*
|
|
11
|
+
* Whether the PDU data is a request or a response is only knowable from the paired transaction, which is
|
|
12
|
+
* cross-packet state — so this single-packet codec keeps the PDU data as raw hex (byte-perfect) and does
|
|
13
|
+
* not sub-decode it. The Length is auto-computed from the data on encode when not supplied, else honored
|
|
14
|
+
* verbatim (a crafted message may carry any Length). A well-formed message round-trips byte-for-byte.
|
|
15
|
+
*/
|
|
16
|
+
export declare class ModbusTCP extends BaseHeader {
|
|
17
|
+
#private;
|
|
18
|
+
get SCHEMA(): ProtocolJSONSchema;
|
|
19
|
+
readonly id: string;
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly nickname: string;
|
|
22
|
+
readonly matchKeys: string[];
|
|
23
|
+
match(): boolean;
|
|
24
|
+
readonly demuxProducers: DemuxProducer[];
|
|
25
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModbusTCP = void 0;
|
|
4
|
+
const BaseHeader_1 = require("../abstracts/BaseHeader");
|
|
5
|
+
const BufferToHex_1 = require("../helper/BufferToHex");
|
|
6
|
+
const HexToBuffer_1 = require("../helper/HexToBuffer");
|
|
7
|
+
const BufferToNumber_1 = require("../helper/BufferToNumber");
|
|
8
|
+
const NumberToBuffer_1 = require("../helper/NumberToBuffer");
|
|
9
|
+
const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
|
|
10
|
+
/**
|
|
11
|
+
* Modbus/TCP (MODBUS Application Protocol V1.1b3 + Modbus Messaging on TCP/IP V1.0b), TCP port 502. Each
|
|
12
|
+
* message is a 7-byte MBAP header — Transaction Identifier, Protocol Identifier (0 for Modbus), Length,
|
|
13
|
+
* and Unit Identifier — followed by the PDU: a Function Code and its data. The Length field counts the
|
|
14
|
+
* Unit Identifier plus the PDU, so it bounds the message (a second pipelined PDU or trailing bytes are
|
|
15
|
+
* left to the codec's recursion / RawData).
|
|
16
|
+
*
|
|
17
|
+
* Whether the PDU data is a request or a response is only knowable from the paired transaction, which is
|
|
18
|
+
* cross-packet state — so this single-packet codec keeps the PDU data as raw hex (byte-perfect) and does
|
|
19
|
+
* not sub-decode it. The Length is auto-computed from the data on encode when not supplied, else honored
|
|
20
|
+
* verbatim (a crafted message may carry any Length). A well-formed message round-trips byte-for-byte.
|
|
21
|
+
*/
|
|
22
|
+
class ModbusTCP extends BaseHeader_1.BaseHeader {
|
|
23
|
+
constructor() {
|
|
24
|
+
super(...arguments);
|
|
25
|
+
this.id = 'modbus';
|
|
26
|
+
this.name = 'Modbus/TCP';
|
|
27
|
+
this.nickname = 'Modbus';
|
|
28
|
+
this.matchKeys = ['tcpport:502'];
|
|
29
|
+
//A leaf header — the PDU data is kept as hex, not demuxed further.
|
|
30
|
+
this.demuxProducers = [];
|
|
31
|
+
}
|
|
32
|
+
static #schemaCache;
|
|
33
|
+
get SCHEMA() {
|
|
34
|
+
return (ModbusTCP.#schemaCache ??= ModbusTCP.#buildSchema());
|
|
35
|
+
}
|
|
36
|
+
static #buildSchema() {
|
|
37
|
+
return {
|
|
38
|
+
type: 'object',
|
|
39
|
+
summary: 'Modbus func=${functionCode} unit=${unitId}',
|
|
40
|
+
properties: {
|
|
41
|
+
transactionId: this.fieldUInt('transactionId', 0, 2, 'Transaction Identifier'),
|
|
42
|
+
protocolId: this.fieldUInt('protocolId', 2, 2, 'Protocol Identifier'),
|
|
43
|
+
length: {
|
|
44
|
+
type: 'integer',
|
|
45
|
+
label: 'Length',
|
|
46
|
+
minimum: 0,
|
|
47
|
+
maximum: 65535,
|
|
48
|
+
decode: function () {
|
|
49
|
+
this.instance.length.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(4, 2)));
|
|
50
|
+
},
|
|
51
|
+
encode: function () {
|
|
52
|
+
//Length counts the Unit Identifier + PDU = 1 (unit) + 1 (function code) + data.
|
|
53
|
+
//Honored when supplied (a crafted message may lie); else derived from the data.
|
|
54
|
+
const provided = this.instance.length.getValue();
|
|
55
|
+
const value = (provided !== undefined && provided !== null)
|
|
56
|
+
? provided
|
|
57
|
+
: 2 + (0, HexToBuffer_1.HexToBuffer)(this.instance.data.getValue('')).length;
|
|
58
|
+
this.instance.length.setValue(value);
|
|
59
|
+
this.writeBytes(4, (0, NumberToBuffer_1.UInt16ToBuffer)(value));
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
unitId: this.fieldUInt('unitId', 6, 1, 'Unit Identifier'),
|
|
63
|
+
functionCode: this.fieldUInt('functionCode', 7, 1, 'Function Code'),
|
|
64
|
+
//The PDU data after the function code, kept verbatim. Bounded by the MBAP Length (the
|
|
65
|
+
//message ends at offset 6 + Length) and the captured bytes, so trailing/pipelined data
|
|
66
|
+
//is not absorbed.
|
|
67
|
+
data: {
|
|
68
|
+
type: 'string',
|
|
69
|
+
label: 'Data',
|
|
70
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
|
71
|
+
decode: function () {
|
|
72
|
+
const remaining = this.packet.length - this.startPos;
|
|
73
|
+
const length = this.instance.length.getValue(0);
|
|
74
|
+
let end = 6 + length;
|
|
75
|
+
if (end > remaining)
|
|
76
|
+
end = remaining;
|
|
77
|
+
this.instance.data.setValue(end > 8 ? (0, BufferToHex_1.BufferToHex)(this.readBytes(8, end - 8)) : '');
|
|
78
|
+
},
|
|
79
|
+
encode: function () {
|
|
80
|
+
const data = this.instance.data.getValue('');
|
|
81
|
+
if (data)
|
|
82
|
+
this.writeBytes(8, (0, HexToBuffer_1.HexToBuffer)(data));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
match() {
|
|
89
|
+
//Modbus/TCP rides on TCP port 502. Require the 7-byte MBAP header + a function code (8 bytes),
|
|
90
|
+
//and a zero Protocol Identifier (the Modbus content signature) so non-Modbus 502 traffic falls
|
|
91
|
+
//through to raw.
|
|
92
|
+
if (!this.prevCodecModule || this.prevCodecModule.id !== 'tcp')
|
|
93
|
+
return false;
|
|
94
|
+
if (this.packet.length - this.startPos < 8)
|
|
95
|
+
return false;
|
|
96
|
+
return (0, BufferToNumber_1.BufferToUInt16)(this.readBytes(2, 2, true)) === 0;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.ModbusTCP = ModbusTCP;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BaseHeader } from '../abstracts/BaseHeader';
|
|
2
|
+
import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
|
|
3
|
+
import { DemuxProducer } from '../types/DemuxProducer';
|
|
4
|
+
/**
|
|
5
|
+
* Modbus/UDP (MODBUS Application Protocol V1.1b3 + Modbus Messaging on TCP/IP V1.0b), UDP port 502. The
|
|
6
|
+
* frame carries the same MBAP + PDU layout as Modbus/TCP but over UDP instead of a TCP stream: a 7-byte
|
|
7
|
+
* MBAP header — Transaction Identifier, Protocol Identifier (0 for Modbus), Length, and Unit Identifier —
|
|
8
|
+
* followed by the PDU (a Function Code and its data). The Length field counts the Unit Identifier plus the
|
|
9
|
+
* PDU, so it bounds the message; a second pipelined PDU or trailing bytes are left to the codec's
|
|
10
|
+
* recursion / RawData.
|
|
11
|
+
*
|
|
12
|
+
* Whether the PDU data is a request or a response is only knowable from the paired transaction, which is
|
|
13
|
+
* cross-packet state — so this single-packet codec keeps the PDU data as raw hex (byte-perfect) and does
|
|
14
|
+
* not sub-decode it. The Length is auto-computed from the data on encode when not supplied, else honored
|
|
15
|
+
* verbatim (a crafted message may carry any Length). A well-formed message round-trips byte-for-byte.
|
|
16
|
+
*/
|
|
17
|
+
export declare class ModbusUDP extends BaseHeader {
|
|
18
|
+
#private;
|
|
19
|
+
get SCHEMA(): ProtocolJSONSchema;
|
|
20
|
+
readonly id: string;
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly nickname: string;
|
|
23
|
+
readonly matchKeys: string[];
|
|
24
|
+
match(): boolean;
|
|
25
|
+
readonly demuxProducers: DemuxProducer[];
|
|
26
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModbusUDP = void 0;
|
|
4
|
+
const BaseHeader_1 = require("../abstracts/BaseHeader");
|
|
5
|
+
const BufferToHex_1 = require("../helper/BufferToHex");
|
|
6
|
+
const HexToBuffer_1 = require("../helper/HexToBuffer");
|
|
7
|
+
const BufferToNumber_1 = require("../helper/BufferToNumber");
|
|
8
|
+
const NumberToBuffer_1 = require("../helper/NumberToBuffer");
|
|
9
|
+
const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
|
|
10
|
+
/**
|
|
11
|
+
* Modbus/UDP (MODBUS Application Protocol V1.1b3 + Modbus Messaging on TCP/IP V1.0b), UDP port 502. The
|
|
12
|
+
* frame carries the same MBAP + PDU layout as Modbus/TCP but over UDP instead of a TCP stream: a 7-byte
|
|
13
|
+
* MBAP header — Transaction Identifier, Protocol Identifier (0 for Modbus), Length, and Unit Identifier —
|
|
14
|
+
* followed by the PDU (a Function Code and its data). The Length field counts the Unit Identifier plus the
|
|
15
|
+
* PDU, so it bounds the message; a second pipelined PDU or trailing bytes are left to the codec's
|
|
16
|
+
* recursion / RawData.
|
|
17
|
+
*
|
|
18
|
+
* Whether the PDU data is a request or a response is only knowable from the paired transaction, which is
|
|
19
|
+
* cross-packet state — so this single-packet codec keeps the PDU data as raw hex (byte-perfect) and does
|
|
20
|
+
* not sub-decode it. The Length is auto-computed from the data on encode when not supplied, else honored
|
|
21
|
+
* verbatim (a crafted message may carry any Length). A well-formed message round-trips byte-for-byte.
|
|
22
|
+
*/
|
|
23
|
+
class ModbusUDP extends BaseHeader_1.BaseHeader {
|
|
24
|
+
constructor() {
|
|
25
|
+
super(...arguments);
|
|
26
|
+
this.id = 'modbusudp';
|
|
27
|
+
this.name = 'Modbus/UDP';
|
|
28
|
+
this.nickname = 'Modbus';
|
|
29
|
+
this.matchKeys = ['udpport:502'];
|
|
30
|
+
//A leaf header — the PDU data is kept as hex, not demuxed further.
|
|
31
|
+
this.demuxProducers = [];
|
|
32
|
+
}
|
|
33
|
+
static #schemaCache;
|
|
34
|
+
get SCHEMA() {
|
|
35
|
+
return (ModbusUDP.#schemaCache ??= ModbusUDP.#buildSchema());
|
|
36
|
+
}
|
|
37
|
+
static #buildSchema() {
|
|
38
|
+
return {
|
|
39
|
+
type: 'object',
|
|
40
|
+
summary: 'Modbus/UDP func=${functionCode} unit=${unitId}',
|
|
41
|
+
properties: {
|
|
42
|
+
transactionId: this.fieldUInt('transactionId', 0, 2, 'Transaction Identifier'),
|
|
43
|
+
protocolId: this.fieldUInt('protocolId', 2, 2, 'Protocol Identifier'),
|
|
44
|
+
length: {
|
|
45
|
+
type: 'integer',
|
|
46
|
+
label: 'Length',
|
|
47
|
+
minimum: 0,
|
|
48
|
+
maximum: 65535,
|
|
49
|
+
decode: function () {
|
|
50
|
+
this.instance.length.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(4, 2)));
|
|
51
|
+
},
|
|
52
|
+
encode: function () {
|
|
53
|
+
//Length counts the Unit Identifier + PDU = 1 (unit) + 1 (function code) + data.
|
|
54
|
+
//Honored when supplied (a crafted message may lie); else derived from the data.
|
|
55
|
+
const provided = this.instance.length.getValue();
|
|
56
|
+
const value = (provided !== undefined && provided !== null)
|
|
57
|
+
? provided
|
|
58
|
+
: 2 + (0, HexToBuffer_1.HexToBuffer)(this.instance.data.getValue('')).length;
|
|
59
|
+
this.instance.length.setValue(value);
|
|
60
|
+
this.writeBytes(4, (0, NumberToBuffer_1.UInt16ToBuffer)(value));
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
unitId: this.fieldUInt('unitId', 6, 1, 'Unit Identifier'),
|
|
64
|
+
functionCode: this.fieldUInt('functionCode', 7, 1, 'Function Code'),
|
|
65
|
+
//The PDU data after the function code, kept verbatim. Bounded by the MBAP Length (the
|
|
66
|
+
//message ends at offset 6 + Length) and the captured bytes, so trailing/pipelined data
|
|
67
|
+
//is not absorbed.
|
|
68
|
+
data: {
|
|
69
|
+
type: 'string',
|
|
70
|
+
label: 'Data',
|
|
71
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
|
72
|
+
decode: function () {
|
|
73
|
+
const remaining = this.packet.length - this.startPos;
|
|
74
|
+
const length = this.instance.length.getValue(0);
|
|
75
|
+
let end = 6 + length;
|
|
76
|
+
if (end > remaining)
|
|
77
|
+
end = remaining;
|
|
78
|
+
this.instance.data.setValue(end > 8 ? (0, BufferToHex_1.BufferToHex)(this.readBytes(8, end - 8)) : '');
|
|
79
|
+
},
|
|
80
|
+
encode: function () {
|
|
81
|
+
const data = this.instance.data.getValue('');
|
|
82
|
+
if (data)
|
|
83
|
+
this.writeBytes(8, (0, HexToBuffer_1.HexToBuffer)(data));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
match() {
|
|
90
|
+
//Modbus/UDP rides on UDP port 502. Require the 7-byte MBAP header + a function code (8 bytes),
|
|
91
|
+
//and a zero Protocol Identifier (the Modbus content signature) so non-Modbus 502 traffic falls
|
|
92
|
+
//through to raw.
|
|
93
|
+
if (!this.prevCodecModule || this.prevCodecModule.id !== 'udp')
|
|
94
|
+
return false;
|
|
95
|
+
if (this.packet.length - this.startPos < 8)
|
|
96
|
+
return false;
|
|
97
|
+
return (0, BufferToNumber_1.BufferToUInt16)(this.readBytes(2, 2, true)) === 0;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.ModbusUDP = ModbusUDP;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BaseHeader } from '../abstracts/BaseHeader';
|
|
2
|
+
import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
|
|
3
|
+
import { DemuxProducer } from '../types/DemuxProducer';
|
|
4
|
+
/**
|
|
5
|
+
* MongoDB Wire Protocol (TCP port 27017). Every message begins with a fixed 16-byte standard message
|
|
6
|
+
* header — messageLength, requestID, responseTo, opCode — followed by an opCode-specific body. The
|
|
7
|
+
* messageLength counts the WHOLE message including the 16-byte header; requestID / responseTo tie a
|
|
8
|
+
* request to its reply; opCode selects the body layout (2013 OP_MSG — the modern, general-purpose
|
|
9
|
+
* message; 2004 OP_QUERY and 1 OP_REPLY — the legacy request/reply pair; plus OP_UPDATE/INSERT/… ).
|
|
10
|
+
*
|
|
11
|
+
* ⚠️ Every multi-byte field in the MongoDB wire protocol is LITTLE-ENDIAN. There is no little-endian
|
|
12
|
+
* helper in this codebase, so the four uint32 header fields are read and written byte-by-byte in their
|
|
13
|
+
* closures (`|` yields a signed int32, so the read applies `>>> 0` to the whole expression to keep a
|
|
14
|
+
* high-bit-set value unsigned).
|
|
15
|
+
*
|
|
16
|
+
* The body layout differs per opCode (OP_MSG's flagBits + sections of BSON, OP_QUERY's collection name /
|
|
17
|
+
* query document, OP_REPLY's cursor + returned documents) and BSON sub-parsing is cross-message,
|
|
18
|
+
* opCode-dependent state, so this single-message codec keeps the body verbatim as `body` hex
|
|
19
|
+
* (byte-perfect) and does not sub-decode it. The messageLength is auto-computed from the body on encode
|
|
20
|
+
* when not supplied, else honored verbatim (a crafted message may lie); the message is bounded by
|
|
21
|
+
* messageLength so a second pipelined message or trailing bytes are left to the codec's recursion /
|
|
22
|
+
* RawData. A well-formed message round-trips byte-for-byte.
|
|
23
|
+
*/
|
|
24
|
+
export declare class MongoDB extends BaseHeader {
|
|
25
|
+
#private;
|
|
26
|
+
get SCHEMA(): ProtocolJSONSchema;
|
|
27
|
+
readonly id: string;
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly nickname: string;
|
|
30
|
+
readonly matchKeys: string[];
|
|
31
|
+
match(): boolean;
|
|
32
|
+
readonly demuxProducers: DemuxProducer[];
|
|
33
|
+
}
|