netkitty 0.0.1
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/.eslintrc.json +53 -0
- package/.idea/codeStyles/Project.xml +18 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +10 -0
- package/.idea/modules.xml +8 -0
- package/.idea/netkitty.iml +13 -0
- package/.idea/vcs.xml +6 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/binding.gyp +5 -0
- package/build/NetKitty.d.ts +31 -0
- package/build/NetKitty.d.ts.map +1 -0
- package/build/NetKitty.js +33 -0
- package/build/errors/ActionNotFoundError.d.ts +5 -0
- package/build/errors/ActionNotFoundError.d.ts.map +1 -0
- package/build/errors/ActionNotFoundError.js +12 -0
- package/build/errors/CodecSchemaValidateError.d.ts +5 -0
- package/build/errors/CodecSchemaValidateError.d.ts.map +1 -0
- package/build/errors/CodecSchemaValidateError.js +12 -0
- package/build/errors/DeviceNotFoundError.d.ts +5 -0
- package/build/errors/DeviceNotFoundError.d.ts.map +1 -0
- package/build/errors/DeviceNotFoundError.js +12 -0
- package/build/errors/NoAvailableCodecError.d.ts +5 -0
- package/build/errors/NoAvailableCodecError.d.ts.map +1 -0
- package/build/errors/NoAvailableCodecError.js +12 -0
- package/build/errors/NpcapLoadError.d.ts +5 -0
- package/build/errors/NpcapLoadError.d.ts.map +1 -0
- package/build/errors/NpcapLoadError.js +12 -0
- package/build/errors/SocketDownError.d.ts +5 -0
- package/build/errors/SocketDownError.d.ts.map +1 -0
- package/build/errors/SocketDownError.js +12 -0
- package/build/errors/UnknownPipeMessageTypeError.d.ts +5 -0
- package/build/errors/UnknownPipeMessageTypeError.d.ts.map +1 -0
- package/build/errors/UnknownPipeMessageTypeError.js +12 -0
- package/build/errors/common/ErrorCode.d.ts +31 -0
- package/build/errors/common/ErrorCode.d.ts.map +1 -0
- package/build/errors/common/ErrorCode.js +33 -0
- package/build/lib/GeneratePipeAddress.d.ts +7 -0
- package/build/lib/GeneratePipeAddress.d.ts.map +1 -0
- package/build/lib/GeneratePipeAddress.js +23 -0
- package/build/lib/GetBinding.d.ts +2 -0
- package/build/lib/GetBinding.d.ts.map +1 -0
- package/build/lib/GetBinding.js +6 -0
- package/build/lib/GetCaptureTemporaryDirectory.d.ts +7 -0
- package/build/lib/GetCaptureTemporaryDirectory.d.ts.map +1 -0
- package/build/lib/GetCaptureTemporaryDirectory.js +15 -0
- package/build/lib/GetDeviceCaptureTemporaryFilename.d.ts +8 -0
- package/build/lib/GetDeviceCaptureTemporaryFilename.d.ts.map +1 -0
- package/build/lib/GetDeviceCaptureTemporaryFilename.js +18 -0
- package/build/lib/codec/Codec.d.ts +33 -0
- package/build/lib/codec/Codec.d.ts.map +1 -0
- package/build/lib/codec/Codec.js +166 -0
- package/build/lib/codec/abstracts/BaseHeader.d.ts +204 -0
- package/build/lib/codec/abstracts/BaseHeader.d.ts.map +1 -0
- package/build/lib/codec/abstracts/BaseHeader.js +339 -0
- package/build/lib/codec/headers/ARP.d.ts +9 -0
- package/build/lib/codec/headers/ARP.d.ts.map +1 -0
- package/build/lib/codec/headers/ARP.js +223 -0
- package/build/lib/codec/headers/EthernetII.d.ts +9 -0
- package/build/lib/codec/headers/EthernetII.d.ts.map +1 -0
- package/build/lib/codec/headers/EthernetII.js +80 -0
- package/build/lib/codec/headers/Goose.d.ts +12 -0
- package/build/lib/codec/headers/Goose.d.ts.map +1 -0
- package/build/lib/codec/headers/Goose.js +701 -0
- package/build/lib/codec/headers/IEC61850SampledValues.d.ts +12 -0
- package/build/lib/codec/headers/IEC61850SampledValues.d.ts.map +1 -0
- package/build/lib/codec/headers/IEC61850SampledValues.js +369 -0
- package/build/lib/codec/headers/IPv4.d.ts +15 -0
- package/build/lib/codec/headers/IPv4.d.ts.map +1 -0
- package/build/lib/codec/headers/IPv4.js +338 -0
- package/build/lib/codec/headers/RawData.d.ts +9 -0
- package/build/lib/codec/headers/RawData.d.ts.map +1 -0
- package/build/lib/codec/headers/RawData.js +34 -0
- package/build/lib/codec/headers/TCP.d.ts +15 -0
- package/build/lib/codec/headers/TCP.d.ts.map +1 -0
- package/build/lib/codec/headers/TCP.js +897 -0
- package/build/lib/codec/headers/UDP.d.ts +15 -0
- package/build/lib/codec/headers/UDP.d.ts.map +1 -0
- package/build/lib/codec/headers/UDP.js +191 -0
- package/build/lib/codec/headers/VLAN_802dot1Q.d.ts +9 -0
- package/build/lib/codec/headers/VLAN_802dot1Q.d.ts.map +1 -0
- package/build/lib/codec/headers/VLAN_802dot1Q.js +77 -0
- package/build/lib/codec/lib/BufferToHex.d.ts +2 -0
- package/build/lib/codec/lib/BufferToHex.d.ts.map +1 -0
- package/build/lib/codec/lib/BufferToHex.js +6 -0
- package/build/lib/codec/lib/BufferToIP.d.ts +13 -0
- package/build/lib/codec/lib/BufferToIP.d.ts.map +1 -0
- package/build/lib/codec/lib/BufferToIP.js +21 -0
- package/build/lib/codec/lib/BufferToNumber.d.ts +10 -0
- package/build/lib/codec/lib/BufferToNumber.d.ts.map +1 -0
- package/build/lib/codec/lib/BufferToNumber.js +22 -0
- package/build/lib/codec/lib/FixHexString.d.ts +7 -0
- package/build/lib/codec/lib/FixHexString.d.ts.map +1 -0
- package/build/lib/codec/lib/FixHexString.js +11 -0
- package/build/lib/codec/lib/FlexibleObject.d.ts +28 -0
- package/build/lib/codec/lib/FlexibleObject.d.ts.map +1 -0
- package/build/lib/codec/lib/FlexibleObject.js +102 -0
- package/build/lib/codec/lib/HexToNumber.d.ts +10 -0
- package/build/lib/codec/lib/HexToNumber.d.ts.map +1 -0
- package/build/lib/codec/lib/HexToNumber.js +39 -0
- package/build/lib/codec/lib/IPToBuffer.d.ts +13 -0
- package/build/lib/codec/lib/IPToBuffer.d.ts.map +1 -0
- package/build/lib/codec/lib/IPToBuffer.js +28 -0
- package/build/lib/codec/lib/NumberToBERBuffer.d.ts +9 -0
- package/build/lib/codec/lib/NumberToBERBuffer.d.ts.map +1 -0
- package/build/lib/codec/lib/NumberToBERBuffer.js +20 -0
- package/build/lib/codec/lib/NumberToBERHex.d.ts +9 -0
- package/build/lib/codec/lib/NumberToBERHex.d.ts.map +1 -0
- package/build/lib/codec/lib/NumberToBERHex.js +23 -0
- package/build/lib/codec/lib/NumberToBuffer.d.ts +10 -0
- package/build/lib/codec/lib/NumberToBuffer.d.ts.map +1 -0
- package/build/lib/codec/lib/NumberToBuffer.js +22 -0
- package/build/lib/codec/lib/NumberToHex.d.ts +10 -0
- package/build/lib/codec/lib/NumberToHex.d.ts.map +1 -0
- package/build/lib/codec/lib/NumberToHex.js +26 -0
- package/build/lib/codec/lib/ProcessPacketPostHandlers.d.ts +14 -0
- package/build/lib/codec/lib/ProcessPacketPostHandlers.d.ts.map +1 -0
- package/build/lib/codec/lib/ProcessPacketPostHandlers.js +53 -0
- package/build/lib/codec/lib/SortPostHandlers.d.ts +8 -0
- package/build/lib/codec/lib/SortPostHandlers.d.ts.map +1 -0
- package/build/lib/codec/lib/SortPostHandlers.js +11 -0
- package/build/lib/codec/lib/StringContentEncodingEnum.d.ts +8 -0
- package/build/lib/codec/lib/StringContentEncodingEnum.d.ts.map +1 -0
- package/build/lib/codec/lib/StringContentEncodingEnum.js +11 -0
- package/build/lib/codec/types/CodecData.d.ts +7 -0
- package/build/lib/codec/types/CodecData.d.ts.map +1 -0
- package/build/lib/codec/types/CodecData.js +2 -0
- package/build/lib/codec/types/CodecDecodeResult.d.ts +9 -0
- package/build/lib/codec/types/CodecDecodeResult.d.ts.map +1 -0
- package/build/lib/codec/types/CodecDecodeResult.js +2 -0
- package/build/lib/codec/types/CodecEncodeInput.d.ts +5 -0
- package/build/lib/codec/types/CodecEncodeInput.d.ts.map +1 -0
- package/build/lib/codec/types/CodecEncodeInput.js +2 -0
- package/build/lib/codec/types/CodecEncodeResult.d.ts +6 -0
- package/build/lib/codec/types/CodecEncodeResult.d.ts.map +1 -0
- package/build/lib/codec/types/CodecEncodeResult.js +2 -0
- package/build/lib/codec/types/CodecErrorInfo.d.ts +6 -0
- package/build/lib/codec/types/CodecErrorInfo.d.ts.map +1 -0
- package/build/lib/codec/types/CodecErrorInfo.js +2 -0
- package/build/lib/codec/types/CodecModule.d.ts +3 -0
- package/build/lib/codec/types/CodecModule.d.ts.map +1 -0
- package/build/lib/codec/types/CodecModule.js +2 -0
- package/build/lib/codec/types/CodecModuleConstructor.d.ts +3 -0
- package/build/lib/codec/types/CodecModuleConstructor.d.ts.map +1 -0
- package/build/lib/codec/types/CodecModuleConstructor.js +2 -0
- package/build/lib/codec/types/CodecSchema.d.ts +7 -0
- package/build/lib/codec/types/CodecSchema.d.ts.map +1 -0
- package/build/lib/codec/types/CodecSchema.js +2 -0
- package/build/lib/codec/types/HeaderTreeNode.d.ts +5 -0
- package/build/lib/codec/types/HeaderTreeNode.d.ts.map +1 -0
- package/build/lib/codec/types/HeaderTreeNode.js +2 -0
- package/build/lib/codec/types/PostHandlerItem.d.ts +5 -0
- package/build/lib/codec/types/PostHandlerItem.d.ts.map +1 -0
- package/build/lib/codec/types/PostHandlerItem.js +2 -0
- package/build/lib/nodepcap/Capture.d.ts +75 -0
- package/build/lib/nodepcap/Capture.d.ts.map +1 -0
- package/build/lib/nodepcap/Capture.js +309 -0
- package/build/lib/nodepcap/GetNetworkInterfaces.d.ts +7 -0
- package/build/lib/nodepcap/GetNetworkInterfaces.d.ts.map +1 -0
- package/build/lib/nodepcap/GetNetworkInterfaces.js +22 -0
- package/build/lib/nodepcap/interfaces/IBindingCapture.d.ts +16 -0
- package/build/lib/nodepcap/interfaces/IBindingCapture.d.ts.map +1 -0
- package/build/lib/nodepcap/interfaces/IBindingCapture.js +2 -0
- package/build/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts +5 -0
- package/build/lib/nodepcap/interfaces/IBindingCaptureOptions.d.ts.map +1 -0
- package/build/lib/nodepcap/interfaces/IBindingCaptureOptions.js +2 -0
- package/build/lib/nodepcap/interfaces/ICaptureOptions.d.ts +19 -0
- package/build/lib/nodepcap/interfaces/ICaptureOptions.d.ts.map +1 -0
- package/build/lib/nodepcap/interfaces/ICaptureOptions.js +2 -0
- package/build/lib/nodepcap/interfaces/INetworkInterface.d.ts +5 -0
- package/build/lib/nodepcap/interfaces/INetworkInterface.d.ts.map +1 -0
- package/build/lib/nodepcap/interfaces/INetworkInterface.js +2 -0
- package/build/lib/nodepcap/lib/BindingCapture.d.ts +15 -0
- package/build/lib/nodepcap/lib/BindingCapture.d.ts.map +1 -0
- package/build/lib/nodepcap/lib/BindingCapture.js +35 -0
- package/build/lib/nodepcap/lib/GetNodePcapBinding.d.ts +2 -0
- package/build/lib/nodepcap/lib/GetNodePcapBinding.d.ts.map +1 -0
- package/build/lib/nodepcap/lib/GetNodePcapBinding.js +55 -0
- package/build/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts +3 -0
- package/build/lib/nodepcap/lib/GetNodePcapBindingCapture.d.ts.map +1 -0
- package/build/lib/nodepcap/lib/GetNodePcapBindingCapture.js +18 -0
- package/build/lib/nodepcap/workers/CaptureWorker.d.ts +2 -0
- package/build/lib/nodepcap/workers/CaptureWorker.d.ts.map +1 -0
- package/build/lib/nodepcap/workers/CaptureWorker.js +25 -0
- package/build/lib/pcap/PCAPGenerator.d.ts +34 -0
- package/build/lib/pcap/PCAPGenerator.d.ts.map +1 -0
- package/build/lib/pcap/PCAPGenerator.js +95 -0
- package/build/lib/pcap/PcapParser.d.ts +27 -0
- package/build/lib/pcap/PcapParser.d.ts.map +1 -0
- package/build/lib/pcap/PcapParser.js +149 -0
- package/build/lib/pcap/PcapReader.d.ts +87 -0
- package/build/lib/pcap/PcapReader.d.ts.map +1 -0
- package/build/lib/pcap/PcapReader.js +207 -0
- package/build/lib/pcap/PcapWriter.d.ts +29 -0
- package/build/lib/pcap/PcapWriter.d.ts.map +1 -0
- package/build/lib/pcap/PcapWriter.js +80 -0
- package/build/lib/pcap/interfaces/IPcapPacketInfo.d.ts +13 -0
- package/build/lib/pcap/interfaces/IPcapPacketInfo.d.ts.map +1 -0
- package/build/lib/pcap/interfaces/IPcapPacketInfo.js +2 -0
- package/build/lib/pipe/PipeClient.d.ts +35 -0
- package/build/lib/pipe/PipeClient.d.ts.map +1 -0
- package/build/lib/pipe/PipeClient.js +71 -0
- package/build/lib/pipe/PipeClientSocket.d.ts +39 -0
- package/build/lib/pipe/PipeClientSocket.d.ts.map +1 -0
- package/build/lib/pipe/PipeClientSocket.js +82 -0
- package/build/lib/pipe/PipeMessage.d.ts +27 -0
- package/build/lib/pipe/PipeMessage.d.ts.map +1 -0
- package/build/lib/pipe/PipeMessage.js +61 -0
- package/build/lib/pipe/PipeMessageHandler.d.ts +16 -0
- package/build/lib/pipe/PipeMessageHandler.d.ts.map +1 -0
- package/build/lib/pipe/PipeMessageHandler.js +95 -0
- package/build/lib/pipe/PipeServer.d.ts +25 -0
- package/build/lib/pipe/PipeServer.d.ts.map +1 -0
- package/build/lib/pipe/PipeServer.js +59 -0
- package/build/lib/schema/ProtocolFieldJSONSchema.d.ts +35 -0
- package/build/lib/schema/ProtocolFieldJSONSchema.d.ts.map +1 -0
- package/build/lib/schema/ProtocolFieldJSONSchema.js +2 -0
- package/build/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts +3 -0
- package/build/lib/schema/ProtocolFieldJSONSchemaDefinition.d.ts.map +1 -0
- package/build/lib/schema/ProtocolFieldJSONSchemaDefinition.js +2 -0
- package/build/lib/schema/ProtocolJSONSchema.d.ts +32 -0
- package/build/lib/schema/ProtocolJSONSchema.d.ts.map +1 -0
- package/build/lib/schema/ProtocolJSONSchema.js +2 -0
- package/build/tests/Test.spec.d.ts +2 -0
- package/build/tests/Test.spec.d.ts.map +1 -0
- package/build/tests/Test.spec.js +25 -0
- package/build/tests/units/CaptureTest.spec.d.ts +2 -0
- package/build/tests/units/CaptureTest.spec.d.ts.map +1 -0
- package/build/tests/units/CaptureTest.spec.js +31 -0
- package/build/tests/units/Codec.spec.d.ts +2 -0
- package/build/tests/units/Codec.spec.d.ts.map +1 -0
- package/build/tests/units/Codec.spec.js +70 -0
- package/cpp/nodepcap/deps/include/Packet32.h +429 -0
- package/cpp/nodepcap/deps/include/pcap/bluetooth.h +56 -0
- package/cpp/nodepcap/deps/include/pcap/bpf.h +292 -0
- package/cpp/nodepcap/deps/include/pcap/can_socketcan.h +56 -0
- package/cpp/nodepcap/deps/include/pcap/compiler-tests.h +163 -0
- package/cpp/nodepcap/deps/include/pcap/dlt.h +1514 -0
- package/cpp/nodepcap/deps/include/pcap/funcattrs.h +325 -0
- package/cpp/nodepcap/deps/include/pcap/ipnet.h +43 -0
- package/cpp/nodepcap/deps/include/pcap/namedb.h +84 -0
- package/cpp/nodepcap/deps/include/pcap/nflog.h +94 -0
- package/cpp/nodepcap/deps/include/pcap/pcap-inttypes.h +101 -0
- package/cpp/nodepcap/deps/include/pcap/pcap.h +1219 -0
- package/cpp/nodepcap/deps/include/pcap/sll.h +149 -0
- package/cpp/nodepcap/deps/include/pcap/socket.h +84 -0
- package/cpp/nodepcap/deps/include/pcap/usb.h +143 -0
- package/cpp/nodepcap/deps/include/pcap/vlan.h +46 -0
- package/cpp/nodepcap/deps/include/pcap-bpf.h +45 -0
- package/cpp/nodepcap/deps/include/pcap-namedb.h +40 -0
- package/cpp/nodepcap/deps/include/pcap.h +43 -0
- 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 +104 -0
- package/cpp/nodepcap/src/binding.cc +14 -0
- package/cpp/nodepcap/src/capture.cc +400 -0
- package/cpp/nodepcap/src/capture.h +53 -0
- package/cpp/nodepcap/src/utils.cc +218 -0
- package/cpp/nodepcap/src/utils.h +13 -0
- package/package.json +65 -0
- package/src/NetKitty.ts +31 -0
- package/src/errors/ActionNotFoundError.ts +6 -0
- package/src/errors/CodecSchemaValidateError.ts +6 -0
- package/src/errors/DeviceNotFoundError.ts +6 -0
- package/src/errors/NoAvailableCodecError.ts +6 -0
- package/src/errors/NpcapLoadError.ts +6 -0
- package/src/errors/SocketDownError.ts +6 -0
- package/src/errors/UnknownPipeMessageTypeError.ts +6 -0
- package/src/errors/common/ErrorCode.ts +30 -0
- package/src/lib/GeneratePipeAddress.ts +17 -0
- package/src/lib/GetBinding.ts +3 -0
- package/src/lib/GetCaptureTemporaryDirectory.ts +12 -0
- package/src/lib/GetDeviceCaptureTemporaryFilename.ts +13 -0
- package/src/lib/codec/Codec.ts +181 -0
- package/src/lib/codec/abstracts/BaseHeader.ts +413 -0
- package/src/lib/codec/headers/ARP.ts +218 -0
- package/src/lib/codec/headers/EthernetII.ts +77 -0
- package/src/lib/codec/headers/Goose.ts +658 -0
- package/src/lib/codec/headers/IEC61850SampledValues.ts +359 -0
- package/src/lib/codec/headers/IPv4.ts +329 -0
- package/src/lib/codec/headers/RawData.ts +34 -0
- package/src/lib/codec/headers/TCP.ts +931 -0
- package/src/lib/codec/headers/UDP.ts +180 -0
- package/src/lib/codec/headers/VLAN_802dot1Q.ts +74 -0
- package/src/lib/codec/lib/BufferToHex.ts +3 -0
- package/src/lib/codec/lib/BufferToIP.ts +19 -0
- package/src/lib/codec/lib/BufferToNumber.ts +31 -0
- package/src/lib/codec/lib/FixHexString.ts +8 -0
- package/src/lib/codec/lib/FlexibleObject.ts +100 -0
- package/src/lib/codec/lib/HexToNumber.ts +25 -0
- package/src/lib/codec/lib/IPToBuffer.ts +25 -0
- package/src/lib/codec/lib/NumberToBERBuffer.ts +19 -0
- package/src/lib/codec/lib/NumberToBERHex.ts +13 -0
- package/src/lib/codec/lib/NumberToBuffer.ts +21 -0
- package/src/lib/codec/lib/NumberToHex.ts +15 -0
- package/src/lib/codec/lib/ProcessPacketPostHandlers.ts +53 -0
- package/src/lib/codec/lib/SortPostHandlers.ts +10 -0
- package/src/lib/codec/lib/StringContentEncodingEnum.ts +7 -0
- package/src/lib/codec/types/CodecData.ts +7 -0
- package/src/lib/codec/types/CodecDecodeResult.ts +9 -0
- package/src/lib/codec/types/CodecEncodeInput.ts +5 -0
- package/src/lib/codec/types/CodecEncodeResult.ts +6 -0
- package/src/lib/codec/types/CodecErrorInfo.ts +5 -0
- package/src/lib/codec/types/CodecModule.ts +3 -0
- package/src/lib/codec/types/CodecModuleConstructor.ts +3 -0
- package/src/lib/codec/types/CodecSchema.ts +7 -0
- package/src/lib/codec/types/HeaderTreeNode.ts +5 -0
- package/src/lib/codec/types/PostHandlerItem.ts +4 -0
- package/src/lib/nodepcap/Capture.ts +291 -0
- package/src/lib/nodepcap/GetNetworkInterfaces.ts +18 -0
- package/src/lib/nodepcap/interfaces/IBindingCapture.ts +27 -0
- package/src/lib/nodepcap/interfaces/IBindingCaptureOptions.ts +4 -0
- package/src/lib/nodepcap/interfaces/ICaptureOptions.ts +19 -0
- package/src/lib/nodepcap/interfaces/INetworkInterface.ts +4 -0
- package/src/lib/nodepcap/lib/BindingCapture.ts +46 -0
- package/src/lib/nodepcap/lib/GetNodePcapBinding.ts +17 -0
- package/src/lib/nodepcap/lib/GetNodePcapBindingCapture.ts +15 -0
- package/src/lib/nodepcap/workers/CaptureWorker.ts +30 -0
- package/src/lib/pcap/PCAPGenerator.ts +118 -0
- package/src/lib/pcap/PcapParser.ts +170 -0
- package/src/lib/pcap/PcapReader.ts +239 -0
- package/src/lib/pcap/PcapWriter.ts +93 -0
- package/src/lib/pcap/interfaces/IPcapPacketInfo.ts +12 -0
- package/src/lib/pipe/PipeClient.ts +91 -0
- package/src/lib/pipe/PipeClientSocket.ts +99 -0
- package/src/lib/pipe/PipeMessage.ts +74 -0
- package/src/lib/pipe/PipeMessageHandler.ts +91 -0
- package/src/lib/pipe/PipeServer.ts +74 -0
- package/src/lib/schema/ProtocolFieldJSONSchema.ts +45 -0
- package/src/lib/schema/ProtocolFieldJSONSchemaDefinition.ts +3 -0
- package/src/lib/schema/ProtocolJSONSchema.ts +37 -0
- package/src/tests/Test.spec.ts +22 -0
- package/src/tests/units/CaptureTest.spec.ts +30 -0
- package/src/tests/units/Codec.spec.ts +85 -0
- package/tsconfig.json +41 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.GeneratePCAPHeader = GeneratePCAPHeader;
|
|
7
|
+
exports.GeneratePCAPData = GeneratePCAPData;
|
|
8
|
+
exports.GeneratePCAP = GeneratePCAP;
|
|
9
|
+
/**
|
|
10
|
+
* 由pcap-generator库改写
|
|
11
|
+
* @see:https://github.com/onomondo/pcap-generator/tree/master
|
|
12
|
+
*/
|
|
13
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
14
|
+
const headerOptions = {
|
|
15
|
+
majorVersion: 2,
|
|
16
|
+
minorVersion: 4,
|
|
17
|
+
gmtOffset: 0,
|
|
18
|
+
timestampAccuracy: 0,
|
|
19
|
+
snapshotLength: 65535,
|
|
20
|
+
linkLayerType: 1
|
|
21
|
+
};
|
|
22
|
+
function generate(packets) {
|
|
23
|
+
const globalHeader = GeneratePCAPHeader();
|
|
24
|
+
const packetsBuffer = Buffer.concat(packets.map((packet) => GeneratePCAPData(packet)));
|
|
25
|
+
return Buffer.concat([globalHeader, packetsBuffer]);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Converts a timestamp in milliseconds to an integer of the seconds part and an integer of the microseconds part
|
|
29
|
+
*
|
|
30
|
+
* @param ms
|
|
31
|
+
*/
|
|
32
|
+
function convertMillisecond2Microsecond(ms) {
|
|
33
|
+
const [seconds, microseconds] = new bignumber_js_1.default(ms).dividedBy(1000).toFixed(6).split('.').map(value => parseInt(value));
|
|
34
|
+
return [seconds, microseconds];
|
|
35
|
+
}
|
|
36
|
+
function makeLessThanAMillion(i) {
|
|
37
|
+
while (i > 1000000) {
|
|
38
|
+
i = Math.floor(i / 10);
|
|
39
|
+
}
|
|
40
|
+
return i;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Generate pcap file header's buffer
|
|
44
|
+
* @constructor
|
|
45
|
+
*/
|
|
46
|
+
function GeneratePCAPHeader() {
|
|
47
|
+
const globalHeader = Buffer.alloc(24);
|
|
48
|
+
globalHeader.writeUInt32BE(2712847316, 0); // 4
|
|
49
|
+
globalHeader.writeUInt16BE(headerOptions.majorVersion, 4); // 2
|
|
50
|
+
globalHeader.writeUInt16BE(headerOptions.minorVersion, 6); // 2
|
|
51
|
+
globalHeader.writeInt32BE(headerOptions.gmtOffset, 8); // 4
|
|
52
|
+
globalHeader.writeUInt32BE(headerOptions.timestampAccuracy, 12); // 4
|
|
53
|
+
globalHeader.writeUInt32BE(headerOptions.snapshotLength, 16); // 4
|
|
54
|
+
globalHeader.writeUInt32BE(headerOptions.linkLayerType, 20); // 4
|
|
55
|
+
return globalHeader;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Generate single record data in pcap file
|
|
59
|
+
* @param packet
|
|
60
|
+
* @constructor
|
|
61
|
+
*/
|
|
62
|
+
function GeneratePCAPData(packet) {
|
|
63
|
+
const packetHeader = Buffer.alloc(16);
|
|
64
|
+
let seconds;
|
|
65
|
+
let microseconds;
|
|
66
|
+
if (packet.microsecond) {
|
|
67
|
+
seconds = packet.microsecond.seconds;
|
|
68
|
+
microseconds = packet.microsecond.microseconds;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
[seconds, microseconds] = convertMillisecond2Microsecond(packet.timestamp);
|
|
72
|
+
}
|
|
73
|
+
packetHeader.writeUInt32BE(seconds, 0); // 4
|
|
74
|
+
if (packet.microsecond) {
|
|
75
|
+
packetHeader.writeUInt32BE(microseconds, 4); // 4 - if in microsecond precision then remove excess of 1,000,000 (see documentation)
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
packetHeader.writeUInt32BE(makeLessThanAMillion(microseconds), 4); // 4 - if in microsecond precision then remove excess of 1,000,000 (see documentation)
|
|
79
|
+
}
|
|
80
|
+
packetHeader.writeUInt32BE(packet.buffer.length, 8); // 4
|
|
81
|
+
packetHeader.writeUInt32BE(packet.buffer.length, 12); // 4
|
|
82
|
+
return Buffer.concat([packetHeader, packet.buffer]);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Generate whole pcap file buffer data
|
|
86
|
+
* @param packets
|
|
87
|
+
* @constructor
|
|
88
|
+
*/
|
|
89
|
+
function GeneratePCAP(packets = []) {
|
|
90
|
+
return generate(packets.map((packet) => ({
|
|
91
|
+
timestamp: packet.timestamp,
|
|
92
|
+
microsecond: packet.microsecond,
|
|
93
|
+
buffer: Buffer.from(packet.frameBase64Data, 'base64')
|
|
94
|
+
})));
|
|
95
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import { ReadStream } from 'node:fs';
|
|
3
|
+
export declare class PcapParser extends EventEmitter {
|
|
4
|
+
protected stream: ReadStream;
|
|
5
|
+
protected buffer: Buffer | null;
|
|
6
|
+
protected errored: boolean;
|
|
7
|
+
protected endianness: 'BE' | 'LE' | null;
|
|
8
|
+
protected index: number;
|
|
9
|
+
protected state: () => boolean;
|
|
10
|
+
protected offset: number;
|
|
11
|
+
protected currentPacketHeader: {
|
|
12
|
+
timestampSeconds: number;
|
|
13
|
+
timestampMicroseconds: number;
|
|
14
|
+
capturedLength: number;
|
|
15
|
+
originalLength: number;
|
|
16
|
+
};
|
|
17
|
+
static parse(input: string | ReadStream): PcapParser;
|
|
18
|
+
constructor(input: string | ReadStream);
|
|
19
|
+
protected updateBuffer(data: Buffer): void;
|
|
20
|
+
protected parseGlobalHeader(): boolean;
|
|
21
|
+
protected parsePacketHeader(): boolean;
|
|
22
|
+
protected parsePacketBody(): boolean;
|
|
23
|
+
protected onData(data: Buffer): void;
|
|
24
|
+
protected onError(err: Error): void;
|
|
25
|
+
protected onEnd(): void;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=PcapParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PcapParser.d.ts","sourceRoot":"","sources":["../../../src/lib/pcap/PcapParser.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,QAAQ,CAAA;AACjC,OAAO,EAAmB,UAAU,EAAC,MAAM,SAAS,CAAA;AAOpD,qBAAa,UAAW,SAAQ,YAAY;IAExC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAA;IAE5B,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IAE/B,SAAS,CAAC,OAAO,EAAE,OAAO,CAAQ;IAElC,SAAS,CAAC,UAAU,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;IAExC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAI;IAE3B,SAAS,CAAC,KAAK,EAAE,MAAM,OAAO,CAAA;IAE9B,SAAS,CAAC,MAAM,EAAE,MAAM,CAAI;IAE5B,SAAS,CAAC,mBAAmB,EAAE;QAC3B,gBAAgB,EAAE,MAAM,CAAA;QACxB,qBAAqB,EAAE,MAAM,CAAA;QAC7B,cAAc,EAAE,MAAM,CAAA;QACtB,cAAc,EAAE,MAAM,CAAA;KACzB,CAAA;WAEa,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,UAAU;gBAI/C,KAAK,EAAE,MAAM,GAAG,UAAU;IAatC,SAAS,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAY1C,SAAS,CAAC,iBAAiB,IAAI,OAAO;IA+CtC,SAAS,CAAC,iBAAiB,IAAI,OAAO;IAmBtC,SAAS,CAAC,eAAe,IAAI,OAAO;IA6BpC,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAOpC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI;IAInC,SAAS,CAAC,KAAK,IAAI,IAAI;CAG1B"}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PcapParser = void 0;
|
|
7
|
+
const events_1 = __importDefault(require("events"));
|
|
8
|
+
const node_fs_1 = require("node:fs");
|
|
9
|
+
const node_util_1 = require("node:util");
|
|
10
|
+
const GLOBAL_HEADER_LENGTH = 24; //bytes
|
|
11
|
+
const PACKET_HEADER_LENGTH = 16; //bytes
|
|
12
|
+
class PcapParser extends events_1.default {
|
|
13
|
+
static parse(input) {
|
|
14
|
+
return new PcapParser(input);
|
|
15
|
+
}
|
|
16
|
+
constructor(input) {
|
|
17
|
+
super();
|
|
18
|
+
this.errored = false;
|
|
19
|
+
this.index = 0;
|
|
20
|
+
this.offset = 0;
|
|
21
|
+
this.stream = (typeof input === 'string') ? (0, node_fs_1.createReadStream)(input) : input;
|
|
22
|
+
this.stream.pause();
|
|
23
|
+
this.stream.on('data', (data) => this.onData(data));
|
|
24
|
+
this.stream.on('error', (err) => this.onError(err));
|
|
25
|
+
this.stream.on('end', () => this.onEnd());
|
|
26
|
+
this.buffer = null;
|
|
27
|
+
this.state = () => this.parseGlobalHeader();
|
|
28
|
+
this.endianness = null;
|
|
29
|
+
process.nextTick(this.stream.resume.bind(this.stream));
|
|
30
|
+
}
|
|
31
|
+
updateBuffer(data) {
|
|
32
|
+
if (data === null || data === undefined)
|
|
33
|
+
return;
|
|
34
|
+
if (this.buffer === null) {
|
|
35
|
+
this.buffer = data;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
let extendedBuffer = Buffer.alloc(this.buffer.length + data.length);
|
|
39
|
+
this.buffer.copy(extendedBuffer);
|
|
40
|
+
data.copy(extendedBuffer, this.buffer.length);
|
|
41
|
+
this.buffer = extendedBuffer;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
parseGlobalHeader() {
|
|
45
|
+
const buffer = this.buffer;
|
|
46
|
+
if (buffer.length >= GLOBAL_HEADER_LENGTH) {
|
|
47
|
+
let msg;
|
|
48
|
+
const magicNumber = buffer.toString('hex', 0, 4);
|
|
49
|
+
// determine pcap endianness
|
|
50
|
+
if (magicNumber == 'a1b2c3d4') {
|
|
51
|
+
this.endianness = 'BE';
|
|
52
|
+
}
|
|
53
|
+
else if (magicNumber == 'd4c3b2a1') {
|
|
54
|
+
this.endianness = 'LE';
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.errored = true;
|
|
58
|
+
this.stream.pause();
|
|
59
|
+
msg = (0, node_util_1.format)('unknown magic number: %s', magicNumber);
|
|
60
|
+
this.emit('error', new Error(msg));
|
|
61
|
+
this.onEnd();
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
const header = {
|
|
65
|
+
magicNumber: buffer['readUInt32' + this.endianness](0, true),
|
|
66
|
+
majorVersion: buffer['readUInt16' + this.endianness](4, true),
|
|
67
|
+
minorVersion: buffer['readUInt16' + this.endianness](6, true),
|
|
68
|
+
gmtOffset: buffer['readInt32' + this.endianness](8, true),
|
|
69
|
+
timestampAccuracy: buffer['readUInt32' + this.endianness](12, true),
|
|
70
|
+
snapshotLength: buffer['readUInt32' + this.endianness](16, true),
|
|
71
|
+
linkLayerType: buffer['readUInt32' + this.endianness](20, true)
|
|
72
|
+
};
|
|
73
|
+
if (header.majorVersion != 2 && header.minorVersion != 4) {
|
|
74
|
+
this.errored = true;
|
|
75
|
+
this.stream.pause();
|
|
76
|
+
msg = (0, node_util_1.format)('unsupported version %d.%d. pcap-parser only parses libpcap file format 2.4', header.majorVersion, header.minorVersion);
|
|
77
|
+
this.emit('error', new Error(msg));
|
|
78
|
+
this.onEnd();
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
this.emit('globalHeader', header);
|
|
82
|
+
this.buffer = buffer.subarray(GLOBAL_HEADER_LENGTH);
|
|
83
|
+
this.state = () => this.parsePacketHeader();
|
|
84
|
+
this.offset = GLOBAL_HEADER_LENGTH;
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
parsePacketHeader() {
|
|
91
|
+
const buffer = this.buffer;
|
|
92
|
+
if (buffer.length >= PACKET_HEADER_LENGTH) {
|
|
93
|
+
const header = {
|
|
94
|
+
timestampSeconds: buffer['readUInt32' + this.endianness](0, true),
|
|
95
|
+
timestampMicroseconds: buffer['readUInt32' + this.endianness](4, true),
|
|
96
|
+
capturedLength: buffer['readUInt32' + this.endianness](8, true),
|
|
97
|
+
originalLength: buffer['readUInt32' + this.endianness](12, true)
|
|
98
|
+
};
|
|
99
|
+
this.currentPacketHeader = header;
|
|
100
|
+
this.emit('packetHeader', header);
|
|
101
|
+
this.buffer = buffer.subarray(PACKET_HEADER_LENGTH);
|
|
102
|
+
this.state = () => this.parsePacketBody();
|
|
103
|
+
this.index += 1;
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
parsePacketBody() {
|
|
109
|
+
const buffer = this.buffer;
|
|
110
|
+
if (buffer.length >= this.currentPacketHeader.capturedLength) {
|
|
111
|
+
const data = buffer.subarray(0, this.currentPacketHeader.capturedLength);
|
|
112
|
+
const packetLength = data.length;
|
|
113
|
+
const recordLength = PACKET_HEADER_LENGTH + packetLength;
|
|
114
|
+
const pcapPacketInfo = {
|
|
115
|
+
index: this.index,
|
|
116
|
+
offset: this.offset,
|
|
117
|
+
length: recordLength,
|
|
118
|
+
recordHeaderOffset: this.offset,
|
|
119
|
+
recordHeaderLength: PACKET_HEADER_LENGTH,
|
|
120
|
+
packetOffset: this.offset + PACKET_HEADER_LENGTH,
|
|
121
|
+
packetLength: data.length,
|
|
122
|
+
seconds: this.currentPacketHeader.timestampSeconds,
|
|
123
|
+
microseconds: this.currentPacketHeader.timestampMicroseconds,
|
|
124
|
+
packet: data.toString('base64')
|
|
125
|
+
};
|
|
126
|
+
this.emit('packetData', data);
|
|
127
|
+
this.emit('packet', pcapPacketInfo);
|
|
128
|
+
this.buffer = buffer.subarray(this.currentPacketHeader.capturedLength);
|
|
129
|
+
this.state = () => this.parsePacketHeader();
|
|
130
|
+
this.offset += recordLength;
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
onData(data) {
|
|
136
|
+
if (this.errored)
|
|
137
|
+
return;
|
|
138
|
+
this.updateBuffer(data);
|
|
139
|
+
while (this.state()) {
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
onError(err) {
|
|
143
|
+
this.emit('error', err);
|
|
144
|
+
}
|
|
145
|
+
onEnd() {
|
|
146
|
+
this.emit('end');
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.PcapParser = PcapParser;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import { FileHandle } 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
|
+
export interface IPcapReaderOptions {
|
|
8
|
+
filename: string;
|
|
9
|
+
watch?: boolean;
|
|
10
|
+
chunkSize?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare class PcapReader extends EventEmitter {
|
|
13
|
+
protected readonly filename: string;
|
|
14
|
+
protected readonly watch: boolean;
|
|
15
|
+
protected readonly chunkSize: number;
|
|
16
|
+
protected duplexPair: DuplexPair;
|
|
17
|
+
protected parser: PcapParser;
|
|
18
|
+
protected index: number;
|
|
19
|
+
protected offset: number;
|
|
20
|
+
protected readDone: boolean;
|
|
21
|
+
protected readBufferFileHandle: FileHandle | null;
|
|
22
|
+
protected get readStream(): ReadStream;
|
|
23
|
+
protected get writeStream(): WriteStream;
|
|
24
|
+
constructor(options: IPcapReaderOptions);
|
|
25
|
+
/**
|
|
26
|
+
* Initialize reader
|
|
27
|
+
* @protected
|
|
28
|
+
*/
|
|
29
|
+
protected initReader(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Reset reader
|
|
32
|
+
* @protected
|
|
33
|
+
*/
|
|
34
|
+
protected reset(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Initialize read packet file handle
|
|
37
|
+
* @protected
|
|
38
|
+
*/
|
|
39
|
+
protected initReadPacketFileHandle(): Promise<FileHandle>;
|
|
40
|
+
/**
|
|
41
|
+
* Initialize read buffer file handle
|
|
42
|
+
* @protected
|
|
43
|
+
*/
|
|
44
|
+
protected initReadBufferFileHandle(): Promise<FileHandle>;
|
|
45
|
+
/**
|
|
46
|
+
* Read file buffer
|
|
47
|
+
* @protected
|
|
48
|
+
*/
|
|
49
|
+
protected readBuffer(): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* Read file continually
|
|
52
|
+
* @protected
|
|
53
|
+
*/
|
|
54
|
+
protected continualRead(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Read the file straight
|
|
57
|
+
* @protected
|
|
58
|
+
*/
|
|
59
|
+
protected straightRead(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Read packet data by record's offset and record's length
|
|
62
|
+
* @param offset
|
|
63
|
+
* @param length
|
|
64
|
+
*/
|
|
65
|
+
readPacket(offset: number, length: number): Promise<Buffer>;
|
|
66
|
+
/**
|
|
67
|
+
* Start reading pcap
|
|
68
|
+
*/
|
|
69
|
+
start(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Stop reading pcap
|
|
72
|
+
*/
|
|
73
|
+
stop(): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Close pcap reader
|
|
76
|
+
*/
|
|
77
|
+
close(): Promise<void>;
|
|
78
|
+
on(eventName: 'packet', listener: (pcapPacketInfo: IPcapPacketInfo) => void): this;
|
|
79
|
+
on(eventName: 'done', listener: (...args: any[]) => void): this;
|
|
80
|
+
on(eventName: 'stop', listener: (...args: any[]) => void): this;
|
|
81
|
+
on(eventName: 'close', listener: (...args: any[]) => void): this;
|
|
82
|
+
once(eventName: 'packet', listener: (pcapPacketInfo: IPcapPacketInfo) => void): this;
|
|
83
|
+
once(eventName: 'done', listener: (...args: any[]) => void): this;
|
|
84
|
+
once(eventName: 'stop', listener: (...args: any[]) => void): this;
|
|
85
|
+
once(eventName: 'close', listener: (...args: any[]) => void): this;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=PcapReader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PcapReader.d.ts","sourceRoot":"","sources":["../../../src/lib/pcap/PcapReader.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PcapReader = void 0;
|
|
7
|
+
const events_1 = __importDefault(require("events"));
|
|
8
|
+
const promises_1 = require("node:fs/promises");
|
|
9
|
+
const duplexpair_1 = __importDefault(require("duplexpair"));
|
|
10
|
+
const PcapParser_1 = require("./PcapParser");
|
|
11
|
+
class PcapReader extends events_1.default {
|
|
12
|
+
get readStream() {
|
|
13
|
+
return this.duplexPair.socket2;
|
|
14
|
+
}
|
|
15
|
+
get writeStream() {
|
|
16
|
+
return this.duplexPair.socket1;
|
|
17
|
+
}
|
|
18
|
+
constructor(options) {
|
|
19
|
+
super();
|
|
20
|
+
this.chunkSize = 1518 * 10;
|
|
21
|
+
this.index = 0;
|
|
22
|
+
this.offset = 0;
|
|
23
|
+
this.readDone = false;
|
|
24
|
+
this.readBufferFileHandle = null;
|
|
25
|
+
this.filename = options.filename;
|
|
26
|
+
this.watch = !!options.watch;
|
|
27
|
+
this.chunkSize = options.chunkSize ? options.chunkSize : this.chunkSize;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Initialize reader
|
|
31
|
+
* @protected
|
|
32
|
+
*/
|
|
33
|
+
initReader() {
|
|
34
|
+
this.duplexPair = new duplexpair_1.default();
|
|
35
|
+
this.parser = PcapParser_1.PcapParser.parse(this.readStream);
|
|
36
|
+
this.parser.on('packet', (pcapPacketInfo) => {
|
|
37
|
+
this.index = pcapPacketInfo.index;
|
|
38
|
+
this.emit('packet', pcapPacketInfo);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Reset reader
|
|
43
|
+
* @protected
|
|
44
|
+
*/
|
|
45
|
+
async reset() {
|
|
46
|
+
await this.stop();
|
|
47
|
+
this.parser?.removeAllListeners();
|
|
48
|
+
this.index = 0;
|
|
49
|
+
this.offset = 0;
|
|
50
|
+
this.initReader();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Initialize read packet file handle
|
|
54
|
+
* @protected
|
|
55
|
+
*/
|
|
56
|
+
async initReadPacketFileHandle() {
|
|
57
|
+
return await (0, promises_1.open)(this.filename, 'r');
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Initialize read buffer file handle
|
|
61
|
+
* @protected
|
|
62
|
+
*/
|
|
63
|
+
async initReadBufferFileHandle() {
|
|
64
|
+
if (!this.readBufferFileHandle)
|
|
65
|
+
this.readBufferFileHandle = await (0, promises_1.open)(this.filename, 'r');
|
|
66
|
+
return this.readBufferFileHandle;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Read file buffer
|
|
70
|
+
* @protected
|
|
71
|
+
*/
|
|
72
|
+
async readBuffer() {
|
|
73
|
+
const readBufferFileHandle = await this.initReadBufferFileHandle();
|
|
74
|
+
try {
|
|
75
|
+
const result = await readBufferFileHandle.read({
|
|
76
|
+
buffer: Buffer.alloc(this.chunkSize),
|
|
77
|
+
offset: 0,
|
|
78
|
+
length: this.chunkSize,
|
|
79
|
+
position: this.offset
|
|
80
|
+
});
|
|
81
|
+
if (result.bytesRead <= 0)
|
|
82
|
+
return true;
|
|
83
|
+
const data = Buffer.alloc(result.bytesRead);
|
|
84
|
+
result.buffer.copy(data, 0, 0, result.bytesRead);
|
|
85
|
+
this.offset += result.bytesRead;
|
|
86
|
+
this.writeStream.write(data);
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Read file continually
|
|
95
|
+
* @protected
|
|
96
|
+
*/
|
|
97
|
+
continualRead() {
|
|
98
|
+
process.nextTick(async () => {
|
|
99
|
+
let read = true;
|
|
100
|
+
this.once('stop', () => read = false);
|
|
101
|
+
let isReachEnd = false;
|
|
102
|
+
while (read || !isReachEnd) {
|
|
103
|
+
isReachEnd = await this.readBuffer();
|
|
104
|
+
if (isReachEnd) {
|
|
105
|
+
await new Promise(resolve => setTimeout(resolve, 1));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
await this.readBufferFileHandle?.close();
|
|
109
|
+
this.readBufferFileHandle = null;
|
|
110
|
+
this.readDone = true;
|
|
111
|
+
this.emit('done');
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Read the file straight
|
|
116
|
+
* @protected
|
|
117
|
+
*/
|
|
118
|
+
straightRead() {
|
|
119
|
+
process.nextTick(async () => {
|
|
120
|
+
let isReachEnd = false;
|
|
121
|
+
let stopped = false;
|
|
122
|
+
this.once('stop', () => stopped = true);
|
|
123
|
+
while (!isReachEnd && !stopped) {
|
|
124
|
+
isReachEnd = await this.readBuffer();
|
|
125
|
+
}
|
|
126
|
+
if (!stopped)
|
|
127
|
+
await this.stop();
|
|
128
|
+
await this.readBufferFileHandle?.close();
|
|
129
|
+
this.readBufferFileHandle = null;
|
|
130
|
+
this.readDone = true;
|
|
131
|
+
this.emit('done');
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Read packet data by record's offset and record's length
|
|
136
|
+
* @param offset
|
|
137
|
+
* @param length
|
|
138
|
+
*/
|
|
139
|
+
async readPacket(offset, length) {
|
|
140
|
+
const fileHandle = await this.initReadPacketFileHandle();
|
|
141
|
+
const recordHeaderLength = 16;
|
|
142
|
+
const packetLength = length - recordHeaderLength;
|
|
143
|
+
const result = await fileHandle.read({
|
|
144
|
+
buffer: Buffer.alloc(packetLength),
|
|
145
|
+
offset: 0,
|
|
146
|
+
length: packetLength,
|
|
147
|
+
position: offset + recordHeaderLength
|
|
148
|
+
});
|
|
149
|
+
await fileHandle.close();
|
|
150
|
+
return result.buffer;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Start reading pcap
|
|
154
|
+
*/
|
|
155
|
+
async start() {
|
|
156
|
+
await this.reset();
|
|
157
|
+
if (this.watch) {
|
|
158
|
+
this.continualRead();
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
this.straightRead();
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Stop reading pcap
|
|
166
|
+
*/
|
|
167
|
+
async stop() {
|
|
168
|
+
if (this.parser) {
|
|
169
|
+
this.emit('stop');
|
|
170
|
+
if (!this.readDone)
|
|
171
|
+
await new Promise(resolve => this.once('done', resolve));
|
|
172
|
+
}
|
|
173
|
+
if (this.duplexPair) {
|
|
174
|
+
await new Promise(resolve => {
|
|
175
|
+
if (this.writeStream.closed)
|
|
176
|
+
return resolve();
|
|
177
|
+
this.writeStream.once('close', () => resolve());
|
|
178
|
+
this.writeStream.once('error', err => !!err);
|
|
179
|
+
this.writeStream.destroy();
|
|
180
|
+
});
|
|
181
|
+
await new Promise(resolve => {
|
|
182
|
+
if (this.readStream.closed)
|
|
183
|
+
return resolve();
|
|
184
|
+
this.readStream.once('close', () => resolve());
|
|
185
|
+
this.readStream.once('error', err => !!err);
|
|
186
|
+
this.readStream.destroy();
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Close pcap reader
|
|
192
|
+
*/
|
|
193
|
+
async close() {
|
|
194
|
+
await this.stop();
|
|
195
|
+
this.emit('close');
|
|
196
|
+
this.removeAllListeners();
|
|
197
|
+
}
|
|
198
|
+
on(eventName, listener) {
|
|
199
|
+
super.on(eventName, listener);
|
|
200
|
+
return this;
|
|
201
|
+
}
|
|
202
|
+
once(eventName, listener) {
|
|
203
|
+
super.once(eventName, listener);
|
|
204
|
+
return this;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
exports.PcapReader = PcapReader;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import { WriteStream } from 'node:fs';
|
|
3
|
+
import { IPcapPacketInfo } from './interfaces/IPcapPacketInfo';
|
|
4
|
+
export interface IPcapWriterOptions {
|
|
5
|
+
filename: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class PcapWriter extends EventEmitter {
|
|
8
|
+
readonly filename: string;
|
|
9
|
+
protected readonly writeStream: WriteStream;
|
|
10
|
+
protected closed: boolean;
|
|
11
|
+
protected index: number;
|
|
12
|
+
protected offset: number;
|
|
13
|
+
get wroteCount(): number;
|
|
14
|
+
constructor(options: IPcapWriterOptions);
|
|
15
|
+
/**
|
|
16
|
+
* Write packet to pcap file
|
|
17
|
+
* @param packet
|
|
18
|
+
* @param seconds
|
|
19
|
+
* @param microseconds
|
|
20
|
+
*/
|
|
21
|
+
write(packet: Buffer, seconds: number, microseconds: number): void;
|
|
22
|
+
/**
|
|
23
|
+
* Close pcap writer
|
|
24
|
+
*/
|
|
25
|
+
close(): Promise<void>;
|
|
26
|
+
on(eventName: 'packet', listener: (wrotePacketInfo: IPcapPacketInfo) => void): this;
|
|
27
|
+
once(eventName: 'packet', listener: (wrotePacketInfo: IPcapPacketInfo) => void): this;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=PcapWriter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PcapWriter.d.ts","sourceRoot":"","sources":["../../../src/lib/pcap/PcapWriter.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,QAAQ,CAAA;AACjC,OAAO,EAAoB,WAAW,EAAC,MAAM,SAAS,CAAA;AAEtD,OAAO,EAAC,eAAe,EAAC,MAAM,8BAA8B,CAAA;AAE5D,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,EAAE,MAAM,CAAA;CACnB;AAED,qBAAa,UAAW,SAAQ,YAAY;IAExC,SAAgB,QAAQ,EAAE,MAAM,CAAA;IAEhC,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAA;IAE3C,SAAS,CAAC,MAAM,EAAE,OAAO,CAAQ;IAEjC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAI;IAE3B,SAAS,CAAC,MAAM,EAAE,MAAM,CAAI;IAE5B,IAAW,UAAU,IAAI,MAAM,CAE9B;gBAEW,OAAO,EAAE,kBAAkB;IASvC;;;;;OAKG;IACI,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI;IA+BzE;;OAEG;IACU,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5B,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,eAAe,EAAE,eAAe,KAAK,IAAI,GAAG,IAAI;IAMnF,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,eAAe,EAAE,eAAe,KAAK,IAAI,GAAG,IAAI;CAK/F"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PcapWriter = void 0;
|
|
7
|
+
const events_1 = __importDefault(require("events"));
|
|
8
|
+
const node_fs_1 = require("node:fs");
|
|
9
|
+
const PCAPGenerator_1 = require("./PCAPGenerator");
|
|
10
|
+
class PcapWriter extends events_1.default {
|
|
11
|
+
get wroteCount() {
|
|
12
|
+
return this.index;
|
|
13
|
+
}
|
|
14
|
+
constructor(options) {
|
|
15
|
+
super();
|
|
16
|
+
this.closed = false;
|
|
17
|
+
this.index = 0;
|
|
18
|
+
this.offset = 0;
|
|
19
|
+
this.filename = options.filename;
|
|
20
|
+
this.writeStream = (0, node_fs_1.createWriteStream)(this.filename, { autoClose: false, flags: 'w' });
|
|
21
|
+
const header = (0, PCAPGenerator_1.GeneratePCAPHeader)();
|
|
22
|
+
this.writeStream.write(header);
|
|
23
|
+
this.offset += header.length;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Write packet to pcap file
|
|
27
|
+
* @param packet
|
|
28
|
+
* @param seconds
|
|
29
|
+
* @param microseconds
|
|
30
|
+
*/
|
|
31
|
+
write(packet, seconds, microseconds) {
|
|
32
|
+
if (this.closed)
|
|
33
|
+
return;
|
|
34
|
+
this.index += 1;
|
|
35
|
+
const startOffset = this.offset;
|
|
36
|
+
const packetLength = packet.length;
|
|
37
|
+
const pcapData = (0, PCAPGenerator_1.GeneratePCAPData)({
|
|
38
|
+
buffer: packet,
|
|
39
|
+
timestamp: Date.now(),
|
|
40
|
+
microsecond: {
|
|
41
|
+
seconds: seconds,
|
|
42
|
+
microseconds: microseconds
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
this.offset += pcapData.length;
|
|
46
|
+
const packetOffset = this.offset - packetLength;
|
|
47
|
+
const recordHeaderLength = packetOffset - startOffset;
|
|
48
|
+
const wrotePacketInfo = {
|
|
49
|
+
index: this.index,
|
|
50
|
+
offset: startOffset,
|
|
51
|
+
length: pcapData.length,
|
|
52
|
+
recordHeaderOffset: startOffset,
|
|
53
|
+
recordHeaderLength: recordHeaderLength,
|
|
54
|
+
packetOffset: packetOffset,
|
|
55
|
+
packetLength: packetLength,
|
|
56
|
+
seconds: seconds,
|
|
57
|
+
microseconds: microseconds,
|
|
58
|
+
packet: packet.toString('base64')
|
|
59
|
+
};
|
|
60
|
+
this.writeStream.write(pcapData, () => this.emit('packet', wrotePacketInfo));
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Close pcap writer
|
|
64
|
+
*/
|
|
65
|
+
async close() {
|
|
66
|
+
this.closed = true;
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
this.writeStream.close(err => err ? reject(err) : resolve());
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
on(eventName, listener) {
|
|
72
|
+
super.on(eventName, listener);
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
once(eventName, listener) {
|
|
76
|
+
super.once(eventName, listener);
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.PcapWriter = PcapWriter;
|