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,123 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 由pcap-generator库改写
|
|
3
|
-
* @see:https://github.com/onomondo/pcap-generator/tree/master
|
|
4
|
-
*/
|
|
5
|
-
import BigNumber from 'bignumber.js'
|
|
6
|
-
|
|
7
|
-
export type GeneratePCAPInputPacket = {
|
|
8
|
-
frameBase64Data: string
|
|
9
|
-
timestamp?: number
|
|
10
|
-
microsecond?: {
|
|
11
|
-
seconds: number
|
|
12
|
-
microseconds: number
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type GeneratePCAPPacket = {
|
|
17
|
-
buffer: Buffer,
|
|
18
|
-
timestamp?: number,
|
|
19
|
-
microsecond?: {
|
|
20
|
-
seconds: number
|
|
21
|
-
microseconds: number
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const headerOptions: {
|
|
26
|
-
majorVersion: number//Major version of pcap. Default: 2
|
|
27
|
-
minorVersion: number//Minor version of pcap. Default: 4
|
|
28
|
-
gmtOffset: number//The GMT offset in pcap. Default: 0
|
|
29
|
-
timestampAccuracy: number//The accuracy of the timestamps. Default: 0
|
|
30
|
-
snapshotLength: number//The snapshot length of the packets. Default: 65535
|
|
31
|
-
linkLayerType: number//The type of packets in the file. E.g. 101 for raw IP packets, or 1 for Ethernet packets. See https://www.tcpdump.org/linktypes.html for more details Default: 101 (Raw IP packets)
|
|
32
|
-
} = {
|
|
33
|
-
majorVersion: 2,
|
|
34
|
-
minorVersion: 4,
|
|
35
|
-
gmtOffset: 0,
|
|
36
|
-
timestampAccuracy: 0,
|
|
37
|
-
snapshotLength: 65535,
|
|
38
|
-
linkLayerType: 1
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function generate(packets: GeneratePCAPPacket[]): Buffer {
|
|
42
|
-
const globalHeader: Buffer = GeneratePCAPHeader()
|
|
43
|
-
const packetsBuffer: Buffer = Buffer.concat(packets.map((packet: GeneratePCAPPacket): Buffer => GeneratePCAPData(packet)))
|
|
44
|
-
return Buffer.concat([globalHeader, packetsBuffer])
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Converts a timestamp in milliseconds to an integer of the seconds part and an integer of the microseconds part
|
|
49
|
-
*
|
|
50
|
-
* @param ms
|
|
51
|
-
*/
|
|
52
|
-
function convertMillisecond2Microsecond(ms: number): [number, number] {
|
|
53
|
-
const [seconds, microseconds] = new BigNumber(ms).dividedBy(1000).toFixed(6).split('.').map(value => parseInt(value))
|
|
54
|
-
return [seconds, microseconds]
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function makeLessThanAMillion(i: number): number {
|
|
58
|
-
while (i > 1000000) {
|
|
59
|
-
i = Math.floor(i / 10)
|
|
60
|
-
}
|
|
61
|
-
return i
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Generate pcap file header's buffer
|
|
66
|
-
* @constructor
|
|
67
|
-
*/
|
|
68
|
-
export function GeneratePCAPHeader(): Buffer {
|
|
69
|
-
const globalHeader: Buffer = Buffer.alloc(24)
|
|
70
|
-
globalHeader.writeUInt32BE(2712847316, 0) // 4
|
|
71
|
-
globalHeader.writeUInt16BE(headerOptions.majorVersion, 4) // 2
|
|
72
|
-
globalHeader.writeUInt16BE(headerOptions.minorVersion, 6) // 2
|
|
73
|
-
globalHeader.writeInt32BE(headerOptions.gmtOffset, 8) // 4
|
|
74
|
-
globalHeader.writeUInt32BE(headerOptions.timestampAccuracy, 12) // 4
|
|
75
|
-
globalHeader.writeUInt32BE(headerOptions.snapshotLength, 16) // 4
|
|
76
|
-
globalHeader.writeUInt32BE(headerOptions.linkLayerType, 20) // 4
|
|
77
|
-
return globalHeader
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Generate single record data in pcap file
|
|
82
|
-
* @param packet
|
|
83
|
-
* @constructor
|
|
84
|
-
*/
|
|
85
|
-
export function GeneratePCAPData(packet: GeneratePCAPPacket): Buffer {
|
|
86
|
-
const packetHeader: Buffer = Buffer.alloc(16)
|
|
87
|
-
let seconds: number
|
|
88
|
-
let microseconds: number
|
|
89
|
-
if (packet.microsecond) {
|
|
90
|
-
seconds = packet.microsecond.seconds
|
|
91
|
-
microseconds = packet.microsecond.microseconds
|
|
92
|
-
} else {
|
|
93
|
-
if (packet.timestamp) {
|
|
94
|
-
[seconds, microseconds] = convertMillisecond2Microsecond(packet.timestamp)
|
|
95
|
-
} else {
|
|
96
|
-
seconds = 0
|
|
97
|
-
microseconds = 0
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
packetHeader.writeUInt32BE(seconds, 0) // 4
|
|
101
|
-
if (packet.microsecond) {
|
|
102
|
-
packetHeader.writeUInt32BE(microseconds, 4) // 4 - if in microsecond precision then remove excess of 1,000,000 (see documentation)
|
|
103
|
-
} else {
|
|
104
|
-
packetHeader.writeUInt32BE(makeLessThanAMillion(microseconds), 4) // 4 - if in microsecond precision then remove excess of 1,000,000 (see documentation)
|
|
105
|
-
}
|
|
106
|
-
packetHeader.writeUInt32BE(packet.buffer.length, 8) // 4
|
|
107
|
-
packetHeader.writeUInt32BE(packet.buffer.length, 12) // 4
|
|
108
|
-
|
|
109
|
-
return Buffer.concat([packetHeader, packet.buffer])
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Generate whole pcap file buffer data
|
|
114
|
-
* @param packets
|
|
115
|
-
* @constructor
|
|
116
|
-
*/
|
|
117
|
-
export function GeneratePCAP(packets: GeneratePCAPInputPacket[] = []): Buffer {
|
|
118
|
-
return generate(packets.map((packet: GeneratePCAPInputPacket): GeneratePCAPPacket => ({
|
|
119
|
-
timestamp: packet.timestamp,
|
|
120
|
-
microsecond: packet.microsecond,
|
|
121
|
-
buffer: Buffer.from(packet.frameBase64Data, 'base64')
|
|
122
|
-
})))
|
|
123
|
-
}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'events'
|
|
2
|
-
import {createReadStream, ReadStream} from 'node:fs'
|
|
3
|
-
import {format} from 'node:util'
|
|
4
|
-
import {IPcapPacketInfo} from './interfaces/IPcapPacketInfo'
|
|
5
|
-
|
|
6
|
-
const GLOBAL_HEADER_LENGTH = 24 //bytes
|
|
7
|
-
const PACKET_HEADER_LENGTH = 16 //bytes
|
|
8
|
-
|
|
9
|
-
export class PcapParser extends EventEmitter {
|
|
10
|
-
|
|
11
|
-
protected stream: ReadStream
|
|
12
|
-
|
|
13
|
-
protected buffer: Buffer | null
|
|
14
|
-
|
|
15
|
-
protected errored: boolean = false
|
|
16
|
-
|
|
17
|
-
protected endianness: 'BE' | 'LE' | null
|
|
18
|
-
|
|
19
|
-
protected index: number = 0
|
|
20
|
-
|
|
21
|
-
protected state: () => boolean
|
|
22
|
-
|
|
23
|
-
protected offset: number = 0
|
|
24
|
-
|
|
25
|
-
protected currentPacketHeader: {
|
|
26
|
-
timestampSeconds: number
|
|
27
|
-
timestampMicroseconds: number
|
|
28
|
-
capturedLength: number
|
|
29
|
-
originalLength: number
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public static parse(input: string | ReadStream): PcapParser {
|
|
33
|
-
return new PcapParser(input)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
constructor(input: string | ReadStream) {
|
|
37
|
-
super()
|
|
38
|
-
this.stream = (typeof input === 'string') ? createReadStream(input) : input
|
|
39
|
-
this.stream.pause()
|
|
40
|
-
this.stream.on('data', (data: string | Buffer): void => this.onData(data as Buffer))
|
|
41
|
-
this.stream.on('error', (err: Error): void => this.onError(err))
|
|
42
|
-
this.stream.on('end', (): void => this.onEnd())
|
|
43
|
-
this.buffer = null
|
|
44
|
-
this.state = () => this.parseGlobalHeader()
|
|
45
|
-
this.endianness = null
|
|
46
|
-
process.nextTick(this.stream.resume.bind(this.stream))
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
protected updateBuffer(data: Buffer): void {
|
|
50
|
-
if (data === null || data === undefined) return
|
|
51
|
-
if (this.buffer === null) {
|
|
52
|
-
this.buffer = data
|
|
53
|
-
} else {
|
|
54
|
-
let extendedBuffer: Buffer = Buffer.alloc(this.buffer.length + data.length)
|
|
55
|
-
this.buffer.copy(extendedBuffer)
|
|
56
|
-
data.copy(extendedBuffer, this.buffer.length)
|
|
57
|
-
this.buffer = extendedBuffer
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
protected parseGlobalHeader(): boolean {
|
|
62
|
-
const buffer: Buffer = this.buffer!
|
|
63
|
-
if (buffer.length >= GLOBAL_HEADER_LENGTH) {
|
|
64
|
-
let msg: string
|
|
65
|
-
const magicNumber: string = buffer.toString('hex', 0, 4)
|
|
66
|
-
// determine pcap endianness
|
|
67
|
-
if (magicNumber == 'a1b2c3d4') {
|
|
68
|
-
this.endianness = 'BE'
|
|
69
|
-
} else if (magicNumber == 'd4c3b2a1' || magicNumber == '4d3cb2a1') {
|
|
70
|
-
this.endianness = 'LE'
|
|
71
|
-
} else {
|
|
72
|
-
this.errored = true
|
|
73
|
-
this.stream.pause()
|
|
74
|
-
msg = format('unknown magic number: %s', magicNumber)
|
|
75
|
-
this.emit('error', new Error(msg))
|
|
76
|
-
this.onEnd()
|
|
77
|
-
return false
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const header = {
|
|
81
|
-
magicNumber: buffer['readUInt32' + this.endianness](0, true),
|
|
82
|
-
majorVersion: buffer['readUInt16' + this.endianness](4, true),
|
|
83
|
-
minorVersion: buffer['readUInt16' + this.endianness](6, true),
|
|
84
|
-
gmtOffset: buffer['readInt32' + this.endianness](8, true),
|
|
85
|
-
timestampAccuracy: buffer['readUInt32' + this.endianness](12, true),
|
|
86
|
-
snapshotLength: buffer['readUInt32' + this.endianness](16, true),
|
|
87
|
-
linkLayerType: buffer['readUInt32' + this.endianness](20, true)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (header.majorVersion != 2 && header.minorVersion != 4) {
|
|
91
|
-
this.errored = true
|
|
92
|
-
this.stream.pause()
|
|
93
|
-
msg = format('unsupported version %d.%d. pcap-parser only parses libpcap file format 2.4', header.majorVersion, header.minorVersion)
|
|
94
|
-
this.emit('error', new Error(msg))
|
|
95
|
-
this.onEnd()
|
|
96
|
-
} else {
|
|
97
|
-
this.emit('globalHeader', header)
|
|
98
|
-
this.buffer = buffer.subarray(GLOBAL_HEADER_LENGTH)
|
|
99
|
-
this.state = (): boolean => this.parsePacketHeader()
|
|
100
|
-
this.offset = GLOBAL_HEADER_LENGTH
|
|
101
|
-
return true
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return false
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
protected parsePacketHeader(): boolean {
|
|
109
|
-
const buffer: Buffer = this.buffer!
|
|
110
|
-
if (buffer.length >= PACKET_HEADER_LENGTH) {
|
|
111
|
-
const header = {
|
|
112
|
-
timestampSeconds: buffer['readUInt32' + this.endianness](0, true),
|
|
113
|
-
timestampMicroseconds: buffer['readUInt32' + this.endianness](4, true),
|
|
114
|
-
capturedLength: buffer['readUInt32' + this.endianness](8, true),
|
|
115
|
-
originalLength: buffer['readUInt32' + this.endianness](12, true)
|
|
116
|
-
}
|
|
117
|
-
this.currentPacketHeader = header
|
|
118
|
-
this.emit('packetHeader', header)
|
|
119
|
-
this.buffer = buffer.subarray(PACKET_HEADER_LENGTH)
|
|
120
|
-
this.state = (): boolean => this.parsePacketBody()
|
|
121
|
-
this.index += 1
|
|
122
|
-
return true
|
|
123
|
-
}
|
|
124
|
-
return false
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
protected parsePacketBody(): boolean {
|
|
128
|
-
const buffer: Buffer = this.buffer!
|
|
129
|
-
|
|
130
|
-
if (buffer.length >= this.currentPacketHeader.capturedLength) {
|
|
131
|
-
const data: Buffer = buffer.subarray(0, this.currentPacketHeader!.capturedLength)
|
|
132
|
-
const packetLength: number = data.length
|
|
133
|
-
const recordLength: number = PACKET_HEADER_LENGTH + packetLength
|
|
134
|
-
const pcapPacketInfo: IPcapPacketInfo = {
|
|
135
|
-
index: this.index,
|
|
136
|
-
offset: this.offset,
|
|
137
|
-
length: recordLength,
|
|
138
|
-
recordHeaderOffset: this.offset,
|
|
139
|
-
recordHeaderLength: PACKET_HEADER_LENGTH,
|
|
140
|
-
packetOffset: this.offset + PACKET_HEADER_LENGTH,
|
|
141
|
-
packetLength: data.length,
|
|
142
|
-
seconds: this.currentPacketHeader.timestampSeconds,
|
|
143
|
-
microseconds: this.currentPacketHeader.timestampMicroseconds,
|
|
144
|
-
packet: data.toString('base64')
|
|
145
|
-
}
|
|
146
|
-
this.emit('packetData', data)
|
|
147
|
-
this.emit('packet', pcapPacketInfo)
|
|
148
|
-
this.buffer = buffer.subarray(this.currentPacketHeader.capturedLength)
|
|
149
|
-
this.state = (): boolean => this.parsePacketHeader()
|
|
150
|
-
this.offset += recordLength
|
|
151
|
-
return true
|
|
152
|
-
}
|
|
153
|
-
return false
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
protected onData(data: Buffer): void {
|
|
157
|
-
if (this.errored) return
|
|
158
|
-
this.updateBuffer(data)
|
|
159
|
-
while (this.state()) {
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
protected onError(err: Error): void {
|
|
164
|
-
this.emit('error', err)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
protected onEnd(): void {
|
|
168
|
-
this.emit('end')
|
|
169
|
-
}
|
|
170
|
-
}
|
|
@@ -1,306 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'events'
|
|
2
|
-
import {FileHandle, FileReadResult, open} from 'node:fs/promises'
|
|
3
|
-
import {ReadStream, WriteStream} from 'node:fs'
|
|
4
|
-
import DuplexPair from 'duplexpair'
|
|
5
|
-
import {PcapParser} from './PcapParser'
|
|
6
|
-
import {IPcapPacketInfo} from './interfaces/IPcapPacketInfo'
|
|
7
|
-
|
|
8
|
-
export interface IPcapReaderOptions {
|
|
9
|
-
filename: string
|
|
10
|
-
watch?: boolean
|
|
11
|
-
chunkSize?: number
|
|
12
|
-
onPacket?: (pcapPacketInfo: IPcapPacketInfo) => Promise<void> | void
|
|
13
|
-
onStart?: () => Promise<void> | void
|
|
14
|
-
onStop?: () => Promise<void> | void
|
|
15
|
-
onDone?: () => Promise<void> | void
|
|
16
|
-
onError?: (err: Error) => void
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class PcapReader extends EventEmitter {
|
|
20
|
-
|
|
21
|
-
protected readonly filename: string
|
|
22
|
-
|
|
23
|
-
protected readonly watch: boolean
|
|
24
|
-
|
|
25
|
-
protected readonly chunkSize: number = 1518 * 10
|
|
26
|
-
|
|
27
|
-
protected duplexPair: DuplexPair
|
|
28
|
-
|
|
29
|
-
protected parser: PcapParser
|
|
30
|
-
|
|
31
|
-
protected index: number = 0
|
|
32
|
-
|
|
33
|
-
protected offset: number = 0
|
|
34
|
-
|
|
35
|
-
protected readDone: boolean = false
|
|
36
|
-
|
|
37
|
-
protected readBufferFileHandle: FileHandle | null = null
|
|
38
|
-
|
|
39
|
-
protected onPacket?: (pcapPacketInfo: IPcapPacketInfo) => Promise<void> | void
|
|
40
|
-
|
|
41
|
-
protected onStart?: () => Promise<void> | void
|
|
42
|
-
|
|
43
|
-
protected onStop?: () => Promise<void> | void
|
|
44
|
-
|
|
45
|
-
protected onDone?: () => Promise<void> | void
|
|
46
|
-
|
|
47
|
-
protected onError?: (err: Error) => void
|
|
48
|
-
|
|
49
|
-
protected paused: boolean = false
|
|
50
|
-
|
|
51
|
-
protected get readStream(): ReadStream {
|
|
52
|
-
return this.duplexPair.socket2
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
protected get writeStream(): WriteStream {
|
|
56
|
-
return this.duplexPair.socket1
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
constructor(options: IPcapReaderOptions) {
|
|
60
|
-
super()
|
|
61
|
-
this.filename = options.filename
|
|
62
|
-
this.watch = !!options.watch
|
|
63
|
-
this.chunkSize = options.chunkSize ? options.chunkSize : this.chunkSize
|
|
64
|
-
if (options.onPacket) this.onPacket = options.onPacket
|
|
65
|
-
if (options.onStart) this.onStart = options.onStart
|
|
66
|
-
if (options.onStop) this.onStop = options.onStop
|
|
67
|
-
if (options.onDone) this.onDone = options.onDone
|
|
68
|
-
if (options.onError) this.onError = options.onError
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Pause read
|
|
73
|
-
* @protected
|
|
74
|
-
*/
|
|
75
|
-
protected pauseRead(): void {
|
|
76
|
-
this.readStream.pause()
|
|
77
|
-
this.paused = true
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Resume read
|
|
82
|
-
* @protected
|
|
83
|
-
*/
|
|
84
|
-
protected resumeRead(): void {
|
|
85
|
-
this.readStream.resume()
|
|
86
|
-
this.paused = false
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Initialize reader
|
|
91
|
-
* @protected
|
|
92
|
-
*/
|
|
93
|
-
protected initReader(): void {
|
|
94
|
-
this.duplexPair = new DuplexPair()
|
|
95
|
-
this.parser = PcapParser.parse(this.readStream)
|
|
96
|
-
this.parser
|
|
97
|
-
.on('packet', async (pcapPacketInfo: IPcapPacketInfo): Promise<void> => {
|
|
98
|
-
this.index = pcapPacketInfo.index
|
|
99
|
-
this.emit('packet', pcapPacketInfo)
|
|
100
|
-
if (this.onPacket) {
|
|
101
|
-
this.pauseRead()
|
|
102
|
-
await this.onPacket(pcapPacketInfo)
|
|
103
|
-
this.resumeRead()
|
|
104
|
-
}
|
|
105
|
-
})
|
|
106
|
-
.on('error', (err: Error): void => {
|
|
107
|
-
this.emit('error', err)
|
|
108
|
-
if (this.onError) this.onError(err)
|
|
109
|
-
})
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Reset reader
|
|
114
|
-
* @protected
|
|
115
|
-
*/
|
|
116
|
-
protected async reset(): Promise<void> {
|
|
117
|
-
await this.stop()
|
|
118
|
-
this.parser?.removeAllListeners()
|
|
119
|
-
this.index = 0
|
|
120
|
-
this.offset = 0
|
|
121
|
-
this.paused = false
|
|
122
|
-
this.initReader()
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Initialize read packet file handle
|
|
127
|
-
* @protected
|
|
128
|
-
*/
|
|
129
|
-
protected async initReadPacketFileHandle(): Promise<FileHandle> {
|
|
130
|
-
return await open(this.filename, 'r')
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Initialize read buffer file handle
|
|
135
|
-
* @protected
|
|
136
|
-
*/
|
|
137
|
-
protected async initReadBufferFileHandle(): Promise<FileHandle> {
|
|
138
|
-
if (!this.readBufferFileHandle) this.readBufferFileHandle = await open(this.filename, 'r')
|
|
139
|
-
return this.readBufferFileHandle
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Read file buffer
|
|
144
|
-
* @protected
|
|
145
|
-
*/
|
|
146
|
-
protected async readBuffer(): Promise<boolean> {
|
|
147
|
-
const readBufferFileHandle: FileHandle = await this.initReadBufferFileHandle()
|
|
148
|
-
try {
|
|
149
|
-
const result: FileReadResult<Buffer> = await readBufferFileHandle.read({
|
|
150
|
-
buffer: Buffer.alloc(this.chunkSize),
|
|
151
|
-
offset: 0,
|
|
152
|
-
length: this.chunkSize,
|
|
153
|
-
position: this.offset
|
|
154
|
-
})
|
|
155
|
-
if (result.bytesRead <= 0) return true
|
|
156
|
-
const data: Buffer = Buffer.alloc(result.bytesRead)
|
|
157
|
-
result.buffer.copy(data, 0, 0, result.bytesRead)
|
|
158
|
-
this.offset += result.bytesRead
|
|
159
|
-
this.writeStream.write(data)
|
|
160
|
-
return false
|
|
161
|
-
} catch (e) {
|
|
162
|
-
return true
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Read file continually
|
|
168
|
-
* @protected
|
|
169
|
-
*/
|
|
170
|
-
protected continualRead(): void {
|
|
171
|
-
process.nextTick(async (): Promise<void> => {
|
|
172
|
-
let read: boolean = true
|
|
173
|
-
this.once('stop', (): boolean => read = false)
|
|
174
|
-
let isReachEnd: boolean = false
|
|
175
|
-
while (read || !isReachEnd) {
|
|
176
|
-
if (this.paused) {
|
|
177
|
-
await new Promise(resolve => setTimeout(resolve, 1))
|
|
178
|
-
continue
|
|
179
|
-
}
|
|
180
|
-
isReachEnd = await this.readBuffer()
|
|
181
|
-
if (isReachEnd) {
|
|
182
|
-
await new Promise(resolve => setTimeout(resolve, 1))
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
await this.readBufferFileHandle?.close()
|
|
186
|
-
this.readBufferFileHandle = null
|
|
187
|
-
this.readDone = true
|
|
188
|
-
this.emit('done')
|
|
189
|
-
if (this.onDone) await this.onDone()
|
|
190
|
-
})
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Read the file straight
|
|
195
|
-
* @protected
|
|
196
|
-
*/
|
|
197
|
-
protected straightRead(): void {
|
|
198
|
-
process.nextTick(async (): Promise<void> => {
|
|
199
|
-
let isReachEnd: boolean = false
|
|
200
|
-
let stopped: boolean = false
|
|
201
|
-
this.once('stop', (): boolean => stopped = true)
|
|
202
|
-
while (!isReachEnd && !stopped) {
|
|
203
|
-
if (this.paused) {
|
|
204
|
-
await new Promise(resolve => setTimeout(resolve, 1))
|
|
205
|
-
continue
|
|
206
|
-
}
|
|
207
|
-
isReachEnd = await this.readBuffer()
|
|
208
|
-
}
|
|
209
|
-
this.readDone = true
|
|
210
|
-
if (!stopped) await this.stop()
|
|
211
|
-
await this.readBufferFileHandle?.close()
|
|
212
|
-
this.readBufferFileHandle = null
|
|
213
|
-
this.emit('done')
|
|
214
|
-
if (this.onDone) await this.onDone()
|
|
215
|
-
})
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Read packet data by record's offset and record's length
|
|
220
|
-
* @param offset
|
|
221
|
-
* @param length
|
|
222
|
-
*/
|
|
223
|
-
public async readPacket(offset: number, length: number): Promise<Buffer> {
|
|
224
|
-
const fileHandle: FileHandle = await this.initReadPacketFileHandle()
|
|
225
|
-
const recordHeaderLength: number = 16
|
|
226
|
-
const packetLength: number = length - recordHeaderLength
|
|
227
|
-
const result: FileReadResult<Buffer> = await fileHandle.read({
|
|
228
|
-
buffer: Buffer.alloc(packetLength),
|
|
229
|
-
offset: 0,
|
|
230
|
-
length: packetLength,
|
|
231
|
-
position: offset + recordHeaderLength
|
|
232
|
-
})
|
|
233
|
-
await fileHandle.close()
|
|
234
|
-
return result.buffer
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Start reading pcap
|
|
239
|
-
*/
|
|
240
|
-
public async start(): Promise<void> {
|
|
241
|
-
await this.reset()
|
|
242
|
-
this.emit('start')
|
|
243
|
-
if (this.onStart) await this.onStart()
|
|
244
|
-
if (this.watch) {
|
|
245
|
-
this.continualRead()
|
|
246
|
-
} else {
|
|
247
|
-
this.straightRead()
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Stop reading pcap
|
|
253
|
-
*/
|
|
254
|
-
public async stop(): Promise<void> {
|
|
255
|
-
if (this.parser) {
|
|
256
|
-
this.emit('stop')
|
|
257
|
-
if (!this.readDone) await new Promise(resolve => this.once('done', resolve))
|
|
258
|
-
if (this.onStop) await this.onStop()
|
|
259
|
-
}
|
|
260
|
-
if (this.duplexPair) {
|
|
261
|
-
await new Promise<void>(resolve => {
|
|
262
|
-
if (this.writeStream.closed) return resolve()
|
|
263
|
-
this.writeStream.once('close', () => resolve())
|
|
264
|
-
this.writeStream.once('error', err => !!err)
|
|
265
|
-
this.writeStream.destroy()
|
|
266
|
-
})
|
|
267
|
-
await new Promise<void>(resolve => {
|
|
268
|
-
if (this.readStream.closed) return resolve()
|
|
269
|
-
this.readStream.once('close', () => resolve())
|
|
270
|
-
this.readStream.once('error', err => !!err)
|
|
271
|
-
this.readStream.destroy()
|
|
272
|
-
})
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Close pcap reader
|
|
278
|
-
*/
|
|
279
|
-
public async close(): Promise<void> {
|
|
280
|
-
await this.stop()
|
|
281
|
-
this.emit('close')
|
|
282
|
-
this.removeAllListeners()
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
public on(eventName: 'packet', listener: (pcapPacketInfo: IPcapPacketInfo) => void): this
|
|
286
|
-
public on(eventName: 'done', listener: (...args: any[]) => void): this
|
|
287
|
-
public on(eventName: 'start', listener: (...args: any[]) => void): this
|
|
288
|
-
public on(eventName: 'stop', listener: (...args: any[]) => void): this
|
|
289
|
-
public on(eventName: 'close', listener: (...args: any[]) => void): this
|
|
290
|
-
public on(eventName: 'error', listener: (error: Error) => void): this
|
|
291
|
-
public on(eventName: string, listener: (...args: any[]) => void): this {
|
|
292
|
-
super.on(eventName, listener)
|
|
293
|
-
return this
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
public once(eventName: 'packet', listener: (pcapPacketInfo: IPcapPacketInfo) => void): this
|
|
297
|
-
public once(eventName: 'done', listener: (...args: any[]) => void): this
|
|
298
|
-
public once(eventName: 'start', listener: (...args: any[]) => void): this
|
|
299
|
-
public once(eventName: 'stop', listener: (...args: any[]) => void): this
|
|
300
|
-
public once(eventName: 'close', listener: (...args: any[]) => void): this
|
|
301
|
-
public once(eventName: 'error', listener: (error: Error) => void): this
|
|
302
|
-
public once(eventName: string, listener: (...args: any[]) => void): this {
|
|
303
|
-
super.once(eventName, listener)
|
|
304
|
-
return this
|
|
305
|
-
}
|
|
306
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'events'
|
|
2
|
-
import {createWriteStream, existsSync, statSync, WriteStream} from 'node:fs'
|
|
3
|
-
import {GeneratePCAPData, GeneratePCAPHeader} from './PCAPGenerator'
|
|
4
|
-
import {IPcapPacketInfo} from './interfaces/IPcapPacketInfo'
|
|
5
|
-
|
|
6
|
-
export interface IPcapWriterOptions {
|
|
7
|
-
filename: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class PcapWriter extends EventEmitter {
|
|
11
|
-
|
|
12
|
-
public readonly filename: string
|
|
13
|
-
|
|
14
|
-
protected readonly writeStream: WriteStream
|
|
15
|
-
|
|
16
|
-
protected closed: boolean = false
|
|
17
|
-
|
|
18
|
-
protected index: number = 0
|
|
19
|
-
|
|
20
|
-
protected offset: number = 0
|
|
21
|
-
|
|
22
|
-
public get wroteCount(): number {
|
|
23
|
-
return this.index
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
constructor(options: IPcapWriterOptions) {
|
|
27
|
-
super()
|
|
28
|
-
this.filename = options.filename
|
|
29
|
-
if (!existsSync(this.filename)) {
|
|
30
|
-
this.writeStream = createWriteStream(this.filename, {autoClose: false, flags: 'w'})
|
|
31
|
-
const header: Buffer = GeneratePCAPHeader()
|
|
32
|
-
this.writeStream.write(header)
|
|
33
|
-
this.offset += header.length
|
|
34
|
-
} else {
|
|
35
|
-
this.writeStream = createWriteStream(this.filename, {autoClose: false, flags: 'a'})
|
|
36
|
-
this.offset += statSync(this.filename).size
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Write packet to pcap file
|
|
42
|
-
* @param packet
|
|
43
|
-
* @param seconds
|
|
44
|
-
* @param microseconds
|
|
45
|
-
*/
|
|
46
|
-
public write(packet: Buffer, seconds: number, microseconds: number): void {
|
|
47
|
-
if (this.closed) return
|
|
48
|
-
this.index += 1
|
|
49
|
-
const startOffset: number = this.offset
|
|
50
|
-
const packetLength: number = packet.length
|
|
51
|
-
const pcapData: Buffer = GeneratePCAPData({
|
|
52
|
-
buffer: packet,
|
|
53
|
-
timestamp: Date.now(),
|
|
54
|
-
microsecond: {
|
|
55
|
-
seconds: seconds,
|
|
56
|
-
microseconds: microseconds
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
this.offset += pcapData.length
|
|
60
|
-
const packetOffset: number = this.offset - packetLength
|
|
61
|
-
const recordHeaderLength: number = packetOffset - startOffset
|
|
62
|
-
const wrotePacketInfo: IPcapPacketInfo = {
|
|
63
|
-
index: this.index,
|
|
64
|
-
offset: startOffset,
|
|
65
|
-
length: pcapData.length,
|
|
66
|
-
recordHeaderOffset: startOffset,
|
|
67
|
-
recordHeaderLength: recordHeaderLength,
|
|
68
|
-
packetOffset: packetOffset,
|
|
69
|
-
packetLength: packetLength,
|
|
70
|
-
seconds: seconds,
|
|
71
|
-
microseconds: microseconds,
|
|
72
|
-
packet: packet.toString('base64')
|
|
73
|
-
}
|
|
74
|
-
this.writeStream.write(pcapData, (): boolean => this.emit('packet', wrotePacketInfo))
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Close pcap writer
|
|
79
|
-
*/
|
|
80
|
-
public async close(): Promise<void> {
|
|
81
|
-
this.closed = true
|
|
82
|
-
return new Promise((resolve, reject): void => {
|
|
83
|
-
this.writeStream.close(err => err ? reject(err) : resolve())
|
|
84
|
-
})
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
public on(eventName: 'packet', listener: (wrotePacketInfo: IPcapPacketInfo) => void): this
|
|
88
|
-
public on(eventName: string, listener: (...args: any[]) => void): this {
|
|
89
|
-
super.on(eventName, listener)
|
|
90
|
-
return this
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public once(eventName: 'packet', listener: (wrotePacketInfo: IPcapPacketInfo) => void): this
|
|
94
|
-
public once(eventName: string, listener: (...args: any[]) => void): this {
|
|
95
|
-
super.once(eventName, listener)
|
|
96
|
-
return this
|
|
97
|
-
}
|
|
98
|
-
}
|