netkitty 0.0.34 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +91 -2
- package/README.zh-CN.md +89 -0
- package/dist/analysis.d.ts +4 -0
- package/dist/{CodecHeaderExports.js → analysis.js} +4 -1
- package/dist/capture.d.ts +5 -0
- package/dist/capture.js +21 -0
- package/dist/codec.d.ts +5 -0
- package/dist/codec.js +21 -0
- package/dist/iface.d.ts +4 -0
- package/dist/iface.js +20 -0
- package/dist/pcap.d.ts +10 -0
- package/dist/pcap.js +27 -0
- package/dist/replay.d.ts +5 -0
- package/dist/replay.js +21 -0
- package/package.json +65 -57
- package/.eslintrc.json +0 -53
- package/.idea/codeStyles/Project.xml +0 -18
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/inspectionProfiles/Project_Default.xml +0 -11
- package/.idea/modules.xml +0 -8
- package/.idea/netkitty.iml +0 -12
- package/.idea/vcs.xml +0 -6
- package/assets/NetKitty.png +0 -0
- package/binding.gyp +0 -5
- package/cpp/nodepcap/deps/include/Packet32.h +0 -429
- package/cpp/nodepcap/deps/include/pcap/bluetooth.h +0 -56
- package/cpp/nodepcap/deps/include/pcap/bpf.h +0 -292
- package/cpp/nodepcap/deps/include/pcap/can_socketcan.h +0 -56
- package/cpp/nodepcap/deps/include/pcap/compiler-tests.h +0 -163
- package/cpp/nodepcap/deps/include/pcap/dlt.h +0 -1514
- package/cpp/nodepcap/deps/include/pcap/funcattrs.h +0 -325
- package/cpp/nodepcap/deps/include/pcap/ipnet.h +0 -43
- package/cpp/nodepcap/deps/include/pcap/namedb.h +0 -84
- package/cpp/nodepcap/deps/include/pcap/nflog.h +0 -94
- package/cpp/nodepcap/deps/include/pcap/pcap-inttypes.h +0 -101
- package/cpp/nodepcap/deps/include/pcap/pcap.h +0 -1219
- package/cpp/nodepcap/deps/include/pcap/sll.h +0 -149
- package/cpp/nodepcap/deps/include/pcap/socket.h +0 -84
- package/cpp/nodepcap/deps/include/pcap/usb.h +0 -143
- package/cpp/nodepcap/deps/include/pcap/vlan.h +0 -46
- package/cpp/nodepcap/deps/include/pcap-bpf.h +0 -45
- package/cpp/nodepcap/deps/include/pcap-namedb.h +0 -40
- package/cpp/nodepcap/deps/include/pcap.h +0 -43
- package/cpp/nodepcap/deps/lib/ARM64/Packet.lib +0 -0
- package/cpp/nodepcap/deps/lib/Packet.lib +0 -0
- package/cpp/nodepcap/deps/lib/wpcap.lib +0 -0
- package/cpp/nodepcap/deps/lib/x64/Packet.lib +0 -0
- package/cpp/nodepcap/deps/lib/x64/wpcap.lib +0 -0
- package/cpp/nodepcap/nodepcap.gypi +0 -104
- package/cpp/nodepcap/src/binding.cc +0 -14
- package/cpp/nodepcap/src/capture.cc +0 -400
- package/cpp/nodepcap/src/capture.h +0 -53
- package/cpp/nodepcap/src/utils.cc +0 -218
- package/cpp/nodepcap/src/utils.h +0 -13
- package/dist/CodecExports.d.ts +0 -34
- package/dist/CodecExports.d.ts.map +0 -1
- package/dist/CodecExports.js +0 -23
- package/dist/CodecHeaderExports.d.ts +0 -2
- package/dist/CodecHeaderExports.d.ts.map +0 -1
- package/dist/HelperExports.d.ts +0 -11
- package/dist/HelperExports.d.ts.map +0 -1
- package/dist/HelperExports.js +0 -72
- package/dist/NetworkExports.d.ts +0 -13
- package/dist/NetworkExports.d.ts.map +0 -1
- package/dist/NetworkExports.js +0 -13
- package/dist/PcapExports.d.ts +0 -30
- package/dist/PcapExports.d.ts.map +0 -1
- package/dist/PcapExports.js +0 -33
- package/dist/errors/ActionNotFoundError.d.ts +0 -5
- package/dist/errors/ActionNotFoundError.d.ts.map +0 -1
- package/dist/errors/ActionNotFoundError.js +0 -12
- package/dist/errors/CodecSchemaValidateError.d.ts +0 -5
- package/dist/errors/CodecSchemaValidateError.d.ts.map +0 -1
- package/dist/errors/CodecSchemaValidateError.js +0 -12
- package/dist/errors/DeviceNotFoundError.d.ts +0 -5
- package/dist/errors/DeviceNotFoundError.d.ts.map +0 -1
- package/dist/errors/DeviceNotFoundError.js +0 -12
- package/dist/errors/NoAvailableCodecError.d.ts +0 -5
- package/dist/errors/NoAvailableCodecError.d.ts.map +0 -1
- package/dist/errors/NoAvailableCodecError.js +0 -12
- package/dist/errors/NpcapLoadError.d.ts +0 -5
- package/dist/errors/NpcapLoadError.d.ts.map +0 -1
- package/dist/errors/NpcapLoadError.js +0 -12
- package/dist/errors/SocketDownError.d.ts +0 -5
- package/dist/errors/SocketDownError.d.ts.map +0 -1
- package/dist/errors/SocketDownError.js +0 -12
- package/dist/errors/UnknownPipeMessageTypeError.d.ts +0 -5
- package/dist/errors/UnknownPipeMessageTypeError.d.ts.map +0 -1
- package/dist/errors/UnknownPipeMessageTypeError.js +0 -12
- package/dist/errors/common/ErrorCode.d.ts +0 -31
- package/dist/errors/common/ErrorCode.d.ts.map +0 -1
- package/dist/errors/common/ErrorCode.js +0 -33
- package/dist/lib/GeneratePipeAddress.d.ts +0 -7
- package/dist/lib/GeneratePipeAddress.d.ts.map +0 -1
- package/dist/lib/GeneratePipeAddress.js +0 -23
- package/dist/lib/GetBinding.d.ts +0 -2
- package/dist/lib/GetBinding.d.ts.map +0 -1
- package/dist/lib/GetBinding.js +0 -6
- package/dist/lib/GetCaptureTemporaryDirectory.d.ts +0 -7
- package/dist/lib/GetCaptureTemporaryDirectory.d.ts.map +0 -1
- package/dist/lib/GetCaptureTemporaryDirectory.js +0 -15
- package/dist/lib/GetDeviceCaptureTemporaryFilename.d.ts +0 -8
- package/dist/lib/GetDeviceCaptureTemporaryFilename.d.ts.map +0 -1
- package/dist/lib/GetDeviceCaptureTemporaryFilename.js +0 -18
- package/dist/lib/codec/Codec.d.ts +0 -32
- package/dist/lib/codec/Codec.d.ts.map +0 -1
- package/dist/lib/codec/Codec.js +0 -183
- package/dist/lib/codec/PacketHeaders.d.ts +0 -22
- package/dist/lib/codec/PacketHeaders.d.ts.map +0 -1
- package/dist/lib/codec/PacketHeaders.js +0 -47
- package/dist/lib/codec/abstracts/BaseHeader.d.ts +0 -217
- package/dist/lib/codec/abstracts/BaseHeader.d.ts.map +0 -1
- package/dist/lib/codec/abstracts/BaseHeader.js +0 -356
- package/dist/lib/codec/headers/ARP.d.ts +0 -10
- package/dist/lib/codec/headers/ARP.d.ts.map +0 -1
- package/dist/lib/codec/headers/ARP.js +0 -224
- package/dist/lib/codec/headers/EthernetII.d.ts +0 -10
- package/dist/lib/codec/headers/EthernetII.d.ts.map +0 -1
- package/dist/lib/codec/headers/EthernetII.js +0 -81
- package/dist/lib/codec/headers/Goose.d.ts +0 -104
- package/dist/lib/codec/headers/Goose.d.ts.map +0 -1
- package/dist/lib/codec/headers/Goose.js +0 -975
- package/dist/lib/codec/headers/ICMP.d.ts +0 -15
- package/dist/lib/codec/headers/ICMP.d.ts.map +0 -1
- package/dist/lib/codec/headers/ICMP.js +0 -147
- package/dist/lib/codec/headers/ICMPv6.d.ts +0 -15
- package/dist/lib/codec/headers/ICMPv6.d.ts.map +0 -1
- package/dist/lib/codec/headers/ICMPv6.js +0 -128
- package/dist/lib/codec/headers/IEC104_I_Frame.d.ts +0 -10
- package/dist/lib/codec/headers/IEC104_I_Frame.d.ts.map +0 -1
- package/dist/lib/codec/headers/IEC104_I_Frame.js +0 -6411
- package/dist/lib/codec/headers/IEC104_S_Frame.d.ts +0 -10
- package/dist/lib/codec/headers/IEC104_S_Frame.d.ts.map +0 -1
- package/dist/lib/codec/headers/IEC104_S_Frame.js +0 -105
- package/dist/lib/codec/headers/IEC104_U_Frame.d.ts +0 -10
- package/dist/lib/codec/headers/IEC104_U_Frame.d.ts.map +0 -1
- package/dist/lib/codec/headers/IEC104_U_Frame.js +0 -155
- package/dist/lib/codec/headers/IEC61850SampledValues.d.ts +0 -13
- package/dist/lib/codec/headers/IEC61850SampledValues.d.ts.map +0 -1
- package/dist/lib/codec/headers/IEC61850SampledValues.js +0 -370
- package/dist/lib/codec/headers/IPv4.d.ts +0 -16
- package/dist/lib/codec/headers/IPv4.d.ts.map +0 -1
- package/dist/lib/codec/headers/IPv4.js +0 -339
- package/dist/lib/codec/headers/IPv6.d.ts +0 -10
- package/dist/lib/codec/headers/IPv6.d.ts.map +0 -1
- package/dist/lib/codec/headers/IPv6.js +0 -177
- package/dist/lib/codec/headers/IPv6HopByHopOptions.d.ts +0 -71
- package/dist/lib/codec/headers/IPv6HopByHopOptions.d.ts.map +0 -1
- package/dist/lib/codec/headers/IPv6HopByHopOptions.js +0 -497
- package/dist/lib/codec/headers/RawData.d.ts +0 -11
- package/dist/lib/codec/headers/RawData.d.ts.map +0 -1
- package/dist/lib/codec/headers/RawData.js +0 -36
- package/dist/lib/codec/headers/TCP.d.ts +0 -16
- package/dist/lib/codec/headers/TCP.d.ts.map +0 -1
- package/dist/lib/codec/headers/TCP.js +0 -899
- package/dist/lib/codec/headers/TLS_Alert.d.ts +0 -10
- package/dist/lib/codec/headers/TLS_Alert.d.ts.map +0 -1
- package/dist/lib/codec/headers/TLS_Alert.js +0 -624
- package/dist/lib/codec/headers/TLS_ApplicationData.d.ts +0 -10
- package/dist/lib/codec/headers/TLS_ApplicationData.d.ts.map +0 -1
- package/dist/lib/codec/headers/TLS_ApplicationData.js +0 -155
- package/dist/lib/codec/headers/TLS_ChangeCipherSpec.d.ts +0 -10
- package/dist/lib/codec/headers/TLS_ChangeCipherSpec.d.ts.map +0 -1
- package/dist/lib/codec/headers/TLS_ChangeCipherSpec.js +0 -154
- package/dist/lib/codec/headers/TLS_Handshake.d.ts +0 -10
- package/dist/lib/codec/headers/TLS_Handshake.d.ts.map +0 -1
- package/dist/lib/codec/headers/TLS_Handshake.js +0 -339
- package/dist/lib/codec/headers/TLS_Heartbeat.d.ts +0 -10
- package/dist/lib/codec/headers/TLS_Heartbeat.d.ts.map +0 -1
- package/dist/lib/codec/headers/TLS_Heartbeat.js +0 -206
- package/dist/lib/codec/headers/UDP.d.ts +0 -16
- package/dist/lib/codec/headers/UDP.d.ts.map +0 -1
- package/dist/lib/codec/headers/UDP.js +0 -192
- package/dist/lib/codec/headers/VLAN_802dot1Q.d.ts +0 -10
- package/dist/lib/codec/headers/VLAN_802dot1Q.d.ts.map +0 -1
- package/dist/lib/codec/headers/VLAN_802dot1Q.js +0 -82
- package/dist/lib/codec/lib/FlexibleObject.d.ts +0 -28
- package/dist/lib/codec/lib/FlexibleObject.d.ts.map +0 -1
- package/dist/lib/codec/lib/FlexibleObject.js +0 -102
- package/dist/lib/codec/lib/GetBERIntegerLengthFromBuffer.d.ts +0 -7
- package/dist/lib/codec/lib/GetBERIntegerLengthFromBuffer.d.ts.map +0 -1
- package/dist/lib/codec/lib/GetBERIntegerLengthFromBuffer.js +0 -16
- package/dist/lib/codec/lib/ProcessPacketPostHandlers.d.ts +0 -14
- package/dist/lib/codec/lib/ProcessPacketPostHandlers.d.ts.map +0 -1
- package/dist/lib/codec/lib/ProcessPacketPostHandlers.js +0 -53
- package/dist/lib/codec/lib/SortPostHandlers.d.ts +0 -8
- package/dist/lib/codec/lib/SortPostHandlers.d.ts.map +0 -1
- package/dist/lib/codec/lib/SortPostHandlers.js +0 -11
- package/dist/lib/codec/lib/StringContentEncodingEnum.d.ts +0 -11
- package/dist/lib/codec/lib/StringContentEncodingEnum.d.ts.map +0 -1
- package/dist/lib/codec/lib/StringContentEncodingEnum.js +0 -14
- package/dist/lib/codec/types/CodecData.d.ts +0 -7
- package/dist/lib/codec/types/CodecData.d.ts.map +0 -1
- package/dist/lib/codec/types/CodecData.js +0 -2
- package/dist/lib/codec/types/CodecDecodeResult.d.ts +0 -11
- package/dist/lib/codec/types/CodecDecodeResult.d.ts.map +0 -1
- package/dist/lib/codec/types/CodecDecodeResult.js +0 -2
- package/dist/lib/codec/types/CodecEncodeInput.d.ts +0 -9
- package/dist/lib/codec/types/CodecEncodeInput.d.ts.map +0 -1
- package/dist/lib/codec/types/CodecEncodeInput.js +0 -2
- package/dist/lib/codec/types/CodecEncodeResult.d.ts +0 -6
- package/dist/lib/codec/types/CodecEncodeResult.d.ts.map +0 -1
- package/dist/lib/codec/types/CodecEncodeResult.js +0 -2
- package/dist/lib/codec/types/CodecErrorInfo.d.ts +0 -6
- package/dist/lib/codec/types/CodecErrorInfo.d.ts.map +0 -1
- package/dist/lib/codec/types/CodecErrorInfo.js +0 -2
- package/dist/lib/codec/types/CodecModule.d.ts +0 -3
- package/dist/lib/codec/types/CodecModule.d.ts.map +0 -1
- package/dist/lib/codec/types/CodecModule.js +0 -2
- package/dist/lib/codec/types/CodecModuleConstructor.d.ts +0 -3
- package/dist/lib/codec/types/CodecModuleConstructor.d.ts.map +0 -1
- package/dist/lib/codec/types/CodecModuleConstructor.js +0 -2
- package/dist/lib/codec/types/CodecSchema.d.ts +0 -7
- package/dist/lib/codec/types/CodecSchema.d.ts.map +0 -1
- package/dist/lib/codec/types/CodecSchema.js +0 -2
- package/dist/lib/codec/types/HeaderTreeNode.d.ts +0 -5
- package/dist/lib/codec/types/HeaderTreeNode.d.ts.map +0 -1
- package/dist/lib/codec/types/HeaderTreeNode.js +0 -2
- package/dist/lib/codec/types/PostHandlerItem.d.ts +0 -5
- package/dist/lib/codec/types/PostHandlerItem.d.ts.map +0 -1
- package/dist/lib/codec/types/PostHandlerItem.js +0 -2
- package/dist/lib/helper/BufferToHex.d.ts +0 -2
- package/dist/lib/helper/BufferToHex.d.ts.map +0 -1
- package/dist/lib/helper/BufferToHex.js +0 -6
- package/dist/lib/helper/BufferToIP.d.ts +0 -13
- package/dist/lib/helper/BufferToIP.d.ts.map +0 -1
- package/dist/lib/helper/BufferToIP.js +0 -21
- package/dist/lib/helper/BufferToNumber.d.ts +0 -10
- package/dist/lib/helper/BufferToNumber.d.ts.map +0 -1
- package/dist/lib/helper/BufferToNumber.js +0 -22
- package/dist/lib/helper/HexToBuffer.d.ts +0 -8
- package/dist/lib/helper/HexToBuffer.d.ts.map +0 -1
- package/dist/lib/helper/HexToBuffer.js +0 -27
- package/dist/lib/helper/HexToNumber.d.ts +0 -10
- package/dist/lib/helper/HexToNumber.d.ts.map +0 -1
- package/dist/lib/helper/HexToNumber.js +0 -39
- package/dist/lib/helper/IPToBuffer.d.ts +0 -13
- package/dist/lib/helper/IPToBuffer.d.ts.map +0 -1
- package/dist/lib/helper/IPToBuffer.js +0 -28
- package/dist/lib/helper/NumberToBERBuffer.d.ts +0 -10
- package/dist/lib/helper/NumberToBERBuffer.d.ts.map +0 -1
- package/dist/lib/helper/NumberToBERBuffer.js +0 -22
- package/dist/lib/helper/NumberToBERHex.d.ts +0 -10
- package/dist/lib/helper/NumberToBERHex.d.ts.map +0 -1
- package/dist/lib/helper/NumberToBERHex.js +0 -27
- package/dist/lib/helper/NumberToBuffer.d.ts +0 -10
- package/dist/lib/helper/NumberToBuffer.d.ts.map +0 -1
- package/dist/lib/helper/NumberToBuffer.js +0 -22
- package/dist/lib/helper/NumberToHex.d.ts +0 -10
- package/dist/lib/helper/NumberToHex.d.ts.map +0 -1
- package/dist/lib/helper/NumberToHex.js +0 -26
- package/dist/lib/nodepcap/Capture.d.ts +0 -81
- package/dist/lib/nodepcap/Capture.d.ts.map +0 -1
- package/dist/lib/nodepcap/Capture.js +0 -323
- package/dist/lib/nodepcap/GetNetworkInterfaces.d.ts +0 -7
- package/dist/lib/nodepcap/GetNetworkInterfaces.d.ts.map +0 -1
- package/dist/lib/nodepcap/GetNetworkInterfaces.js +0 -22
- package/dist/lib/nodepcap/interfaces/IBindingCapture.d.ts +0 -16
- package/dist/lib/nodepcap/interfaces/IBindingCapture.d.ts.map +0 -1
- package/dist/lib/nodepcap/interfaces/IBindingCapture.js +0 -2
- package/dist/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts +0 -5
- package/dist/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts.map +0 -1
- package/dist/lib/nodepcap/interfaces/IBindingCaptureOptions.js +0 -2
- package/dist/lib/nodepcap/interfaces/ICaptureOptions.d.ts +0 -23
- package/dist/lib/nodepcap/interfaces/ICaptureOptions.d.ts.map +0 -1
- package/dist/lib/nodepcap/interfaces/ICaptureOptions.js +0 -2
- package/dist/lib/nodepcap/interfaces/INetworkInterface.d.ts +0 -5
- package/dist/lib/nodepcap/interfaces/INetworkInterface.d.ts.map +0 -1
- package/dist/lib/nodepcap/interfaces/INetworkInterface.js +0 -2
- package/dist/lib/nodepcap/lib/BindingCapture.d.ts +0 -15
- package/dist/lib/nodepcap/lib/BindingCapture.d.ts.map +0 -1
- package/dist/lib/nodepcap/lib/BindingCapture.js +0 -35
- package/dist/lib/nodepcap/lib/GetNodePcapBinding.d.ts +0 -2
- package/dist/lib/nodepcap/lib/GetNodePcapBinding.d.ts.map +0 -1
- package/dist/lib/nodepcap/lib/GetNodePcapBinding.js +0 -55
- package/dist/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts +0 -3
- package/dist/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts.map +0 -1
- package/dist/lib/nodepcap/lib/GetNodePcapBindingCapture.js +0 -18
- package/dist/lib/nodepcap/workers/CaptureWorker.d.ts +0 -2
- package/dist/lib/nodepcap/workers/CaptureWorker.d.ts.map +0 -1
- package/dist/lib/nodepcap/workers/CaptureWorker.js +0 -25
- package/dist/lib/pcap/PCAPGenerator.d.ts +0 -34
- package/dist/lib/pcap/PCAPGenerator.d.ts.map +0 -1
- package/dist/lib/pcap/PCAPGenerator.js +0 -101
- package/dist/lib/pcap/PcapParser.d.ts +0 -27
- package/dist/lib/pcap/PcapParser.d.ts.map +0 -1
- package/dist/lib/pcap/PcapParser.js +0 -149
- package/dist/lib/pcap/PcapReader.d.ts +0 -112
- package/dist/lib/pcap/PcapReader.d.ts.map +0 -1
- package/dist/lib/pcap/PcapReader.js +0 -263
- package/dist/lib/pcap/PcapWriter.d.ts +0 -29
- package/dist/lib/pcap/PcapWriter.d.ts.map +0 -1
- package/dist/lib/pcap/PcapWriter.js +0 -86
- package/dist/lib/pcap/interfaces/IPcapPacketInfo.d.ts +0 -13
- package/dist/lib/pcap/interfaces/IPcapPacketInfo.d.ts.map +0 -1
- package/dist/lib/pcap/interfaces/IPcapPacketInfo.js +0 -2
- package/dist/lib/pipe/PipeClient.d.ts +0 -35
- package/dist/lib/pipe/PipeClient.d.ts.map +0 -1
- package/dist/lib/pipe/PipeClient.js +0 -71
- package/dist/lib/pipe/PipeClientSocket.d.ts +0 -39
- package/dist/lib/pipe/PipeClientSocket.d.ts.map +0 -1
- package/dist/lib/pipe/PipeClientSocket.js +0 -82
- package/dist/lib/pipe/PipeMessage.d.ts +0 -27
- package/dist/lib/pipe/PipeMessage.d.ts.map +0 -1
- package/dist/lib/pipe/PipeMessage.js +0 -61
- package/dist/lib/pipe/PipeMessageHandler.d.ts +0 -16
- package/dist/lib/pipe/PipeMessageHandler.d.ts.map +0 -1
- package/dist/lib/pipe/PipeMessageHandler.js +0 -95
- package/dist/lib/pipe/PipeServer.d.ts +0 -25
- package/dist/lib/pipe/PipeServer.d.ts.map +0 -1
- package/dist/lib/pipe/PipeServer.js +0 -59
- package/dist/lib/schema/ProtocolFieldJSONSchema.d.ts +0 -35
- package/dist/lib/schema/ProtocolFieldJSONSchema.d.ts.map +0 -1
- package/dist/lib/schema/ProtocolFieldJSONSchema.js +0 -2
- package/dist/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts +0 -3
- package/dist/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts.map +0 -1
- package/dist/lib/schema/ProtocolFieldJSONSchemaDefinition.js +0 -2
- package/dist/lib/schema/ProtocolJSONSchema.d.ts +0 -32
- package/dist/lib/schema/ProtocolJSONSchema.d.ts.map +0 -1
- package/dist/lib/schema/ProtocolJSONSchema.js +0 -2
- package/dist/tests/Test.spec.d.ts +0 -2
- package/dist/tests/Test.spec.d.ts.map +0 -1
- package/dist/tests/Test.spec.js +0 -25
- package/dist/tests/units/CaptureTest.spec.d.ts +0 -2
- package/dist/tests/units/CaptureTest.spec.d.ts.map +0 -1
- package/dist/tests/units/CaptureTest.spec.js +0 -32
- package/dist/tests/units/Codec.spec.d.ts +0 -2
- package/dist/tests/units/Codec.spec.d.ts.map +0 -1
- package/dist/tests/units/Codec.spec.js +0 -86
- package/dist/tests/units/ReadPCAP.spec.d.ts +0 -2
- package/dist/tests/units/ReadPCAP.spec.d.ts.map +0 -1
- package/dist/tests/units/ReadPCAP.spec.js +0 -14
- package/src/CodecExports.ts +0 -33
- package/src/CodecHeaderExports.ts +0 -1
- package/src/HelperExports.ts +0 -78
- package/src/NetworkExports.ts +0 -12
- package/src/PcapExports.ts +0 -32
- package/src/errors/ActionNotFoundError.ts +0 -6
- package/src/errors/CodecSchemaValidateError.ts +0 -6
- package/src/errors/DeviceNotFoundError.ts +0 -6
- package/src/errors/NoAvailableCodecError.ts +0 -6
- package/src/errors/NpcapLoadError.ts +0 -6
- package/src/errors/SocketDownError.ts +0 -6
- package/src/errors/UnknownPipeMessageTypeError.ts +0 -6
- package/src/errors/common/ErrorCode.ts +0 -30
- package/src/lib/GeneratePipeAddress.ts +0 -17
- package/src/lib/GetBinding.ts +0 -3
- package/src/lib/GetCaptureTemporaryDirectory.ts +0 -12
- package/src/lib/GetDeviceCaptureTemporaryFilename.ts +0 -13
- package/src/lib/codec/Codec.ts +0 -164
- package/src/lib/codec/PacketHeaders.ts +0 -23
- package/src/lib/codec/abstracts/BaseHeader.ts +0 -435
- package/src/lib/codec/headers/ARP.ts +0 -220
- package/src/lib/codec/headers/EthernetII.ts +0 -79
- package/src/lib/codec/headers/Goose.ts +0 -1003
- package/src/lib/codec/headers/ICMP.ts +0 -151
- package/src/lib/codec/headers/ICMPv6.ts +0 -128
- package/src/lib/codec/headers/IEC104_I_Frame.ts +0 -7373
- package/src/lib/codec/headers/IEC104_S_Frame.ts +0 -97
- package/src/lib/codec/headers/IEC104_U_Frame.ts +0 -139
- package/src/lib/codec/headers/IEC61850SampledValues.ts +0 -361
- package/src/lib/codec/headers/IPv4.ts +0 -331
- package/src/lib/codec/headers/IPv6.ts +0 -176
- package/src/lib/codec/headers/IPv6HopByHopOptions.ts +0 -532
- package/src/lib/codec/headers/RawData.ts +0 -38
- package/src/lib/codec/headers/TCP.ts +0 -934
- package/src/lib/codec/headers/TLS_Alert.ts +0 -539
- package/src/lib/codec/headers/TLS_ApplicationData.ts +0 -145
- package/src/lib/codec/headers/TLS_ChangeCipherSpec.ts +0 -146
- package/src/lib/codec/headers/TLS_Handshake.ts +0 -313
- package/src/lib/codec/headers/TLS_Heartbeat.ts +0 -188
- package/src/lib/codec/headers/UDP.ts +0 -182
- package/src/lib/codec/headers/VLAN_802dot1Q.ts +0 -79
- package/src/lib/codec/lib/FlexibleObject.ts +0 -100
- package/src/lib/codec/lib/GetBERIntegerLengthFromBuffer.ts +0 -12
- package/src/lib/codec/lib/ProcessPacketPostHandlers.ts +0 -53
- package/src/lib/codec/lib/SortPostHandlers.ts +0 -10
- package/src/lib/codec/lib/StringContentEncodingEnum.ts +0 -10
- package/src/lib/codec/types/CodecData.ts +0 -7
- package/src/lib/codec/types/CodecDecodeResult.ts +0 -11
- package/src/lib/codec/types/CodecEncodeInput.ts +0 -9
- package/src/lib/codec/types/CodecEncodeResult.ts +0 -6
- package/src/lib/codec/types/CodecErrorInfo.ts +0 -5
- package/src/lib/codec/types/CodecModule.ts +0 -3
- package/src/lib/codec/types/CodecModuleConstructor.ts +0 -3
- package/src/lib/codec/types/CodecSchema.ts +0 -7
- package/src/lib/codec/types/HeaderTreeNode.ts +0 -5
- package/src/lib/codec/types/PostHandlerItem.ts +0 -4
- package/src/lib/helper/BufferToHex.ts +0 -3
- package/src/lib/helper/BufferToIP.ts +0 -19
- package/src/lib/helper/BufferToNumber.ts +0 -31
- package/src/lib/helper/HexToBuffer.ts +0 -22
- package/src/lib/helper/HexToNumber.ts +0 -25
- package/src/lib/helper/IPToBuffer.ts +0 -25
- package/src/lib/helper/NumberToBERBuffer.ts +0 -21
- package/src/lib/helper/NumberToBERHex.ts +0 -17
- package/src/lib/helper/NumberToBuffer.ts +0 -21
- package/src/lib/helper/NumberToHex.ts +0 -15
- package/src/lib/nodepcap/Capture.ts +0 -304
- package/src/lib/nodepcap/GetNetworkInterfaces.ts +0 -18
- package/src/lib/nodepcap/interfaces/IBindingCapture.ts +0 -27
- package/src/lib/nodepcap/interfaces/IBindingCaptureOptions.ts +0 -4
- package/src/lib/nodepcap/interfaces/ICaptureOptions.ts +0 -24
- package/src/lib/nodepcap/interfaces/INetworkInterface.ts +0 -4
- package/src/lib/nodepcap/lib/BindingCapture.ts +0 -46
- package/src/lib/nodepcap/lib/GetNodePcapBinding.ts +0 -17
- package/src/lib/nodepcap/lib/GetNodePcapBindingCapture.ts +0 -15
- package/src/lib/nodepcap/workers/CaptureWorker.ts +0 -30
- package/src/lib/pcap/PCAPGenerator.ts +0 -123
- package/src/lib/pcap/PcapParser.ts +0 -170
- package/src/lib/pcap/PcapReader.ts +0 -306
- package/src/lib/pcap/PcapWriter.ts +0 -98
- package/src/lib/pcap/interfaces/IPcapPacketInfo.ts +0 -12
- package/src/lib/pipe/PipeClient.ts +0 -91
- package/src/lib/pipe/PipeClientSocket.ts +0 -99
- package/src/lib/pipe/PipeMessage.ts +0 -74
- package/src/lib/pipe/PipeMessageHandler.ts +0 -91
- package/src/lib/pipe/PipeServer.ts +0 -74
- package/src/lib/schema/ProtocolFieldJSONSchema.ts +0 -45
- package/src/lib/schema/ProtocolFieldJSONSchemaDefinition.ts +0 -3
- package/src/lib/schema/ProtocolJSONSchema.ts +0 -37
- package/src/tests/Test.spec.ts +0 -22
- package/src/tests/units/CaptureTest.spec.ts +0 -31
- package/src/tests/units/Codec.spec.ts +0 -102
- package/src/tests/units/ReadPCAP.spec.ts +0 -13
- package/test.pcap +0 -0
- package/tsconfig.json +0 -42
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Float32ToBERHex,
|
|
3
|
-
Int16ToBERHex,
|
|
4
|
-
Int32ToBERHex,
|
|
5
|
-
Int64ToBERHex,
|
|
6
|
-
Int8ToBERHex,
|
|
7
|
-
UInt16ToBERHex,
|
|
8
|
-
UInt32ToBERHex,
|
|
9
|
-
UInt64ToBERHex,
|
|
10
|
-
UInt8ToBERHex
|
|
11
|
-
} from './NumberToBERHex'
|
|
12
|
-
|
|
13
|
-
export const Int8ToBERBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(Int8ToBERHex(value), 'hex')
|
|
14
|
-
export const Int16ToBERBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(Int16ToBERHex(value), 'hex')
|
|
15
|
-
export const Int32ToBERBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(Int32ToBERHex(value), 'hex')
|
|
16
|
-
export const Int64ToBERBuffer: (value: bigint) => Buffer = (value: bigint): Buffer => Buffer.from(Int64ToBERHex(value), 'hex')
|
|
17
|
-
export const UInt8ToBERBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(UInt8ToBERHex(value), 'hex')
|
|
18
|
-
export const UInt16ToBERBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(UInt16ToBERHex(value), 'hex')
|
|
19
|
-
export const UInt32ToBERBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(UInt32ToBERHex(value), 'hex')
|
|
20
|
-
export const UInt64ToBERBuffer: (value: bigint) => Buffer = (value: bigint): Buffer => Buffer.from(UInt64ToBERHex(value), 'hex')
|
|
21
|
-
export const Float32ToBERBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(Float32ToBERHex(value), 'hex')
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {Float32ToHex} from './NumberToHex'
|
|
2
|
-
|
|
3
|
-
function toBERHex(rawHex: string): string {
|
|
4
|
-
const hex: string = rawHex.padStart(rawHex.length + rawHex.length % 2, '0')
|
|
5
|
-
return Buffer.from(hex, 'hex')[0].toString(2).padStart(8, '0').startsWith('1') ? `00${hex}` : hex
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const Int8ToBERHex: (value: number) => string = (value: number): string => toBERHex(new Uint8Array(Int8Array.from([value]).buffer)[0].toString(16))
|
|
9
|
-
export const Int16ToBERHex: (value: number) => string = (value: number): string => toBERHex(new Uint16Array(Int16Array.from([value]).buffer)[0].toString(16))
|
|
10
|
-
export const Int32ToBERHex: (value: number) => string = (value: number): string => toBERHex(new Uint32Array(Int32Array.from([value]).buffer)[0].toString(16))
|
|
11
|
-
export const Int64ToBERHex: (value: bigint) => string = (value: bigint): string => toBERHex(BigInt(value).toString(16))
|
|
12
|
-
export const UInt8ToBERHex: (value: number) => string = (value: number): string => toBERHex(value.toString(16))
|
|
13
|
-
export const UInt16ToBERHex: (value: number) => string = (value: number): string => toBERHex(value.toString(16))
|
|
14
|
-
export const UInt32ToBERHex: (value: number) => string = (value: number): string => toBERHex(value.toString(16))
|
|
15
|
-
export const UInt64ToBERHex: (value: bigint) => string = (value: bigint): string => toBERHex(BigInt(value).toString(16))
|
|
16
|
-
//Float32 precision is always 8, therefore add '08' prefix for Float32ToHex result
|
|
17
|
-
export const Float32ToBERHex: (value: number) => string = (value: number): string => `08${Float32ToHex(value)}`
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Float32ToHex,
|
|
3
|
-
Int16ToHex,
|
|
4
|
-
Int32ToHex,
|
|
5
|
-
Int64ToHex,
|
|
6
|
-
Int8ToHex,
|
|
7
|
-
UInt16ToHex,
|
|
8
|
-
UInt32ToHex,
|
|
9
|
-
UInt64ToHex,
|
|
10
|
-
UInt8ToHex
|
|
11
|
-
} from './NumberToHex'
|
|
12
|
-
|
|
13
|
-
export const Int8ToBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(Int8ToHex(value), 'hex')
|
|
14
|
-
export const Int16ToBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(Int16ToHex(value), 'hex')
|
|
15
|
-
export const Int32ToBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(Int32ToHex(value), 'hex')
|
|
16
|
-
export const Int64ToBuffer: (value: bigint) => Buffer = (value: bigint): Buffer => Buffer.from(Int64ToHex(value), 'hex')
|
|
17
|
-
export const UInt8ToBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(UInt8ToHex(value), 'hex')
|
|
18
|
-
export const UInt16ToBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(UInt16ToHex(value), 'hex')
|
|
19
|
-
export const UInt32ToBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(UInt32ToHex(value), 'hex')
|
|
20
|
-
export const UInt64ToBuffer: (value: bigint) => Buffer = (value: bigint): Buffer => Buffer.from(UInt64ToHex(value), 'hex')
|
|
21
|
-
export const Float32ToBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(Float32ToHex(value), 'hex')
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export const Int8ToHex: (value: number) => string = (value: number): string => new Uint8Array(Int8Array.from([value]).buffer)[0].toString(16).padStart(2, '0')
|
|
2
|
-
export const Int16ToHex: (value: number) => string = (value: number): string => new Uint16Array(Int16Array.from([value]).buffer)[0].toString(16).padStart(4, '0')
|
|
3
|
-
export const Int32ToHex: (value: number) => string = (value: number): string => new Uint32Array(Int32Array.from([value]).buffer)[0].toString(16).padStart(8, '0')
|
|
4
|
-
export const Int64ToHex: (value: bigint) => string = (value: bigint): string => BigInt(value).toString(16).padStart(16, '0')
|
|
5
|
-
export const UInt8ToHex: (value: number) => string = (value: number): string => value.toString(16).padStart(2, '0')
|
|
6
|
-
export const UInt16ToHex: (value: number) => string = (value: number): string => value.toString(16).padStart(4, '0')
|
|
7
|
-
export const UInt32ToHex: (value: number) => string = (value: number): string => value.toString(16).padStart(8, '0')
|
|
8
|
-
export const UInt64ToHex: (value: bigint) => string = (value: bigint): string => BigInt(value).toString(16).padStart(16, '0')
|
|
9
|
-
|
|
10
|
-
export const Float32ToHex: (value: number) => string = (value: number): string => {
|
|
11
|
-
const buffer = new ArrayBuffer(4)
|
|
12
|
-
const dataView = new DataView(buffer)
|
|
13
|
-
dataView.setFloat32(0, value, false)
|
|
14
|
-
return dataView.getUint32(0, false).toString(16).padStart(8, '0')
|
|
15
|
-
}
|
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
import {GetNetworkInterfaces} from './GetNetworkInterfaces'
|
|
2
|
-
import {INetworkInterface} from './interfaces/INetworkInterface'
|
|
3
|
-
import {ICaptureOptions} from './interfaces/ICaptureOptions'
|
|
4
|
-
import {existsSync, rmSync, writeFileSync} from 'node:fs'
|
|
5
|
-
import {GetDeviceCaptureTemporaryFilename} from '../GetDeviceCaptureTemporaryFilename'
|
|
6
|
-
import {ChildProcess} from 'node:child_process'
|
|
7
|
-
import path from 'node:path'
|
|
8
|
-
import isElectron from 'is-electron'
|
|
9
|
-
import * as childProcess from 'child_process'
|
|
10
|
-
import {utilityProcess, UtilityProcess} from 'electron'
|
|
11
|
-
import {PipeServer} from '../pipe/PipeServer'
|
|
12
|
-
import {PipeClientSocket} from '../pipe/PipeClientSocket'
|
|
13
|
-
import {randomInt} from 'crypto'
|
|
14
|
-
import {cp, rm} from 'node:fs/promises'
|
|
15
|
-
import EventEmitter from 'events'
|
|
16
|
-
import {DeviceNotFoundError} from '../../errors/DeviceNotFoundError'
|
|
17
|
-
import {tmpdir} from 'node:os'
|
|
18
|
-
import {IPcapPacketInfo} from '../pcap/interfaces/IPcapPacketInfo'
|
|
19
|
-
import {GeneratePCAPHeader} from '../pcap/PCAPGenerator'
|
|
20
|
-
|
|
21
|
-
export class Capture extends EventEmitter {
|
|
22
|
-
|
|
23
|
-
readonly #workerModule: string = path.resolve(__dirname, './workers/CaptureWorker.js')
|
|
24
|
-
|
|
25
|
-
readonly #device: string
|
|
26
|
-
|
|
27
|
-
readonly #tmpDir: string
|
|
28
|
-
|
|
29
|
-
readonly #temporaryFilename: string
|
|
30
|
-
|
|
31
|
-
readonly #pipeServer: PipeServer
|
|
32
|
-
|
|
33
|
-
#hasWorker: boolean = false
|
|
34
|
-
|
|
35
|
-
#worker: ChildProcess | UtilityProcess | undefined
|
|
36
|
-
|
|
37
|
-
#workerId: string | undefined
|
|
38
|
-
|
|
39
|
-
#workerSocket: PipeClientSocket | undefined
|
|
40
|
-
|
|
41
|
-
#workerDestroying: boolean = false
|
|
42
|
-
|
|
43
|
-
#started: boolean = false
|
|
44
|
-
|
|
45
|
-
#paused: boolean = false
|
|
46
|
-
|
|
47
|
-
#operating: boolean = false
|
|
48
|
-
|
|
49
|
-
#filter: string = ''
|
|
50
|
-
|
|
51
|
-
#count: number = 0
|
|
52
|
-
|
|
53
|
-
public get filter(): string {
|
|
54
|
-
return this.#filter
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public get temporaryFilename(): string {
|
|
58
|
-
return this.#temporaryFilename
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public get count(): number {
|
|
62
|
-
return this.#count
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Constructor
|
|
67
|
-
* @param options
|
|
68
|
-
*/
|
|
69
|
-
constructor(options: ICaptureOptions) {
|
|
70
|
-
super()
|
|
71
|
-
this.#workerModule = options.workerModule ? options.workerModule : this.#workerModule
|
|
72
|
-
this.#device = options.device
|
|
73
|
-
this.#filter = options.filter ? options.filter : ''
|
|
74
|
-
this.#tmpDir = options.tmpDir ? options.tmpDir : path.resolve(tmpdir(), 'netkitty-tmp')
|
|
75
|
-
if (!options.workerModule) {
|
|
76
|
-
//Use origin worker module, check capture device is available
|
|
77
|
-
if (!GetNetworkInterfaces().filter((availableDevice: INetworkInterface): boolean => availableDevice.name === this.#device).length) throw new DeviceNotFoundError(`Device ${this.#device} not found`)
|
|
78
|
-
}
|
|
79
|
-
this.#temporaryFilename = options.temporaryFilename ? options.temporaryFilename : GetDeviceCaptureTemporaryFilename(this.#device, this.#tmpDir)
|
|
80
|
-
this.#pipeServer = new PipeServer()
|
|
81
|
-
this.cleanTemporaryFile()
|
|
82
|
-
writeFileSync(this.#temporaryFilename, GeneratePCAPHeader())
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Create and initialize capture worker
|
|
87
|
-
* @protected
|
|
88
|
-
*/
|
|
89
|
-
protected createCaptureWorker(): void {
|
|
90
|
-
this.#hasWorker = true
|
|
91
|
-
this.#workerId = `CW_${Date.now().toString(16)}${randomInt(32).toString(16)}`
|
|
92
|
-
const env: Record<string, string> = {
|
|
93
|
-
captureWorkerId: this.#workerId,
|
|
94
|
-
captureDevice: this.#device,
|
|
95
|
-
captureFilter: this.#filter,
|
|
96
|
-
captureTemporaryFilename: this.#temporaryFilename,
|
|
97
|
-
socketPath: this.#pipeServer.socketPath
|
|
98
|
-
}
|
|
99
|
-
this.getWorkerSocket().then((socket: PipeClientSocket): void => {
|
|
100
|
-
socket.on('packet', (packetInfo: IPcapPacketInfo): void => {
|
|
101
|
-
this.emit('rawPacket', packetInfo.index, packetInfo.packet, packetInfo.seconds, packetInfo.microseconds)
|
|
102
|
-
this.emit('packet', packetInfo)
|
|
103
|
-
this.#count += 1
|
|
104
|
-
})
|
|
105
|
-
})
|
|
106
|
-
this.#worker = isElectron() ? utilityProcess.fork(this.#workerModule, [], {env: env}) : childProcess.fork(this.#workerModule, [], {env: env})
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Destroy capture worker
|
|
111
|
-
* @protected
|
|
112
|
-
*/
|
|
113
|
-
protected async destroyCaptureWorker(): Promise<void> {
|
|
114
|
-
if (!this.#hasWorker) return
|
|
115
|
-
if (this.#workerDestroying) {
|
|
116
|
-
while (this.#workerDestroying) await new Promise(resolve => setTimeout(resolve, 10))
|
|
117
|
-
return
|
|
118
|
-
}
|
|
119
|
-
this.#workerDestroying = true
|
|
120
|
-
await new Promise<void>(resolve => {
|
|
121
|
-
if (this.#workerSocket && this.#worker) {
|
|
122
|
-
const disconnectHandler: () => void = (): void => {
|
|
123
|
-
clearTimeout(notifyExitTimeout)
|
|
124
|
-
return resolve()
|
|
125
|
-
}
|
|
126
|
-
this.#workerSocket.once('disconnect', disconnectHandler)
|
|
127
|
-
this.#workerSocket.notify('exit')
|
|
128
|
-
const notifyExitTimeout: NodeJS.Timeout = setTimeout((): void => {
|
|
129
|
-
this.#workerSocket?.off('disconnect', disconnectHandler)
|
|
130
|
-
this.#worker?.kill('SIGINT')
|
|
131
|
-
return resolve()
|
|
132
|
-
}, 10000)
|
|
133
|
-
}
|
|
134
|
-
})
|
|
135
|
-
this.#workerSocket = undefined
|
|
136
|
-
this.#worker = undefined
|
|
137
|
-
this.#workerId = undefined
|
|
138
|
-
this.#workerDestroying = false
|
|
139
|
-
this.#hasWorker = false
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Get worker socket
|
|
144
|
-
* @protected
|
|
145
|
-
*/
|
|
146
|
-
protected async getWorkerSocket(): Promise<PipeClientSocket> {
|
|
147
|
-
return new Promise(resolve => {
|
|
148
|
-
if (!this.#workerSocket) {
|
|
149
|
-
this.#pipeServer.once('connect', (clientSocket: PipeClientSocket): void => {
|
|
150
|
-
this.#workerSocket = clientSocket
|
|
151
|
-
return resolve(this.#workerSocket)
|
|
152
|
-
})
|
|
153
|
-
} else {
|
|
154
|
-
return resolve(this.#workerSocket)
|
|
155
|
-
}
|
|
156
|
-
})
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Clean resources before start capture
|
|
161
|
-
* @param removeTmpFile
|
|
162
|
-
* @protected
|
|
163
|
-
*/
|
|
164
|
-
protected async cleanResources(removeTmpFile: boolean = true): Promise<void> {
|
|
165
|
-
//Clean cached capture data
|
|
166
|
-
if (existsSync(this.#temporaryFilename) && removeTmpFile) this.cleanTemporaryFile()
|
|
167
|
-
//Clean old worker resources
|
|
168
|
-
if (this.#worker && this.#workerSocket) await this.destroyCaptureWorker()
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Clean temporary pcap file
|
|
173
|
-
* @protected
|
|
174
|
-
*/
|
|
175
|
-
protected cleanTemporaryFile(): void {
|
|
176
|
-
rmSync(this.#temporaryFilename, {
|
|
177
|
-
recursive: true,
|
|
178
|
-
force: true
|
|
179
|
-
})
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Wait other operation done
|
|
184
|
-
* @protected
|
|
185
|
-
*/
|
|
186
|
-
protected async waitOperationDone(): Promise<void> {
|
|
187
|
-
while (this.#operating) await new Promise(resolve => setTimeout(resolve, 10))
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Start capture packets
|
|
192
|
-
*/
|
|
193
|
-
public async start(): Promise<void> {
|
|
194
|
-
if (this.#paused) return await this.resume()
|
|
195
|
-
if (this.#started) return
|
|
196
|
-
await this.waitOperationDone()
|
|
197
|
-
this.#operating = true
|
|
198
|
-
try {
|
|
199
|
-
this.#started = true
|
|
200
|
-
await this.cleanResources(false)
|
|
201
|
-
this.createCaptureWorker()
|
|
202
|
-
const workerSocket: PipeClientSocket = await this.getWorkerSocket()
|
|
203
|
-
await workerSocket.invoke('start')
|
|
204
|
-
} catch (e) {
|
|
205
|
-
this.#started = false
|
|
206
|
-
this.#operating = false
|
|
207
|
-
throw e
|
|
208
|
-
}
|
|
209
|
-
this.#operating = false
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Stop capture packets
|
|
214
|
-
*/
|
|
215
|
-
public async stop(): Promise<void> {
|
|
216
|
-
if (!this.#started) return
|
|
217
|
-
if (this.#workerDestroying) return
|
|
218
|
-
await this.waitOperationDone()
|
|
219
|
-
this.#operating = true
|
|
220
|
-
const workerSocket: PipeClientSocket = await this.getWorkerSocket()
|
|
221
|
-
await workerSocket.invoke('stop')
|
|
222
|
-
while (await workerSocket.invoke('count') !== this.count) await new Promise(resolve => setTimeout(resolve, 10))
|
|
223
|
-
await this.destroyCaptureWorker()
|
|
224
|
-
this.#started = false
|
|
225
|
-
this.#operating = false
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Pause capture packets
|
|
230
|
-
*/
|
|
231
|
-
public async pause(): Promise<void> {
|
|
232
|
-
if (!this.#started) return
|
|
233
|
-
if (!this.#hasWorker) return
|
|
234
|
-
if (this.#workerDestroying) return
|
|
235
|
-
await this.waitOperationDone()
|
|
236
|
-
this.#operating = true
|
|
237
|
-
const workerSocket: PipeClientSocket = await this.getWorkerSocket()
|
|
238
|
-
await workerSocket.invoke('stop')
|
|
239
|
-
while (await workerSocket.invoke('count') !== this.count) await new Promise(resolve => setTimeout(resolve, 10))
|
|
240
|
-
this.#paused = true
|
|
241
|
-
this.#operating = false
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Resume capture packets
|
|
246
|
-
*/
|
|
247
|
-
public async resume(): Promise<void> {
|
|
248
|
-
if (!this.#started) return
|
|
249
|
-
if (!this.#hasWorker) return
|
|
250
|
-
if (this.#workerDestroying) return
|
|
251
|
-
await this.waitOperationDone()
|
|
252
|
-
this.#operating = true
|
|
253
|
-
const workerSocket: PipeClientSocket = await this.getWorkerSocket()
|
|
254
|
-
await workerSocket.invoke('start')
|
|
255
|
-
this.#paused = false
|
|
256
|
-
this.#operating = false
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Set capture filter
|
|
261
|
-
* @param filter
|
|
262
|
-
*/
|
|
263
|
-
public async setFilter(filter: string): Promise<void> {
|
|
264
|
-
if (!this.#started) return
|
|
265
|
-
if (!this.#hasWorker) return
|
|
266
|
-
if (this.#workerDestroying) return
|
|
267
|
-
await this.waitOperationDone()
|
|
268
|
-
this.#operating = true
|
|
269
|
-
const workerSocket: PipeClientSocket = await this.getWorkerSocket()
|
|
270
|
-
await workerSocket.invoke('setFilter', filter)
|
|
271
|
-
this.#filter = filter
|
|
272
|
-
this.#operating = false
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Save captured pcap to destination
|
|
277
|
-
* @param destination
|
|
278
|
-
*/
|
|
279
|
-
public async saveTo(destination: string): Promise<void> {
|
|
280
|
-
await cp(this.temporaryFilename, destination)
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Dispose capture
|
|
285
|
-
*/
|
|
286
|
-
public async dispose(): Promise<void> {
|
|
287
|
-
await this.stop()
|
|
288
|
-
await this.cleanResources()
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
public on(eventName: 'packet', listener: (pcapPacketInfo: IPcapPacketInfo) => void): this
|
|
292
|
-
public on(eventName: 'rawPacket', listener: (index: number, packet: string, seconds: number, microseconds: number) => void): this
|
|
293
|
-
public on(eventName: string, listener: (...args: any[]) => void): this {
|
|
294
|
-
super.on(eventName, listener)
|
|
295
|
-
return this
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
public once(eventName: 'packet', listener: (pcapPacketInfo: IPcapPacketInfo) => void): this
|
|
299
|
-
public once(eventName: 'rawPacket', listener: (index: number, packet: string, seconds: number, microseconds: number) => void): this
|
|
300
|
-
public once(eventName: string, listener: (...args: any[]) => void): this {
|
|
301
|
-
super.once(eventName, listener)
|
|
302
|
-
return this
|
|
303
|
-
}
|
|
304
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import {INetworkInterface} from './interfaces/INetworkInterface'
|
|
2
|
-
import {GetNodePcapBinding} from './lib/GetNodePcapBinding'
|
|
3
|
-
import sortArray from 'sort-array'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Get network interfaces
|
|
7
|
-
* @constructor
|
|
8
|
-
*/
|
|
9
|
-
export function GetNetworkInterfaces(): INetworkInterface[] {
|
|
10
|
-
const ifaces: INetworkInterface[] = GetNodePcapBinding().GetNetworkInterfaces()
|
|
11
|
-
return sortArray(ifaces.map((iface: INetworkInterface): INetworkInterface => ({
|
|
12
|
-
name: iface.name,
|
|
13
|
-
mac: iface.mac.toLowerCase()
|
|
14
|
-
})), {
|
|
15
|
-
by: 'name',
|
|
16
|
-
order: 'asc'
|
|
17
|
-
})
|
|
18
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'events'
|
|
2
|
-
import {IBindingCaptureOptions} from './IBindingCaptureOptions'
|
|
3
|
-
|
|
4
|
-
export interface IBindingCapture extends EventEmitter {
|
|
5
|
-
|
|
6
|
-
new(options: IBindingCaptureOptions): IBindingCapture
|
|
7
|
-
|
|
8
|
-
start(): void
|
|
9
|
-
|
|
10
|
-
stop(): void
|
|
11
|
-
|
|
12
|
-
setFilter(filter: string): void
|
|
13
|
-
|
|
14
|
-
send(packet: Buffer): void
|
|
15
|
-
|
|
16
|
-
on(eventName: 'data', callback: (data: Buffer, sec: number, usec: number) => void): this
|
|
17
|
-
|
|
18
|
-
on(eventName: string, listener: (...args: any[]) => void): this
|
|
19
|
-
|
|
20
|
-
off(eventName: 'data', callback: (data: Buffer, sec: number, usec: number) => void): this
|
|
21
|
-
|
|
22
|
-
off(eventName: string, listener: (...args: any[]) => void): this
|
|
23
|
-
|
|
24
|
-
removeAllListeners(eventName?: 'data'): this
|
|
25
|
-
|
|
26
|
-
removeAllListeners(eventName?: string): this
|
|
27
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export interface ICaptureOptions {
|
|
2
|
-
/**
|
|
3
|
-
* Ethernet interface
|
|
4
|
-
*/
|
|
5
|
-
device: string
|
|
6
|
-
/**
|
|
7
|
-
* Capture filter
|
|
8
|
-
*/
|
|
9
|
-
filter?: string
|
|
10
|
-
/**
|
|
11
|
-
* Custom capture worker module path
|
|
12
|
-
*/
|
|
13
|
-
workerModule?: string
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The temporary folder path for storing captured pcap files
|
|
17
|
-
*/
|
|
18
|
-
tmpDir?: string
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Temporary filename
|
|
22
|
-
*/
|
|
23
|
-
temporaryFilename?:string
|
|
24
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import {IBindingCapture} from '../interfaces/IBindingCapture'
|
|
2
|
-
import {GetNodePcapBindingCapture} from './GetNodePcapBindingCapture'
|
|
3
|
-
import {IBindingCaptureOptions} from '../interfaces/IBindingCaptureOptions'
|
|
4
|
-
|
|
5
|
-
const BindingCaptureClass: IBindingCapture = GetNodePcapBindingCapture()
|
|
6
|
-
|
|
7
|
-
export class BindingCapture extends BindingCaptureClass {
|
|
8
|
-
|
|
9
|
-
constructor(options: IBindingCaptureOptions) {
|
|
10
|
-
super(options)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public start(): void {
|
|
14
|
-
super.start()
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public stop(): void {
|
|
18
|
-
super.stop()
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public setFilter(filter: string): void {
|
|
22
|
-
super.setFilter(filter)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public send(packet: Buffer): void {
|
|
26
|
-
super.send(packet)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public on(eventName: 'data', callback: (data: Buffer, sec: number, usec: number) => void): this
|
|
30
|
-
public on(eventName: string, listener: (...args: any[]) => void): this {
|
|
31
|
-
super.on(eventName, listener)
|
|
32
|
-
return this
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public off(eventName: 'data', callback: (data: Buffer, sec: number, usec: number) => void): this
|
|
36
|
-
public off(eventName: string, listener: (...args: any[]) => void): this {
|
|
37
|
-
super.off(eventName, listener)
|
|
38
|
-
return this
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public removeAllListeners(eventName?: 'data'): this
|
|
42
|
-
public removeAllListeners(eventName?: string): this {
|
|
43
|
-
super.removeAllListeners(eventName)
|
|
44
|
-
return this
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {GetBinding} from '../../GetBinding'
|
|
2
|
-
import path from 'node:path'
|
|
3
|
-
import * as os from 'node:os'
|
|
4
|
-
import {NpcapLoadError} from '../../../errors/NpcapLoadError'
|
|
5
|
-
|
|
6
|
-
let binding: any
|
|
7
|
-
|
|
8
|
-
export function GetNodePcapBinding(): any {
|
|
9
|
-
if (!binding) {
|
|
10
|
-
binding = GetBinding(path.resolve(__dirname, '../../../../bindings/nodepcap/nodepcap.node'))
|
|
11
|
-
if (os.platform() === 'win32') {
|
|
12
|
-
const prepareResult: boolean = binding.Prepare()
|
|
13
|
-
if (!prepareResult) throw new NpcapLoadError('Npcap loading failed. Please confirm whether Npcap has been installed.')
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return binding
|
|
17
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import {GetNodePcapBinding} from './GetNodePcapBinding'
|
|
2
|
-
import {inherits} from 'util'
|
|
3
|
-
import EventEmitter from 'events'
|
|
4
|
-
import {IBindingCapture} from '../interfaces/IBindingCapture'
|
|
5
|
-
|
|
6
|
-
let BindingCaptureClass: any
|
|
7
|
-
|
|
8
|
-
export function GetNodePcapBindingCapture(): IBindingCapture {
|
|
9
|
-
if (!BindingCaptureClass) {
|
|
10
|
-
const NodePcapBinding: any = GetNodePcapBinding()
|
|
11
|
-
BindingCaptureClass = NodePcapBinding.Capture
|
|
12
|
-
inherits(BindingCaptureClass, EventEmitter)
|
|
13
|
-
}
|
|
14
|
-
return BindingCaptureClass
|
|
15
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import {BindingCapture} from '../lib/BindingCapture'
|
|
2
|
-
import {PipeClient} from '../../pipe/PipeClient'
|
|
3
|
-
import {PcapWriter} from '../../pcap/PcapWriter'
|
|
4
|
-
import {IPcapPacketInfo} from '../../pcap/interfaces/IPcapPacketInfo'
|
|
5
|
-
|
|
6
|
-
const captureTemporaryFilename: string = process.env.captureTemporaryFilename!
|
|
7
|
-
|
|
8
|
-
const pcapWrite: PcapWriter = new PcapWriter({
|
|
9
|
-
filename: captureTemporaryFilename
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
const bindingCapture: BindingCapture = new BindingCapture({
|
|
13
|
-
iface: process.env.captureDevice!,
|
|
14
|
-
filter: process.env.captureFilter ? process.env.captureFilter : ''
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
const pipeClient: PipeClient = new PipeClient({
|
|
18
|
-
id: process.env.captureWorkerId!,
|
|
19
|
-
socketPath: process.env.socketPath!,
|
|
20
|
-
actions: {
|
|
21
|
-
count: async (): Promise<number> => pcapWrite.wroteCount,
|
|
22
|
-
start: async (): Promise<void> => bindingCapture.start(),
|
|
23
|
-
stop: async (): Promise<void> => bindingCapture.stop(),
|
|
24
|
-
setFilter: async (filter: string): Promise<void> => bindingCapture.setFilter(filter)
|
|
25
|
-
}
|
|
26
|
-
}).once('exit', (): Promise<void> => pcapWrite.close().finally((): void => process.exit(0)))
|
|
27
|
-
|
|
28
|
-
pcapWrite.on('packet', (wrotePacketInfo: IPcapPacketInfo): void => pipeClient.notify('packet', wrotePacketInfo))
|
|
29
|
-
|
|
30
|
-
bindingCapture.on('data', (data: Buffer, sec: number, usec: number): void => pcapWrite.write(data, sec, usec))
|