@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.
Files changed (463) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +21 -0
  3. package/README.md +352 -0
  4. package/README.zh-CN.md +342 -0
  5. package/dist/Codec.d.ts +133 -0
  6. package/dist/Codec.js +632 -0
  7. package/dist/PacketHeaders.d.ts +189 -0
  8. package/dist/PacketHeaders.js +384 -0
  9. package/dist/abstracts/BaseHeader.d.ts +325 -0
  10. package/dist/abstracts/BaseHeader.js +734 -0
  11. package/dist/errors/CodecSchemaValidateError.d.ts +4 -0
  12. package/dist/errors/CodecSchemaValidateError.js +11 -0
  13. package/dist/headers/ADSAMS.d.ts +33 -0
  14. package/dist/headers/ADSAMS.js +208 -0
  15. package/dist/headers/AH.d.ts +28 -0
  16. package/dist/headers/AH.js +137 -0
  17. package/dist/headers/AMQP.d.ts +31 -0
  18. package/dist/headers/AMQP.js +316 -0
  19. package/dist/headers/ARP.d.ts +26 -0
  20. package/dist/headers/ARP.js +243 -0
  21. package/dist/headers/BACnetIP.d.ts +27 -0
  22. package/dist/headers/BACnetIP.js +97 -0
  23. package/dist/headers/BFD.d.ts +28 -0
  24. package/dist/headers/BFD.js +155 -0
  25. package/dist/headers/BGP.d.ts +27 -0
  26. package/dist/headers/BGP.js +111 -0
  27. package/dist/headers/BSAPIP.d.ts +33 -0
  28. package/dist/headers/BSAPIP.js +78 -0
  29. package/dist/headers/Babel.d.ts +32 -0
  30. package/dist/headers/Babel.js +224 -0
  31. package/dist/headers/BitTorrent.d.ts +28 -0
  32. package/dist/headers/BitTorrent.js +72 -0
  33. package/dist/headers/C37118.d.ts +26 -0
  34. package/dist/headers/C37118.js +147 -0
  35. package/dist/headers/CAPWAP.d.ts +38 -0
  36. package/dist/headers/CAPWAP.js +275 -0
  37. package/dist/headers/CDP.d.ts +25 -0
  38. package/dist/headers/CDP.js +117 -0
  39. package/dist/headers/CMS.d.ts +33 -0
  40. package/dist/headers/CMS.js +238 -0
  41. package/dist/headers/COTP.d.ts +30 -0
  42. package/dist/headers/COTP.js +193 -0
  43. package/dist/headers/CassandraCQL.d.ts +28 -0
  44. package/dist/headers/CassandraCQL.js +117 -0
  45. package/dist/headers/CoAP.d.ts +29 -0
  46. package/dist/headers/CoAP.js +140 -0
  47. package/dist/headers/Codesys.d.ts +32 -0
  48. package/dist/headers/Codesys.js +119 -0
  49. package/dist/headers/Collectd.d.ts +29 -0
  50. package/dist/headers/Collectd.js +154 -0
  51. package/dist/headers/DCCP.d.ts +30 -0
  52. package/dist/headers/DCCP.js +204 -0
  53. package/dist/headers/DHCP.d.ts +26 -0
  54. package/dist/headers/DHCP.js +148 -0
  55. package/dist/headers/DHCPFailover.d.ts +30 -0
  56. package/dist/headers/DHCPFailover.js +104 -0
  57. package/dist/headers/DHCPv6.d.ts +25 -0
  58. package/dist/headers/DHCPv6.js +145 -0
  59. package/dist/headers/DNP3.d.ts +27 -0
  60. package/dist/headers/DNP3.js +150 -0
  61. package/dist/headers/DNS.d.ts +55 -0
  62. package/dist/headers/DNS.js +309 -0
  63. package/dist/headers/DTLS.d.ts +33 -0
  64. package/dist/headers/DTLS.js +142 -0
  65. package/dist/headers/Diameter.d.ts +34 -0
  66. package/dist/headers/Diameter.js +229 -0
  67. package/dist/headers/EAPOL.d.ts +32 -0
  68. package/dist/headers/EAPOL.js +135 -0
  69. package/dist/headers/EIGRP.d.ts +28 -0
  70. package/dist/headers/EIGRP.js +165 -0
  71. package/dist/headers/ENIP.d.ts +31 -0
  72. package/dist/headers/ENIP.js +164 -0
  73. package/dist/headers/ESP.d.ts +27 -0
  74. package/dist/headers/ESP.js +140 -0
  75. package/dist/headers/Elasticsearch.d.ts +30 -0
  76. package/dist/headers/Elasticsearch.js +125 -0
  77. package/dist/headers/EtherCAT.d.ts +35 -0
  78. package/dist/headers/EtherCAT.js +150 -0
  79. package/dist/headers/EthernetII.d.ts +28 -0
  80. package/dist/headers/EthernetII.js +117 -0
  81. package/dist/headers/FCoE.d.ts +38 -0
  82. package/dist/headers/FCoE.js +210 -0
  83. package/dist/headers/FTP.d.ts +34 -0
  84. package/dist/headers/FTP.js +158 -0
  85. package/dist/headers/Finger.d.ts +41 -0
  86. package/dist/headers/Finger.js +135 -0
  87. package/dist/headers/FoundationFieldbusHSE.d.ts +43 -0
  88. package/dist/headers/FoundationFieldbusHSE.js +163 -0
  89. package/dist/headers/GELF.d.ts +35 -0
  90. package/dist/headers/GELF.js +261 -0
  91. package/dist/headers/GENEVE.d.ts +26 -0
  92. package/dist/headers/GENEVE.js +209 -0
  93. package/dist/headers/GESRTP.d.ts +32 -0
  94. package/dist/headers/GESRTP.js +141 -0
  95. package/dist/headers/GLBP.d.ts +29 -0
  96. package/dist/headers/GLBP.js +159 -0
  97. package/dist/headers/GRE.d.ts +27 -0
  98. package/dist/headers/GRE.js +181 -0
  99. package/dist/headers/GTPU.d.ts +25 -0
  100. package/dist/headers/GTPU.js +203 -0
  101. package/dist/headers/GTPv2C.d.ts +30 -0
  102. package/dist/headers/GTPv2C.js +281 -0
  103. package/dist/headers/GitProtocol.d.ts +34 -0
  104. package/dist/headers/GitProtocol.js +141 -0
  105. package/dist/headers/Goose.d.ts +115 -0
  106. package/dist/headers/Goose.js +1067 -0
  107. package/dist/headers/Gopher.d.ts +43 -0
  108. package/dist/headers/Gopher.js +182 -0
  109. package/dist/headers/HARTIP.d.ts +30 -0
  110. package/dist/headers/HARTIP.js +145 -0
  111. package/dist/headers/HSR.d.ts +27 -0
  112. package/dist/headers/HSR.js +105 -0
  113. package/dist/headers/HSRP.d.ts +26 -0
  114. package/dist/headers/HSRP.js +173 -0
  115. package/dist/headers/HTTP.d.ts +32 -0
  116. package/dist/headers/HTTP.js +153 -0
  117. package/dist/headers/HTTP2.d.ts +34 -0
  118. package/dist/headers/HTTP2.js +190 -0
  119. package/dist/headers/IAX2.d.ts +33 -0
  120. package/dist/headers/IAX2.js +274 -0
  121. package/dist/headers/ICMP.d.ts +15 -0
  122. package/dist/headers/ICMP.js +148 -0
  123. package/dist/headers/ICMPv6.d.ts +15 -0
  124. package/dist/headers/ICMPv6.js +129 -0
  125. package/dist/headers/IEC104_I_Frame.d.ts +23 -0
  126. package/dist/headers/IEC104_I_Frame.js +6489 -0
  127. package/dist/headers/IEC104_S_Frame.d.ts +26 -0
  128. package/dist/headers/IEC104_S_Frame.js +135 -0
  129. package/dist/headers/IEC104_U_Frame.d.ts +27 -0
  130. package/dist/headers/IEC104_U_Frame.js +176 -0
  131. package/dist/headers/IEC61850SampledValues.d.ts +20 -0
  132. package/dist/headers/IEC61850SampledValues.js +420 -0
  133. package/dist/headers/IGMP.d.ts +31 -0
  134. package/dist/headers/IGMP.js +274 -0
  135. package/dist/headers/IMAP.d.ts +32 -0
  136. package/dist/headers/IMAP.js +185 -0
  137. package/dist/headers/IPFIX.d.ts +29 -0
  138. package/dist/headers/IPFIX.js +156 -0
  139. package/dist/headers/IPv4.d.ts +20 -0
  140. package/dist/headers/IPv4.js +370 -0
  141. package/dist/headers/IPv6.d.ts +29 -0
  142. package/dist/headers/IPv6.js +209 -0
  143. package/dist/headers/IPv6HopByHopOptions.d.ts +81 -0
  144. package/dist/headers/IPv6HopByHopOptions.js +495 -0
  145. package/dist/headers/IRC.d.ts +34 -0
  146. package/dist/headers/IRC.js +175 -0
  147. package/dist/headers/ISAKMP.d.ts +29 -0
  148. package/dist/headers/ISAKMP.js +197 -0
  149. package/dist/headers/ISCSI.d.ts +39 -0
  150. package/dist/headers/ISCSI.js +289 -0
  151. package/dist/headers/ISIS.d.ts +25 -0
  152. package/dist/headers/ISIS.js +79 -0
  153. package/dist/headers/ISOSession.d.ts +27 -0
  154. package/dist/headers/ISOSession.js +343 -0
  155. package/dist/headers/Ident.d.ts +42 -0
  156. package/dist/headers/Ident.js +184 -0
  157. package/dist/headers/KNXnetIP.d.ts +30 -0
  158. package/dist/headers/KNXnetIP.js +135 -0
  159. package/dist/headers/Kafka.d.ts +35 -0
  160. package/dist/headers/Kafka.js +128 -0
  161. package/dist/headers/Kerberos.d.ts +30 -0
  162. package/dist/headers/Kerberos.js +217 -0
  163. package/dist/headers/L2TP.d.ts +26 -0
  164. package/dist/headers/L2TP.js +297 -0
  165. package/dist/headers/LACP.d.ts +31 -0
  166. package/dist/headers/LACP.js +151 -0
  167. package/dist/headers/LDAP.d.ts +31 -0
  168. package/dist/headers/LDAP.js +226 -0
  169. package/dist/headers/LDP.d.ts +31 -0
  170. package/dist/headers/LDP.js +138 -0
  171. package/dist/headers/LISP.d.ts +30 -0
  172. package/dist/headers/LISP.js +103 -0
  173. package/dist/headers/LLC.d.ts +27 -0
  174. package/dist/headers/LLC.js +81 -0
  175. package/dist/headers/LLDP.d.ts +26 -0
  176. package/dist/headers/LLDP.js +126 -0
  177. package/dist/headers/LLMNR.d.ts +23 -0
  178. package/dist/headers/LLMNR.js +40 -0
  179. package/dist/headers/LPD.d.ts +31 -0
  180. package/dist/headers/LPD.js +159 -0
  181. package/dist/headers/MACsec.d.ts +34 -0
  182. package/dist/headers/MACsec.js +178 -0
  183. package/dist/headers/MDNS.d.ts +26 -0
  184. package/dist/headers/MDNS.js +45 -0
  185. package/dist/headers/MGCP.d.ts +30 -0
  186. package/dist/headers/MGCP.js +155 -0
  187. package/dist/headers/MMS.d.ts +29 -0
  188. package/dist/headers/MMS.js +243 -0
  189. package/dist/headers/MPLS.d.ts +31 -0
  190. package/dist/headers/MPLS.js +145 -0
  191. package/dist/headers/MQTT.d.ts +30 -0
  192. package/dist/headers/MQTT.js +173 -0
  193. package/dist/headers/MQTTSN.d.ts +34 -0
  194. package/dist/headers/MQTTSN.js +177 -0
  195. package/dist/headers/MarkerProtocol.d.ts +32 -0
  196. package/dist/headers/MarkerProtocol.js +153 -0
  197. package/dist/headers/Megaco.d.ts +32 -0
  198. package/dist/headers/Megaco.js +144 -0
  199. package/dist/headers/Memcached.d.ts +44 -0
  200. package/dist/headers/Memcached.js +285 -0
  201. package/dist/headers/ModbusTCP.d.ts +25 -0
  202. package/dist/headers/ModbusTCP.js +99 -0
  203. package/dist/headers/ModbusUDP.d.ts +26 -0
  204. package/dist/headers/ModbusUDP.js +100 -0
  205. package/dist/headers/MongoDB.d.ts +33 -0
  206. package/dist/headers/MongoDB.js +143 -0
  207. package/dist/headers/MySQL.d.ts +30 -0
  208. package/dist/headers/MySQL.js +114 -0
  209. package/dist/headers/NATS.d.ts +29 -0
  210. package/dist/headers/NATS.js +135 -0
  211. package/dist/headers/NBDS.d.ts +34 -0
  212. package/dist/headers/NBDS.js +176 -0
  213. package/dist/headers/NBNS.d.ts +34 -0
  214. package/dist/headers/NBNS.js +78 -0
  215. package/dist/headers/NBSS.d.ts +36 -0
  216. package/dist/headers/NBSS.js +137 -0
  217. package/dist/headers/NFS.d.ts +36 -0
  218. package/dist/headers/NFS.js +273 -0
  219. package/dist/headers/NHRP.d.ts +32 -0
  220. package/dist/headers/NHRP.js +154 -0
  221. package/dist/headers/NNTP.d.ts +35 -0
  222. package/dist/headers/NNTP.js +162 -0
  223. package/dist/headers/NTP.d.ts +18 -0
  224. package/dist/headers/NTP.js +73 -0
  225. package/dist/headers/NetFlowV5.d.ts +28 -0
  226. package/dist/headers/NetFlowV5.js +205 -0
  227. package/dist/headers/OLSR.d.ts +31 -0
  228. package/dist/headers/OLSR.js +213 -0
  229. package/dist/headers/OPCUA.d.ts +33 -0
  230. package/dist/headers/OPCUA.js +165 -0
  231. package/dist/headers/OPCUAPubSub.d.ts +33 -0
  232. package/dist/headers/OPCUAPubSub.js +144 -0
  233. package/dist/headers/OSPF.d.ts +31 -0
  234. package/dist/headers/OSPF.js +365 -0
  235. package/dist/headers/OmronFINS.d.ts +31 -0
  236. package/dist/headers/OmronFINS.js +90 -0
  237. package/dist/headers/OpenFlow.d.ts +30 -0
  238. package/dist/headers/OpenFlow.js +113 -0
  239. package/dist/headers/OpenVPN.d.ts +35 -0
  240. package/dist/headers/OpenVPN.js +214 -0
  241. package/dist/headers/PCWorx.d.ts +35 -0
  242. package/dist/headers/PCWorx.js +115 -0
  243. package/dist/headers/PIM.d.ts +27 -0
  244. package/dist/headers/PIM.js +129 -0
  245. package/dist/headers/POP3.d.ts +31 -0
  246. package/dist/headers/POP3.js +152 -0
  247. package/dist/headers/POWERLINK.d.ts +28 -0
  248. package/dist/headers/POWERLINK.js +116 -0
  249. package/dist/headers/PPPoEDiscovery.d.ts +29 -0
  250. package/dist/headers/PPPoEDiscovery.js +198 -0
  251. package/dist/headers/PPPoESession.d.ts +28 -0
  252. package/dist/headers/PPPoESession.js +125 -0
  253. package/dist/headers/PPTP.d.ts +30 -0
  254. package/dist/headers/PPTP.js +122 -0
  255. package/dist/headers/PROFINETRT.d.ts +28 -0
  256. package/dist/headers/PROFINETRT.js +74 -0
  257. package/dist/headers/PTP.d.ts +34 -0
  258. package/dist/headers/PTP.js +213 -0
  259. package/dist/headers/PostgreSQL.d.ts +40 -0
  260. package/dist/headers/PostgreSQL.js +236 -0
  261. package/dist/headers/QUIC.d.ts +34 -0
  262. package/dist/headers/QUIC.js +308 -0
  263. package/dist/headers/RADIUS.d.ts +24 -0
  264. package/dist/headers/RADIUS.js +138 -0
  265. package/dist/headers/RDP.d.ts +27 -0
  266. package/dist/headers/RDP.js +93 -0
  267. package/dist/headers/RFB.d.ts +39 -0
  268. package/dist/headers/RFB.js +151 -0
  269. package/dist/headers/RGoose.d.ts +72 -0
  270. package/dist/headers/RGoose.js +340 -0
  271. package/dist/headers/RIP.d.ts +29 -0
  272. package/dist/headers/RIP.js +133 -0
  273. package/dist/headers/RIPng.d.ts +26 -0
  274. package/dist/headers/RIPng.js +140 -0
  275. package/dist/headers/RMCP.d.ts +26 -0
  276. package/dist/headers/RMCP.js +155 -0
  277. package/dist/headers/RSVP.d.ts +31 -0
  278. package/dist/headers/RSVP.js +263 -0
  279. package/dist/headers/RTCP.d.ts +34 -0
  280. package/dist/headers/RTCP.js +217 -0
  281. package/dist/headers/RTP.d.ts +33 -0
  282. package/dist/headers/RTP.js +291 -0
  283. package/dist/headers/RTPS.d.ts +33 -0
  284. package/dist/headers/RTPS.js +182 -0
  285. package/dist/headers/RTSP.d.ts +36 -0
  286. package/dist/headers/RTSP.js +184 -0
  287. package/dist/headers/RawData.d.ts +17 -0
  288. package/dist/headers/RawData.js +43 -0
  289. package/dist/headers/Redis.d.ts +32 -0
  290. package/dist/headers/Redis.js +202 -0
  291. package/dist/headers/Rlogin.d.ts +42 -0
  292. package/dist/headers/Rlogin.js +139 -0
  293. package/dist/headers/Rsync.d.ts +28 -0
  294. package/dist/headers/Rsync.js +117 -0
  295. package/dist/headers/S7comm.d.ts +36 -0
  296. package/dist/headers/S7comm.js +244 -0
  297. package/dist/headers/SCTP.d.ts +35 -0
  298. package/dist/headers/SCTP.js +174 -0
  299. package/dist/headers/SFlow.d.ts +29 -0
  300. package/dist/headers/SFlow.js +242 -0
  301. package/dist/headers/SIP.d.ts +27 -0
  302. package/dist/headers/SIP.js +146 -0
  303. package/dist/headers/SLMP.d.ts +36 -0
  304. package/dist/headers/SLMP.js +154 -0
  305. package/dist/headers/SLP.d.ts +30 -0
  306. package/dist/headers/SLP.js +207 -0
  307. package/dist/headers/SLPv1.d.ts +32 -0
  308. package/dist/headers/SLPv1.js +138 -0
  309. package/dist/headers/SMB1.d.ts +37 -0
  310. package/dist/headers/SMB1.js +200 -0
  311. package/dist/headers/SMB2.d.ts +36 -0
  312. package/dist/headers/SMB2.js +203 -0
  313. package/dist/headers/SMPP.d.ts +33 -0
  314. package/dist/headers/SMPP.js +119 -0
  315. package/dist/headers/SMTP.d.ts +33 -0
  316. package/dist/headers/SMTP.js +157 -0
  317. package/dist/headers/SNAP.d.ts +22 -0
  318. package/dist/headers/SNAP.js +68 -0
  319. package/dist/headers/SNMP.d.ts +28 -0
  320. package/dist/headers/SNMP.js +302 -0
  321. package/dist/headers/SOCKS4.d.ts +42 -0
  322. package/dist/headers/SOCKS4.js +302 -0
  323. package/dist/headers/SOCKS5.d.ts +45 -0
  324. package/dist/headers/SOCKS5.js +223 -0
  325. package/dist/headers/SSDP.d.ts +27 -0
  326. package/dist/headers/SSDP.js +161 -0
  327. package/dist/headers/SSH.d.ts +44 -0
  328. package/dist/headers/SSH.js +274 -0
  329. package/dist/headers/STOMP.d.ts +48 -0
  330. package/dist/headers/STOMP.js +177 -0
  331. package/dist/headers/STP.d.ts +26 -0
  332. package/dist/headers/STP.js +150 -0
  333. package/dist/headers/STUN.d.ts +25 -0
  334. package/dist/headers/STUN.js +183 -0
  335. package/dist/headers/SercosIII.d.ts +43 -0
  336. package/dist/headers/SercosIII.js +199 -0
  337. package/dist/headers/Skinny.d.ts +32 -0
  338. package/dist/headers/Skinny.js +139 -0
  339. package/dist/headers/StatsD.d.ts +27 -0
  340. package/dist/headers/StatsD.js +134 -0
  341. package/dist/headers/SunRPC.d.ts +34 -0
  342. package/dist/headers/SunRPC.js +268 -0
  343. package/dist/headers/Syslog.d.ts +21 -0
  344. package/dist/headers/Syslog.js +91 -0
  345. package/dist/headers/TCP.d.ts +19 -0
  346. package/dist/headers/TCP.js +905 -0
  347. package/dist/headers/TFTP.d.ts +28 -0
  348. package/dist/headers/TFTP.js +224 -0
  349. package/dist/headers/TLS_Alert.d.ts +24 -0
  350. package/dist/headers/TLS_Alert.js +639 -0
  351. package/dist/headers/TLS_ApplicationData.d.ts +24 -0
  352. package/dist/headers/TLS_ApplicationData.js +170 -0
  353. package/dist/headers/TLS_ChangeCipherSpec.d.ts +23 -0
  354. package/dist/headers/TLS_ChangeCipherSpec.js +168 -0
  355. package/dist/headers/TLS_Handshake.d.ts +65 -0
  356. package/dist/headers/TLS_Handshake.js +860 -0
  357. package/dist/headers/TLS_Heartbeat.d.ts +27 -0
  358. package/dist/headers/TLS_Heartbeat.js +247 -0
  359. package/dist/headers/TPKT.d.ts +26 -0
  360. package/dist/headers/TPKT.js +99 -0
  361. package/dist/headers/TacacsPlus.d.ts +27 -0
  362. package/dist/headers/TacacsPlus.js +133 -0
  363. package/dist/headers/Telnet.d.ts +40 -0
  364. package/dist/headers/Telnet.js +193 -0
  365. package/dist/headers/Teredo.d.ts +40 -0
  366. package/dist/headers/Teredo.js +251 -0
  367. package/dist/headers/TimeProtocol.d.ts +25 -0
  368. package/dist/headers/TimeProtocol.js +53 -0
  369. package/dist/headers/UDP.d.ts +19 -0
  370. package/dist/headers/UDP.js +171 -0
  371. package/dist/headers/VLAN_802dot1Q.d.ts +24 -0
  372. package/dist/headers/VLAN_802dot1Q.js +96 -0
  373. package/dist/headers/VRRP.d.ts +26 -0
  374. package/dist/headers/VRRP.js +309 -0
  375. package/dist/headers/VXLAN.d.ts +24 -0
  376. package/dist/headers/VXLAN.js +75 -0
  377. package/dist/headers/WCCP.d.ts +29 -0
  378. package/dist/headers/WCCP.js +117 -0
  379. package/dist/headers/WHOIS.d.ts +37 -0
  380. package/dist/headers/WHOIS.js +126 -0
  381. package/dist/headers/WSDiscovery.d.ts +29 -0
  382. package/dist/headers/WSDiscovery.js +118 -0
  383. package/dist/headers/WakeOnLAN.d.ts +30 -0
  384. package/dist/headers/WakeOnLAN.js +126 -0
  385. package/dist/headers/WebSocket.d.ts +26 -0
  386. package/dist/headers/WebSocket.js +173 -0
  387. package/dist/headers/WireGuard.d.ts +38 -0
  388. package/dist/headers/WireGuard.js +216 -0
  389. package/dist/headers/XMPP.d.ts +37 -0
  390. package/dist/headers/XMPP.js +149 -0
  391. package/dist/headers/Zabbix.d.ts +35 -0
  392. package/dist/headers/Zabbix.js +153 -0
  393. package/dist/headers/cms/AcsiPdu.d.ts +45 -0
  394. package/dist/headers/cms/AcsiPdu.js +112 -0
  395. package/dist/headers/cms/PerDecoder.d.ts +68 -0
  396. package/dist/headers/cms/PerDecoder.js +211 -0
  397. package/dist/headers/cms/PerReader.d.ts +64 -0
  398. package/dist/headers/cms/PerReader.js +155 -0
  399. package/dist/helper/BufferToHex.d.ts +5 -0
  400. package/dist/helper/BufferToHex.js +10 -0
  401. package/dist/helper/BufferToIP.d.ts +12 -0
  402. package/dist/helper/BufferToIP.js +23 -0
  403. package/dist/helper/BufferToNumber.d.ts +18 -0
  404. package/dist/helper/BufferToNumber.js +47 -0
  405. package/dist/helper/HexToBuffer.d.ts +7 -0
  406. package/dist/helper/HexToBuffer.js +27 -0
  407. package/dist/helper/HexToNumber.d.ts +18 -0
  408. package/dist/helper/HexToNumber.js +48 -0
  409. package/dist/helper/IPToBuffer.d.ts +12 -0
  410. package/dist/helper/IPToBuffer.js +34 -0
  411. package/dist/helper/NumberToBERBuffer.d.ts +18 -0
  412. package/dist/helper/NumberToBERBuffer.js +31 -0
  413. package/dist/helper/NumberToBERHex.d.ts +18 -0
  414. package/dist/helper/NumberToBERHex.js +52 -0
  415. package/dist/helper/NumberToBuffer.d.ts +18 -0
  416. package/dist/helper/NumberToBuffer.js +38 -0
  417. package/dist/helper/NumberToHex.d.ts +18 -0
  418. package/dist/helper/NumberToHex.js +35 -0
  419. package/dist/index.d.ts +52 -0
  420. package/dist/index.js +113 -0
  421. package/dist/lib/FlexibleObject.d.ts +27 -0
  422. package/dist/lib/FlexibleObject.js +113 -0
  423. package/dist/lib/GetBERIntegerLengthFromBuffer.d.ts +6 -0
  424. package/dist/lib/GetBERIntegerLengthFromBuffer.js +16 -0
  425. package/dist/lib/ProcessPacketPostHandlers.d.ts +13 -0
  426. package/dist/lib/ProcessPacketPostHandlers.js +53 -0
  427. package/dist/lib/SortPostHandlers.d.ts +7 -0
  428. package/dist/lib/SortPostHandlers.js +11 -0
  429. package/dist/lib/StringContentEncodingEnum.d.ts +10 -0
  430. package/dist/lib/StringContentEncodingEnum.js +14 -0
  431. package/dist/schema/ProtocolFieldJSONSchema.d.ts +35 -0
  432. package/dist/schema/ProtocolFieldJSONSchema.js +2 -0
  433. package/dist/schema/ProtocolFieldJSONSchemaDefinition.d.ts +2 -0
  434. package/dist/schema/ProtocolFieldJSONSchemaDefinition.js +2 -0
  435. package/dist/schema/ProtocolJSONSchema.d.ts +32 -0
  436. package/dist/schema/ProtocolJSONSchema.js +2 -0
  437. package/dist/types/CodecData.d.ts +7 -0
  438. package/dist/types/CodecData.js +2 -0
  439. package/dist/types/CodecDecodeResult.d.ts +10 -0
  440. package/dist/types/CodecDecodeResult.js +2 -0
  441. package/dist/types/CodecEncodeInput.d.ts +2 -0
  442. package/dist/types/CodecEncodeInput.js +2 -0
  443. package/dist/types/CodecEncodeResult.d.ts +5 -0
  444. package/dist/types/CodecEncodeResult.js +2 -0
  445. package/dist/types/CodecErrorInfo.d.ts +5 -0
  446. package/dist/types/CodecErrorInfo.js +2 -0
  447. package/dist/types/CodecModule.d.ts +2 -0
  448. package/dist/types/CodecModule.js +2 -0
  449. package/dist/types/CodecModuleConstructor.d.ts +2 -0
  450. package/dist/types/CodecModuleConstructor.js +2 -0
  451. package/dist/types/CodecSchema.d.ts +6 -0
  452. package/dist/types/CodecSchema.js +2 -0
  453. package/dist/types/DemuxProducer.d.ts +23 -0
  454. package/dist/types/DemuxProducer.js +2 -0
  455. package/dist/types/Dissection.d.ts +23 -0
  456. package/dist/types/Dissection.js +2 -0
  457. package/dist/types/HeaderTreeNode.d.ts +4 -0
  458. package/dist/types/HeaderTreeNode.js +2 -0
  459. package/dist/types/LayerGraph.d.ts +32 -0
  460. package/dist/types/LayerGraph.js +2 -0
  461. package/dist/types/PostHandlerItem.d.ts +4 -0
  462. package/dist/types/PostHandlerItem.js +2 -0
  463. package/package.json +141 -0
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WakeOnLAN = 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 StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
8
+ /**
9
+ * Wake-on-LAN "magic packet" (AMD Magic Packet Technology), carried directly in an Ethernet II frame
10
+ * with EtherType 0x0842 (an Ethernet child — no IP/UDP). The magic packet has a fixed shape: a 6-byte
11
+ * synchronization stream of all ones (0xFF ×6), followed by the target adapter's 6-byte MAC address
12
+ * repeated exactly 16 times (96 bytes), optionally followed by a 0/4/6-byte SecureOn password. There is
13
+ * no length field — the payload runs to the end of the frame.
14
+ *
15
+ * The 16 MAC repetitions are, by definition, identical, so the target MAC is surfaced once (decoded from
16
+ * the first repetition) and re-emitted 16× on encode — a well-formed magic packet round-trips
17
+ * byte-for-byte. The 6-byte sync stream is kept verbatim as hex (so an odd/crafted stream still
18
+ * reproduces) and any trailing SecureOn password bytes are kept verbatim as hex (0/4/6 bytes; taken to
19
+ * the end of the frame). Nothing is recomputed on encode. WoL is a leaf header — nothing rides above it.
20
+ *
21
+ * Note: WoL magic packets are also frequently sent as the payload of a UDP datagram (well-known ports 9
22
+ * and 7, or 0). This codec handles only the EtherType 0x0842 direct-on-Ethernet framing; the UDP-carried
23
+ * form is a separate demux (udpport) and is not attempted here.
24
+ */
25
+ class WakeOnLAN extends BaseHeader_1.BaseHeader {
26
+ constructor() {
27
+ super(...arguments);
28
+ this.id = 'wol';
29
+ this.name = 'Wake-on-LAN';
30
+ this.nickname = 'WoL';
31
+ this.matchKeys = ['ethertype:0842'];
32
+ //A leaf header — nothing demuxes above Wake-on-LAN.
33
+ this.demuxProducers = [];
34
+ }
35
+ static #schemaCache;
36
+ get SCHEMA() {
37
+ return (WakeOnLAN.#schemaCache ??= WakeOnLAN.#buildSchema());
38
+ }
39
+ static #buildSchema() {
40
+ return {
41
+ type: 'object',
42
+ summary: 'WoL target=${targetMac}',
43
+ properties: {
44
+ //The 6-byte synchronization stream. In a well-formed magic packet it is all ones
45
+ //(0xFF ×6); kept verbatim as hex so a crafted stream still round-trips byte-for-byte.
46
+ syncStream: this.fieldHex('syncStream', 0, 6, 'Sync Stream'),
47
+ //The target adapter's MAC address, decoded from the first of the 16 identical repetitions
48
+ //(offset 6). On encode it is written back 16 times over offsets 6..101 (96 bytes) — the
49
+ //defining property of a magic packet, so a well-formed packet reproduces exactly.
50
+ targetMac: {
51
+ type: 'string',
52
+ label: 'Target MAC',
53
+ minLength: 17,
54
+ maxLength: 17,
55
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.MAC,
56
+ decode: function () {
57
+ //Read (consume) the whole 96-byte MAC block so the header length covers all 16
58
+ //repetitions; the value is taken from the first repetition (they are identical).
59
+ const block = this.readBytes(6, 96);
60
+ this.instance.targetMac.setValue(Array.from(block.subarray(0, 6))
61
+ .map((value) => value.toString(16).padStart(2, '0'))
62
+ .join(':'));
63
+ },
64
+ encode: function () {
65
+ const mac = this.instance.targetMac
66
+ .getValue('00:00:00:00:00:00', (nodePath) => this.recordError(nodePath, 'Not Found'))
67
+ .toString()
68
+ .split(':')
69
+ .map((value) => parseInt(value, 16))
70
+ .map((value) => value ? value : 0);
71
+ const macBuffer = Buffer.alloc(6, Buffer.from(mac));
72
+ //Re-emit the 6-byte MAC 16 times (offsets 6..101) — the magic-packet MAC block.
73
+ for (let i = 0; i < 16; i++)
74
+ this.writeBytes(6 + i * 6, macBuffer);
75
+ }
76
+ },
77
+ //Optional SecureOn password after the 96-byte MAC block (0/4/6 bytes, RFC-less vendor
78
+ //extension). Kept verbatim as hex, taken to the end of the frame; empty when absent.
79
+ //WoL is a leaf so it consumes to the end — nothing is left for the codec's recursion.
80
+ password: {
81
+ type: 'string',
82
+ label: 'SecureOn Password',
83
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
84
+ decode: function () {
85
+ const available = this.packet.length - this.startPos;
86
+ this.instance.password.setValue(available > 102 ? (0, BufferToHex_1.BufferToHex)(this.readBytes(102, available - 102)) : '');
87
+ },
88
+ encode: function () {
89
+ const password = this.instance.password.getValue('');
90
+ if (password)
91
+ this.writeBytes(102, (0, HexToBuffer_1.HexToBuffer)(password));
92
+ }
93
+ }
94
+ }
95
+ };
96
+ }
97
+ match() {
98
+ //An Ethernet child selected by EtherType 0x0842 (stored as a lowercase 4-hex string). Require the
99
+ //full sync stream + MAC block (6 + 96 = 102 bytes) and the all-ones 6-byte sync-stream signature,
100
+ //so non-magic 0x0842 traffic falls through to raw.
101
+ if (!this.prevCodecModule || this.prevCodecModule.id !== 'eth')
102
+ return false;
103
+ if (this.prevCodecModule.instance.etherType.getValue() !== '0842')
104
+ return false;
105
+ if (this.packet.length - this.startPos < 102)
106
+ return false;
107
+ const sync = this.readBytes(0, 6, true);
108
+ for (let i = 0; i < 6; i++) {
109
+ if (sync[i] !== 0xff)
110
+ return false;
111
+ }
112
+ //A valid magic packet repeats the target MAC identically 16 times. Since this codec re-emits the
113
+ //block by reconstructing it from a single MAC, a frame whose 16 repetitions are NOT all identical
114
+ //could not round-trip byte-for-byte — so it is not a magic packet: leave it to RawData rather than
115
+ //claim it and silently rewrite the block.
116
+ const block = this.readBytes(6, 96, true);
117
+ for (let rep = 1; rep < 16; rep++) {
118
+ for (let b = 0; b < 6; b++) {
119
+ if (block[rep * 6 + b] !== block[b])
120
+ return false;
121
+ }
122
+ }
123
+ return true;
124
+ }
125
+ }
126
+ exports.WakeOnLAN = WakeOnLAN;
@@ -0,0 +1,26 @@
1
+ import { BaseHeader } from '../abstracts/BaseHeader';
2
+ import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
3
+ import { DemuxProducer } from '../types/DemuxProducer';
4
+ /**
5
+ * WebSocket — the RFC 6455 framing (post-HTTP-Upgrade). A frame is: byte 0 = FIN (1) + 3 reserved bits +
6
+ * a 4-bit Opcode (0 continuation, 1 text, 2 binary, 8 close, 9 ping, 10 pong); byte 1 = MASK (1) + a
7
+ * 7-bit payload length; an extended length (2 bytes if the 7-bit length is 126, 8 bytes if 127); a 4-byte
8
+ * masking key when MASK is set; then the (masked) application payload.
9
+ *
10
+ * WebSocket is NOT auto-registered in the default codec: which TCP stream is a WebSocket is decided by a
11
+ * prior HTTP `Upgrade` handshake — cross-packet state a single-packet stateless codec cannot track — so
12
+ * matching a frame on content alone would over-claim ordinary TCP payloads. It is therefore a
13
+ * decode-as-only frame codec: reachable via `new Codec([WebSocket])` (or a future upgrade-aware
14
+ * reassembly layer). The frame itself round-trips byte-for-byte; the payload is kept verbatim (masked
15
+ * bytes are not unmasked — that would change the bytes and break the round-trip).
16
+ */
17
+ export declare class WebSocket 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,173 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WebSocket = 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 StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
8
+ /**
9
+ * WebSocket — the RFC 6455 framing (post-HTTP-Upgrade). A frame is: byte 0 = FIN (1) + 3 reserved bits +
10
+ * a 4-bit Opcode (0 continuation, 1 text, 2 binary, 8 close, 9 ping, 10 pong); byte 1 = MASK (1) + a
11
+ * 7-bit payload length; an extended length (2 bytes if the 7-bit length is 126, 8 bytes if 127); a 4-byte
12
+ * masking key when MASK is set; then the (masked) application payload.
13
+ *
14
+ * WebSocket is NOT auto-registered in the default codec: which TCP stream is a WebSocket is decided by a
15
+ * prior HTTP `Upgrade` handshake — cross-packet state a single-packet stateless codec cannot track — so
16
+ * matching a frame on content alone would over-claim ordinary TCP payloads. It is therefore a
17
+ * decode-as-only frame codec: reachable via `new Codec([WebSocket])` (or a future upgrade-aware
18
+ * reassembly layer). The frame itself round-trips byte-for-byte; the payload is kept verbatim (masked
19
+ * bytes are not unmasked — that would change the bytes and break the round-trip).
20
+ */
21
+ class WebSocket extends BaseHeader_1.BaseHeader {
22
+ constructor() {
23
+ super(...arguments);
24
+ this.id = 'websocket';
25
+ this.name = 'WebSocket';
26
+ this.nickname = 'WS';
27
+ //Decode-as-only: no matchKeys (never auto-selected). When explicitly added via new Codec([WebSocket])
28
+ //it claims a TCP payload whose first two bytes are a plausible frame (a valid opcode, no reserved
29
+ //bits) — enough to guard against obvious non-frames while the caller has opted in.
30
+ this.matchKeys = [];
31
+ //A leaf — the payload is application data (possibly masked), kept verbatim.
32
+ this.demuxProducers = [];
33
+ }
34
+ static #schemaCache;
35
+ get SCHEMA() {
36
+ return (WebSocket.#schemaCache ??= WebSocket.#buildSchema());
37
+ }
38
+ /** Number of extended-length bytes implied by the 7-bit length: 2 for 126, 8 for 127, else 0. */
39
+ #extendedLengthBytes() {
40
+ const payloadLen = this.instance.payloadLen.getValue(0);
41
+ return payloadLen === 126 ? 2 : payloadLen === 127 ? 8 : 0;
42
+ }
43
+ /** Offset where the masking key (if any) begins: after byte 0/1 and the extended length. */
44
+ #maskOffset() {
45
+ return 2 + this.#extendedLengthBytes();
46
+ }
47
+ /** Offset where the payload begins: after the masking key when MASK is set. */
48
+ #payloadOffset() {
49
+ return this.#maskOffset() + (this.instance.mask.getValue(false) ? 4 : 0);
50
+ }
51
+ /** A single boolean bit within `byteOffset` at MSB-relative `bitOffset`. */
52
+ static #bitField(name, byteOffset, bitOffset, label) {
53
+ return {
54
+ type: 'boolean',
55
+ label: label,
56
+ decode: function () {
57
+ this.instance[name].setValue(!!this.readBits(byteOffset, 1, bitOffset, 1));
58
+ },
59
+ encode: function () {
60
+ this.writeBits(byteOffset, 1, bitOffset, 1, this.instance[name].getValue(false) ? 1 : 0);
61
+ }
62
+ };
63
+ }
64
+ static #buildSchema() {
65
+ return {
66
+ type: 'object',
67
+ summary: 'WebSocket opcode=${opcode}',
68
+ properties: {
69
+ fin: this.#bitField('fin', 0, 0, 'FIN'),
70
+ rsv1: this.#bitField('rsv1', 0, 1, 'RSV1'),
71
+ rsv2: this.#bitField('rsv2', 0, 2, 'RSV2'),
72
+ rsv3: this.#bitField('rsv3', 0, 3, 'RSV3'),
73
+ opcode: {
74
+ type: 'integer', label: 'Opcode', minimum: 0, maximum: 15,
75
+ decode: function () {
76
+ this.instance.opcode.setValue(this.readBits(0, 1, 4, 4));
77
+ },
78
+ encode: function () {
79
+ let value = this.instance.opcode.getValue(0);
80
+ if (value > 15)
81
+ value = 15;
82
+ if (value < 0)
83
+ value = 0;
84
+ this.writeBits(0, 1, 4, 4, value);
85
+ }
86
+ },
87
+ mask: this.#bitField('mask', 1, 0, 'Mask'),
88
+ payloadLen: {
89
+ type: 'integer', label: 'Payload Length (7-bit)', minimum: 0, maximum: 127,
90
+ decode: function () {
91
+ this.instance.payloadLen.setValue(this.readBits(1, 1, 1, 7));
92
+ },
93
+ encode: function () {
94
+ let value = this.instance.payloadLen.getValue(0);
95
+ if (value > 127)
96
+ value = 127;
97
+ if (value < 0)
98
+ value = 0;
99
+ this.writeBits(1, 1, 1, 7, value);
100
+ }
101
+ },
102
+ //Extended payload length: 2 or 8 bytes (kept verbatim as hex), present per the 7-bit length.
103
+ extendedPayloadLength: {
104
+ type: 'string', label: 'Extended Payload Length', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
105
+ decode: function () {
106
+ const bytes = this.#extendedLengthBytes();
107
+ this.instance.extendedPayloadLength.setValue(bytes > 0 ? (0, BufferToHex_1.BufferToHex)(this.readBytes(2, bytes)) : '');
108
+ },
109
+ encode: function () {
110
+ const value = this.instance.extendedPayloadLength.getValue('');
111
+ if (value)
112
+ this.writeBytes(2, (0, HexToBuffer_1.HexToBuffer)(value));
113
+ }
114
+ },
115
+ //4-byte masking key, present only when MASK is set.
116
+ maskingKey: {
117
+ type: 'string', label: 'Masking Key', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
118
+ decode: function () {
119
+ if (!this.instance.mask.getValue(false))
120
+ return;
121
+ this.instance.maskingKey.setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(this.#maskOffset(), 4)));
122
+ },
123
+ encode: function () {
124
+ if (!this.instance.mask.getValue(false))
125
+ return;
126
+ const value = this.instance.maskingKey.getValue('');
127
+ if (value)
128
+ this.writeBytes(this.#maskOffset(), (0, HexToBuffer_1.HexToBuffer)(value));
129
+ }
130
+ },
131
+ //The application payload, kept verbatim (masked bytes are NOT unmasked — that would alter
132
+ //the wire bytes and break the round-trip). Length is the 7-bit length, or the extended
133
+ //length, bounded by the captured bytes.
134
+ payload: {
135
+ type: 'string', label: 'Payload', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
136
+ decode: function () {
137
+ const offset = this.#payloadOffset();
138
+ const available = this.packet.length - this.startPos;
139
+ const payloadLen = this.instance.payloadLen.getValue(0);
140
+ const extended = this.instance.extendedPayloadLength.getValue('');
141
+ let length = extended ? parseInt(extended, 16) : payloadLen;
142
+ if (!Number.isFinite(length) || length < 0)
143
+ length = 0;
144
+ if (offset + length > available)
145
+ length = available - offset;
146
+ if (length < 0)
147
+ length = 0;
148
+ this.instance.payload.setValue(length > 0 ? (0, BufferToHex_1.BufferToHex)(this.readBytes(offset, length)) : '');
149
+ },
150
+ encode: function () {
151
+ const payload = this.instance.payload.getValue('');
152
+ if (payload)
153
+ this.writeBytes(this.#payloadOffset(), (0, HexToBuffer_1.HexToBuffer)(payload));
154
+ }
155
+ }
156
+ }
157
+ };
158
+ }
159
+ match() {
160
+ const prev = this.prevCodecModule;
161
+ if (!prev || prev.id !== 'tcp')
162
+ return false;
163
+ if (this.packet.length - this.startPos < 2)
164
+ return false;
165
+ const byte0 = this.readBytes(0, 1, true)[0];
166
+ //Reserved bits must be 0 (no extension negotiated) and the opcode must be a defined one.
167
+ if ((byte0 & 0x70) !== 0)
168
+ return false;
169
+ const opcode = byte0 & 0x0f;
170
+ return opcode === 0x0 || opcode === 0x1 || opcode === 0x2 || opcode === 0x8 || opcode === 0x9 || opcode === 0xa;
171
+ }
172
+ }
173
+ exports.WebSocket = WebSocket;
@@ -0,0 +1,38 @@
1
+ import { BaseHeader } from '../abstracts/BaseHeader';
2
+ import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
3
+ import { DemuxProducer } from '../types/DemuxProducer';
4
+ /**
5
+ * WireGuard (the WireGuard protocol, RFC-less / Noise_IKpsk2), UDP — commonly port 51820 but the port is
6
+ * freely configurable per-peer. Every WireGuard packet opens with a 4-byte prefix: a 1-byte Message Type
7
+ * (1 = Handshake Initiation, 2 = Handshake Response, 3 = Cookie Reply, 4 = Transport Data) and 3 Reserved
8
+ * bytes that the spec fixes at zero. The remaining layout is entirely Message-Type-driven:
9
+ *
10
+ * - Type 1 (Handshake Initiation, 148 bytes): sender(4 LE) + ephemeral(32) + static(48) + timestamp(28)
11
+ * + mac1(16) + mac2(16).
12
+ * - Type 2 (Handshake Response, 92 bytes): sender(4 LE) + receiver(4 LE) + ephemeral(32) + empty(16)
13
+ * + mac1(16) + mac2(16).
14
+ * - Type 3 (Cookie Reply, 64 bytes): receiver(4 LE) + nonce(24) + cookie(32).
15
+ * - Type 4 (Transport Data, variable): receiver(4 LE) + counter(8 LE) + encryptedPacket(rest).
16
+ *
17
+ * ⚠️ The sender / receiver indices are LITTLE-ENDIAN uint32 (WireGuard is little-endian on the wire), and
18
+ * there is no little-endian helper in this codebase, so they are read/written byte-by-byte in their
19
+ * closures (`>>> 0` on the WHOLE `|` expression so the high-bit value stays unsigned). The Transport-Data
20
+ * counter is a 64-bit LE nonce counter; it is kept as an 8-byte HEX field rather than a JS number to
21
+ * avoid the >2^53 precision loss (and it round-trips its little-endian bytes verbatim). Every crypto blob
22
+ * (ephemeral/static/timestamp/empty/nonce/cookie/mac1/mac2 and the encrypted payload) is opaque AEAD
23
+ * output, kept verbatim as HEX. A well-formed packet round-trips byte-for-byte.
24
+ *
25
+ * Field presence is branched on Message Type: each field's decode/encode consults a per-type offset table
26
+ * (`#offsetFor`) and no-ops when the field does not belong to the current type, so the four wire formats
27
+ * share one schema without phantom bytes.
28
+ */
29
+ export declare class WireGuard extends BaseHeader {
30
+ #private;
31
+ get SCHEMA(): ProtocolJSONSchema;
32
+ readonly id: string;
33
+ readonly name: string;
34
+ readonly nickname: string;
35
+ readonly matchKeys: string[];
36
+ match(): boolean;
37
+ readonly demuxProducers: DemuxProducer[];
38
+ }
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WireGuard = 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 StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
8
+ /**
9
+ * WireGuard (the WireGuard protocol, RFC-less / Noise_IKpsk2), UDP — commonly port 51820 but the port is
10
+ * freely configurable per-peer. Every WireGuard packet opens with a 4-byte prefix: a 1-byte Message Type
11
+ * (1 = Handshake Initiation, 2 = Handshake Response, 3 = Cookie Reply, 4 = Transport Data) and 3 Reserved
12
+ * bytes that the spec fixes at zero. The remaining layout is entirely Message-Type-driven:
13
+ *
14
+ * - Type 1 (Handshake Initiation, 148 bytes): sender(4 LE) + ephemeral(32) + static(48) + timestamp(28)
15
+ * + mac1(16) + mac2(16).
16
+ * - Type 2 (Handshake Response, 92 bytes): sender(4 LE) + receiver(4 LE) + ephemeral(32) + empty(16)
17
+ * + mac1(16) + mac2(16).
18
+ * - Type 3 (Cookie Reply, 64 bytes): receiver(4 LE) + nonce(24) + cookie(32).
19
+ * - Type 4 (Transport Data, variable): receiver(4 LE) + counter(8 LE) + encryptedPacket(rest).
20
+ *
21
+ * ⚠️ The sender / receiver indices are LITTLE-ENDIAN uint32 (WireGuard is little-endian on the wire), and
22
+ * there is no little-endian helper in this codebase, so they are read/written byte-by-byte in their
23
+ * closures (`>>> 0` on the WHOLE `|` expression so the high-bit value stays unsigned). The Transport-Data
24
+ * counter is a 64-bit LE nonce counter; it is kept as an 8-byte HEX field rather than a JS number to
25
+ * avoid the >2^53 precision loss (and it round-trips its little-endian bytes verbatim). Every crypto blob
26
+ * (ephemeral/static/timestamp/empty/nonce/cookie/mac1/mac2 and the encrypted payload) is opaque AEAD
27
+ * output, kept verbatim as HEX. A well-formed packet round-trips byte-for-byte.
28
+ *
29
+ * Field presence is branched on Message Type: each field's decode/encode consults a per-type offset table
30
+ * (`#offsetFor`) and no-ops when the field does not belong to the current type, so the four wire formats
31
+ * share one schema without phantom bytes.
32
+ */
33
+ class WireGuard extends BaseHeader_1.BaseHeader {
34
+ constructor() {
35
+ super(...arguments);
36
+ this.id = 'wireguard';
37
+ this.name = 'WireGuard';
38
+ this.nickname = 'WireGuard';
39
+ this.matchKeys = ['udpport:51820'];
40
+ //A leaf header — the payload beyond the header is AEAD-encrypted ciphertext with no further structure.
41
+ this.demuxProducers = [];
42
+ }
43
+ static #schemaCache;
44
+ get SCHEMA() {
45
+ return (WireGuard.#schemaCache ??= WireGuard.#buildSchema());
46
+ }
47
+ /** Fixed on-wire size of a Message Type with a fixed layout (types 1/2/3); 0 for the variable type 4. */
48
+ static #FIXED_SIZE = { 1: 148, 2: 92, 3: 64 };
49
+ /** The WireGuard payload available in this datagram, clamped by the UDP length (drops trailing FCS/padding). */
50
+ #payloadLength() {
51
+ let available = this.packet.length - this.startPos;
52
+ if (this.prevCodecModule && this.prevCodecModule.id === 'udp') {
53
+ const udpLength = this.prevCodecModule.instance.length.getValue(0);
54
+ if (udpLength >= 8 && udpLength - 8 < available)
55
+ available = udpLength - 8;
56
+ }
57
+ return available < 0 ? 0 : available;
58
+ }
59
+ /**
60
+ * Header-relative byte offset of `field` for the CURRENT Message Type, or -1 when the field does not
61
+ * belong to this type. Message Type has been decoded (or, on encode, provided) before any other field
62
+ * runs — it is the first schema property — so `instance.messageType` is authoritative here.
63
+ */
64
+ #offsetFor(field) {
65
+ const messageType = this.instance.messageType.getValue(0);
66
+ let layout;
67
+ switch (messageType) {
68
+ case 1:
69
+ layout = { sender: 4, ephemeral: 8, static: 40, timestamp: 88, mac1: 116, mac2: 132 };
70
+ break;
71
+ case 2:
72
+ layout = { sender: 4, receiver: 8, ephemeral: 12, empty: 44, mac1: 60, mac2: 76 };
73
+ break;
74
+ case 3:
75
+ layout = { receiver: 4, nonce: 8, cookie: 32 };
76
+ break;
77
+ case 4:
78
+ layout = { receiver: 4, counter: 8 };
79
+ break;
80
+ default: layout = {};
81
+ }
82
+ const offset = layout[field];
83
+ return offset === undefined ? -1 : offset;
84
+ }
85
+ /** A little-endian unsigned 32-bit index (sender/receiver) whose offset depends on the Message Type. */
86
+ static #fieldUInt32LE(name, label) {
87
+ return {
88
+ type: 'integer',
89
+ label: label,
90
+ minimum: 0,
91
+ maximum: 4294967295,
92
+ decode: function () {
93
+ const offset = this.#offsetFor(name);
94
+ if (offset < 0)
95
+ return;
96
+ const b = this.readBytes(offset, 4);
97
+ this.instance[name].setValue((b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24)) >>> 0);
98
+ },
99
+ encode: function () {
100
+ const offset = this.#offsetFor(name);
101
+ if (offset < 0)
102
+ return;
103
+ const node = this.instance[name];
104
+ let value = node.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
105
+ if (value > 4294967295) {
106
+ this.recordError(node.getPath(), 'Maximum value is 4294967295');
107
+ value = 4294967295;
108
+ }
109
+ if (value < 0) {
110
+ this.recordError(node.getPath(), 'Minimum value is 0');
111
+ value = 0;
112
+ }
113
+ node.setValue(value);
114
+ this.writeBytes(offset, Buffer.from([value & 0xff, (value >> 8) & 0xff, (value >> 16) & 0xff, (value >>> 24) & 0xff]));
115
+ }
116
+ };
117
+ }
118
+ /** A fixed-width opaque crypto blob (HEX) whose offset depends on the Message Type. */
119
+ static #fieldBlob(name, byteLength, label) {
120
+ const zero = '00'.repeat(byteLength);
121
+ return {
122
+ type: 'string',
123
+ label: label,
124
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
125
+ decode: function () {
126
+ const offset = this.#offsetFor(name);
127
+ if (offset < 0)
128
+ return;
129
+ this.instance[name].setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(offset, byteLength)));
130
+ },
131
+ encode: function () {
132
+ const offset = this.#offsetFor(name);
133
+ if (offset < 0)
134
+ return;
135
+ this.writeBytes(offset, (0, HexToBuffer_1.HexToBuffer)(this.instance[name].getValue(zero)));
136
+ }
137
+ };
138
+ }
139
+ static #buildSchema() {
140
+ return {
141
+ type: 'object',
142
+ summary: 'WireGuard type=${messageType}',
143
+ properties: {
144
+ //Message Type first: every other field's presence/offset is branched on it.
145
+ messageType: this.fieldUInt('messageType', 0, 1, 'Message Type'),
146
+ //3 Reserved bytes, spec-fixed at zero. Kept as a field (not asserted) so it is visible/editable;
147
+ //match() requires them zero as part of the content signature, so a non-zero-reserved datagram
148
+ //is not claimed as WireGuard (it falls to raw) rather than round-tripping through this codec.
149
+ reserved: this.fieldHex('reserved', 1, 3, 'Reserved'),
150
+ //Sender index (types 1, 2) — LITTLE-ENDIAN uint32.
151
+ sender: this.#fieldUInt32LE('sender', 'Sender Index'),
152
+ //Receiver index (types 2, 3, 4) — LITTLE-ENDIAN uint32.
153
+ receiver: this.#fieldUInt32LE('receiver', 'Receiver Index'),
154
+ //Handshake crypto blobs (types 1, 2), all opaque AEAD/Curve25519 output kept verbatim.
155
+ ephemeral: this.#fieldBlob('ephemeral', 32, 'Unencrypted Ephemeral'),
156
+ static: this.#fieldBlob('static', 48, 'Encrypted Static'),
157
+ timestamp: this.#fieldBlob('timestamp', 28, 'Encrypted Timestamp'),
158
+ empty: this.#fieldBlob('empty', 16, 'Encrypted Empty'),
159
+ //Cookie Reply blobs (type 3).
160
+ nonce: this.#fieldBlob('nonce', 24, 'Nonce'),
161
+ cookie: this.#fieldBlob('cookie', 32, 'Encrypted Cookie'),
162
+ //Transport Data (type 4): a 64-bit LE counter kept as HEX (avoids >2^53 precision loss) and
163
+ //the encrypted packet — the rest of the datagram, bounded by the UDP length.
164
+ counter: this.#fieldBlob('counter', 8, 'Counter'),
165
+ mac1: this.#fieldBlob('mac1', 16, 'MAC1'),
166
+ mac2: this.#fieldBlob('mac2', 16, 'MAC2'),
167
+ encryptedPacket: {
168
+ type: 'string',
169
+ label: 'Encrypted Packet',
170
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
171
+ decode: function () {
172
+ const messageType = this.instance.messageType.getValue(0);
173
+ if (messageType !== 4)
174
+ return;
175
+ const available = this.#payloadLength();
176
+ this.instance.encryptedPacket.setValue(available > 16 ? (0, BufferToHex_1.BufferToHex)(this.readBytes(16, available - 16)) : '');
177
+ },
178
+ encode: function () {
179
+ const messageType = this.instance.messageType.getValue(0);
180
+ if (messageType !== 4)
181
+ return;
182
+ const data = this.instance.encryptedPacket.getValue('');
183
+ if (data)
184
+ this.writeBytes(16, (0, HexToBuffer_1.HexToBuffer)(data));
185
+ }
186
+ }
187
+ }
188
+ };
189
+ }
190
+ match() {
191
+ //WireGuard's port is configurable, so this codec is registered ONLY in the udp/51820 demux bucket
192
+ //(no heuristicFallback): the 1-byte Message Type + 3 zero Reserved bytes is a weakish 4-byte content
193
+ //signature that would over-match on arbitrary ports, so the well-known port gates it. Within the
194
+ //bucket, require Message Type ∈ {1,2,3,4}, the 3 Reserved bytes zero, and the fixed-layout types to
195
+ //carry their full length — otherwise fall through to raw.
196
+ if (!this.prevCodecModule || this.prevCodecModule.id !== 'udp')
197
+ return false;
198
+ const available = this.#payloadLength();
199
+ if (available < 4)
200
+ return false;
201
+ const messageType = this.readBytes(0, 1, true)[0];
202
+ if (messageType < 1 || messageType > 4)
203
+ return false;
204
+ const reserved = this.readBytes(1, 3, true);
205
+ if (reserved[0] !== 0 || reserved[1] !== 0 || reserved[2] !== 0)
206
+ return false;
207
+ const fixedSize = WireGuard.#FIXED_SIZE[messageType];
208
+ if (fixedSize !== undefined && available < fixedSize)
209
+ return false;
210
+ //Type 4 needs at least the 16-byte transport header (type+reserved+receiver+counter).
211
+ if (messageType === 4 && available < 16)
212
+ return false;
213
+ return true;
214
+ }
215
+ }
216
+ exports.WireGuard = WireGuard;
@@ -0,0 +1,37 @@
1
+ import { BaseHeader } from '../abstracts/BaseHeader';
2
+ import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
3
+ import { DemuxProducer } from '../types/DemuxProducer';
4
+ /**
5
+ * XMPP — the Extensible Messaging and Presence Protocol (RFC 6120), the XML-streaming protocol behind
6
+ * Jabber and many IM/presence systems. It rides over TCP: client-to-server on port 5222, server-to-server
7
+ * on port 5269. Unlike a request/response protocol, an XMPP session is a pair of open-ended XML streams —
8
+ * each peer opens a `<stream:stream>` root element and then emits a sequence of "stanzas" (`<message>`,
9
+ * `<presence>`, `<iq>`) as child elements until the stream is closed with `</stream:stream>`. A single
10
+ * captured packet therefore carries an arbitrary FRAGMENT of that XML text: the stream preamble
11
+ * (`<?xml version='1.0'?><stream:stream …>`), one or more whole stanzas, or even a partial element split
12
+ * across TCP segments.
13
+ *
14
+ * Like SIP and HTTP, the payload is text whose full internal structure (namespaces, arbitrary nested
15
+ * elements, significant whitespace, entity encoding) is far richer than a form needs, and byte ordering /
16
+ * whitespace is significant to the XML stream parser on the other end. So the ENTIRE raw payload is kept
17
+ * verbatim as the authoritative `message` field (hex) and re-emitted untouched; only lightweight
18
+ * display-only metadata (the first element's tag name, whether it is a stream header, whether an XML
19
+ * declaration is present) is parsed on decode. Encode never reconstructs the XML from the metadata — it
20
+ * writes `message` back byte-for-byte — so any conformant (or even malformed) XMPP fragment round-trips
21
+ * exactly.
22
+ *
23
+ * Note: XMPP stanzas can span multiple TCP segments and TLS/SASL negotiation (STARTTLS) switches the
24
+ * stream to ciphertext mid-session; reassembly and post-STARTTLS decryption are out of scope. This
25
+ * single-segment codec keeps whatever XML bytes are present in the current segment verbatim, which is
26
+ * byte-perfect for the single-packet case.
27
+ */
28
+ export declare class XMPP extends BaseHeader {
29
+ #private;
30
+ get SCHEMA(): ProtocolJSONSchema;
31
+ readonly id: string;
32
+ readonly name: string;
33
+ readonly nickname: string;
34
+ readonly matchKeys: string[];
35
+ match(): boolean;
36
+ readonly demuxProducers: DemuxProducer[];
37
+ }