netkitty 0.0.35 → 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 (428) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +91 -2
  3. package/README.zh-CN.md +89 -0
  4. package/dist/analysis.d.ts +4 -0
  5. package/dist/{CodecHeaderExports.js → analysis.js} +4 -1
  6. package/dist/capture.d.ts +5 -0
  7. package/dist/capture.js +21 -0
  8. package/dist/codec.d.ts +5 -0
  9. package/dist/codec.js +21 -0
  10. package/dist/iface.d.ts +4 -0
  11. package/dist/iface.js +20 -0
  12. package/dist/pcap.d.ts +10 -0
  13. package/dist/pcap.js +27 -0
  14. package/dist/replay.d.ts +5 -0
  15. package/dist/replay.js +21 -0
  16. package/package.json +65 -59
  17. package/.eslintrc.json +0 -53
  18. package/.idea/codeStyles/Project.xml +0 -18
  19. package/.idea/codeStyles/codeStyleConfig.xml +0 -5
  20. package/.idea/inspectionProfiles/Project_Default.xml +0 -11
  21. package/.idea/modules.xml +0 -8
  22. package/.idea/netkitty.iml +0 -12
  23. package/.idea/vcs.xml +0 -6
  24. package/assets/NetKitty.png +0 -0
  25. package/binding.gyp +0 -5
  26. package/cpp/nodepcap/deps/include/Packet32.h +0 -429
  27. package/cpp/nodepcap/deps/include/pcap/bluetooth.h +0 -56
  28. package/cpp/nodepcap/deps/include/pcap/bpf.h +0 -292
  29. package/cpp/nodepcap/deps/include/pcap/can_socketcan.h +0 -56
  30. package/cpp/nodepcap/deps/include/pcap/compiler-tests.h +0 -163
  31. package/cpp/nodepcap/deps/include/pcap/dlt.h +0 -1514
  32. package/cpp/nodepcap/deps/include/pcap/funcattrs.h +0 -325
  33. package/cpp/nodepcap/deps/include/pcap/ipnet.h +0 -43
  34. package/cpp/nodepcap/deps/include/pcap/namedb.h +0 -84
  35. package/cpp/nodepcap/deps/include/pcap/nflog.h +0 -94
  36. package/cpp/nodepcap/deps/include/pcap/pcap-inttypes.h +0 -101
  37. package/cpp/nodepcap/deps/include/pcap/pcap.h +0 -1219
  38. package/cpp/nodepcap/deps/include/pcap/sll.h +0 -149
  39. package/cpp/nodepcap/deps/include/pcap/socket.h +0 -84
  40. package/cpp/nodepcap/deps/include/pcap/usb.h +0 -143
  41. package/cpp/nodepcap/deps/include/pcap/vlan.h +0 -46
  42. package/cpp/nodepcap/deps/include/pcap-bpf.h +0 -45
  43. package/cpp/nodepcap/deps/include/pcap-namedb.h +0 -40
  44. package/cpp/nodepcap/deps/include/pcap.h +0 -43
  45. package/cpp/nodepcap/deps/lib/ARM64/Packet.lib +0 -0
  46. package/cpp/nodepcap/deps/lib/Packet.lib +0 -0
  47. package/cpp/nodepcap/deps/lib/wpcap.lib +0 -0
  48. package/cpp/nodepcap/deps/lib/x64/Packet.lib +0 -0
  49. package/cpp/nodepcap/deps/lib/x64/wpcap.lib +0 -0
  50. package/cpp/nodepcap/nodepcap.gypi +0 -104
  51. package/cpp/nodepcap/src/binding.cc +0 -14
  52. package/cpp/nodepcap/src/capture.cc +0 -400
  53. package/cpp/nodepcap/src/capture.h +0 -53
  54. package/cpp/nodepcap/src/utils.cc +0 -218
  55. package/cpp/nodepcap/src/utils.h +0 -13
  56. package/dist/CodecExports.d.ts +0 -34
  57. package/dist/CodecExports.d.ts.map +0 -1
  58. package/dist/CodecExports.js +0 -23
  59. package/dist/CodecHeaderExports.d.ts +0 -2
  60. package/dist/CodecHeaderExports.d.ts.map +0 -1
  61. package/dist/HelperExports.d.ts +0 -11
  62. package/dist/HelperExports.d.ts.map +0 -1
  63. package/dist/HelperExports.js +0 -72
  64. package/dist/NetworkExports.d.ts +0 -13
  65. package/dist/NetworkExports.d.ts.map +0 -1
  66. package/dist/NetworkExports.js +0 -13
  67. package/dist/PcapExports.d.ts +0 -30
  68. package/dist/PcapExports.d.ts.map +0 -1
  69. package/dist/PcapExports.js +0 -33
  70. package/dist/errors/ActionNotFoundError.d.ts +0 -5
  71. package/dist/errors/ActionNotFoundError.d.ts.map +0 -1
  72. package/dist/errors/ActionNotFoundError.js +0 -12
  73. package/dist/errors/CodecSchemaValidateError.d.ts +0 -5
  74. package/dist/errors/CodecSchemaValidateError.d.ts.map +0 -1
  75. package/dist/errors/CodecSchemaValidateError.js +0 -12
  76. package/dist/errors/DeviceNotFoundError.d.ts +0 -5
  77. package/dist/errors/DeviceNotFoundError.d.ts.map +0 -1
  78. package/dist/errors/DeviceNotFoundError.js +0 -12
  79. package/dist/errors/NoAvailableCodecError.d.ts +0 -5
  80. package/dist/errors/NoAvailableCodecError.d.ts.map +0 -1
  81. package/dist/errors/NoAvailableCodecError.js +0 -12
  82. package/dist/errors/NpcapLoadError.d.ts +0 -5
  83. package/dist/errors/NpcapLoadError.d.ts.map +0 -1
  84. package/dist/errors/NpcapLoadError.js +0 -12
  85. package/dist/errors/SocketDownError.d.ts +0 -5
  86. package/dist/errors/SocketDownError.d.ts.map +0 -1
  87. package/dist/errors/SocketDownError.js +0 -12
  88. package/dist/errors/UnknownPipeMessageTypeError.d.ts +0 -5
  89. package/dist/errors/UnknownPipeMessageTypeError.d.ts.map +0 -1
  90. package/dist/errors/UnknownPipeMessageTypeError.js +0 -12
  91. package/dist/errors/common/ErrorCode.d.ts +0 -31
  92. package/dist/errors/common/ErrorCode.d.ts.map +0 -1
  93. package/dist/errors/common/ErrorCode.js +0 -33
  94. package/dist/lib/GeneratePipeAddress.d.ts +0 -7
  95. package/dist/lib/GeneratePipeAddress.d.ts.map +0 -1
  96. package/dist/lib/GeneratePipeAddress.js +0 -23
  97. package/dist/lib/GetBinding.d.ts +0 -2
  98. package/dist/lib/GetBinding.d.ts.map +0 -1
  99. package/dist/lib/GetBinding.js +0 -6
  100. package/dist/lib/GetCaptureTemporaryDirectory.d.ts +0 -7
  101. package/dist/lib/GetCaptureTemporaryDirectory.d.ts.map +0 -1
  102. package/dist/lib/GetCaptureTemporaryDirectory.js +0 -15
  103. package/dist/lib/GetDeviceCaptureTemporaryFilename.d.ts +0 -8
  104. package/dist/lib/GetDeviceCaptureTemporaryFilename.d.ts.map +0 -1
  105. package/dist/lib/GetDeviceCaptureTemporaryFilename.js +0 -18
  106. package/dist/lib/codec/Codec.d.ts +0 -32
  107. package/dist/lib/codec/Codec.d.ts.map +0 -1
  108. package/dist/lib/codec/Codec.js +0 -183
  109. package/dist/lib/codec/PacketHeaders.d.ts +0 -22
  110. package/dist/lib/codec/PacketHeaders.d.ts.map +0 -1
  111. package/dist/lib/codec/PacketHeaders.js +0 -47
  112. package/dist/lib/codec/abstracts/BaseHeader.d.ts +0 -217
  113. package/dist/lib/codec/abstracts/BaseHeader.d.ts.map +0 -1
  114. package/dist/lib/codec/abstracts/BaseHeader.js +0 -356
  115. package/dist/lib/codec/headers/ARP.d.ts +0 -10
  116. package/dist/lib/codec/headers/ARP.d.ts.map +0 -1
  117. package/dist/lib/codec/headers/ARP.js +0 -224
  118. package/dist/lib/codec/headers/EthernetII.d.ts +0 -10
  119. package/dist/lib/codec/headers/EthernetII.d.ts.map +0 -1
  120. package/dist/lib/codec/headers/EthernetII.js +0 -81
  121. package/dist/lib/codec/headers/Goose.d.ts +0 -104
  122. package/dist/lib/codec/headers/Goose.d.ts.map +0 -1
  123. package/dist/lib/codec/headers/Goose.js +0 -1005
  124. package/dist/lib/codec/headers/ICMP.d.ts +0 -15
  125. package/dist/lib/codec/headers/ICMP.d.ts.map +0 -1
  126. package/dist/lib/codec/headers/ICMP.js +0 -147
  127. package/dist/lib/codec/headers/ICMPv6.d.ts +0 -15
  128. package/dist/lib/codec/headers/ICMPv6.d.ts.map +0 -1
  129. package/dist/lib/codec/headers/ICMPv6.js +0 -128
  130. package/dist/lib/codec/headers/IEC104_I_Frame.d.ts +0 -10
  131. package/dist/lib/codec/headers/IEC104_I_Frame.d.ts.map +0 -1
  132. package/dist/lib/codec/headers/IEC104_I_Frame.js +0 -6411
  133. package/dist/lib/codec/headers/IEC104_S_Frame.d.ts +0 -10
  134. package/dist/lib/codec/headers/IEC104_S_Frame.d.ts.map +0 -1
  135. package/dist/lib/codec/headers/IEC104_S_Frame.js +0 -105
  136. package/dist/lib/codec/headers/IEC104_U_Frame.d.ts +0 -10
  137. package/dist/lib/codec/headers/IEC104_U_Frame.d.ts.map +0 -1
  138. package/dist/lib/codec/headers/IEC104_U_Frame.js +0 -155
  139. package/dist/lib/codec/headers/IEC61850SampledValues.d.ts +0 -13
  140. package/dist/lib/codec/headers/IEC61850SampledValues.d.ts.map +0 -1
  141. package/dist/lib/codec/headers/IEC61850SampledValues.js +0 -370
  142. package/dist/lib/codec/headers/IPv4.d.ts +0 -16
  143. package/dist/lib/codec/headers/IPv4.d.ts.map +0 -1
  144. package/dist/lib/codec/headers/IPv4.js +0 -339
  145. package/dist/lib/codec/headers/IPv6.d.ts +0 -10
  146. package/dist/lib/codec/headers/IPv6.d.ts.map +0 -1
  147. package/dist/lib/codec/headers/IPv6.js +0 -177
  148. package/dist/lib/codec/headers/IPv6HopByHopOptions.d.ts +0 -71
  149. package/dist/lib/codec/headers/IPv6HopByHopOptions.d.ts.map +0 -1
  150. package/dist/lib/codec/headers/IPv6HopByHopOptions.js +0 -517
  151. package/dist/lib/codec/headers/RawData.d.ts +0 -11
  152. package/dist/lib/codec/headers/RawData.d.ts.map +0 -1
  153. package/dist/lib/codec/headers/RawData.js +0 -36
  154. package/dist/lib/codec/headers/TCP.d.ts +0 -16
  155. package/dist/lib/codec/headers/TCP.d.ts.map +0 -1
  156. package/dist/lib/codec/headers/TCP.js +0 -917
  157. package/dist/lib/codec/headers/TLS_Alert.d.ts +0 -10
  158. package/dist/lib/codec/headers/TLS_Alert.d.ts.map +0 -1
  159. package/dist/lib/codec/headers/TLS_Alert.js +0 -624
  160. package/dist/lib/codec/headers/TLS_ApplicationData.d.ts +0 -10
  161. package/dist/lib/codec/headers/TLS_ApplicationData.d.ts.map +0 -1
  162. package/dist/lib/codec/headers/TLS_ApplicationData.js +0 -155
  163. package/dist/lib/codec/headers/TLS_ChangeCipherSpec.d.ts +0 -10
  164. package/dist/lib/codec/headers/TLS_ChangeCipherSpec.d.ts.map +0 -1
  165. package/dist/lib/codec/headers/TLS_ChangeCipherSpec.js +0 -154
  166. package/dist/lib/codec/headers/TLS_Handshake.d.ts +0 -10
  167. package/dist/lib/codec/headers/TLS_Handshake.d.ts.map +0 -1
  168. package/dist/lib/codec/headers/TLS_Handshake.js +0 -339
  169. package/dist/lib/codec/headers/TLS_Heartbeat.d.ts +0 -10
  170. package/dist/lib/codec/headers/TLS_Heartbeat.d.ts.map +0 -1
  171. package/dist/lib/codec/headers/TLS_Heartbeat.js +0 -206
  172. package/dist/lib/codec/headers/UDP.d.ts +0 -16
  173. package/dist/lib/codec/headers/UDP.d.ts.map +0 -1
  174. package/dist/lib/codec/headers/UDP.js +0 -192
  175. package/dist/lib/codec/headers/VLAN_802dot1Q.d.ts +0 -10
  176. package/dist/lib/codec/headers/VLAN_802dot1Q.d.ts.map +0 -1
  177. package/dist/lib/codec/headers/VLAN_802dot1Q.js +0 -82
  178. package/dist/lib/codec/lib/FlexibleObject.d.ts +0 -28
  179. package/dist/lib/codec/lib/FlexibleObject.d.ts.map +0 -1
  180. package/dist/lib/codec/lib/FlexibleObject.js +0 -102
  181. package/dist/lib/codec/lib/GetBERIntegerLengthFromBuffer.d.ts +0 -7
  182. package/dist/lib/codec/lib/GetBERIntegerLengthFromBuffer.d.ts.map +0 -1
  183. package/dist/lib/codec/lib/GetBERIntegerLengthFromBuffer.js +0 -16
  184. package/dist/lib/codec/lib/ProcessPacketPostHandlers.d.ts +0 -14
  185. package/dist/lib/codec/lib/ProcessPacketPostHandlers.d.ts.map +0 -1
  186. package/dist/lib/codec/lib/ProcessPacketPostHandlers.js +0 -53
  187. package/dist/lib/codec/lib/SortPostHandlers.d.ts +0 -8
  188. package/dist/lib/codec/lib/SortPostHandlers.d.ts.map +0 -1
  189. package/dist/lib/codec/lib/SortPostHandlers.js +0 -11
  190. package/dist/lib/codec/lib/StringContentEncodingEnum.d.ts +0 -11
  191. package/dist/lib/codec/lib/StringContentEncodingEnum.d.ts.map +0 -1
  192. package/dist/lib/codec/lib/StringContentEncodingEnum.js +0 -14
  193. package/dist/lib/codec/types/CodecData.d.ts +0 -7
  194. package/dist/lib/codec/types/CodecData.d.ts.map +0 -1
  195. package/dist/lib/codec/types/CodecData.js +0 -2
  196. package/dist/lib/codec/types/CodecDecodeResult.d.ts +0 -11
  197. package/dist/lib/codec/types/CodecDecodeResult.d.ts.map +0 -1
  198. package/dist/lib/codec/types/CodecDecodeResult.js +0 -2
  199. package/dist/lib/codec/types/CodecEncodeInput.d.ts +0 -9
  200. package/dist/lib/codec/types/CodecEncodeInput.d.ts.map +0 -1
  201. package/dist/lib/codec/types/CodecEncodeInput.js +0 -2
  202. package/dist/lib/codec/types/CodecEncodeResult.d.ts +0 -6
  203. package/dist/lib/codec/types/CodecEncodeResult.d.ts.map +0 -1
  204. package/dist/lib/codec/types/CodecEncodeResult.js +0 -2
  205. package/dist/lib/codec/types/CodecErrorInfo.d.ts +0 -6
  206. package/dist/lib/codec/types/CodecErrorInfo.d.ts.map +0 -1
  207. package/dist/lib/codec/types/CodecErrorInfo.js +0 -2
  208. package/dist/lib/codec/types/CodecModule.d.ts +0 -3
  209. package/dist/lib/codec/types/CodecModule.d.ts.map +0 -1
  210. package/dist/lib/codec/types/CodecModule.js +0 -2
  211. package/dist/lib/codec/types/CodecModuleConstructor.d.ts +0 -3
  212. package/dist/lib/codec/types/CodecModuleConstructor.d.ts.map +0 -1
  213. package/dist/lib/codec/types/CodecModuleConstructor.js +0 -2
  214. package/dist/lib/codec/types/CodecSchema.d.ts +0 -7
  215. package/dist/lib/codec/types/CodecSchema.d.ts.map +0 -1
  216. package/dist/lib/codec/types/CodecSchema.js +0 -2
  217. package/dist/lib/codec/types/HeaderTreeNode.d.ts +0 -5
  218. package/dist/lib/codec/types/HeaderTreeNode.d.ts.map +0 -1
  219. package/dist/lib/codec/types/HeaderTreeNode.js +0 -2
  220. package/dist/lib/codec/types/PostHandlerItem.d.ts +0 -5
  221. package/dist/lib/codec/types/PostHandlerItem.d.ts.map +0 -1
  222. package/dist/lib/codec/types/PostHandlerItem.js +0 -2
  223. package/dist/lib/helper/BufferToHex.d.ts +0 -2
  224. package/dist/lib/helper/BufferToHex.d.ts.map +0 -1
  225. package/dist/lib/helper/BufferToHex.js +0 -6
  226. package/dist/lib/helper/BufferToIP.d.ts +0 -13
  227. package/dist/lib/helper/BufferToIP.d.ts.map +0 -1
  228. package/dist/lib/helper/BufferToIP.js +0 -21
  229. package/dist/lib/helper/BufferToNumber.d.ts +0 -10
  230. package/dist/lib/helper/BufferToNumber.d.ts.map +0 -1
  231. package/dist/lib/helper/BufferToNumber.js +0 -22
  232. package/dist/lib/helper/HexToBuffer.d.ts +0 -8
  233. package/dist/lib/helper/HexToBuffer.d.ts.map +0 -1
  234. package/dist/lib/helper/HexToBuffer.js +0 -27
  235. package/dist/lib/helper/HexToNumber.d.ts +0 -10
  236. package/dist/lib/helper/HexToNumber.d.ts.map +0 -1
  237. package/dist/lib/helper/HexToNumber.js +0 -39
  238. package/dist/lib/helper/IPToBuffer.d.ts +0 -13
  239. package/dist/lib/helper/IPToBuffer.d.ts.map +0 -1
  240. package/dist/lib/helper/IPToBuffer.js +0 -28
  241. package/dist/lib/helper/NumberToBERBuffer.d.ts +0 -10
  242. package/dist/lib/helper/NumberToBERBuffer.d.ts.map +0 -1
  243. package/dist/lib/helper/NumberToBERBuffer.js +0 -22
  244. package/dist/lib/helper/NumberToBERHex.d.ts +0 -10
  245. package/dist/lib/helper/NumberToBERHex.d.ts.map +0 -1
  246. package/dist/lib/helper/NumberToBERHex.js +0 -27
  247. package/dist/lib/helper/NumberToBuffer.d.ts +0 -10
  248. package/dist/lib/helper/NumberToBuffer.d.ts.map +0 -1
  249. package/dist/lib/helper/NumberToBuffer.js +0 -22
  250. package/dist/lib/helper/NumberToHex.d.ts +0 -10
  251. package/dist/lib/helper/NumberToHex.d.ts.map +0 -1
  252. package/dist/lib/helper/NumberToHex.js +0 -26
  253. package/dist/lib/nodepcap/Capture.d.ts +0 -81
  254. package/dist/lib/nodepcap/Capture.d.ts.map +0 -1
  255. package/dist/lib/nodepcap/Capture.js +0 -323
  256. package/dist/lib/nodepcap/GetNetworkInterfaces.d.ts +0 -7
  257. package/dist/lib/nodepcap/GetNetworkInterfaces.d.ts.map +0 -1
  258. package/dist/lib/nodepcap/GetNetworkInterfaces.js +0 -22
  259. package/dist/lib/nodepcap/interfaces/IBindingCapture.d.ts +0 -16
  260. package/dist/lib/nodepcap/interfaces/IBindingCapture.d.ts.map +0 -1
  261. package/dist/lib/nodepcap/interfaces/IBindingCapture.js +0 -2
  262. package/dist/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts +0 -5
  263. package/dist/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts.map +0 -1
  264. package/dist/lib/nodepcap/interfaces/IBindingCaptureOptions.js +0 -2
  265. package/dist/lib/nodepcap/interfaces/ICaptureOptions.d.ts +0 -23
  266. package/dist/lib/nodepcap/interfaces/ICaptureOptions.d.ts.map +0 -1
  267. package/dist/lib/nodepcap/interfaces/ICaptureOptions.js +0 -2
  268. package/dist/lib/nodepcap/interfaces/INetworkInterface.d.ts +0 -5
  269. package/dist/lib/nodepcap/interfaces/INetworkInterface.d.ts.map +0 -1
  270. package/dist/lib/nodepcap/interfaces/INetworkInterface.js +0 -2
  271. package/dist/lib/nodepcap/lib/BindingCapture.d.ts +0 -15
  272. package/dist/lib/nodepcap/lib/BindingCapture.d.ts.map +0 -1
  273. package/dist/lib/nodepcap/lib/BindingCapture.js +0 -35
  274. package/dist/lib/nodepcap/lib/GetNodePcapBinding.d.ts +0 -2
  275. package/dist/lib/nodepcap/lib/GetNodePcapBinding.d.ts.map +0 -1
  276. package/dist/lib/nodepcap/lib/GetNodePcapBinding.js +0 -55
  277. package/dist/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts +0 -3
  278. package/dist/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts.map +0 -1
  279. package/dist/lib/nodepcap/lib/GetNodePcapBindingCapture.js +0 -18
  280. package/dist/lib/nodepcap/workers/CaptureWorker.d.ts +0 -2
  281. package/dist/lib/nodepcap/workers/CaptureWorker.d.ts.map +0 -1
  282. package/dist/lib/nodepcap/workers/CaptureWorker.js +0 -25
  283. package/dist/lib/pcap/PCAPGenerator.d.ts +0 -34
  284. package/dist/lib/pcap/PCAPGenerator.d.ts.map +0 -1
  285. package/dist/lib/pcap/PCAPGenerator.js +0 -101
  286. package/dist/lib/pcap/PcapParser.d.ts +0 -27
  287. package/dist/lib/pcap/PcapParser.d.ts.map +0 -1
  288. package/dist/lib/pcap/PcapParser.js +0 -149
  289. package/dist/lib/pcap/PcapReader.d.ts +0 -112
  290. package/dist/lib/pcap/PcapReader.d.ts.map +0 -1
  291. package/dist/lib/pcap/PcapReader.js +0 -263
  292. package/dist/lib/pcap/PcapWriter.d.ts +0 -29
  293. package/dist/lib/pcap/PcapWriter.d.ts.map +0 -1
  294. package/dist/lib/pcap/PcapWriter.js +0 -86
  295. package/dist/lib/pcap/interfaces/IPcapPacketInfo.d.ts +0 -13
  296. package/dist/lib/pcap/interfaces/IPcapPacketInfo.d.ts.map +0 -1
  297. package/dist/lib/pcap/interfaces/IPcapPacketInfo.js +0 -2
  298. package/dist/lib/pipe/PipeClient.d.ts +0 -35
  299. package/dist/lib/pipe/PipeClient.d.ts.map +0 -1
  300. package/dist/lib/pipe/PipeClient.js +0 -71
  301. package/dist/lib/pipe/PipeClientSocket.d.ts +0 -39
  302. package/dist/lib/pipe/PipeClientSocket.d.ts.map +0 -1
  303. package/dist/lib/pipe/PipeClientSocket.js +0 -82
  304. package/dist/lib/pipe/PipeMessage.d.ts +0 -27
  305. package/dist/lib/pipe/PipeMessage.d.ts.map +0 -1
  306. package/dist/lib/pipe/PipeMessage.js +0 -61
  307. package/dist/lib/pipe/PipeMessageHandler.d.ts +0 -16
  308. package/dist/lib/pipe/PipeMessageHandler.d.ts.map +0 -1
  309. package/dist/lib/pipe/PipeMessageHandler.js +0 -95
  310. package/dist/lib/pipe/PipeServer.d.ts +0 -25
  311. package/dist/lib/pipe/PipeServer.d.ts.map +0 -1
  312. package/dist/lib/pipe/PipeServer.js +0 -59
  313. package/dist/lib/schema/ProtocolFieldJSONSchema.d.ts +0 -36
  314. package/dist/lib/schema/ProtocolFieldJSONSchema.d.ts.map +0 -1
  315. package/dist/lib/schema/ProtocolFieldJSONSchema.js +0 -2
  316. package/dist/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts +0 -3
  317. package/dist/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts.map +0 -1
  318. package/dist/lib/schema/ProtocolFieldJSONSchemaDefinition.js +0 -2
  319. package/dist/lib/schema/ProtocolJSONSchema.d.ts +0 -32
  320. package/dist/lib/schema/ProtocolJSONSchema.d.ts.map +0 -1
  321. package/dist/lib/schema/ProtocolJSONSchema.js +0 -2
  322. package/dist/tests/Test.spec.d.ts +0 -2
  323. package/dist/tests/Test.spec.d.ts.map +0 -1
  324. package/dist/tests/Test.spec.js +0 -25
  325. package/dist/tests/units/CaptureTest.spec.d.ts +0 -2
  326. package/dist/tests/units/CaptureTest.spec.d.ts.map +0 -1
  327. package/dist/tests/units/CaptureTest.spec.js +0 -32
  328. package/dist/tests/units/Codec.spec.d.ts +0 -2
  329. package/dist/tests/units/Codec.spec.d.ts.map +0 -1
  330. package/dist/tests/units/Codec.spec.js +0 -86
  331. package/dist/tests/units/ReadPCAP.spec.d.ts +0 -2
  332. package/dist/tests/units/ReadPCAP.spec.d.ts.map +0 -1
  333. package/dist/tests/units/ReadPCAP.spec.js +0 -14
  334. package/src/CodecExports.ts +0 -33
  335. package/src/CodecHeaderExports.ts +0 -1
  336. package/src/HelperExports.ts +0 -78
  337. package/src/NetworkExports.ts +0 -12
  338. package/src/PcapExports.ts +0 -32
  339. package/src/errors/ActionNotFoundError.ts +0 -6
  340. package/src/errors/CodecSchemaValidateError.ts +0 -6
  341. package/src/errors/DeviceNotFoundError.ts +0 -6
  342. package/src/errors/NoAvailableCodecError.ts +0 -6
  343. package/src/errors/NpcapLoadError.ts +0 -6
  344. package/src/errors/SocketDownError.ts +0 -6
  345. package/src/errors/UnknownPipeMessageTypeError.ts +0 -6
  346. package/src/errors/common/ErrorCode.ts +0 -30
  347. package/src/lib/GeneratePipeAddress.ts +0 -17
  348. package/src/lib/GetBinding.ts +0 -3
  349. package/src/lib/GetCaptureTemporaryDirectory.ts +0 -12
  350. package/src/lib/GetDeviceCaptureTemporaryFilename.ts +0 -13
  351. package/src/lib/codec/Codec.ts +0 -164
  352. package/src/lib/codec/PacketHeaders.ts +0 -23
  353. package/src/lib/codec/abstracts/BaseHeader.ts +0 -435
  354. package/src/lib/codec/headers/ARP.ts +0 -220
  355. package/src/lib/codec/headers/EthernetII.ts +0 -79
  356. package/src/lib/codec/headers/Goose.ts +0 -1033
  357. package/src/lib/codec/headers/ICMP.ts +0 -151
  358. package/src/lib/codec/headers/ICMPv6.ts +0 -128
  359. package/src/lib/codec/headers/IEC104_I_Frame.ts +0 -7373
  360. package/src/lib/codec/headers/IEC104_S_Frame.ts +0 -97
  361. package/src/lib/codec/headers/IEC104_U_Frame.ts +0 -139
  362. package/src/lib/codec/headers/IEC61850SampledValues.ts +0 -361
  363. package/src/lib/codec/headers/IPv4.ts +0 -331
  364. package/src/lib/codec/headers/IPv6.ts +0 -176
  365. package/src/lib/codec/headers/IPv6HopByHopOptions.ts +0 -552
  366. package/src/lib/codec/headers/RawData.ts +0 -38
  367. package/src/lib/codec/headers/TCP.ts +0 -952
  368. package/src/lib/codec/headers/TLS_Alert.ts +0 -539
  369. package/src/lib/codec/headers/TLS_ApplicationData.ts +0 -145
  370. package/src/lib/codec/headers/TLS_ChangeCipherSpec.ts +0 -146
  371. package/src/lib/codec/headers/TLS_Handshake.ts +0 -313
  372. package/src/lib/codec/headers/TLS_Heartbeat.ts +0 -188
  373. package/src/lib/codec/headers/UDP.ts +0 -182
  374. package/src/lib/codec/headers/VLAN_802dot1Q.ts +0 -79
  375. package/src/lib/codec/lib/FlexibleObject.ts +0 -100
  376. package/src/lib/codec/lib/GetBERIntegerLengthFromBuffer.ts +0 -12
  377. package/src/lib/codec/lib/ProcessPacketPostHandlers.ts +0 -53
  378. package/src/lib/codec/lib/SortPostHandlers.ts +0 -10
  379. package/src/lib/codec/lib/StringContentEncodingEnum.ts +0 -10
  380. package/src/lib/codec/types/CodecData.ts +0 -7
  381. package/src/lib/codec/types/CodecDecodeResult.ts +0 -11
  382. package/src/lib/codec/types/CodecEncodeInput.ts +0 -9
  383. package/src/lib/codec/types/CodecEncodeResult.ts +0 -6
  384. package/src/lib/codec/types/CodecErrorInfo.ts +0 -5
  385. package/src/lib/codec/types/CodecModule.ts +0 -3
  386. package/src/lib/codec/types/CodecModuleConstructor.ts +0 -3
  387. package/src/lib/codec/types/CodecSchema.ts +0 -7
  388. package/src/lib/codec/types/HeaderTreeNode.ts +0 -5
  389. package/src/lib/codec/types/PostHandlerItem.ts +0 -4
  390. package/src/lib/helper/BufferToHex.ts +0 -3
  391. package/src/lib/helper/BufferToIP.ts +0 -19
  392. package/src/lib/helper/BufferToNumber.ts +0 -31
  393. package/src/lib/helper/HexToBuffer.ts +0 -22
  394. package/src/lib/helper/HexToNumber.ts +0 -25
  395. package/src/lib/helper/IPToBuffer.ts +0 -25
  396. package/src/lib/helper/NumberToBERBuffer.ts +0 -21
  397. package/src/lib/helper/NumberToBERHex.ts +0 -17
  398. package/src/lib/helper/NumberToBuffer.ts +0 -21
  399. package/src/lib/helper/NumberToHex.ts +0 -15
  400. package/src/lib/nodepcap/Capture.ts +0 -304
  401. package/src/lib/nodepcap/GetNetworkInterfaces.ts +0 -18
  402. package/src/lib/nodepcap/interfaces/IBindingCapture.ts +0 -27
  403. package/src/lib/nodepcap/interfaces/IBindingCaptureOptions.ts +0 -4
  404. package/src/lib/nodepcap/interfaces/ICaptureOptions.ts +0 -24
  405. package/src/lib/nodepcap/interfaces/INetworkInterface.ts +0 -4
  406. package/src/lib/nodepcap/lib/BindingCapture.ts +0 -46
  407. package/src/lib/nodepcap/lib/GetNodePcapBinding.ts +0 -17
  408. package/src/lib/nodepcap/lib/GetNodePcapBindingCapture.ts +0 -15
  409. package/src/lib/nodepcap/workers/CaptureWorker.ts +0 -30
  410. package/src/lib/pcap/PCAPGenerator.ts +0 -123
  411. package/src/lib/pcap/PcapParser.ts +0 -170
  412. package/src/lib/pcap/PcapReader.ts +0 -306
  413. package/src/lib/pcap/PcapWriter.ts +0 -98
  414. package/src/lib/pcap/interfaces/IPcapPacketInfo.ts +0 -12
  415. package/src/lib/pipe/PipeClient.ts +0 -91
  416. package/src/lib/pipe/PipeClientSocket.ts +0 -99
  417. package/src/lib/pipe/PipeMessage.ts +0 -74
  418. package/src/lib/pipe/PipeMessageHandler.ts +0 -91
  419. package/src/lib/pipe/PipeServer.ts +0 -74
  420. package/src/lib/schema/ProtocolFieldJSONSchema.ts +0 -47
  421. package/src/lib/schema/ProtocolFieldJSONSchemaDefinition.ts +0 -3
  422. package/src/lib/schema/ProtocolJSONSchema.ts +0 -37
  423. package/src/tests/Test.spec.ts +0 -22
  424. package/src/tests/units/CaptureTest.spec.ts +0 -31
  425. package/src/tests/units/Codec.spec.ts +0 -102
  426. package/src/tests/units/ReadPCAP.spec.ts +0 -13
  427. package/test.pcap +0 -0
  428. package/tsconfig.json +0 -42
