netkitty 0.0.35 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 -59
- 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 -1005
- 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 -517
- 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 -917
- 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 -36
- 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 -1033
- 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 -552
- package/src/lib/codec/headers/RawData.ts +0 -38
- package/src/lib/codec/headers/TCP.ts +0 -952
- 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 -47
- 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,435 +0,0 @@
|
|
|
1
|
-
import {ProtocolJSONSchema} from '../../schema/ProtocolJSONSchema'
|
|
2
|
-
import {CodecModule} from '../types/CodecModule'
|
|
3
|
-
import {ProtocolFieldJSONSchema} from '../../schema/ProtocolFieldJSONSchema'
|
|
4
|
-
import {CodecErrorInfo} from '../types/CodecErrorInfo'
|
|
5
|
-
import {PostHandlerItem} from '../types/PostHandlerItem'
|
|
6
|
-
import {SortPostHandlers} from '../lib/SortPostHandlers'
|
|
7
|
-
import {CodecData} from '../types/CodecData'
|
|
8
|
-
import {FlexibleObject} from '../lib/FlexibleObject'
|
|
9
|
-
import {Ajv, ErrorObject, ValidateFunction} from 'ajv'
|
|
10
|
-
import {HeaderTreeNode} from '../types/HeaderTreeNode'
|
|
11
|
-
import {CodecSchemaValidateError} from '../../../errors/CodecSchemaValidateError'
|
|
12
|
-
|
|
13
|
-
const CONSTRUCTOR_VALIDATE_KEY: string = '__validate'
|
|
14
|
-
|
|
15
|
-
export abstract class BaseHeader {
|
|
16
|
-
|
|
17
|
-
protected static get CODEC_INSTANCE(): CodecModule {
|
|
18
|
-
return new (this as any)()
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
protected static CREATE_CODEC_INSTANCE_WITCH_CODEC_MODULES(codecData: CodecData, codecModules: CodecModule[]): CodecModule {
|
|
22
|
-
return this.CREATE_INSTANCE(codecData, codecModules)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public static get PROTOCOL_ID(): string {
|
|
26
|
-
return this.CODEC_INSTANCE.id
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
public static get PROTOCOL_NAME(): string {
|
|
30
|
-
return this.CODEC_INSTANCE.name
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public static get PROTOCOL_SCHEMA(): ProtocolJSONSchema {
|
|
34
|
-
const schema: ProtocolJSONSchema = JSON.parse(JSON.stringify(this.CODEC_INSTANCE.SCHEMA))
|
|
35
|
-
if (!Object.hasOwn(this, CONSTRUCTOR_VALIDATE_KEY)) {
|
|
36
|
-
const validate: ValidateFunction = new Ajv({
|
|
37
|
-
strict: false,
|
|
38
|
-
useDefaults: true,
|
|
39
|
-
coerceTypes: true
|
|
40
|
-
}).compile(schema)
|
|
41
|
-
Object.defineProperty(this, CONSTRUCTOR_VALIDATE_KEY, {
|
|
42
|
-
enumerable: false,
|
|
43
|
-
configurable: false,
|
|
44
|
-
value: validate
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
return schema
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public static MATCH(codecData: CodecData, codecModules: CodecModule[]): boolean {
|
|
51
|
-
return this.CREATE_CODEC_INSTANCE_WITCH_CODEC_MODULES(codecData, codecModules ? codecModules : []).match()
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public static CREATE_INSTANCE(codecData: CodecData, codecModules: CodecModule[]): CodecModule {
|
|
55
|
-
return new (this as any)(codecData, codecModules)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Protocol schema definition
|
|
60
|
-
*/
|
|
61
|
-
public readonly abstract SCHEMA: ProtocolJSONSchema
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Program used header id
|
|
65
|
-
*/
|
|
66
|
-
public readonly abstract id: string
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Human-readable header name
|
|
70
|
-
*/
|
|
71
|
-
public readonly abstract name: string
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Human-readable header nickname
|
|
75
|
-
*/
|
|
76
|
-
public readonly abstract nickname: string
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Current header is a protocol or not
|
|
80
|
-
*/
|
|
81
|
-
public readonly isProtocol: boolean = true
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Encode/Decode error info objects
|
|
85
|
-
*/
|
|
86
|
-
public errors: CodecErrorInfo[] = []
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Header schema instance
|
|
90
|
-
*/
|
|
91
|
-
public instance: FlexibleObject = new FlexibleObject()
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Entire packet buffer data getter
|
|
95
|
-
*/
|
|
96
|
-
public get packet(): Buffer {
|
|
97
|
-
return this.codecData.packet
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Entire packet buffer data setter
|
|
102
|
-
* @param packet
|
|
103
|
-
*/
|
|
104
|
-
public set packet(packet: Buffer) {
|
|
105
|
-
this.codecData.packet = packet
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* The start position of this header in the entire packet's buffer
|
|
110
|
-
*/
|
|
111
|
-
public startPos: number = 0
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* The end position of this header in the entire packet's buffer
|
|
115
|
-
*/
|
|
116
|
-
public get endPos(): number {
|
|
117
|
-
return this.startPos + this.headerLength
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Readonly Header length
|
|
122
|
-
*/
|
|
123
|
-
public get length(): number {
|
|
124
|
-
return this.headerLength
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Header length
|
|
129
|
-
* @protected
|
|
130
|
-
*/
|
|
131
|
-
protected headerLength: number = 0
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Previous Codec module
|
|
135
|
-
* @protected
|
|
136
|
-
*/
|
|
137
|
-
protected readonly prevCodecModule: CodecModule
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Codec modules
|
|
141
|
-
* @protected
|
|
142
|
-
*/
|
|
143
|
-
protected readonly codecModules: CodecModule[]
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Previous codec modules
|
|
147
|
-
* @protected
|
|
148
|
-
*/
|
|
149
|
-
protected readonly prevCodecModules: CodecModule[]
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Current header index in packet headers
|
|
153
|
-
* @protected
|
|
154
|
-
*/
|
|
155
|
-
protected readonly headerIndex: number = 0
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Post packet handlers
|
|
159
|
-
* @protected
|
|
160
|
-
*/
|
|
161
|
-
protected get postPacketHandlers(): PostHandlerItem[] {
|
|
162
|
-
if (this.codecData.postHandlers[this.headerIndex] === undefined) this.codecData.postHandlers[this.headerIndex] = []
|
|
163
|
-
return this.codecData.postHandlers[this.headerIndex]
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Registered post encode handlers (CodecModule)
|
|
168
|
-
* @protected
|
|
169
|
-
*/
|
|
170
|
-
protected readonly postSelfEncodeHandlers: PostHandlerItem[] = []
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Registered post decode handlers (CodecModule)
|
|
174
|
-
* @protected
|
|
175
|
-
*/
|
|
176
|
-
protected readonly postSelfDecodeHandlers: PostHandlerItem[] = []
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Codec data
|
|
180
|
-
* @protected
|
|
181
|
-
*/
|
|
182
|
-
protected readonly codecData: CodecData
|
|
183
|
-
|
|
184
|
-
constructor(codecData: CodecData, codecModules: CodecModule[]) {
|
|
185
|
-
this.codecData = codecData
|
|
186
|
-
this.startPos = codecData?.startPos ? codecData.startPos : 0
|
|
187
|
-
codecModules = codecModules ? codecModules : []
|
|
188
|
-
this.codecModules = codecModules
|
|
189
|
-
this.prevCodecModules = [...codecModules]
|
|
190
|
-
const prevCodecModuleIndex: number = this.prevCodecModules.length - 1
|
|
191
|
-
this.prevCodecModule = this.prevCodecModules[prevCodecModuleIndex > -1 ? prevCodecModuleIndex : 0]
|
|
192
|
-
this.headerIndex = this.prevCodecModules.length
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Get packet data offset
|
|
197
|
-
* @param offset
|
|
198
|
-
* @protected
|
|
199
|
-
*/
|
|
200
|
-
protected getPacketOffset(offset: number): number {
|
|
201
|
-
return this.startPos + offset
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Is data buffer fits current header codec
|
|
206
|
-
*/
|
|
207
|
-
public abstract match(): boolean
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Internal read bytes from buffer
|
|
211
|
-
* @param offset
|
|
212
|
-
* @param length
|
|
213
|
-
* @param expandBufferLength
|
|
214
|
-
* @param changeHeaderLength
|
|
215
|
-
* @private
|
|
216
|
-
*/
|
|
217
|
-
#readBytes(offset: number, length: number, expandBufferLength: boolean, changeHeaderLength: boolean): Buffer {
|
|
218
|
-
const packetOffset: number = this.getPacketOffset(offset)
|
|
219
|
-
let readEndPos: number = packetOffset + length
|
|
220
|
-
if (this.packet.length < readEndPos) {
|
|
221
|
-
if (expandBufferLength) {
|
|
222
|
-
this.packet = Buffer.concat([this.packet, Buffer.alloc(readEndPos - this.packet.length, 0)])
|
|
223
|
-
} else {
|
|
224
|
-
readEndPos = this.packet.length
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
const headerLength: number = readEndPos - this.startPos
|
|
228
|
-
if (changeHeaderLength) this.headerLength = this.headerLength < headerLength ? headerLength : this.headerLength
|
|
229
|
-
return this.packet.subarray(packetOffset, packetOffset + length)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* Read bytes from buffer
|
|
234
|
-
* @param offset
|
|
235
|
-
* @param length
|
|
236
|
-
* @param dryRun
|
|
237
|
-
* @protected
|
|
238
|
-
*/
|
|
239
|
-
protected readBytes(offset: number, length: number, dryRun: boolean = false): Buffer {
|
|
240
|
-
return this.#readBytes(offset, length, false, !dryRun)
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Write bytes to buffer
|
|
245
|
-
* @param offset
|
|
246
|
-
* @param buffer
|
|
247
|
-
* @protected
|
|
248
|
-
*/
|
|
249
|
-
protected writeBytes(offset: number, buffer: Buffer): void {
|
|
250
|
-
const packetOffset: number = this.getPacketOffset(offset)
|
|
251
|
-
const writeEndPos: number = packetOffset + buffer.length
|
|
252
|
-
this.#readBytes(offset, buffer.length, true, true)
|
|
253
|
-
this.packet.fill(buffer, packetOffset, writeEndPos)
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Read bits from buffer
|
|
258
|
-
* @param offset
|
|
259
|
-
* @param length
|
|
260
|
-
* @param bitOffset
|
|
261
|
-
* @param bitLength
|
|
262
|
-
* @protected
|
|
263
|
-
*/
|
|
264
|
-
protected readBits(offset: number, length: number, bitOffset: number, bitLength: number): number {
|
|
265
|
-
const buffer: Buffer = this.#readBytes(offset, length, false, true)
|
|
266
|
-
const bitString: string = parseInt(buffer.toString('hex'), 16).toString(2).padStart(length * 8, '0')
|
|
267
|
-
return parseInt(bitString.substring(bitOffset, bitOffset + bitLength), 2)
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Write bits to buffer
|
|
272
|
-
* @param offset
|
|
273
|
-
* @param length
|
|
274
|
-
* @param bitOffset
|
|
275
|
-
* @param bitLength
|
|
276
|
-
* @param value
|
|
277
|
-
* @protected
|
|
278
|
-
*/
|
|
279
|
-
protected writeBits(offset: number, length: number, bitOffset: number, bitLength: number, value: number): void {
|
|
280
|
-
const buffer: Buffer = this.#readBytes(offset, length, true, true)
|
|
281
|
-
let bitArray: string[] = Array.from(parseInt(buffer.toString('hex'), 16).toString(2).padStart(buffer.length * 8, '0'))
|
|
282
|
-
const valueBitArray: string[] = Array.from(value.toString(2).padStart(bitLength, '0'))
|
|
283
|
-
bitArray = bitArray.map((bit: string, index: number): string => {
|
|
284
|
-
if (index < bitOffset) return bit
|
|
285
|
-
if (index >= (bitOffset + bitLength)) return bit
|
|
286
|
-
return valueBitArray[index - bitOffset]
|
|
287
|
-
})
|
|
288
|
-
this.writeBytes(offset, Buffer.from(parseInt(bitArray.join(''), 2).toString(16).padStart(buffer.length * 2, '0'), 'hex'))
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* Get field codecs from schema tree
|
|
293
|
-
* @param schema
|
|
294
|
-
* @param codecName
|
|
295
|
-
* @param execBeforeSubCodecs
|
|
296
|
-
* @param codecs
|
|
297
|
-
* @protected
|
|
298
|
-
*/
|
|
299
|
-
protected getFieldCodecs(schema: ProtocolFieldJSONSchema, codecName: string, execBeforeSubCodecs: boolean, codecs: (() => Promise<void>)[] = []): (() => Promise<void>)[] {
|
|
300
|
-
if (!schema.properties) return codecs
|
|
301
|
-
for (const propertyName of Object.keys(schema.properties)) {
|
|
302
|
-
const fieldSchema: ProtocolFieldJSONSchema = schema.properties[propertyName]
|
|
303
|
-
let codec: (() => void | Promise<void>) | undefined = fieldSchema[codecName]
|
|
304
|
-
if (!codec) codec = async (): Promise<void> => (void (0))
|
|
305
|
-
if (execBeforeSubCodecs) codecs.push(async (): Promise<void> => await codec())
|
|
306
|
-
if (fieldSchema.properties) this.getFieldCodecs(fieldSchema, codecName, execBeforeSubCodecs, codecs)
|
|
307
|
-
if (!execBeforeSubCodecs) codecs.push(async (): Promise<void> => await codec())
|
|
308
|
-
}
|
|
309
|
-
return codecs
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* Record encode/decode error
|
|
314
|
-
* @param path
|
|
315
|
-
* @param message
|
|
316
|
-
* @protected
|
|
317
|
-
*/
|
|
318
|
-
protected recordError(path: string, message: string): void {
|
|
319
|
-
this.errors.push({
|
|
320
|
-
id: this.id,
|
|
321
|
-
path: path,
|
|
322
|
-
message: message
|
|
323
|
-
})
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/**
|
|
327
|
-
* Register post encode handler for current codec
|
|
328
|
-
* @param handler
|
|
329
|
-
* @param priority
|
|
330
|
-
* @protected
|
|
331
|
-
*/
|
|
332
|
-
protected addPostSelfEncodeHandler(handler: () => void | Promise<void>, priority: number = 0): void {
|
|
333
|
-
this.postSelfEncodeHandlers.push({
|
|
334
|
-
priority: priority,
|
|
335
|
-
handler: handler
|
|
336
|
-
})
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* Register post decode handler for current codec
|
|
341
|
-
* @param handler
|
|
342
|
-
* @param priority
|
|
343
|
-
* @protected
|
|
344
|
-
*/
|
|
345
|
-
protected addPostSelfDecodeHandler(handler: () => void | Promise<void>, priority: number = 0): void {
|
|
346
|
-
this.postSelfDecodeHandlers.push({
|
|
347
|
-
priority: priority,
|
|
348
|
-
handler: handler
|
|
349
|
-
})
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Register post encode handler for packet
|
|
354
|
-
* @description Registered handler call sequence: LIFO (Last In First Out)
|
|
355
|
-
* @param handler
|
|
356
|
-
* @param priority
|
|
357
|
-
* @protected
|
|
358
|
-
*/
|
|
359
|
-
protected addPostPacketEncodeHandler(handler: () => void | Promise<void>, priority: number = 0): void {
|
|
360
|
-
this.postPacketHandlers.push({
|
|
361
|
-
priority: priority,
|
|
362
|
-
handler: handler
|
|
363
|
-
})
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
/**
|
|
367
|
-
* Register post decode handler for packet
|
|
368
|
-
* @description Registered handler call sequence: FIFO (First In First Out)
|
|
369
|
-
* @param handler
|
|
370
|
-
* @param priority
|
|
371
|
-
* @protected
|
|
372
|
-
*/
|
|
373
|
-
protected addPostPacketDecodeHandler(handler: () => void | Promise<void>, priority: number = 0): void {
|
|
374
|
-
this.postPacketHandlers.push({
|
|
375
|
-
priority: priority,
|
|
376
|
-
handler: handler
|
|
377
|
-
})
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Validate input json node is valid
|
|
382
|
-
* @param headerTreeNode
|
|
383
|
-
*/
|
|
384
|
-
public validate(headerTreeNode: HeaderTreeNode): HeaderTreeNode {
|
|
385
|
-
let validate: ValidateFunction = this.constructor[CONSTRUCTOR_VALIDATE_KEY]
|
|
386
|
-
if (!validate) {
|
|
387
|
-
validate = new Ajv({
|
|
388
|
-
strict: false,
|
|
389
|
-
useDefaults: true,
|
|
390
|
-
coerceTypes: true
|
|
391
|
-
}).compile(this.SCHEMA)
|
|
392
|
-
this.constructor[CONSTRUCTOR_VALIDATE_KEY] = validate
|
|
393
|
-
}
|
|
394
|
-
const isValid: boolean = validate(headerTreeNode)
|
|
395
|
-
if (!isValid) {
|
|
396
|
-
let errorObject: ErrorObject | undefined | null
|
|
397
|
-
if (validate.errors) errorObject = validate.errors[0]
|
|
398
|
-
const errorMessage: string = errorObject?.message ? errorObject.message : 'Unknown Error'
|
|
399
|
-
throw new CodecSchemaValidateError(errorMessage)
|
|
400
|
-
}
|
|
401
|
-
return headerTreeNode
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* Decode packet header field by field
|
|
406
|
-
*/
|
|
407
|
-
public async decode(): Promise<void> {
|
|
408
|
-
const decodes: (() => Promise<void>)[] = this.getFieldCodecs(this.SCHEMA as ProtocolFieldJSONSchema, 'decode', true)
|
|
409
|
-
for (const decode of decodes) {
|
|
410
|
-
await decode()
|
|
411
|
-
}
|
|
412
|
-
const postSelfDecodeHandlers: PostHandlerItem[] = SortPostHandlers(this.postSelfDecodeHandlers)
|
|
413
|
-
let postDecodeHandler: PostHandlerItem | undefined = postSelfDecodeHandlers.shift()
|
|
414
|
-
while (postDecodeHandler) {
|
|
415
|
-
await postDecodeHandler.handler()
|
|
416
|
-
postDecodeHandler = postSelfDecodeHandlers.shift()
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
/**
|
|
421
|
-
* Encode packet header field by field
|
|
422
|
-
*/
|
|
423
|
-
public async encode(): Promise<void> {
|
|
424
|
-
const encodes: (() => Promise<void>)[] = this.getFieldCodecs(this.SCHEMA as ProtocolFieldJSONSchema, 'encode', false)
|
|
425
|
-
for (const encode of encodes) {
|
|
426
|
-
await encode()
|
|
427
|
-
}
|
|
428
|
-
const postSelfEncodeHandlers: PostHandlerItem[] = SortPostHandlers(this.postSelfEncodeHandlers)
|
|
429
|
-
let postEncodeHandler: PostHandlerItem | undefined = postSelfEncodeHandlers.shift()
|
|
430
|
-
while (postEncodeHandler) {
|
|
431
|
-
await postEncodeHandler.handler()
|
|
432
|
-
postEncodeHandler = postSelfEncodeHandlers.shift()
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
}
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
import {ProtocolJSONSchema} from '../../schema/ProtocolJSONSchema'
|
|
2
|
-
import {BaseHeader} from '../abstracts/BaseHeader'
|
|
3
|
-
import {UInt16ToHex, UInt8ToHex} from '../../helper/NumberToHex'
|
|
4
|
-
import {StringContentEncodingEnum} from '../lib/StringContentEncodingEnum'
|
|
5
|
-
import {HexToUInt16} from '../../helper/HexToNumber'
|
|
6
|
-
import {BufferToInt16, BufferToUInt16, BufferToUInt8} from '../../helper/BufferToNumber'
|
|
7
|
-
import {BufferToHex} from '../../helper/BufferToHex'
|
|
8
|
-
import {UInt16ToBuffer, UInt8ToBuffer} from '../../helper/NumberToBuffer'
|
|
9
|
-
import {BufferToIPv4} from '../../helper/BufferToIP'
|
|
10
|
-
import {IPv4ToBuffer} from '../../helper/IPToBuffer'
|
|
11
|
-
|
|
12
|
-
export class ARP extends BaseHeader {
|
|
13
|
-
|
|
14
|
-
public SCHEMA: ProtocolJSONSchema = {
|
|
15
|
-
type: 'object',
|
|
16
|
-
properties: {
|
|
17
|
-
hardware: {
|
|
18
|
-
type: 'object',
|
|
19
|
-
label: 'Hardware',
|
|
20
|
-
properties: {
|
|
21
|
-
type: {
|
|
22
|
-
type: 'number',
|
|
23
|
-
label: 'Type',
|
|
24
|
-
minimum: 0,
|
|
25
|
-
maximum: 65535,
|
|
26
|
-
decode: (): void => {
|
|
27
|
-
this.instance.hardware.type.setValue(BufferToInt16(this.readBytes(0, 2)))
|
|
28
|
-
},
|
|
29
|
-
encode: (): void => {
|
|
30
|
-
let hwType: number = this.instance.hardware.type.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
|
|
31
|
-
if (hwType > 65535) {
|
|
32
|
-
this.recordError(this.instance.hardware.type.getPath(), 'Maximum value is 65535')
|
|
33
|
-
hwType = 65535
|
|
34
|
-
}
|
|
35
|
-
if (hwType < 0) {
|
|
36
|
-
this.recordError(this.instance.hardware.type.getPath(), 'Minimum value is 0')
|
|
37
|
-
hwType = 0
|
|
38
|
-
}
|
|
39
|
-
this.instance.hardware.type.setValue(hwType)
|
|
40
|
-
this.writeBytes(0, UInt16ToBuffer(hwType))
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
size: {
|
|
44
|
-
type: 'number',
|
|
45
|
-
label: 'Size',
|
|
46
|
-
minimum: 0,
|
|
47
|
-
maximum: 255,
|
|
48
|
-
decode: (): void => {
|
|
49
|
-
this.instance.hardware.size.setValue(BufferToUInt8(this.readBytes(4, 1)))
|
|
50
|
-
},
|
|
51
|
-
encode: (): void => {
|
|
52
|
-
let hwSize: number = this.instance.hardware.size.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
|
|
53
|
-
if (hwSize > 255) {
|
|
54
|
-
this.recordError(this.instance.hardware.size.getPath(), 'Maximum value is 255')
|
|
55
|
-
hwSize = 255
|
|
56
|
-
}
|
|
57
|
-
if (hwSize < 0) {
|
|
58
|
-
this.recordError(this.instance.hardware.size.getPath(), 'Minimum value is 0')
|
|
59
|
-
hwSize = 0
|
|
60
|
-
}
|
|
61
|
-
this.instance.hardware.size.setValue(hwSize)
|
|
62
|
-
this.writeBytes(4, UInt8ToBuffer(hwSize))
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
protocol: {
|
|
68
|
-
type: 'object',
|
|
69
|
-
label: 'Protocol',
|
|
70
|
-
properties: {
|
|
71
|
-
type: {
|
|
72
|
-
type: 'string',
|
|
73
|
-
label: 'Type',
|
|
74
|
-
minLength: 4,
|
|
75
|
-
maxLength: 4,
|
|
76
|
-
contentEncoding: StringContentEncodingEnum.HEX,
|
|
77
|
-
decode: (): void => {
|
|
78
|
-
this.instance.protocol.type.setValue(BufferToHex(this.readBytes(2, 2)))
|
|
79
|
-
},
|
|
80
|
-
encode: (): void => {
|
|
81
|
-
let protoTypeHex: string = this.instance.protocol.type.getValue('0000', (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
|
|
82
|
-
let protoType: number = HexToUInt16(protoTypeHex)
|
|
83
|
-
if (isNaN(protoType)) {
|
|
84
|
-
this.recordError(this.instance.protocol.type.getPath(), 'Invalid hex value')
|
|
85
|
-
protoType = 0
|
|
86
|
-
}
|
|
87
|
-
this.instance.protocol.type.setValue(protoType)
|
|
88
|
-
this.writeBytes(2, UInt16ToBuffer(protoType))
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
size: {
|
|
92
|
-
type: 'number',
|
|
93
|
-
label: 'Size',
|
|
94
|
-
minimum: 0,
|
|
95
|
-
maximum: 255,
|
|
96
|
-
decode: (): void => {
|
|
97
|
-
this.instance.protocol.size.setValue(BufferToUInt8(this.readBytes(5, 1)))
|
|
98
|
-
},
|
|
99
|
-
encode: (): void => {
|
|
100
|
-
let protoSize: number = this.instance.protocol.size.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
|
|
101
|
-
if (protoSize > 255) {
|
|
102
|
-
this.recordError(this.instance.protocol.size.getPath(), 'Maximum value is 255')
|
|
103
|
-
protoSize = 255
|
|
104
|
-
}
|
|
105
|
-
if (protoSize < 0) {
|
|
106
|
-
this.recordError(this.instance.protocol.size.getPath(), 'Minimum value is 0')
|
|
107
|
-
protoSize = 0
|
|
108
|
-
}
|
|
109
|
-
this.instance.protocol.size.setValue(protoSize)
|
|
110
|
-
this.writeBytes(5, UInt8ToBuffer(protoSize))
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
opcode: {
|
|
116
|
-
type: 'number',
|
|
117
|
-
label: 'Opcode',
|
|
118
|
-
enum: [1, 2, 3, 4],
|
|
119
|
-
decode: (): void => {
|
|
120
|
-
this.instance.opcode.setValue(BufferToUInt16(this.readBytes(6, 2)))
|
|
121
|
-
if (![1, 2, 3, 4].includes(this.instance.opcode.getValue())) this.recordError(this.instance.opcode.getPath(), 'Opcode should be 1, 2, 3 or 4')
|
|
122
|
-
},
|
|
123
|
-
encode: (): void => {
|
|
124
|
-
let opcode: number = this.instance.opcode.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
|
|
125
|
-
if (![1, 2, 3, 4].includes(opcode)) this.recordError(this.instance.opcode.getPath(), 'Opcode should be 1, 2, 3 or 4')
|
|
126
|
-
this.instance.opcode.setValue(opcode)
|
|
127
|
-
this.writeBytes(6, UInt16ToBuffer(opcode))
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
sender: {
|
|
131
|
-
type: 'object',
|
|
132
|
-
label: 'Sender',
|
|
133
|
-
properties: {
|
|
134
|
-
mac: {
|
|
135
|
-
type: 'string',
|
|
136
|
-
label: 'MAC address',
|
|
137
|
-
minLength: 17,
|
|
138
|
-
maxLength: 17,
|
|
139
|
-
contentEncoding: StringContentEncodingEnum.UTF8,
|
|
140
|
-
decode: (): void => {
|
|
141
|
-
const macAddrBuffer: Buffer = Buffer.alloc(6, this.readBytes(8, 6))
|
|
142
|
-
this.instance.sender.mac.setValue(Array.from(macAddrBuffer).map((value: number): string => UInt8ToHex(value)).join(':'))
|
|
143
|
-
},
|
|
144
|
-
encode: (): void => {
|
|
145
|
-
let macStr: string = this.instance.sender.mac.getValue()
|
|
146
|
-
const rawMacBuffer: Buffer = Buffer.from(macStr.split(':').map((value: string): number => parseInt(value, 16)).map((value: number): number => value ? value : 0))
|
|
147
|
-
if (rawMacBuffer.length !== 6) this.recordError(this.instance.sender.mac.getPath(), 'Invalid MAC address length')
|
|
148
|
-
this.writeBytes(8, Buffer.alloc(6, rawMacBuffer))
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
ipv4: {
|
|
152
|
-
type: 'string',
|
|
153
|
-
label: 'IP address',
|
|
154
|
-
minLength: 7,
|
|
155
|
-
maxLength: 15,
|
|
156
|
-
contentEncoding: StringContentEncodingEnum.UTF8,
|
|
157
|
-
decode: (): void => {
|
|
158
|
-
const ipv4Buffer: Buffer = Buffer.alloc(4, this.readBytes(14, 4))
|
|
159
|
-
this.instance.sender.ipv4.setValue(BufferToIPv4(ipv4Buffer))
|
|
160
|
-
},
|
|
161
|
-
encode: (): void => {
|
|
162
|
-
let ipv4Str: string = this.instance.sender.ipv4.getValue()
|
|
163
|
-
this.writeBytes(14, IPv4ToBuffer(ipv4Str))
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
target: {
|
|
169
|
-
type: 'object',
|
|
170
|
-
label: 'Target',
|
|
171
|
-
properties: {
|
|
172
|
-
mac: {
|
|
173
|
-
type: 'string',
|
|
174
|
-
label: 'MAC address',
|
|
175
|
-
minLength: 17,
|
|
176
|
-
maxLength: 17,
|
|
177
|
-
contentEncoding: StringContentEncodingEnum.UTF8,
|
|
178
|
-
decode: (): void => {
|
|
179
|
-
const macAddrBuffer: Buffer = Buffer.alloc(6, this.readBytes(18, 6))
|
|
180
|
-
this.instance.target.mac.setValue(Array.from(macAddrBuffer).map((value: number): string => UInt8ToHex(value)).join(':'))
|
|
181
|
-
},
|
|
182
|
-
encode: (): void => {
|
|
183
|
-
let macStr: string = this.instance.target.mac.getValue()
|
|
184
|
-
const rawMacBuffer: Buffer = Buffer.from(macStr.split(':').map((value: string): number => parseInt(value, 16)).map((value: number): number => value ? value : 0))
|
|
185
|
-
if (rawMacBuffer.length !== 6) this.recordError(this.instance.target.mac.getPath(), 'Invalid MAC address length')
|
|
186
|
-
this.writeBytes(18, Buffer.alloc(6, rawMacBuffer))
|
|
187
|
-
}
|
|
188
|
-
},
|
|
189
|
-
ipv4: {
|
|
190
|
-
type: 'string',
|
|
191
|
-
label: 'IP address',
|
|
192
|
-
minLength: 7,
|
|
193
|
-
maxLength: 15,
|
|
194
|
-
contentEncoding: StringContentEncodingEnum.UTF8,
|
|
195
|
-
decode: (): void => {
|
|
196
|
-
const ipv4Buffer: Buffer = Buffer.alloc(4, this.readBytes(24, 4))
|
|
197
|
-
this.instance.target.ipv4.setValue(BufferToIPv4(ipv4Buffer))
|
|
198
|
-
},
|
|
199
|
-
encode: (): void => {
|
|
200
|
-
let ipv4Str: string = this.instance.target.ipv4.getValue()
|
|
201
|
-
this.writeBytes(24, IPv4ToBuffer(ipv4Str))
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
public readonly id: string = 'arp'
|
|
210
|
-
|
|
211
|
-
public readonly name: string = 'Address Resolution Protocol'
|
|
212
|
-
|
|
213
|
-
public readonly nickname: string = 'ARP'
|
|
214
|
-
|
|
215
|
-
public match(): boolean {
|
|
216
|
-
if (!this.prevCodecModule) return false
|
|
217
|
-
return this.prevCodecModule.instance.etherType.getValue() === UInt16ToHex(0x0806)
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
}
|