netkitty 0.0.20 → 0.0.22
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 +2 -2
- package/.idea/inspectionProfiles/Project_Default.xml +2 -1
- package/.idea/netkitty.iml +0 -1
- package/cpp/nodepcap/deps/include/Packet32.h +429 -429
- package/cpp/nodepcap/deps/include/pcap/bluetooth.h +56 -56
- package/cpp/nodepcap/deps/include/pcap/bpf.h +292 -292
- package/cpp/nodepcap/deps/include/pcap/can_socketcan.h +56 -56
- package/cpp/nodepcap/deps/include/pcap/compiler-tests.h +163 -163
- package/cpp/nodepcap/deps/include/pcap/dlt.h +1514 -1514
- package/cpp/nodepcap/deps/include/pcap/funcattrs.h +325 -325
- package/cpp/nodepcap/deps/include/pcap/ipnet.h +43 -43
- package/cpp/nodepcap/deps/include/pcap/namedb.h +84 -84
- package/cpp/nodepcap/deps/include/pcap/nflog.h +94 -94
- package/cpp/nodepcap/deps/include/pcap/pcap-inttypes.h +101 -101
- package/cpp/nodepcap/deps/include/pcap/pcap.h +1219 -1219
- package/cpp/nodepcap/deps/include/pcap/sll.h +149 -149
- package/cpp/nodepcap/deps/include/pcap/socket.h +84 -84
- package/cpp/nodepcap/deps/include/pcap/usb.h +143 -143
- package/cpp/nodepcap/deps/include/pcap/vlan.h +46 -46
- package/cpp/nodepcap/deps/include/pcap-bpf.h +45 -45
- package/cpp/nodepcap/deps/include/pcap-namedb.h +40 -40
- package/cpp/nodepcap/deps/include/pcap.h +43 -43
- package/dist/PcapExports.d.ts +13 -0
- package/dist/PcapExports.d.ts.map +1 -1
- package/dist/PcapExports.js +16 -1
- package/dist/lib/codec/Codec.js +1 -1
- package/dist/lib/codec/PacketHeaders.d.ts +5 -0
- package/dist/lib/codec/PacketHeaders.d.ts.map +1 -1
- package/dist/lib/codec/PacketHeaders.js +13 -1
- package/dist/lib/codec/abstracts/BaseHeader.d.ts +2 -2
- package/dist/lib/codec/abstracts/BaseHeader.d.ts.map +1 -1
- package/dist/lib/codec/abstracts/BaseHeader.js +4 -4
- package/dist/lib/codec/headers/EthernetII.js +1 -1
- package/dist/lib/codec/headers/Goose.js +5 -5
- package/dist/lib/codec/headers/IEC61850SampledValues.js +1 -1
- package/dist/lib/codec/headers/IPv4.js +2 -2
- package/dist/lib/codec/headers/TLS_Alert.d.ts +10 -0
- package/dist/lib/codec/headers/TLS_Alert.d.ts.map +1 -0
- package/dist/lib/codec/headers/TLS_Alert.js +624 -0
- package/dist/lib/codec/headers/TLS_ApplicationData.d.ts +10 -0
- package/dist/lib/codec/headers/TLS_ApplicationData.d.ts.map +1 -0
- package/dist/lib/codec/headers/TLS_ApplicationData.js +155 -0
- package/dist/lib/codec/headers/TLS_ChangeCipherSpec.d.ts +10 -0
- package/dist/lib/codec/headers/TLS_ChangeCipherSpec.d.ts.map +1 -0
- package/dist/lib/codec/headers/TLS_ChangeCipherSpec.js +154 -0
- package/dist/lib/codec/headers/TLS_Handshake.d.ts +10 -0
- package/dist/lib/codec/headers/TLS_Handshake.d.ts.map +1 -0
- package/dist/lib/codec/headers/TLS_Handshake.js +339 -0
- package/dist/lib/codec/headers/TLS_Heartbeat.d.ts +10 -0
- package/dist/lib/codec/headers/TLS_Heartbeat.d.ts.map +1 -0
- package/dist/lib/codec/headers/TLS_Heartbeat.js +206 -0
- package/dist/lib/codec/headers/VLAN_802dot1Q.js +1 -1
- package/dist/lib/pcap/PCAPGenerator.d.ts +2 -2
- package/dist/lib/pcap/PCAPGenerator.d.ts.map +1 -1
- package/dist/lib/pcap/PCAPGenerator.js +7 -1
- package/package.json +1 -1
- package/src/PcapExports.ts +16 -0
- package/src/lib/codec/Codec.ts +1 -1
- package/src/lib/codec/PacketHeaders.ts +7 -0
- package/src/lib/codec/abstracts/BaseHeader.ts +4 -4
- package/src/lib/codec/headers/EthernetII.ts +1 -1
- package/src/lib/codec/headers/Goose.ts +5 -5
- package/src/lib/codec/headers/IEC61850SampledValues.ts +1 -1
- package/src/lib/codec/headers/IPv4.ts +2 -2
- package/src/lib/codec/headers/TLS_Alert.ts +539 -0
- package/src/lib/codec/headers/TLS_ApplicationData.ts +145 -0
- package/src/lib/codec/headers/TLS_ChangeCipherSpec.ts +146 -0
- package/src/lib/codec/headers/TLS_Handshake.ts +313 -0
- package/src/lib/codec/headers/TLS_Heartbeat.ts +188 -0
- package/src/lib/codec/headers/VLAN_802dot1Q.ts +1 -1
- package/src/lib/pcap/PCAPGenerator.ts +8 -3
- package/dist/NetKitty.d.ts +0 -1
- package/dist/NetKitty.d.ts.map +0 -1
- package/dist/NetKitty.js +0 -90
- package/src/NetKitty.ts +0 -91
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ProtocolJSONSchema } from '../../schema/ProtocolJSONSchema';
|
|
2
|
+
import { BaseHeader } from '../abstracts/BaseHeader';
|
|
3
|
+
export declare class TLS_Heartbeat extends BaseHeader {
|
|
4
|
+
SCHEMA: ProtocolJSONSchema;
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
nickname: string;
|
|
8
|
+
match(): boolean;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=TLS_Heartbeat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TLS_Heartbeat.d.ts","sourceRoot":"","sources":["../../../../src/lib/codec/headers/TLS_Heartbeat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAclD,qBAAa,aAAc,SAAQ,UAAU;IAClC,MAAM,EAAE,kBAAkB,CA+JhC;IACM,EAAE,EAAE,MAAM,CAAkB;IAC5B,IAAI,EAAE,MAAM,CAAiD;IAC7D,QAAQ,EAAE,MAAM,CAAQ;IAExB,KAAK,IAAI,OAAO;CAO1B"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TLS_Heartbeat = void 0;
|
|
4
|
+
const BaseHeader_1 = require("../abstracts/BaseHeader");
|
|
5
|
+
const BufferToNumber_1 = require("../../helper/BufferToNumber");
|
|
6
|
+
const HexToBuffer_1 = require("../../helper/HexToBuffer");
|
|
7
|
+
const BufferToHex_1 = require("../../helper/BufferToHex");
|
|
8
|
+
const NumberToBuffer_1 = require("../../helper/NumberToBuffer");
|
|
9
|
+
var TLSver;
|
|
10
|
+
(function (TLSver) {
|
|
11
|
+
TLSver["SSL_3_0"] = "SSL3.0";
|
|
12
|
+
TLSver["TLS_1_0"] = "TLS1.0";
|
|
13
|
+
TLSver["TLS_1_1"] = "TLS1.1";
|
|
14
|
+
TLSver["TLS_1_2"] = "TLS1.2";
|
|
15
|
+
TLSver["TLS_1_3"] = "TLS1.3";
|
|
16
|
+
})(TLSver || (TLSver = {}));
|
|
17
|
+
class TLS_Heartbeat extends BaseHeader_1.BaseHeader {
|
|
18
|
+
constructor() {
|
|
19
|
+
super(...arguments);
|
|
20
|
+
this.SCHEMA = {
|
|
21
|
+
type: 'object',
|
|
22
|
+
properties: {
|
|
23
|
+
contentType: {
|
|
24
|
+
type: 'integer',
|
|
25
|
+
label: 'Content Type',
|
|
26
|
+
minimum: 0,
|
|
27
|
+
maximum: 255,
|
|
28
|
+
decode: () => {
|
|
29
|
+
this.instance.contentType.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(0, 1)));
|
|
30
|
+
},
|
|
31
|
+
encode: () => {
|
|
32
|
+
const contentType = this.instance.contentType.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
33
|
+
this.writeBytes(0, (0, NumberToBuffer_1.UInt8ToBuffer)(contentType));
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
version: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
label: 'Version',
|
|
39
|
+
minimum: 0,
|
|
40
|
+
maximum: 65535,
|
|
41
|
+
decode: () => {
|
|
42
|
+
const version = (0, BufferToNumber_1.BufferToUInt16)(this.readBytes(1, 2));
|
|
43
|
+
switch (version) {
|
|
44
|
+
case 768:
|
|
45
|
+
{
|
|
46
|
+
this.instance.version.setValue(TLSver.SSL_3_0);
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
case 769:
|
|
50
|
+
{
|
|
51
|
+
this.instance.version.setValue(TLSver.TLS_1_0);
|
|
52
|
+
}
|
|
53
|
+
break;
|
|
54
|
+
case 770:
|
|
55
|
+
{
|
|
56
|
+
this.instance.version.setValue(TLSver.TLS_1_1);
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
59
|
+
case 771:
|
|
60
|
+
{
|
|
61
|
+
this.instance.version.setValue(TLSver.TLS_1_2);
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
case 772:
|
|
65
|
+
{
|
|
66
|
+
this.instance.version.setValue(TLSver.TLS_1_3);
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
default: {
|
|
70
|
+
this.instance.version.setValue(0);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
encode: () => {
|
|
75
|
+
const version = this.instance.version.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
76
|
+
switch (version) {
|
|
77
|
+
case TLSver.SSL_3_0:
|
|
78
|
+
{
|
|
79
|
+
this.writeBytes(1, (0, NumberToBuffer_1.UInt16ToBuffer)(768));
|
|
80
|
+
}
|
|
81
|
+
break;
|
|
82
|
+
case TLSver.TLS_1_0:
|
|
83
|
+
{
|
|
84
|
+
this.writeBytes(1, (0, NumberToBuffer_1.UInt16ToBuffer)(769));
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
case TLSver.TLS_1_1:
|
|
88
|
+
{
|
|
89
|
+
this.writeBytes(1, (0, NumberToBuffer_1.UInt16ToBuffer)(770));
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
case TLSver.TLS_1_2:
|
|
93
|
+
{
|
|
94
|
+
this.writeBytes(1, (0, NumberToBuffer_1.UInt16ToBuffer)(771));
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
case TLSver.TLS_1_3:
|
|
98
|
+
{
|
|
99
|
+
this.writeBytes(1, (0, NumberToBuffer_1.UInt16ToBuffer)(772));
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
default: {
|
|
103
|
+
this.writeBytes(1, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
length: {
|
|
109
|
+
type: 'integer',
|
|
110
|
+
label: 'Length',
|
|
111
|
+
minimum: 0,
|
|
112
|
+
maximum: 65535,
|
|
113
|
+
decode: () => {
|
|
114
|
+
this.instance.length.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(3, 2)));
|
|
115
|
+
},
|
|
116
|
+
encode: () => {
|
|
117
|
+
const length = this.instance.length.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
118
|
+
this.writeBytes(3, (0, NumberToBuffer_1.UInt16ToBuffer)(length));
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
heartbeatType: {
|
|
122
|
+
type: 'string',
|
|
123
|
+
label: 'Heartbeat Type',
|
|
124
|
+
minimum: 0,
|
|
125
|
+
maximum: 255,
|
|
126
|
+
decode: () => {
|
|
127
|
+
const heartbeatType = (0, BufferToNumber_1.BufferToUInt8)(this.readBytes(5, 1));
|
|
128
|
+
switch (heartbeatType) {
|
|
129
|
+
case 1:
|
|
130
|
+
{
|
|
131
|
+
this.instance.heartbeatType.setValue('HeartbeatRequest');
|
|
132
|
+
}
|
|
133
|
+
break;
|
|
134
|
+
case 2:
|
|
135
|
+
{
|
|
136
|
+
this.instance.heartbeatType.setValue('HeartbeatResponse');
|
|
137
|
+
}
|
|
138
|
+
break;
|
|
139
|
+
default: {
|
|
140
|
+
this.instance.heartbeatType.setValue(heartbeatType);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
encode: () => {
|
|
145
|
+
const heartbeatType = this.instance.heartbeatType.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
146
|
+
switch (heartbeatType) {
|
|
147
|
+
case 'HeartbeatRequest':
|
|
148
|
+
{
|
|
149
|
+
this.writeBytes(5, (0, NumberToBuffer_1.UInt8ToBuffer)(1));
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
case 'HeartbeatResponse':
|
|
153
|
+
{
|
|
154
|
+
this.writeBytes(5, (0, NumberToBuffer_1.UInt8ToBuffer)(2));
|
|
155
|
+
}
|
|
156
|
+
break;
|
|
157
|
+
default: {
|
|
158
|
+
const heartbeatType1 = parseInt(heartbeatType);
|
|
159
|
+
this.writeBytes(5, (0, NumberToBuffer_1.UInt8ToBuffer)(heartbeatType1));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
payloadLength: {
|
|
165
|
+
type: 'integer',
|
|
166
|
+
label: 'Payload Length',
|
|
167
|
+
minimum: 0,
|
|
168
|
+
maximum: 65535,
|
|
169
|
+
decode: () => {
|
|
170
|
+
this.instance.payloadLength.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(6, 2)));
|
|
171
|
+
},
|
|
172
|
+
encode: () => {
|
|
173
|
+
const payloadLength = this.instance.payloadLength.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
174
|
+
this.writeBytes(6, (0, NumberToBuffer_1.UInt16ToBuffer)(payloadLength));
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
payloadMessage: {
|
|
178
|
+
type: 'string',
|
|
179
|
+
label: 'Payload Message',
|
|
180
|
+
decode: () => {
|
|
181
|
+
const payloadLength = this.instance.payloadLength.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
182
|
+
const payloadMessage = (0, BufferToHex_1.BufferToHex)(this.readBytes(8, payloadLength));
|
|
183
|
+
this.instance.payloadMessage.setValue(payloadMessage);
|
|
184
|
+
},
|
|
185
|
+
encode: () => {
|
|
186
|
+
const payloadMessage = this.instance.payloadMessage.getValue('0', (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
187
|
+
this.writeBytes(8, (0, HexToBuffer_1.HexToBuffer)(payloadMessage));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
this.id = 'tls-heartbeat';
|
|
193
|
+
this.name = 'Transport Layer Security(Heartbeat Protocol)';
|
|
194
|
+
this.nickname = 'TLS';
|
|
195
|
+
}
|
|
196
|
+
match() {
|
|
197
|
+
if (!this.prevCodecModule)
|
|
198
|
+
return false;
|
|
199
|
+
if ((0, BufferToHex_1.BufferToHex)(this.readBytes(0, 1)) != '18')
|
|
200
|
+
return false;
|
|
201
|
+
const version = (0, BufferToNumber_1.BufferToUInt16)(this.readBytes(1, 2));
|
|
202
|
+
const validVersions = [768, 769, 770, 771, 772];
|
|
203
|
+
return validVersions.includes(version);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
exports.TLS_Heartbeat = TLS_Heartbeat;
|
|
@@ -56,7 +56,7 @@ class VLAN_802dot1Q extends BaseHeader_1.BaseHeader {
|
|
|
56
56
|
this.instance.etherType.setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(2, 2)));
|
|
57
57
|
},
|
|
58
58
|
encode: () => {
|
|
59
|
-
|
|
59
|
+
const etherType = this.instance.etherType.getValue((0, NumberToHex_1.UInt16ToHex)(0x0000), (nodePath) => this.recordError(nodePath, 'Not Found'));
|
|
60
60
|
const typeBuffer = Buffer.from(etherType, 'hex');
|
|
61
61
|
if (typeBuffer.length < 2)
|
|
62
62
|
typeBuffer.fill(0, 0, 1);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type GeneratePCAPInputPacket = {
|
|
2
|
-
timestamp: number;
|
|
3
2
|
frameBase64Data: string;
|
|
3
|
+
timestamp?: number;
|
|
4
4
|
microsecond?: {
|
|
5
5
|
seconds: number;
|
|
6
6
|
microseconds: number;
|
|
@@ -8,7 +8,7 @@ export type GeneratePCAPInputPacket = {
|
|
|
8
8
|
};
|
|
9
9
|
export type GeneratePCAPPacket = {
|
|
10
10
|
buffer: Buffer;
|
|
11
|
-
timestamp
|
|
11
|
+
timestamp?: number;
|
|
12
12
|
microsecond?: {
|
|
13
13
|
seconds: number;
|
|
14
14
|
microseconds: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PCAPGenerator.d.ts","sourceRoot":"","sources":["../../../src/lib/pcap/PCAPGenerator.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,uBAAuB,GAAG;IAClC,
|
|
1
|
+
{"version":3,"file":"PCAPGenerator.d.ts","sourceRoot":"","sources":["../../../src/lib/pcap/PCAPGenerator.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,uBAAuB,GAAG;IAClC,eAAe,EAAE,MAAM,CAAA;IACvB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE;QACV,OAAO,EAAE,MAAM,CAAA;QACf,YAAY,EAAE,MAAM,CAAA;KACvB,CAAA;CACJ,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE;QACV,OAAO,EAAE,MAAM,CAAA;QACf,YAAY,EAAE,MAAM,CAAA;KACvB,CAAA;CACJ,CAAA;AAyCD;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAU3C;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM,CAyBnE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,uBAAuB,EAAO,GAAG,MAAM,CAM5E"}
|
|
@@ -68,7 +68,13 @@ function GeneratePCAPData(packet) {
|
|
|
68
68
|
microseconds = packet.microsecond.microseconds;
|
|
69
69
|
}
|
|
70
70
|
else {
|
|
71
|
-
|
|
71
|
+
if (packet.timestamp) {
|
|
72
|
+
[seconds, microseconds] = convertMillisecond2Microsecond(packet.timestamp);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
seconds = 0;
|
|
76
|
+
microseconds = 0;
|
|
77
|
+
}
|
|
72
78
|
}
|
|
73
79
|
packetHeader.writeUInt32BE(seconds, 0); // 4
|
|
74
80
|
if (packet.microsecond) {
|
package/package.json
CHANGED
package/src/PcapExports.ts
CHANGED
|
@@ -14,3 +14,19 @@ export {PcapParser} from './lib/pcap/PcapParser'
|
|
|
14
14
|
* Types
|
|
15
15
|
*/
|
|
16
16
|
export {type IPcapPacketInfo} from './lib/pcap/interfaces/IPcapPacketInfo'
|
|
17
|
+
export type {GeneratePCAPInputPacket, GeneratePCAPPacket} from './lib/pcap/PCAPGenerator'
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Generate PCAP header
|
|
21
|
+
*/
|
|
22
|
+
export {GeneratePCAPHeader} from './lib/pcap/PCAPGenerator'
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Generate PCAP Data
|
|
26
|
+
*/
|
|
27
|
+
export {GeneratePCAPData} from './lib/pcap/PCAPGenerator'
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Generate PCAP file with full data
|
|
31
|
+
*/
|
|
32
|
+
export {GeneratePCAP} from './lib/pcap/PCAPGenerator'
|
package/src/lib/codec/Codec.ts
CHANGED
|
@@ -104,7 +104,7 @@ export class Codec {
|
|
|
104
104
|
* @private
|
|
105
105
|
*/
|
|
106
106
|
async #decode(codecData: CodecData, codecModules: CodecModule[] = []): Promise<void> {
|
|
107
|
-
const codecModuleConstructor: CodecModuleConstructor | undefined = this.HEADER_CODECS.find((codecModuleConstructor: CodecModuleConstructor): boolean => codecModuleConstructor.MATCH(codecModules))
|
|
107
|
+
const codecModuleConstructor: CodecModuleConstructor | undefined = this.HEADER_CODECS.find((codecModuleConstructor: CodecModuleConstructor): boolean => codecModuleConstructor.MATCH(codecData, codecModules))
|
|
108
108
|
//This unavailable error should not be thrown, the raw data codec will always match unknown data successfully
|
|
109
109
|
if (!codecModuleConstructor) throw new NoAvailableCodecError('No available codec constructor')
|
|
110
110
|
const codecModule: CodecModule = codecModuleConstructor.CREATE_INSTANCE(codecData, codecModules)
|
|
@@ -11,3 +11,10 @@ export {RawData} from './headers/RawData'
|
|
|
11
11
|
export {TCP} from './headers/TCP'
|
|
12
12
|
export {UDP} from './headers/UDP'
|
|
13
13
|
export {VLAN_802dot1Q} from './headers/VLAN_802dot1Q'
|
|
14
|
+
//阿才写的代码
|
|
15
|
+
export {TLS_Alert} from './headers/TLS_Alert'
|
|
16
|
+
export {TLS_ApplicationData} from './headers/TLS_ApplicationData'
|
|
17
|
+
export {TLS_ChangeCipherSpec} from './headers/TLS_ChangeCipherSpec'
|
|
18
|
+
export {TLS_Handshake} from './headers/TLS_Handshake'
|
|
19
|
+
export {TLS_Heartbeat} from './headers/TLS_Heartbeat'
|
|
20
|
+
//阿才写的代码
|
|
@@ -18,8 +18,8 @@ export abstract class BaseHeader {
|
|
|
18
18
|
return new (this as any)()
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
protected static CREATE_CODEC_INSTANCE_WITCH_CODEC_MODULES(codecModules: CodecModule[]): CodecModule {
|
|
22
|
-
return
|
|
21
|
+
protected static CREATE_CODEC_INSTANCE_WITCH_CODEC_MODULES(codecData: CodecData, codecModules: CodecModule[]): CodecModule {
|
|
22
|
+
return this.CREATE_INSTANCE(codecData, codecModules)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
public static get PROTOCOL_ID(): string {
|
|
@@ -47,8 +47,8 @@ export abstract class BaseHeader {
|
|
|
47
47
|
return schema
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
public static MATCH(codecModules: CodecModule[]): boolean {
|
|
51
|
-
return this.CREATE_CODEC_INSTANCE_WITCH_CODEC_MODULES(codecModules ? codecModules : []).match()
|
|
50
|
+
public static MATCH(codecData: CodecData, codecModules: CodecModule[]): boolean {
|
|
51
|
+
return this.CREATE_CODEC_INSTANCE_WITCH_CODEC_MODULES(codecData, codecModules ? codecModules : []).match()
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
public static CREATE_INSTANCE(codecData: CodecData, codecModules: CodecModule[]): CodecModule {
|
|
@@ -56,7 +56,7 @@ export class EthernetII extends BaseHeader {
|
|
|
56
56
|
this.instance.etherType.setValue(this.readBytes(12, 2).toString('hex').padStart(4, '0'))
|
|
57
57
|
},
|
|
58
58
|
encode: (): void => {
|
|
59
|
-
|
|
59
|
+
const etherType: string = this.instance.etherType.getValue(UInt16ToHex(0x0000), (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
|
|
60
60
|
const typeBuffer: Buffer = Buffer.from(etherType, 'hex')
|
|
61
61
|
if (typeBuffer.length < 2) typeBuffer.fill(0, 0, 1)
|
|
62
62
|
this.writeBytes(12, typeBuffer.subarray(0, 2))
|
|
@@ -99,7 +99,7 @@ export class Goose extends BaseHeader {
|
|
|
99
99
|
this.instance.reserved1.reserved.setValue(this.readBits(4, 2, 1, 16))
|
|
100
100
|
},
|
|
101
101
|
encode: (): void => {
|
|
102
|
-
|
|
102
|
+
const reserved: number = this.instance.reserved1.reserved.getValue(0)
|
|
103
103
|
this.writeBits(4, 2, 1, 16, reserved)
|
|
104
104
|
}
|
|
105
105
|
}
|
|
@@ -312,7 +312,7 @@ export class Goose extends BaseHeader {
|
|
|
312
312
|
this.instance.goosePdu.simulation.setValue(!!simulationNum)
|
|
313
313
|
},
|
|
314
314
|
encode: (): void => {
|
|
315
|
-
|
|
315
|
+
const simulationValue: boolean | undefined = this.instance.goosePdu.simulation.getValue(undefined, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
|
|
316
316
|
if (simulationValue === undefined) return
|
|
317
317
|
const simulationNum: number = simulationValue ? 1 : 0
|
|
318
318
|
const simulationTLV: TLV = new TLV(0x87, Buffer.from(simulationNum.toString(16).padStart(2, '0'), 'hex'))
|
|
@@ -349,7 +349,7 @@ export class Goose extends BaseHeader {
|
|
|
349
349
|
this.instance.goosePdu.ndsCom.setValue(!!ndsComNum)
|
|
350
350
|
},
|
|
351
351
|
encode: (): void => {
|
|
352
|
-
|
|
352
|
+
const ndsComValue: boolean | undefined = this.instance.goosePdu.ndsCom.getValue(undefined, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
|
|
353
353
|
if (ndsComValue === undefined) return
|
|
354
354
|
const ndsComNum: number = ndsComValue ? 1 : 0
|
|
355
355
|
const ndsComTLV: TLV = new TLV(0x89, Buffer.from(ndsComNum.toString(16).padStart(2, '0'), 'hex'))
|
|
@@ -365,7 +365,7 @@ export class Goose extends BaseHeader {
|
|
|
365
365
|
this.instance.goosePdu.numDatSetEntries.setValue(parseInt(numDatSetEntriesStr, 16))
|
|
366
366
|
},
|
|
367
367
|
encode: (): void => {
|
|
368
|
-
|
|
368
|
+
const numDatSetEntriesValue: number | undefined = this.instance.goosePdu.numDatSetEntries.getValue(undefined, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
|
|
369
369
|
if (numDatSetEntriesValue === undefined) return
|
|
370
370
|
const numDatSetEntriesTLV: TLV = new TLV(0x8A, UInt32ToBERBuffer(numDatSetEntriesValue))
|
|
371
371
|
this.TLVChild.push(numDatSetEntriesTLV)
|
|
@@ -569,7 +569,7 @@ export class Goose extends BaseHeader {
|
|
|
569
569
|
return new TLV(0x85, Buffer.from(Int32ToBERHex(intValue).padStart(5 * 2, '0'), 'hex'))
|
|
570
570
|
}
|
|
571
571
|
case'INT64': {
|
|
572
|
-
|
|
572
|
+
const intValue: bigint = BigInt(dataItem.value)
|
|
573
573
|
if (intValue < BigInt('-9223372036854775808') || intValue > BigInt('9223372036854775807')) this.recordError(errorNodePath, 'Invalid INT64 value')
|
|
574
574
|
return new TLV(0x85, Buffer.from(Int64ToBERHex(intValue).padStart(9 * 2, '0'), 'hex'))
|
|
575
575
|
}
|
|
@@ -124,7 +124,7 @@ export class IEC61850SampledValues extends BaseHeader {
|
|
|
124
124
|
let buffer: Buffer = Buffer.from([])
|
|
125
125
|
this.TLVChild.forEach(TLVItem => buffer = Buffer.concat([buffer, TLVItem.bTag, TLVItem.bLength, TLVItem.bValue]))
|
|
126
126
|
const svPduTLV: TLV = new TLV(0x60, buffer)
|
|
127
|
-
|
|
127
|
+
const svPduBuffer: Buffer = Buffer.concat([svPduTLV.bTag, svPduTLV.bLength, svPduTLV.bValue])
|
|
128
128
|
this.writeBytes(8, svPduBuffer)
|
|
129
129
|
/**
|
|
130
130
|
* Update the length only if it is not set
|
|
@@ -21,7 +21,7 @@ export class IPv4 extends BaseHeader {
|
|
|
21
21
|
const header: Uint8Array = Uint8Array.from(headerBuffer)
|
|
22
22
|
let sum: number = 0
|
|
23
23
|
for (let i: number = 0; i < header.length; i += 2) {
|
|
24
|
-
|
|
24
|
+
const word = (header[i] << 8) + (header[i + 1] || 0)
|
|
25
25
|
sum += word
|
|
26
26
|
}
|
|
27
27
|
while (sum >>> 16) {
|
|
@@ -111,7 +111,7 @@ export class IPv4 extends BaseHeader {
|
|
|
111
111
|
},
|
|
112
112
|
encode: (): void => {
|
|
113
113
|
//This field's real value needs down stream codec invoke recode to fill
|
|
114
|
-
|
|
114
|
+
const length: number = this.instance.length.getValue(0)
|
|
115
115
|
if (length) {
|
|
116
116
|
this.writeBytes(2, UInt16ToBuffer(length))
|
|
117
117
|
} else {
|