@@ -1,952 +0,0 @@
1
- import {ProtocolJSONSchema} from '../../schema/ProtocolJSONSchema'
2
- import {BaseHeader} from '../abstracts/BaseHeader'
3
- import {BufferToUInt16, BufferToUInt32, BufferToUInt64, BufferToUInt8} from '../../helper/BufferToNumber'
4
- import {UInt16ToBuffer, UInt32ToBuffer, UInt64ToBuffer, UInt8ToBuffer} from '../../helper/NumberToBuffer'
5
- import {IPv6ToBuffer} from '../../helper/IPToBuffer'
6
- import {CodecModule} from '../types/CodecModule'
7
- import {StringContentEncodingEnum} from '../lib/StringContentEncodingEnum'
8
- import {UInt64ToHex} from '../../helper/NumberToHex'
9
- import {HexToUInt64} from '../../helper/HexToNumber'
10
-
11
- enum TCPOption {
12
- End_of_Option_List = 'EOL',
13
- No_Operation = 'NOP',
14
- Maximum_Segment_Size = 'MSS',
15
- Window_Scale = 'Window-Scale',
16
- Selective_Acknowledgment_Permitted = 'SACK-Permitted',
17
- Selective_Acknowledgment = 'SACK',
18
- Timestamp = 'TS',
19
- User_Timeout = 'UTO',
20
- TCP_Authentication_Option = 'TCP-AO'
21
- }
22
-
23
- type OPTION_EOL = {
24
- option: TCPOption.End_of_Option_List
25
- }
26
-
27
- type OPTION_NOP = {
28
- option: TCPOption.No_Operation
29
- }
30
-
31
- type OPTION_MSS = {
32
- option: TCPOption.Maximum_Segment_Size
33
- mss: number
34
- }
35
-
36
- type OPTION_WINDOW_SCALE = {
37
- option: TCPOption.Window_Scale
38
- shift: number
39
- }
40
-
41
- type OPTION_SACK_PERMITTED = {
42
- option: TCPOption.Selective_Acknowledgment_Permitted
43
- }
44
-
45
- type OPTION_SACK = {
46
- option: TCPOption.Selective_Acknowledgment
47
- blocks: string[]
48
- }
49
-
50
- type OPTION_TS = {
51
- option: TCPOption.Timestamp
52
- tsval: number
53
- tsecr: number
54
- }
55
-
56
- type OPTION_UTO = {
57
- option: TCPOption.User_Timeout
58
- timeout: number
59
- granularity: number
60
- }
61
-
62
- type OPTION_TCP_AO = {
63
- option: TCPOption.TCP_Authentication_Option
64
- data: string
65
- }
66
-
67
- type OPTION_DEFAULT = {
68
- kind: number
69
- data: string
70
- }
71
-
72
- type OptionItem =
73
- OPTION_EOL
74
- | OPTION_NOP
75
- | OPTION_MSS
76
- | OPTION_WINDOW_SCALE
77
- | OPTION_SACK_PERMITTED
78
- | OPTION_SACK
79
- | OPTION_TS
80
- | OPTION_UTO
81
- | OPTION_TCP_AO
82
- | OPTION_DEFAULT
83
-
84
- export class TCP extends BaseHeader {
85
-
86
- /**
87
- * Calculate TCP Checksum
88
- * @param tcpHeaderBuffer
89
- * @protected
90
- */
91
- protected calculateTCPChecksum(tcpHeaderBuffer: Buffer): number {
92
- const tcpHeaderLength: number = tcpHeaderBuffer.length
93
- const ipVersion: number = this.prevCodecModule.instance.version.getValue()
94
- let pseudoHeaderBuffer: Buffer = Buffer.from([])
95
- const sourceIp: string = this.prevCodecModule.instance.sip.getValue()
96
- const destinationIp: string = this.prevCodecModule.instance.dip.getValue()
97
- if (ipVersion === 4) {
98
- //4 Bytes
99
- const sourceIPv4Buffer: Buffer = Buffer.from(sourceIp.split('.').map((value: string): number => parseInt(value)))
100
- const destinationIPv4Buffer: Buffer = Buffer.from(destinationIp.split('.').map((value: string): number => parseInt(value)))
101
- //IPv4 Pseudo header
102
- pseudoHeaderBuffer = Buffer.concat([
103
- sourceIPv4Buffer,
104
- destinationIPv4Buffer,
105
- UInt8ToBuffer(0), //Reserved field
106
- UInt8ToBuffer(6), //Protocol type (TCP = 6)
107
- Buffer.from([(tcpHeaderLength >> 8) & 0xFF]),
108
- Buffer.from([tcpHeaderLength & 0xFF])
109
- ])
110
- } else if (ipVersion === 6) {
111
- //16 Bytes
112
- const sourceIPv6Buffer: Buffer = IPv6ToBuffer(sourceIp)
113
- const destinationIPv6Buffer: Buffer = IPv6ToBuffer(destinationIp)
114
- //IPv6 Pseudo header
115
- pseudoHeaderBuffer = Buffer.concat([
116
- sourceIPv6Buffer,
117
- destinationIPv6Buffer,
118
- UInt8ToBuffer(0), //Reserved field
119
- UInt8ToBuffer(0), //Reserved field
120
- UInt8ToBuffer(0), //Reserved field
121
- UInt8ToBuffer(6), //Protocol type (TCP = 6)
122
- Buffer.from([(tcpHeaderLength >> 8) & 0xFF]),
123
- Buffer.from([tcpHeaderLength & 0xFF])
124
- ])
125
- } else {
126
- return 0
127
- }
128
- const dataBuffer: Buffer = Buffer.concat([pseudoHeaderBuffer, tcpHeaderBuffer])
129
- const data: Uint8Array = Uint8Array.from(dataBuffer)
130
- let sum: number = 0
131
- for (let i: number = 0; i < data.length; i += 2) sum += (data[i] << 8) + (data[i + 1] || 0)
132
- while (sum >>> 16) sum = (sum & 0xFFFF) + (sum >>> 16)
133
- return (~sum) & 0xFFFF
134
- }
135
-
136
- public SCHEMA: ProtocolJSONSchema = {
137
- type: 'object',
138
- properties: {
139
- srcport: {
140
- type: 'integer',
141
- label: 'Source Port',
142
- minimum: 0,
143
- maximum: 65535,
144
- decode: (): void => {
145
- this.instance.srcport.setValue(BufferToUInt16(this.readBytes(0, 2)))
146
- },
147
- encode: (): void => {
148
- let srcport: number = this.instance.srcport.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
149
- if (srcport > 65535) {
150
- this.recordError(this.instance.srcport.getPath(), 'Maximum value is 65535')
151
- srcport = 65535
152
- }
153
- if (srcport < 0) {
154
- this.recordError(this.instance.srcport.getPath(), 'Minimum value is 0')
155
- srcport = 0
156
- }
157
- this.instance.srcport.setValue(srcport)
158
- this.writeBytes(0, UInt16ToBuffer(srcport))
159
- }
160
- },
161
- dstport: {
162
- type: 'integer',
163
- label: 'Destination Port',
164
- minimum: 0,
165
- maximum: 65535,
166
- decode: (): void => {
167
- this.instance.dstport.setValue(BufferToUInt16(this.readBytes(2, 2)))
168
- },
169
- encode: (): void => {
170
- let dstport: number = this.instance.dstport.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
171
- if (dstport > 65535) {
172
- this.recordError(this.instance.dstport.getPath(), 'Maximum value is 65535')
173
- dstport = 65535
174
- }
175
- if (dstport < 0) {
176
- this.recordError(this.instance.dstport.getPath(), 'Minimum value is 0')
177
- dstport = 0
178
- }
179
- this.instance.dstport.setValue(dstport)
180
- this.writeBytes(2, UInt16ToBuffer(dstport))
181
- }
182
- },
183
- seq: {
184
- type: 'integer',
185
- label: 'Sequence Number',
186
- minimum: 0,
187
- maximum: 4294967295,
188
- decode: (): void => {
189
- this.instance.seq.setValue(BufferToUInt32(this.readBytes(4, 4)))
190
- },
191
- encode: (): void => {
192
- let seqNum: number = this.instance.seq.getValue(0)
193
- if (seqNum > 4294967295) {
194
- this.recordError(this.instance.seq.getPath(), 'Maximum value is 4294967295')
195
- seqNum = 4294967295
196
- }
197
- if (seqNum < 0) {
198
- this.recordError(this.instance.seq.getPath(), 'Minimum value is 0')
199
- seqNum = 0
200
- }
201
- this.instance.seq.setValue(seqNum)
202
- this.writeBytes(4, UInt32ToBuffer(seqNum))
203
- }
204
- },
205
- ack: {
206
- type: 'integer',
207
- label: 'Acknowledgment Number',
208
- minimum: 0,
209
- maximum: 4294967295,
210
- decode: (): void => {
211
- this.instance.ack.setValue(BufferToUInt32(this.readBytes(8, 4)))
212
- },
213
- encode: (): void => {
214
- let ackNum: number = this.instance.ack.getValue(0)
215
- if (ackNum > 4294967295) {
216
- this.recordError(this.instance.ack.getPath(), 'Maximum value is 4294967295')
217
- ackNum = 4294967295
218
- }
219
- if (ackNum < 0) {
220
- this.recordError(this.instance.ack.getPath(), 'Minimum value is 0')
221
- ackNum = 0
222
- }
223
- this.instance.ack.setValue(ackNum)
224
- this.writeBytes(8, UInt32ToBuffer(ackNum))
225
- }
226
- },
227
- hdrLen: {
228
- type: 'integer',
229
- label: 'Header Length',
230
- minimum: 0,
231
- maximum: 60,
232
- decode: (): void => {
233
- this.instance.hdrLen.setValue(this.readBits(12, 1, 0, 4) * 4)
234
- },
235
- encode: (): void => {
236
- let hdrLen: number = this.instance.hdrLen.getValue(0)
237
- if (hdrLen) {
238
- this.instance.hdrLen.setValue(hdrLen)
239
- this.writeBits(12, 1, 0, 4, hdrLen ? Math.floor(hdrLen / 4) : 0)
240
- } else {
241
- this.addPostSelfEncodeHandler((): void => {
242
- this.instance.hdrLen.setValue(Math.floor(this.length / 4) * 4)
243
- this.writeBits(12, 1, 0, 4, Math.floor(this.length / 4))
244
- }, 1)
245
- }
246
- }
247
- },
248
- flags: {
249
- type: 'object',
250
- label: 'Flags',
251
- properties: {
252
- res: {
253
- type: 'integer',
254
- label: 'Reserved',
255
- minimum: 0,
256
- maximum: 7,
257
- decode: (): void => {
258
- this.instance.flags.res.setValue(this.readBits(12, 1, 4, 3))
259
- },
260
- encode: (): void => {
261
- let reserved: number = this.instance.flags.res.getValue(0)
262
- if (reserved > 7) {
263
- this.recordError(this.instance.flags.res.getPath(), 'Maximum value is 7')
264
- reserved = 7
265
- }
266
- if (reserved < 0) {
267
- this.recordError(this.instance.flags.res.getPath(), 'Minimum value is 0')
268
- reserved = 0
269
- }
270
- this.instance.flags.res.setValue(reserved)
271
- this.writeBits(12, 1, 4, 3, reserved)
272
- }
273
- },
274
- ae: {
275
- type: 'boolean',
276
- label: 'Accurate ECN',
277
- decode: (): void => {
278
- this.instance.flags.ae.setValue(!!this.readBits(12, 1, 7, 1))
279
- },
280
- encode: (): void => {
281
- const accurateECN: boolean = !!this.instance.flags.ae.getValue()
282
- this.instance.flags.ae.setValue(accurateECN)
283
- this.writeBits(12, 1, 7, 1, accurateECN ? 1 : 0)
284
- }
285
- },
286
- cwr: {
287
- type: 'boolean',
288
- label: 'Congestion Window Reduced',
289
- decode: (): void => {
290
- this.instance.flags.cwr.setValue(!!this.readBits(13, 1, 0, 1))
291
- },
292
- encode: (): void => {
293
- const congestionWindowReduced: boolean = !!this.instance.flags.cwr.getValue()
294
- this.instance.flags.cwr.setValue(congestionWindowReduced)
295
- this.writeBits(13, 1, 0, 1, congestionWindowReduced ? 1 : 0)
296
- }
297
- },
298
- ece: {
299
- type: 'boolean',
300
- label: 'ECN-Echo',
301
- decode: (): void => {
302
- this.instance.flags.ece.setValue(!!this.readBits(13, 1, 1, 1))
303
- },
304
- encode: (): void => {
305
- const ECNEcho: boolean = !!this.instance.flags.ece.getValue()
306
- this.instance.flags.ece.setValue(ECNEcho)
307
- this.writeBits(13, 1, 1, 1, ECNEcho ? 1 : 0)
308
- }
309
- },
310
- urg: {
311
- type: 'boolean',
312
- label: 'Urgent',
313
- decode: (): void => {
314
- this.instance.flags.urg.setValue(!!this.readBits(13, 1, 2, 1))
315
- },
316
- encode: (): void => {
317
- const urgent: boolean = !!this.instance.flags.urg.getValue()
318
- this.instance.flags.urg.setValue(urgent)
319
- this.writeBits(13, 1, 2, 1, urgent ? 1 : 0)
320
- }
321
- },
322
- ack: {
323
- type: 'boolean',
324
- label: 'Acknowledgment',
325
- decode: (): void => {
326
- this.instance.flags.ack.setValue(!!this.readBits(13, 1, 3, 1))
327
- },
328
- encode: (): void => {
329
- const acknowledgment: boolean = !!this.instance.flags.ack.getValue()
330
- this.instance.flags.ack.setValue(acknowledgment)
331
- this.writeBits(13, 1, 3, 1, acknowledgment ? 1 : 0)
332
- }
333
- },
334
- push: {
335
- type: 'boolean',
336
- label: 'Push',
337
- decode: (): void => {
338
- this.instance.flags.push.setValue(!!this.readBits(13, 1, 4, 1))
339
- },
340
- encode: (): void => {
341
- const push: boolean = !!this.instance.flags.push.getValue()
342
- this.instance.flags.push.setValue(push)
343
- this.writeBits(13, 1, 4, 1, push ? 1 : 0)
344
- }
345
- },
346
- rst: {
347
- type: 'boolean',
348
- label: 'Reset',
349
- decode: (): void => {
350
- this.instance.flags.rst.setValue(!!this.readBits(13, 1, 5, 1))
351
- },
352
- encode: (): void => {
353
- const reset: boolean = !!this.instance.flags.rst.getValue()
354
- this.instance.flags.rst.setValue(reset)
355
- this.writeBits(13, 1, 5, 1, reset ? 1 : 0)
356
- }
357
- },
358
- syn: {
359
- type: 'boolean',
360
- label: 'Syn',
361
- decode: (): void => {
362
- this.instance.flags.syn.setValue(!!this.readBits(13, 1, 6, 1))
363
- },
364
- encode: (): void => {
365
- const syn: boolean = !!this.instance.flags.syn.getValue()
366
- this.instance.flags.syn.setValue(syn)
367
- this.writeBits(13, 1, 6, 1, syn ? 1 : 0)
368
- }
369
- },
370
- fin: {
371
- type: 'boolean',
372
- label: 'Fin',
373
- decode: (): void => {
374
- this.instance.flags.fin.setValue(!!this.readBits(13, 1, 7, 1))
375
- },
376
- encode: (): void => {
377
- const fin: boolean = !!this.instance.flags.fin.getValue()
378
- this.instance.flags.fin.setValue(fin)
379
- this.writeBits(13, 1, 7, 1, fin ? 1 : 0)
380
- }
381
- }
382
- }
383
- },
384
- window: {
385
- type: 'integer',
386
- label: 'Window Size',
387
- minimum: 0,
388
- maximum: 65535,
389
- decode: (): void => {
390
- this.instance.window.setValue(BufferToUInt16(this.readBytes(14, 2)))
391
- },
392
- encode: (): void => {
393
- let windowSize: number = this.instance.window.getValue(0)
394
- if (windowSize > 65535) {
395
- this.recordError(this.instance.window.getPath(), 'Maximum value is 65535')
396
- windowSize = 65535
397
- }
398
- if (windowSize < 0) {
399
- this.recordError(this.instance.window.getPath(), 'Minimum value is 0')
400
- windowSize = 0
401
- }
402
- this.instance.window.setValue(windowSize)
403
- this.writeBytes(14, UInt16ToBuffer(windowSize))
404
- }
405
- },
406
- checksum: {
407
- type: 'integer',
408
- label: 'Checksum',
409
- minimum: 0,
410
- maximum: 65535,
411
- decode: (): void => {
412
- this.instance.checksum.setValue(BufferToUInt16(this.readBytes(16, 2)))
413
- },
414
- encode: (): void => {
415
- let checksum: number = this.instance.checksum.getValue(0)
416
- if (checksum) {
417
- this.instance.checksum.setValue(checksum)
418
- this.writeBytes(16, UInt16ToBuffer(checksum))
419
- } else {
420
- this.instance.checksum.setValue(checksum)
421
- this.writeBytes(16, UInt16ToBuffer(checksum))
422
- this.addPostPacketEncodeHandler((): void => {
423
- //Calculate checksum after packet encoded
424
- let startPos: number = 0
425
- let endPos: number = 0
426
- this.codecModules.forEach((codecModule: CodecModule): void => {
427
- if (codecModule === this) startPos = codecModule.startPos
428
- endPos = codecModule.endPos > endPos ? codecModule.endPos : endPos
429
- })
430
- const calcChecksum: number = this.calculateTCPChecksum(this.packet.subarray(startPos, endPos))
431
- this.instance.checksum.setValue(calcChecksum)
432
- this.writeBytes(16, UInt16ToBuffer(calcChecksum))
433
- }, 100)
434
- }
435
- }
436
- },
437
- urgPtr: {
438
- type: 'integer',
439
- label: 'Urgent Pointer',
440
- minimum: 0,
441
- maximum: 65535,
442
- decode: (): void => {
443
- this.instance.urgPtr.setValue(BufferToUInt16(this.readBytes(18, 2)))
444
- },
445
- encode: (): void => {
446
- let urgPtr: number = this.instance.urgPtr.getValue(0)
447
- if (urgPtr > 65535) {
448
- this.recordError(this.instance.urgPtr.getPath(), 'Maximum value is 65535')
449
- urgPtr = 65535
450
- }
451
- if (urgPtr < 0) {
452
- this.recordError(this.instance.urgPtr.getPath(), 'Minimum value is 0')
453
- urgPtr = 0
454
- }
455
- this.instance.urgPtr.setValue(urgPtr)
456
- this.writeBytes(18, UInt16ToBuffer(urgPtr))
457
- }
458
- },
459
- options: {
460
- type: 'array',
461
- label: 'Options',
462
- items: {
463
- anyOf: [
464
- //Kind = 0 (End of Option List, EOL)
465
- {
466
- type: 'object',
467
- label: 'End of Option List',
468
- properties: {
469
- option: {
470
- type: 'string',
471
- label: 'Option',
472
- enum: [TCPOption.End_of_Option_List],
473
- const: TCPOption.End_of_Option_List,
474
- hidden: true
475
- }
476
- }
477
- },
478
- //Kind = 1 (No-Operation, NOP)
479
- {
480
- type: 'object',
481
- label: 'No-Operation',
482
- properties: {
483
- option: {
484
- type: 'string',
485
- label: 'Option',
486
- enum: [TCPOption.No_Operation],
487
- const: TCPOption.No_Operation,
488
- hidden: true
489
- }
490
- }
491
- },
492
- //Kind = 2 (Maximum Segment Size, MSS)
493
- {
494
- type: 'object',
495
- label: 'Maximum Segment Size',
496
- properties: {
497
- option: {
498
- type: 'string',
499
- label: 'Option',
500
- enum: [TCPOption.Maximum_Segment_Size],
501
- const: TCPOption.Maximum_Segment_Size,
502
- hidden: true
503
- },
504
- mss: {
505
- type: 'integer',
506
- label: 'MSS',
507
- maximum: 65535,
508
- minimum: 0
509
- }
510
- }
511
- },
512
- //Kind = 3 (Window Scale)
513
- {
514
- type: 'object',
515
- label: 'Window Scale',
516
- properties: {
517
- option: {
518
- type: 'string',
519
- label: 'Option',
520
- enum: [TCPOption.Window_Scale],
521
- const: TCPOption.Window_Scale,
522
- hidden: true
523
- },
524
- shift: {
525
- type: 'integer',
526
- label: 'Shift count',
527
- minimum: 0,
528
- maximum: 14
529
- }
530
- }
531
- },
532
- //Kind = 4 (Selective Acknowledgment Permitted, SACK-Permitted)
533
- {
534
- type: 'object',
535
- label: 'Selective Acknowledgment Permitted',
536
- properties: {
537
- option: {
538
- type: 'string',
539
- label: 'Option',
540
- enum: [TCPOption.Selective_Acknowledgment_Permitted],
541
- const: TCPOption.Selective_Acknowledgment_Permitted,
542
- hidden: true
543
- }
544
- }
545
- },
546
- //Kind = 5 (Selective Acknowledgment, SACK)
547
- {
548
- type: 'object',
549
- label: 'Selective Acknowledgment',
550
- properties: {
551
- option: {
552
- type: 'string',
553
- label: 'Option',
554
- enum: [TCPOption.Selective_Acknowledgment],
555
- const: TCPOption.Selective_Acknowledgment,
556
- hidden: true
557
- },
558
- blocks: {
559
- type: 'array',
560
- label: 'SACK Blocks',
561
- items: {
562
- type: 'string',
563
- maxLength: 16,
564
- minLength: 16,
565
- contentEncoding: StringContentEncodingEnum.HEX
566
- }
567
- }
568
- }
569
- },
570
- //Kind = 8 (Timestamp, TS)
571
- {
572
- type: 'object',
573
- label: 'Timestamp',
574
- properties: {
575
- option: {
576
- type: 'string',
577
- label: 'Option',
578
- enum: [TCPOption.Timestamp],
579
- const: TCPOption.Timestamp,
580
- hidden: true
581
- },
582
- tsval: {
583
- type: 'integer',
584
- label: 'TSval',
585
- minimum: 0,
586
- maximum: 4294967295
587
- },
588
- tsecr: {
589
- type: 'integer',
590
- label: 'TSecr',
591
- minimum: 0,
592
- maximum: 4294967295
593
- }
594
- }
595
- },
596
- //Kind = 28 (User Timeout, UTO)
597
- {
598
- type: 'object',
599
- label: 'User Timeout',
600
- properties: {
601
- option: {
602
- type: 'string',
603
- label: 'Option',
604
- enum: [TCPOption.User_Timeout],
605
- const: TCPOption.User_Timeout,
606
- hidden: true
607
- },
608
- timeout: {
609
- type: 'integer',
610
- label: 'Timeout',
611
- minimum: 0,
612
- maximum: 65535
613
- },
614
- granularity: {
615
- type: 'integer',
616
- label: 'Granularity',
617
- enum: [0, 1]
618
- }
619
- }
620
- },
621
- //Kind = 29 (TCP Authentication Option, TCP-AO)
622
- {
623
- type: 'object',
624
- label: 'TCP Authentication Option',
625
- properties: {
626
- option: {
627
- type: 'string',
628
- label: 'Option',
629
- enum: [TCPOption.TCP_Authentication_Option],
630
- const: TCPOption.TCP_Authentication_Option,
631
- hidden: true
632
- },
633
- data: {
634
- type: 'string',
635
- label: 'Data',
636
- contentEncoding: StringContentEncodingEnum.HEX
637
- }
638
- }
639
- },
640
- //Default
641
- {
642
- type: 'object',
643
- label: 'Default',
644
- properties: {
645
- kind: {
646
- type: 'integer',
647
- label: 'Kind'
648
- },
649
- data: {
650
- type: 'string',
651
- contentEncoding: StringContentEncodingEnum.HEX,
652
- label: 'Data'
653
- }
654
- }
655
- }
656
- ]
657
- },
658
- decode: (): void => {
659
- const hdrLen: number = this.instance.hdrLen.getValue()
660
- const optionsLength: number = hdrLen - this.length
661
- if (!optionsLength) return
662
- let optionOffset: number = this.length
663
- const options: OptionItem[] = []
664
- let index: number = 0
665
- while (optionOffset < hdrLen) {
666
- const kind: number = BufferToUInt8(this.readBytes(optionOffset, 1))
667
- optionOffset += 1
668
- switch (kind) {
669
- //Kind = 0 (End of Option List, EOL)
670
- case 0: {
671
- options.push({
672
- option: TCPOption.End_of_Option_List
673
- })
674
- }
675
- break
676
- //Kind = 1 (No-Operation, NOP)
677
- case 1: {
678
- options.push({
679
- option: TCPOption.No_Operation
680
- })
681
- }
682
- break
683
- //Kind = 2 (Maximum Segment Size, MSS)
684
- case 2: {
685
- let length: number = BufferToUInt8(this.readBytes(optionOffset, 1))
686
- if (length !== 4) this.recordError(this.instance.options.getPath(index), 'MSS option TLV length should be 4')
687
- optionOffset += 1
688
- let value: number = BufferToUInt16(this.readBytes(optionOffset, 2))
689
- optionOffset += 2
690
- options.push({
691
- option: TCPOption.Maximum_Segment_Size,
692
- mss: value
693
- })
694
- }
695
- break
696
- //Kind = 3 (Window Scale)
697
- case 3: {
698
- let length: number = BufferToUInt8(this.readBytes(optionOffset, 1))
699
- if (length !== 3) this.recordError(this.instance.options.getPath(index), 'Window Scale option TLV length should be 3')
700
- optionOffset += 1
701
- let value: number = BufferToUInt8(this.readBytes(optionOffset, 1))
702
- optionOffset += 1
703
- if (value < 0 || value > 14) this.recordError(this.instance.options.getPath(index), 'Window Scale option TLV value should between 0 and 14')
704
- options.push({
705
- option: TCPOption.Window_Scale,
706
- shift: value
707
- })
708
- }
709
- break
710
- //Kind = 4 (Selective Acknowledgment Permitted, SACK-Permitted)
711
- case 4: {
712
- let length: number = BufferToUInt8(this.readBytes(optionOffset, 1))
713
- optionOffset += 1
714
- if (length !== 2) this.recordError(this.instance.options.getPath(index), 'SACK-Permitted option TLV length should be 2')
715
- options.push({
716
- option: TCPOption.Selective_Acknowledgment_Permitted
717
- })
718
- }
719
- break
720
- //Kind = 5 (Selective Acknowledgment, SACK)
721
- case 5: {
722
- let length: number = BufferToUInt8(this.readBytes(optionOffset, 1))
723
- optionOffset += 1
724
- let sackBlockTotalLength: number = length - 2
725
- if (sackBlockTotalLength < 0) {
726
- this.recordError(this.instance.options.getPath(index), 'SACK option block count should not less than 0')
727
- sackBlockTotalLength = 0
728
- }
729
- let sackBlockCount: number = sackBlockTotalLength ? Math.floor(sackBlockTotalLength / 8) : 0
730
- const sackBlocks: string[] = []
731
- while (sackBlockCount > 0) {
732
- sackBlocks.push(UInt64ToHex(BigInt(`0x${BufferToUInt64(this.readBytes(optionOffset, 8)).toString(16)}`)))
733
- optionOffset += 8
734
- sackBlockCount -= 1
735
- }
736
- options.push({
737
- option: TCPOption.Selective_Acknowledgment,
738
- blocks: sackBlocks
739
- })
740
- }
741
- break
742
- //Kind = 8 (Timestamp, TS)
743
- case 8: {
744
- let length: number = BufferToUInt8(this.readBytes(optionOffset, 1))
745
- optionOffset += 1
746
- if (length !== 10) this.recordError(this.instance.options.getPath(index), 'Timestamp option TLV length should be 10')
747
- let tsval: number = BufferToUInt32(this.readBytes(optionOffset, 4))
748
- optionOffset += 4
749
- let tsecr: number = BufferToUInt32(this.readBytes(optionOffset, 4))
750
- optionOffset += 4
751
- options.push({
752
- option: TCPOption.Timestamp,
753
- tsval: tsval,
754
- tsecr: tsecr
755
- })
756
- }
757
- break
758
- //Kind = 28 (User Timeout, UTO)
759
- case 28: {
760
- let length: number = BufferToUInt8(this.readBytes(optionOffset, 1))
761
- optionOffset += 1
762
- if (length !== 5) this.recordError(this.instance.options.getPath(index), 'UTO option TLV length should be 5')
763
- let timeout: number = BufferToUInt16(this.readBytes(optionOffset, 2))
764
- optionOffset += 2
765
- let granularity: number = BufferToUInt8(this.readBytes(optionOffset, 1))
766
- optionOffset += 1
767
- options.push({
768
- option: TCPOption.User_Timeout,
769
- timeout: timeout,
770
- granularity: granularity
771
- })
772
- }
773
- break
774
- //Kind = 29 (TCP Authentication Option, TCP-AO)
775
- case 29: {
776
- let length: number = BufferToUInt8(this.readBytes(optionOffset, 1))
777
- optionOffset += 1
778
- let dataLength: number = length - 2
779
- if (dataLength < 0) {
780
- this.recordError(this.instance.options.getPath(index), 'TCP Authentication Option TLV length should not less than 2')
781
- dataLength = 0
782
- }
783
- let data: Buffer
784
- if (dataLength) {
785
- data = this.readBytes(optionOffset, dataLength)
786
- optionOffset += dataLength
787
- } else {
788
- data = Buffer.from([])
789
- }
790
- options.push({
791
- option: TCPOption.TCP_Authentication_Option,
792
- data: data.toString('hex')
793
- })
794
- }
795
- break
796
- default: {
797
- let length: number = BufferToUInt8(this.readBytes(optionOffset, 1))
798
- let dataLength: number = length - 2
799
- if (dataLength < 0) {
800
- this.recordError(this.instance.options.getPath(index), 'Option TLV length should not less than 2')
801
- dataLength = 0
802
- }
803
- let data: Buffer
804
- if (dataLength) {
805
- data = this.readBytes(optionOffset, dataLength)
806
- optionOffset += dataLength
807
- } else {
808
- data = Buffer.from([])
809
- }
810
- options.push({
811
- kind: kind,
812
- data: data.toString('hex')
813
- })
814
- }
815
- }
816
- index += 1
817
- }
818
- this.instance.options.setValue(options)
819
- },
820
- encode: (): void => {
821
- const options: (OptionItem[]) | undefined = this.instance.options.getValue()
822
- if (!options) return
823
- let optionOffset: number = this.length
824
- options.forEach((optionItem: OptionItem): void => {
825
- const namedOptionItem: OPTION_EOL | OPTION_NOP | OPTION_MSS | OPTION_WINDOW_SCALE | OPTION_SACK_PERMITTED | OPTION_SACK | OPTION_TS | OPTION_UTO | OPTION_TCP_AO = optionItem as any
826
- switch (namedOptionItem.option) {
827
- case TCPOption.End_of_Option_List: {
828
- const optionEOL: OPTION_EOL = optionItem as OPTION_EOL
829
- this.writeBytes(optionOffset, UInt8ToBuffer(0))
830
- optionOffset += 1
831
- return
832
- }
833
- case TCPOption.No_Operation: {
834
- const optionNOP: OPTION_NOP = optionItem as OPTION_NOP
835
- this.writeBytes(optionOffset, UInt8ToBuffer(1))
836
- optionOffset += 1
837
- return
838
- }
839
- case TCPOption.Maximum_Segment_Size: {
840
- const optionMSS: OPTION_MSS = optionItem as OPTION_MSS
841
- const mssBuffer: Buffer = Buffer.concat([
842
- UInt8ToBuffer(2),
843
- UInt8ToBuffer(4),
844
- UInt16ToBuffer(optionMSS.mss)
845
- ])
846
- this.writeBytes(optionOffset, mssBuffer)
847
- optionOffset += mssBuffer.length
848
- return
849
- }
850
- case TCPOption.Window_Scale: {
851
- const optionWS: OPTION_WINDOW_SCALE = optionItem as OPTION_WINDOW_SCALE
852
- const wsBuffer: Buffer = Buffer.concat([
853
- UInt8ToBuffer(3),
854
- UInt8ToBuffer(3),
855
- UInt8ToBuffer(optionWS.shift)
856
- ])
857
- this.writeBytes(optionOffset, wsBuffer)
858
- optionOffset += wsBuffer.length
859
- return
860
- }
861
- case TCPOption.Selective_Acknowledgment_Permitted: {
862
- const optionSackPermitted: OPTION_SACK_PERMITTED = optionItem as OPTION_SACK_PERMITTED
863
- const sackPermittedBuffer: Buffer = Buffer.concat([
864
- UInt8ToBuffer(4),
865
- UInt8ToBuffer(2)
866
- ])
867
- this.writeBytes(optionOffset, sackPermittedBuffer)
868
- optionOffset += sackPermittedBuffer.length
869
- return
870
- }
871
- case TCPOption.Selective_Acknowledgment: {
872
- const optionSack: OPTION_SACK = optionItem as OPTION_SACK
873
- const kindBuffer: Buffer = UInt8ToBuffer(5)
874
- let length: number = 2
875
- let blocksBuffer: Buffer = Buffer.from([])
876
- optionSack.blocks.forEach((block: string): void => {
877
- blocksBuffer = Buffer.concat([blocksBuffer, UInt64ToBuffer(HexToUInt64(block))])
878
- })
879
- const sackBuffer: Buffer = Buffer.concat([kindBuffer, UInt8ToBuffer(length + blocksBuffer.length), blocksBuffer])
880
- this.writeBytes(optionOffset, sackBuffer)
881
- optionOffset += sackBuffer.length
882
- return
883
- }
884
- case TCPOption.Timestamp: {
885
- const optionTS: OPTION_TS = optionItem as OPTION_TS
886
- const tsBuffer: Buffer = Buffer.concat([
887
- UInt8ToBuffer(8),
888
- UInt8ToBuffer(10),
889
- UInt32ToBuffer(optionTS.tsval ? optionTS.tsval : 0),
890
- UInt32ToBuffer(optionTS.tsecr ? optionTS.tsecr : 0)
891
- ])
892
- this.writeBytes(optionOffset, tsBuffer)
893
- optionOffset += tsBuffer.length
894
- return
895
- }
896
- case TCPOption.User_Timeout: {
897
- const optionUTO: OPTION_UTO = optionItem as OPTION_UTO
898
- const utoBuffer: Buffer = Buffer.concat([
899
- UInt8ToBuffer(28),
900
- UInt8ToBuffer(5),
901
- UInt16ToBuffer(optionUTO.timeout ? optionUTO.timeout : 0),
902
- UInt8ToBuffer(optionUTO.granularity ? optionUTO.granularity : 0)
903
- ])
904
- this.writeBytes(optionOffset, utoBuffer)
905
- optionOffset += utoBuffer.length
906
- return
907
- }
908
- case TCPOption.TCP_Authentication_Option: {
909
- const optionTcpAo: OPTION_TCP_AO = optionItem as OPTION_TCP_AO
910
- const kindBuffer: Buffer = UInt8ToBuffer(29)
911
- const dataBuffer: Buffer = Buffer.from(optionTcpAo.data, 'hex')
912
- const lengthBuffer: Buffer = UInt8ToBuffer(dataBuffer.length + 2)
913
- const tcpAoBuffer: Buffer = Buffer.concat([kindBuffer, lengthBuffer, dataBuffer])
914
- this.writeBytes(optionOffset, tcpAoBuffer)
915
- optionOffset += tcpAoBuffer.length
916
- return
917
- }
918
- default: {
919
- const defaultOptionItem: OPTION_DEFAULT = optionItem as OPTION_DEFAULT
920
- const kind: number = defaultOptionItem.kind
921
- const hexBuffer: Buffer = Buffer.from(defaultOptionItem.data.toString(), 'hex')
922
- const length: number = hexBuffer.length + 2
923
- const defaultOptionBuffer: Buffer = Buffer.concat([UInt8ToBuffer(kind), UInt8ToBuffer(length), hexBuffer])
924
- this.writeBytes(optionOffset, defaultOptionBuffer)
925
- optionOffset += defaultOptionBuffer.length
926
- }
927
- }
928
- })
929
- if (this.length > 60) return this.recordError(this.instance.options.getPath(), 'Options too large')
930
- const headerBitLength: number = this.length * 8
931
- if (headerBitLength % 4) {
932
- //Add Padding
933
- this.writeBytes(this.length, Buffer.from([0x00]))
934
- }
935
- }
936
- }
937
- }
938
- }
939
-
940
- public readonly id: string = 'tcp'
941
-
942
- public readonly name: string = 'Transmission Control Protocol'
943
-
944
- public readonly nickname: string = 'TCP'
945
-
946
- public match(): boolean {
947
- if (!this.prevCodecModule) return false
948
- if (this.prevCodecModule.instance.protocol.getValue() === 0x06) return true
949
- return false
950
- }
951
-
952
- }