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,180 @@
|
|
|
1
|
+
import {ProtocolJSONSchema} from '../../schema/ProtocolJSONSchema'
|
|
2
|
+
import {BaseHeader} from '../abstracts/BaseHeader'
|
|
3
|
+
import {BufferToUInt16} from '../lib/BufferToNumber'
|
|
4
|
+
import {UInt16ToBuffer, UInt8ToBuffer} from '../lib/NumberToBuffer'
|
|
5
|
+
import {IPv6ToBuffer} from '../lib/IPToBuffer'
|
|
6
|
+
import {CodecModule} from '../types/CodecModule'
|
|
7
|
+
|
|
8
|
+
export class UDP extends BaseHeader {
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Calculate UDP Checksum
|
|
12
|
+
* @protected
|
|
13
|
+
* @param udpHeaderBuffer
|
|
14
|
+
*/
|
|
15
|
+
protected calculateUDPChecksum(udpHeaderBuffer: Buffer): number {
|
|
16
|
+
const udpHeaderLength: number = udpHeaderBuffer.length
|
|
17
|
+
const ipVersion: number = this.prevCodecModule.instance.version.getValue()
|
|
18
|
+
let pseudoHeaderBuffer: Buffer = Buffer.from([])
|
|
19
|
+
const sourceIp: string = this.prevCodecModule.instance.sip.getValue()
|
|
20
|
+
const destinationIp: string = this.prevCodecModule.instance.dip.getValue()
|
|
21
|
+
if (ipVersion === 4) {
|
|
22
|
+
//4 Bytes
|
|
23
|
+
const sourceIPv4Buffer: Buffer = Buffer.from(sourceIp.split('.').map((value: string): number => parseInt(value)))
|
|
24
|
+
const destinationIPv4Buffer: Buffer = Buffer.from(destinationIp.split('.').map((value: string): number => parseInt(value)))
|
|
25
|
+
//IPv4 Pseudo header
|
|
26
|
+
pseudoHeaderBuffer = Buffer.concat([
|
|
27
|
+
sourceIPv4Buffer,
|
|
28
|
+
destinationIPv4Buffer,
|
|
29
|
+
UInt8ToBuffer(0), //Reserved field
|
|
30
|
+
UInt8ToBuffer(17), //Protocol type (UDP = 17)
|
|
31
|
+
Buffer.from([(udpHeaderLength >> 8) & 0xFF]),
|
|
32
|
+
Buffer.from([udpHeaderLength & 0xFF])
|
|
33
|
+
])
|
|
34
|
+
} else if (ipVersion === 6) {
|
|
35
|
+
//16 Bytes
|
|
36
|
+
const sourceIPv6Buffer: Buffer = IPv6ToBuffer(sourceIp)
|
|
37
|
+
const destinationIPv6Buffer: Buffer = IPv6ToBuffer(destinationIp)
|
|
38
|
+
//IPv6 Pseudo header
|
|
39
|
+
pseudoHeaderBuffer = Buffer.concat([
|
|
40
|
+
sourceIPv6Buffer,
|
|
41
|
+
destinationIPv6Buffer,
|
|
42
|
+
UInt8ToBuffer(0), //Reserved field
|
|
43
|
+
UInt8ToBuffer(0), //Reserved field
|
|
44
|
+
UInt8ToBuffer(0), //Reserved field
|
|
45
|
+
UInt8ToBuffer(17), //Protocol type (UDP = 17)
|
|
46
|
+
Buffer.from([(udpHeaderLength >> 8) & 0xFF]),
|
|
47
|
+
Buffer.from([udpHeaderLength & 0xFF])
|
|
48
|
+
])
|
|
49
|
+
} else {
|
|
50
|
+
return 0
|
|
51
|
+
}
|
|
52
|
+
let dataBuffer: Buffer = Buffer.concat([pseudoHeaderBuffer, udpHeaderBuffer])
|
|
53
|
+
if (dataBuffer.length % 2) dataBuffer = Buffer.concat([dataBuffer, Buffer.from('00', 'hex')])
|
|
54
|
+
const data: Uint8Array = Uint8Array.from(dataBuffer)
|
|
55
|
+
let sum: number = 0
|
|
56
|
+
for (let i: number = 0; i < data.length; i += 2) sum += (data[i] << 8) + (data[i + 1] || 0)
|
|
57
|
+
while (sum > 0xFFFF) sum = (sum & 0xFFFF) + (sum >>> 16)
|
|
58
|
+
return (~sum) & 0xFFFF
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public SCHEMA: ProtocolJSONSchema = {
|
|
62
|
+
type: 'object',
|
|
63
|
+
properties: {
|
|
64
|
+
srcport: {
|
|
65
|
+
type: 'integer',
|
|
66
|
+
label: 'Source Port',
|
|
67
|
+
minimum: 0,
|
|
68
|
+
maximum: 65535,
|
|
69
|
+
decode: (): void => {
|
|
70
|
+
this.instance.srcport.setValue(BufferToUInt16(this.readBytes(0, 2)))
|
|
71
|
+
},
|
|
72
|
+
encode: (): void => {
|
|
73
|
+
let srcport: number = this.instance.srcport.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
|
|
74
|
+
if (srcport > 65535) {
|
|
75
|
+
this.recordError(this.instance.srcport.getPath(), 'Maximum value is 65535')
|
|
76
|
+
srcport = 65535
|
|
77
|
+
}
|
|
78
|
+
if (srcport < 0) {
|
|
79
|
+
this.recordError(this.instance.srcport.getPath(), 'Minimum value is 0')
|
|
80
|
+
srcport = 0
|
|
81
|
+
}
|
|
82
|
+
this.instance.srcport.setValue(srcport)
|
|
83
|
+
this.writeBytes(0, UInt16ToBuffer(srcport))
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
dstport: {
|
|
87
|
+
type: 'integer',
|
|
88
|
+
label: 'Destination Port',
|
|
89
|
+
minimum: 0,
|
|
90
|
+
maximum: 65535,
|
|
91
|
+
decode: (): void => {
|
|
92
|
+
this.instance.dstport.setValue(BufferToUInt16(this.readBytes(2, 2)))
|
|
93
|
+
},
|
|
94
|
+
encode: (): void => {
|
|
95
|
+
let dstport: number = this.instance.dstport.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
|
|
96
|
+
if (dstport > 65535) {
|
|
97
|
+
this.recordError(this.instance.dstport.getPath(), 'Maximum value is 65535')
|
|
98
|
+
dstport = 65535
|
|
99
|
+
}
|
|
100
|
+
if (dstport < 0) {
|
|
101
|
+
this.recordError(this.instance.dstport.getPath(), 'Minimum value is 0')
|
|
102
|
+
dstport = 0
|
|
103
|
+
}
|
|
104
|
+
this.instance.dstport.setValue(dstport)
|
|
105
|
+
this.writeBytes(2, UInt16ToBuffer(dstport))
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
length: {
|
|
109
|
+
type: 'integer',
|
|
110
|
+
label: 'Length',
|
|
111
|
+
minimum: 0,
|
|
112
|
+
maximum: 65535,
|
|
113
|
+
decode: (): void => {
|
|
114
|
+
this.instance.length.setValue(BufferToUInt16(this.readBytes(4, 2)))
|
|
115
|
+
},
|
|
116
|
+
encode: (): void => {
|
|
117
|
+
let length: number = this.instance.length.getValue(0)
|
|
118
|
+
if (length) {
|
|
119
|
+
this.instance.length.setValue(length)
|
|
120
|
+
this.writeBytes(4, UInt16ToBuffer(length))
|
|
121
|
+
} else {
|
|
122
|
+
this.instance.length.setValue(length)
|
|
123
|
+
this.writeBytes(4, UInt16ToBuffer(length))
|
|
124
|
+
this.addPostPacketEncodeHandler((): void => {
|
|
125
|
+
let startCount: boolean = false
|
|
126
|
+
let udpLength: number = 0
|
|
127
|
+
this.codecModules.forEach((codecModule: CodecModule): void => {
|
|
128
|
+
if (codecModule === this) startCount = true
|
|
129
|
+
if (startCount) udpLength += codecModule.length
|
|
130
|
+
})
|
|
131
|
+
this.instance.length.setValue(udpLength)
|
|
132
|
+
this.writeBytes(4, UInt16ToBuffer(udpLength))
|
|
133
|
+
}, 1)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
checksum: {
|
|
138
|
+
type: 'integer',
|
|
139
|
+
label: 'Checksum',
|
|
140
|
+
minimum: 0,
|
|
141
|
+
maximum: 65535,
|
|
142
|
+
decode: (): void => {
|
|
143
|
+
this.instance.checksum.setValue(BufferToUInt16(this.readBytes(6, 2)))
|
|
144
|
+
},
|
|
145
|
+
encode: (): void => {
|
|
146
|
+
const checksum: number = this.instance.checksum.getValue(0)
|
|
147
|
+
if (checksum) {
|
|
148
|
+
this.instance.checksum.setValue(checksum)
|
|
149
|
+
this.writeBytes(6, UInt16ToBuffer(checksum))
|
|
150
|
+
} else {
|
|
151
|
+
this.writeBytes(6, UInt16ToBuffer(checksum))
|
|
152
|
+
this.instance.checksum.setValue(checksum)
|
|
153
|
+
this.addPostPacketEncodeHandler((): void => {
|
|
154
|
+
let startCount: boolean = false
|
|
155
|
+
let udpHeaderWithDataLength: number = 0
|
|
156
|
+
this.codecModules.forEach((codecModule: CodecModule): void => {
|
|
157
|
+
if (codecModule === this) startCount = true
|
|
158
|
+
if (startCount) udpHeaderWithDataLength += codecModule.length
|
|
159
|
+
})
|
|
160
|
+
const calcChecksum: number = this.calculateUDPChecksum(this.packet.subarray(this.startPos, this.startPos + udpHeaderWithDataLength))
|
|
161
|
+
this.instance.checksum.setValue(calcChecksum)
|
|
162
|
+
this.writeBytes(6, UInt16ToBuffer(calcChecksum))
|
|
163
|
+
}, 2)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
public id: string = 'udp'
|
|
171
|
+
|
|
172
|
+
public name: string = 'User Datagram Protocol'
|
|
173
|
+
|
|
174
|
+
public match(): boolean {
|
|
175
|
+
if (!this.prevCodecModule) return false
|
|
176
|
+
if (this.prevCodecModule.instance.protocol.getValue() === 0x11) return true
|
|
177
|
+
return false
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {ProtocolJSONSchema} from '../../schema/ProtocolJSONSchema'
|
|
2
|
+
import {BaseHeader} from '../abstracts/BaseHeader'
|
|
3
|
+
import {UInt16ToHex} from '../lib/NumberToHex'
|
|
4
|
+
import {BufferToUInt16} from '../lib/BufferToNumber'
|
|
5
|
+
|
|
6
|
+
export class VLAN_802dot1Q extends BaseHeader {
|
|
7
|
+
public SCHEMA: ProtocolJSONSchema = {
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
priority: {
|
|
11
|
+
type: 'integer',
|
|
12
|
+
minimum: 0,
|
|
13
|
+
maximum: 7,
|
|
14
|
+
default: 0,
|
|
15
|
+
decode: (): void => {
|
|
16
|
+
this.instance.priority.setValue(this.readBits(0, 2, 0, 3))
|
|
17
|
+
},
|
|
18
|
+
encode: (): void => {
|
|
19
|
+
const priorityValue: number = this.instance.priority.getValue(0)
|
|
20
|
+
this.instance.priority.setValue(priorityValue)
|
|
21
|
+
this.writeBits(0, 2, 0, 3, priorityValue)
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
dei: {
|
|
25
|
+
type: 'boolean',
|
|
26
|
+
decode: (): void => {
|
|
27
|
+
this.instance.dei.setValue(!!this.readBits(0, 2, 3, 1))
|
|
28
|
+
},
|
|
29
|
+
encode: (): void => {
|
|
30
|
+
const dei: boolean = !!this.instance.dei.getValue()
|
|
31
|
+
this.instance.dei.setValue(dei)
|
|
32
|
+
this.writeBits(0, 2, 3, 1, dei ? 1 : 0)
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
id: {
|
|
36
|
+
type: 'integer',
|
|
37
|
+
minimum: 0,
|
|
38
|
+
maximum: 4095,
|
|
39
|
+
decode: (): void => {
|
|
40
|
+
this.instance.id.setValue(this.readBits(0, 2, 4, 12))
|
|
41
|
+
},
|
|
42
|
+
encode: (): void => {
|
|
43
|
+
const vlanId: number = this.instance.id.getValue(0)
|
|
44
|
+
this.instance.id.setValue(vlanId)
|
|
45
|
+
this.writeBits(0, 2, 4, 12, vlanId)
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
etherType: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
minLength: 4,
|
|
51
|
+
maxLength: 4,
|
|
52
|
+
decode: (): void => {
|
|
53
|
+
this.instance.etherType.setValue(BufferToUInt16(this.readBytes(2, 2)))
|
|
54
|
+
},
|
|
55
|
+
encode: (): void => {
|
|
56
|
+
let etherType: string = this.instance.etherType.getValue(UInt16ToHex(0x0000), (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
|
|
57
|
+
const typeBuffer: Buffer = Buffer.from(etherType, 'hex')
|
|
58
|
+
if (typeBuffer.length < 2) typeBuffer.fill(0, 0, 1)
|
|
59
|
+
this.writeBytes(2, typeBuffer.subarray(0, 2))
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public id: string = 'vlan'
|
|
67
|
+
|
|
68
|
+
public name: string = '802.1Q Virtual LAN'
|
|
69
|
+
|
|
70
|
+
public match(): boolean {
|
|
71
|
+
if (!this.prevCodecModule) return false
|
|
72
|
+
return this.prevCodecModule.instance.etherType.getValue() === UInt16ToHex(0x8100)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {Address4, Address6} from 'ip-address'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Convert Buffer to IPv4 string
|
|
5
|
+
* @param buffer
|
|
6
|
+
* @constructor
|
|
7
|
+
*/
|
|
8
|
+
export function BufferToIPv4(buffer: Buffer): string {
|
|
9
|
+
return Address4.fromBigInt(BigInt(`0x${Buffer.alloc(4, buffer).toString('hex').padStart(8, '0')}`)).address
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Convert Buffer to IPv6 string
|
|
14
|
+
* @param buffer
|
|
15
|
+
* @constructor
|
|
16
|
+
*/
|
|
17
|
+
export function BufferToIPv6(buffer: Buffer): string {
|
|
18
|
+
return Address6.fromBigInt(BigInt(`0x${Buffer.alloc(16, buffer).toString('hex').padStart(32, '0')}`)).address
|
|
19
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
HexToFloat32,
|
|
3
|
+
HexToInt16,
|
|
4
|
+
HexToInt32,
|
|
5
|
+
HexToInt64,
|
|
6
|
+
HexToInt8,
|
|
7
|
+
HexToUInt16,
|
|
8
|
+
HexToUInt32,
|
|
9
|
+
HexToUInt64,
|
|
10
|
+
HexToUInt8
|
|
11
|
+
} from './HexToNumber'
|
|
12
|
+
|
|
13
|
+
export const BufferToInt8: (buffer: Buffer) => number = (buffer: Buffer): number => HexToInt8(buffer.toString('hex'))
|
|
14
|
+
export const BufferToInt16: (buffer: Buffer) => number = (buffer: Buffer): number => HexToInt16(buffer.toString('hex'))
|
|
15
|
+
export const BufferToInt32: (buffer: Buffer) => number = (buffer: Buffer): number => HexToInt32(buffer.toString('hex'))
|
|
16
|
+
export const BufferToInt64: (buffer: Buffer) => bigint = (buffer: Buffer): bigint => HexToInt64(buffer.toString('hex'))
|
|
17
|
+
export const BufferToUInt8: (buffer: Buffer) => number = (buffer: Buffer): number => HexToUInt8(buffer.toString('hex'))
|
|
18
|
+
export const BufferToUInt16: (buffer: Buffer) => number = (buffer: Buffer): number => HexToUInt16(buffer.toString('hex'))
|
|
19
|
+
export const BufferToUInt32: (buffer: Buffer) => number = (buffer: Buffer): number => HexToUInt32(buffer.toString('hex'))
|
|
20
|
+
export const BufferToUInt64: (buffer: Buffer) => bigint = (buffer: Buffer): bigint => HexToUInt64(buffer.toString('hex'))
|
|
21
|
+
export const BufferToFloat32: (buffer: Buffer) => number = (buffer: Buffer): number => HexToFloat32(buffer.toString('hex'))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export class FlexibleObject {
|
|
2
|
+
|
|
3
|
+
readonly #parent: FlexibleObject | undefined
|
|
4
|
+
|
|
5
|
+
readonly #paths: string[]
|
|
6
|
+
|
|
7
|
+
#data: any
|
|
8
|
+
|
|
9
|
+
#undefined: boolean = true
|
|
10
|
+
|
|
11
|
+
#markFlexibleObjectDefined(): void {
|
|
12
|
+
if (!this.#undefined) return
|
|
13
|
+
this.#undefined = false
|
|
14
|
+
if (this.#parent) this.#parent.#markFlexibleObjectDefined()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
constructor(data?: object, parent?: FlexibleObject, paths?: string[]) {
|
|
18
|
+
this.#parent = parent
|
|
19
|
+
this.#data = {}
|
|
20
|
+
this.#paths = paths ? paths : []
|
|
21
|
+
if (data !== undefined) this.setValue(data)
|
|
22
|
+
return new Proxy(this, {
|
|
23
|
+
get: (target: FlexibleObject, p: string): any => {
|
|
24
|
+
if (this[p]) return (...args: any[]): any => (this[p] as any)(...args)
|
|
25
|
+
if (target.#data[p] === undefined) target.#data[p] = new FlexibleObject(target.#data[p], this, [...this.#paths, p])
|
|
26
|
+
return target.#data[p]
|
|
27
|
+
},
|
|
28
|
+
set: (target: FlexibleObject, p: string, newValue: any): boolean => {
|
|
29
|
+
return false
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Set object node value
|
|
36
|
+
* @param value
|
|
37
|
+
*/
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
public setValue(value: any): void {
|
|
40
|
+
if (typeof value === 'object' && !Array.isArray(value)) {
|
|
41
|
+
Object.keys(value).forEach(key => {
|
|
42
|
+
this.#data[key] = new FlexibleObject(this.#data[key], this, [...this.#paths, key])
|
|
43
|
+
this.#data[key].setValue(value[key])
|
|
44
|
+
})
|
|
45
|
+
} else {
|
|
46
|
+
this.#data = value
|
|
47
|
+
}
|
|
48
|
+
this.#markFlexibleObjectDefined()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Get object node value
|
|
53
|
+
* @param defaultValue
|
|
54
|
+
* @param onUndefinedCallback
|
|
55
|
+
* @param getPathIndex
|
|
56
|
+
*/
|
|
57
|
+
// @ts-ignore
|
|
58
|
+
public getValue<T = any>(defaultValue?: T, onUndefinedCallback?: (nodePath: string) => void, getPathIndex?: number): T {
|
|
59
|
+
if (this.#undefined) {
|
|
60
|
+
if (onUndefinedCallback) onUndefinedCallback(this.getPath(getPathIndex))
|
|
61
|
+
if (defaultValue !== undefined) {
|
|
62
|
+
return defaultValue
|
|
63
|
+
}
|
|
64
|
+
return undefined as any
|
|
65
|
+
}
|
|
66
|
+
if (typeof this.#data === 'object' && !Array.isArray(this.#data)) {
|
|
67
|
+
const dumpObject: object = {}
|
|
68
|
+
Object.keys(this.#data).forEach((key: string): void => {
|
|
69
|
+
const dumpResult: any = this.#data[key].getValue()
|
|
70
|
+
if (dumpResult === undefined) return
|
|
71
|
+
dumpObject[key] = dumpResult
|
|
72
|
+
})
|
|
73
|
+
return dumpObject as any
|
|
74
|
+
} else {
|
|
75
|
+
return this.#undefined ? undefined as any : this.#data
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Is current object's value undefined
|
|
81
|
+
*/
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
public isUndefined(): boolean {
|
|
84
|
+
return this.#undefined
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Get current object path
|
|
89
|
+
* The index parameter indicates array item if this object is an array
|
|
90
|
+
* @param index
|
|
91
|
+
*/
|
|
92
|
+
// @ts-ignore
|
|
93
|
+
public getPath(index?: number): string {
|
|
94
|
+
const objPath: string = this.#paths.join('.')
|
|
95
|
+
if (index === undefined) return objPath
|
|
96
|
+
return `${objPath}[${index}]`
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
[p: string]: FlexibleObject
|
|
100
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const HexToInt8: (hex: string) => number = (hex: string): number => Int8Array.from([parseInt(hex, 16)])[0]
|
|
2
|
+
export const HexToInt16: (hex: string) => number = (hex: string): number => Int16Array.from([parseInt(hex, 16)])[0]
|
|
3
|
+
export const HexToInt32: (hex: string) => number = (hex: string): number => Int32Array.from([parseInt(hex, 16)])[0]
|
|
4
|
+
export const HexToInt64: (hex: string) => bigint = (hex: string): bigint => {
|
|
5
|
+
const INT64_MAX: bigint = BigInt('9223372036854775807')
|
|
6
|
+
const INT64_MIN: bigint = BigInt('-9223372036854775808')
|
|
7
|
+
const bigIntValue: bigint = BigInt(`0x${hex}`)
|
|
8
|
+
if (bigIntValue < INT64_MIN || bigIntValue > INT64_MAX) return INT64_MAX
|
|
9
|
+
return bigIntValue
|
|
10
|
+
}
|
|
11
|
+
export const HexToUInt8: (hex: string) => number = (hex: string): number => Uint8Array.from([parseInt(hex, 16)])[0]
|
|
12
|
+
export const HexToUInt16: (hex: string) => number = (hex: string): number => Uint16Array.from([parseInt(hex, 16)])[0]
|
|
13
|
+
export const HexToUInt32: (hex: string) => number = (hex: string): number => Uint32Array.from([parseInt(hex, 16)])[0]
|
|
14
|
+
export const HexToUInt64: (hex: string) => bigint = (hex: string): bigint => {
|
|
15
|
+
const INT64_MAX: bigint = BigInt('18446744073709551615')
|
|
16
|
+
const bigIntValue: bigint = BigInt(`0x${hex}`)
|
|
17
|
+
if (bigIntValue < 0n || bigIntValue > INT64_MAX) return INT64_MAX
|
|
18
|
+
return bigIntValue
|
|
19
|
+
}
|
|
20
|
+
export const HexToFloat32: (hex: string) => number = (hex: string): number => {
|
|
21
|
+
const buffer = new ArrayBuffer(4)
|
|
22
|
+
const dataView = new DataView(buffer)
|
|
23
|
+
dataView.setUint32(0, parseInt(hex, 16), false)
|
|
24
|
+
return dataView.getFloat32(0, false)
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {Address6} from 'ip-address'
|
|
2
|
+
import {UInt32ToBuffer} from './NumberToBuffer'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Convert IPv4 string to Buffer
|
|
6
|
+
* @param ipv4
|
|
7
|
+
* @constructor
|
|
8
|
+
*/
|
|
9
|
+
export function IPv4ToBuffer(ipv4: string): Buffer {
|
|
10
|
+
const numArr: number[] = ipv4.split('.').map((value: string): number => parseInt(value)).map((value: number): number => value ? value : 0)
|
|
11
|
+
return UInt32ToBuffer(parseInt(Buffer.from(numArr).toString('hex'), 16))
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Convert IPv6 string to Buffer
|
|
16
|
+
* @param ipv6
|
|
17
|
+
* @constructor
|
|
18
|
+
*/
|
|
19
|
+
export function IPv6ToBuffer(ipv6: string): Buffer {
|
|
20
|
+
try {
|
|
21
|
+
return Buffer.from(new Address6(ipv6).toByteArray())
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return Buffer.alloc(16, 0)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Int16ToBERHex,
|
|
3
|
+
Int32ToBERHex,
|
|
4
|
+
Int64ToBERHex,
|
|
5
|
+
Int8ToBERHex,
|
|
6
|
+
UInt16ToBERHex,
|
|
7
|
+
UInt32ToBERHex,
|
|
8
|
+
UInt64ToBERHex,
|
|
9
|
+
UInt8ToBERHex
|
|
10
|
+
} from './NumberToBERHex'
|
|
11
|
+
|
|
12
|
+
export const Int8ToBERBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(Int8ToBERHex(value), 'hex')
|
|
13
|
+
export const Int16ToBERBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(Int16ToBERHex(value), 'hex')
|
|
14
|
+
export const Int32ToBERBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(Int32ToBERHex(value), 'hex')
|
|
15
|
+
export const Int64ToBERBuffer: (value: bigint) => Buffer = (value: bigint): Buffer => Buffer.from(Int64ToBERHex(value), 'hex')
|
|
16
|
+
export const UInt8ToBERBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(UInt8ToBERHex(value), 'hex')
|
|
17
|
+
export const UInt16ToBERBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(UInt16ToBERHex(value), 'hex')
|
|
18
|
+
export const UInt32ToBERBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(UInt32ToBERHex(value), 'hex')
|
|
19
|
+
export const UInt64ToBERBuffer: (value: bigint) => Buffer = (value: bigint): Buffer => Buffer.from(UInt64ToBERHex(value), 'hex')
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function toBERHex(rawHex: string): string {
|
|
2
|
+
const hex: string = rawHex.padStart(rawHex.length + rawHex.length % 2, '0')
|
|
3
|
+
return Buffer.from(hex, 'hex')[0].toString(2).padStart(8, '0').startsWith('1') ? `00${hex}` : hex
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export const Int8ToBERHex: (value: number) => string = (value: number): string => toBERHex(new Uint8Array(Int8Array.from([value]).buffer)[0].toString(16))
|
|
7
|
+
export const Int16ToBERHex: (value: number) => string = (value: number): string => toBERHex(new Uint16Array(Int16Array.from([value]).buffer)[0].toString(16))
|
|
8
|
+
export const Int32ToBERHex: (value: number) => string = (value: number): string => toBERHex(new Uint32Array(Int32Array.from([value]).buffer)[0].toString(16))
|
|
9
|
+
export const Int64ToBERHex: (value: bigint) => string = (value: bigint): string => toBERHex(BigInt(value).toString(16))
|
|
10
|
+
export const UInt8ToBERHex: (value: number) => string = (value: number): string => toBERHex(value.toString(16))
|
|
11
|
+
export const UInt16ToBERHex: (value: number) => string = (value: number): string => toBERHex(value.toString(16))
|
|
12
|
+
export const UInt32ToBERHex: (value: number) => string = (value: number): string => toBERHex(value.toString(16))
|
|
13
|
+
export const UInt64ToBERHex: (value: bigint) => string = (value: bigint): string => toBERHex(BigInt(value).toString(16))
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Float32ToHex,
|
|
3
|
+
Int16ToHex,
|
|
4
|
+
Int32ToHex,
|
|
5
|
+
Int64ToHex,
|
|
6
|
+
Int8ToHex,
|
|
7
|
+
UInt16ToHex,
|
|
8
|
+
UInt32ToHex,
|
|
9
|
+
UInt64ToHex,
|
|
10
|
+
UInt8ToHex
|
|
11
|
+
} from './NumberToHex'
|
|
12
|
+
|
|
13
|
+
export const Int8ToBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(Int8ToHex(value), 'hex')
|
|
14
|
+
export const Int16ToBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(Int16ToHex(value), 'hex')
|
|
15
|
+
export const Int32ToBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(Int32ToHex(value), 'hex')
|
|
16
|
+
export const Int64ToBuffer: (value: bigint) => Buffer = (value: bigint): Buffer => Buffer.from(Int64ToHex(value), 'hex')
|
|
17
|
+
export const UInt8ToBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(UInt8ToHex(value), 'hex')
|
|
18
|
+
export const UInt16ToBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(UInt16ToHex(value), 'hex')
|
|
19
|
+
export const UInt32ToBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(UInt32ToHex(value), 'hex')
|
|
20
|
+
export const UInt64ToBuffer: (value: bigint) => Buffer = (value: bigint): Buffer => Buffer.from(UInt64ToHex(value), 'hex')
|
|
21
|
+
export const Float32ToBuffer: (value: number) => Buffer = (value: number): Buffer => Buffer.from(Float32ToHex(value), 'hex')
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const Int8ToHex: (value: number) => string = (value: number): string => new Uint8Array(Int8Array.from([value]).buffer)[0].toString(16).padStart(2, '0')
|
|
2
|
+
export const Int16ToHex: (value: number) => string = (value: number): string => new Uint16Array(Int16Array.from([value]).buffer)[0].toString(16).padStart(4, '0')
|
|
3
|
+
export const Int32ToHex: (value: number) => string = (value: number): string => new Uint32Array(Int32Array.from([value]).buffer)[0].toString(16).padStart(8, '0')
|
|
4
|
+
export const Int64ToHex: (value: bigint) => string = (value: bigint): string => BigInt(value).toString(16).padStart(16, '0')
|
|
5
|
+
export const UInt8ToHex: (value: number) => string = (value: number): string => value.toString(16).padStart(2, '0')
|
|
6
|
+
export const UInt16ToHex: (value: number) => string = (value: number): string => value.toString(16).padStart(4, '0')
|
|
7
|
+
export const UInt32ToHex: (value: number) => string = (value: number): string => value.toString(16).padStart(8, '0')
|
|
8
|
+
export const UInt64ToHex: (value: bigint) => string = (value: bigint): string => BigInt(value).toString(16).padStart(16, '0')
|
|
9
|
+
|
|
10
|
+
export const Float32ToHex: (value: number) => string = (value: number): string => {
|
|
11
|
+
const buffer = new ArrayBuffer(4)
|
|
12
|
+
const dataView = new DataView(buffer)
|
|
13
|
+
dataView.setFloat32(0, value, false)
|
|
14
|
+
return dataView.getUint32(0, false).toString(16).padStart(8, '0')
|
|
15
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {PostHandlerItem} from '../types/PostHandlerItem'
|
|
2
|
+
import {SortPostHandlers} from './SortPostHandlers'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Process packet post handlers
|
|
6
|
+
* @param handlerItemsArray
|
|
7
|
+
* @param asc
|
|
8
|
+
*/
|
|
9
|
+
function processPacketPostHandlers(handlerItemsArray: PostHandlerItem[][], asc: boolean): PostHandlerItem[][] {
|
|
10
|
+
let indexFactor: number = 10
|
|
11
|
+
return handlerItemsArray
|
|
12
|
+
.map((handlerItems: PostHandlerItem[]): PostHandlerItem[] => {
|
|
13
|
+
return SortPostHandlers(handlerItems).map((handlerItem: PostHandlerItem, index: number): PostHandlerItem => {
|
|
14
|
+
handlerItem.priority = index + 1
|
|
15
|
+
let factor: number = 10
|
|
16
|
+
let priority: number = handlerItem.priority
|
|
17
|
+
while (priority > 1) {
|
|
18
|
+
priority /= 10
|
|
19
|
+
factor *= 10
|
|
20
|
+
}
|
|
21
|
+
indexFactor = indexFactor < factor ? factor : indexFactor
|
|
22
|
+
return handlerItem
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
.map((handlerItems: PostHandlerItem[], headerIndex: number): PostHandlerItem[] => {
|
|
26
|
+
const basePriority: number = (headerIndex + 1) * indexFactor
|
|
27
|
+
const unsortedItems: PostHandlerItem[] = handlerItems.map((handlerItem: PostHandlerItem): PostHandlerItem => {
|
|
28
|
+
handlerItem.priority = basePriority + handlerItem.priority
|
|
29
|
+
return handlerItem
|
|
30
|
+
})
|
|
31
|
+
return asc ?
|
|
32
|
+
unsortedItems.sort((a: PostHandlerItem, b: PostHandlerItem): number => a.priority - b.priority) :
|
|
33
|
+
unsortedItems.sort((a: PostHandlerItem, b: PostHandlerItem): number => b.priority - a.priority)
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Process packet post encode handlers
|
|
39
|
+
* @param handlerItemsArray
|
|
40
|
+
* @constructor
|
|
41
|
+
*/
|
|
42
|
+
export function ProcessPacketEncodePostHandlers(handlerItemsArray: PostHandlerItem[][]): PostHandlerItem[] {
|
|
43
|
+
return processPacketPostHandlers(handlerItemsArray, true).reverse().flat()
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Process packet post decode handlers
|
|
48
|
+
* @param handlerItemsArray
|
|
49
|
+
* @constructor
|
|
50
|
+
*/
|
|
51
|
+
export function ProcessPacketDecodePostHandlers(handlerItemsArray: PostHandlerItem[][]): PostHandlerItem[] {
|
|
52
|
+
return processPacketPostHandlers(handlerItemsArray, true).flat()
|
|
53
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {PostHandlerItem} from '../types/PostHandlerItem'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sort post handlers
|
|
5
|
+
* @param handlers
|
|
6
|
+
* @constructor
|
|
7
|
+
*/
|
|
8
|
+
export function SortPostHandlers(handlers: PostHandlerItem[]): PostHandlerItem[] {
|
|
9
|
+
return handlers.sort((a: PostHandlerItem, b: PostHandlerItem): number => a.priority - b.priority)
|
|
10
|
+
}
|