netkitty 0.0.30 → 0.0.31

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.
@@ -0,0 +1,97 @@
1
+ import {ProtocolJSONSchema} from '../../schema/ProtocolJSONSchema'
2
+ import {BufferToUInt8} from '../../helper/BufferToNumber'
3
+ import {BufferToHex} from '../../helper/BufferToHex'
4
+ import {HexToBuffer} from '../../helper/HexToBuffer'
5
+ import {BaseHeader} from '../abstracts/BaseHeader'
6
+ import {UInt8ToBuffer} from '../../helper/NumberToBuffer'
7
+
8
+
9
+ export class IEC104_S_Frame extends BaseHeader {
10
+ public SCHEMA: ProtocolJSONSchema = {
11
+ type: 'object',
12
+ properties: {
13
+ startByte: {
14
+ type: 'integer',
15
+ label: 'Start Byte',
16
+ minimum: 0,
17
+ maximum: 255,
18
+ decode: (): void => {
19
+ this.instance.startByte.setValue(BufferToUInt8(this.readBytes(0, 1)))
20
+ },
21
+ encode: (): void => {
22
+ this.writeBytes(0, UInt8ToBuffer(this.instance.startByte.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))))
23
+ }
24
+ },
25
+ apduLength: {
26
+ type: 'integer',
27
+ label: 'APDU Length',
28
+ minimum: 0,
29
+ maximum: 255,
30
+ decode: (): void => {
31
+ this.instance.apduLength.setValue(BufferToUInt8(this.readBytes(1, 1)))
32
+ },
33
+ encode: (): void => {
34
+ this.writeBytes(1, UInt8ToBuffer(this.instance.apduLength.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))))
35
+ }
36
+ },
37
+ controlField: {
38
+ type: 'string',
39
+ label: 'Control Field',
40
+ decode: (): void => {
41
+ this.instance.controlField.setValue(BufferToHex(this.readBytes(2, 4)))
42
+ },
43
+ encode: (): void => {
44
+ this.writeBytes(2, HexToBuffer(this.instance.controlField.getValue('0', (nodePath: string): void => this.recordError(nodePath, 'Not Found'))))
45
+ }
46
+ },
47
+ apciType: {
48
+ type: 'string',
49
+ label: 'APCI Type',
50
+ minimum: 0,
51
+ maximum: 3,
52
+ decode: (): void => {
53
+ const controlType: number = this.readBits(2, 1, 7, 1)
54
+ switch (controlType) {
55
+ case 1: {
56
+ this.instance.apciType.setValue('S-Format')
57
+ }
58
+ break
59
+ default: {
60
+ this.recordError(this.instance.apciType.getPath(), 'Illegal acpiType!')
61
+ this.instance.apciType.setValue(controlType)
62
+ }
63
+ }
64
+ },
65
+ encode: (): void => {
66
+ const controlType: string = this.instance.apciType.getValue('0', (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
67
+ switch (controlType) {
68
+ case 'S-Format': {
69
+ this.writeBits(2, 1, 7, 1, 1)
70
+ }
71
+ break
72
+ default: {
73
+ this.writeBits(2, 1, 7, 1, this.instance.apciType.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found')))
74
+ }
75
+ }
76
+ }
77
+ }
78
+ }
79
+ }
80
+ public id: string = 'IEC104_S_Frame'
81
+ public name: string = 'IEC 60870-5-104'
82
+ public nickname: string = 'iec60870_104'
83
+
84
+ public match(): boolean {
85
+ if (!this.prevCodecModules) return false
86
+ if (BufferToUInt8(this.readBytes(0, 1)) != 104) return false
87
+ const type: number = this.readBits(2, 1, 6, 2)
88
+ switch (type) {
89
+ case 1: {
90
+ return true
91
+ }
92
+ default: {
93
+ return false
94
+ }
95
+ }
96
+ };
97
+ }
@@ -0,0 +1,139 @@
1
+ import {ProtocolJSONSchema} from '../../schema/ProtocolJSONSchema'
2
+ import {BufferToUInt8} from '../../helper/BufferToNumber'
3
+ import {BufferToHex} from '../../helper/BufferToHex'
4
+ import {HexToBuffer} from '../../helper/HexToBuffer'
5
+ import {BaseHeader} from '../abstracts/BaseHeader'
6
+ import {UInt32ToBuffer, UInt8ToBuffer} from '../../helper/NumberToBuffer'
7
+
8
+
9
+ export class IEC104_U_Frame extends BaseHeader {
10
+ public SCHEMA: ProtocolJSONSchema = {
11
+ type: 'object',
12
+ properties: {
13
+ startByte: {
14
+ type: 'integer',
15
+ label: 'Start Byte',
16
+ minimum: 0,
17
+ maximum: 255,
18
+ decode: (): void => {
19
+ this.instance.startByte.setValue(BufferToUInt8(this.readBytes(0, 1)))
20
+ },
21
+ encode: (): void => {
22
+ this.writeBytes(0, UInt8ToBuffer(this.instance.startByte.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))))
23
+ }
24
+ },
25
+ apduLength: {
26
+ type: 'integer',
27
+ label: 'APDU Length',
28
+ minimum: 0,
29
+ maximum: 255,
30
+ decode: (): void => {
31
+ this.instance.apduLength.setValue(BufferToUInt8(this.readBytes(1, 1)))
32
+ },
33
+ encode: (): void => {
34
+ this.writeBytes(1, UInt8ToBuffer(this.instance.apduLength.getValue(0, (nodePath: string): void => this.recordError(nodePath, 'Not Found'))))
35
+ }
36
+ },
37
+ controlField: {
38
+ type: 'string',
39
+ label: 'Control Field',
40
+ decode: (): void => {
41
+ this.instance.controlField.setValue(BufferToHex(this.readBytes(2, 4)))
42
+ },
43
+ encode: (): void => {
44
+ this.writeBytes(2, HexToBuffer(this.instance.controlField.getValue('0', (nodePath: string): void => this.recordError(nodePath, 'Not Found'))))
45
+ }
46
+ },
47
+ apciType: {
48
+ type: 'string',
49
+ label: 'APCI Type',
50
+ minimum: 0,
51
+ maximum: 3,
52
+ decode: (): void => {
53
+ const uframeType: string = BufferToHex(this.readBytes(2, 4))
54
+ switch (uframeType) {
55
+ case '43000000': {
56
+ this.instance.apciType.setValue('U-Format Type:Test Frame Activation')
57
+ }
58
+ break
59
+ case '83000000': {
60
+ this.instance.apciType.setValue('U-Format Type:Test Frame Confirmation')
61
+ }
62
+ break
63
+ case '13000000': {
64
+ this.instance.apciType.setValue('U-Format Type:Stop Data Transfer Activation')
65
+ }
66
+ break
67
+ case '23000000': {
68
+ this.instance.apciType.setValue('U-Format Type:Stop Data Transfer Confirmation')
69
+ }
70
+ break
71
+ case '07000000': {
72
+ this.instance.apciType.setValue('U-Format Type:Start Data Transfer Activation')
73
+ }
74
+ break
75
+ case '0B000000': {
76
+ this.instance.apciType.setValue('U-Format Type:Start Data Transfer Confirmation')
77
+ }
78
+ break
79
+ default: {
80
+ this.recordError(this.instance.apciType.getPath(), 'Illegal acpiType!')
81
+ this.instance.apciType.setValue(uframeType)
82
+ }
83
+ }
84
+ },
85
+ encode: (): void => {
86
+ const controlType: string = this.instance.apciType.getValue('0', (nodePath: string): void => this.recordError(nodePath, 'Not Found'))
87
+ switch (controlType) {
88
+ case 'U-Format Type:Test Frame Activation': {
89
+ this.writeBytes(2, UInt32ToBuffer(1124073472))
90
+ }
91
+ break
92
+ case 'U-Format Type:Test Frame Confirmation': {
93
+ this.writeBytes(2, UInt32ToBuffer(2197815296))
94
+ }
95
+ break
96
+ case 'U-Format Type:Stop Data Transfer Activation': {
97
+ this.writeBytes(2, UInt32ToBuffer(318767104))
98
+ }
99
+ break
100
+ case 'U-Format Type:Stop Data Transfer Confirmation': {
101
+ this.writeBytes(2, UInt32ToBuffer(587202560))
102
+ }
103
+ break
104
+ case 'U-Format Type:Start Data Transfer Activation': {
105
+ this.writeBytes(2, UInt32ToBuffer(117440512))
106
+ }
107
+ break
108
+ case 'U-Format Type:Start Data Transfer Confirmation': {
109
+ this.writeBytes(2, UInt32ToBuffer(184549376))
110
+ }
111
+ break
112
+ default: {
113
+ this.writeBytes(2, HexToBuffer(this.instance.apciType.getValue('0', (nodePath: string): void => this.recordError(nodePath, 'Not Found'))))
114
+ }
115
+ }
116
+ }
117
+ }
118
+
119
+
120
+ }
121
+ }
122
+ public id: string = 'IEC104_U_Frame'
123
+ public name: string = 'IEC 60870-5-104'
124
+ public nickname: string = 'iec60870_104'
125
+
126
+ public match(): boolean {
127
+ if (!this.prevCodecModules) return false
128
+ if (BufferToUInt8(this.readBytes(0, 1)) != 104) return false
129
+ const type: number = this.readBits(2, 1, 6, 2)
130
+ switch (type) {
131
+ case 3: {
132
+ return true
133
+ }
134
+ default: {
135
+ return false
136
+ }
137
+ }
138
+ };
139
+ }
@@ -12,6 +12,7 @@ export class VLAN_802dot1Q extends BaseHeader {
12
12
  minimum: 0,
13
13
  maximum: 7,
14
14
  default: 0,
15
+ label: 'Priority',
15
16
  decode: (): void => {
16
17
  this.instance.priority.setValue(this.readBits(0, 2, 0, 3))
17
18
  },
@@ -23,6 +24,7 @@ export class VLAN_802dot1Q extends BaseHeader {
23
24
  },
24
25
  dei: {
25
26
  type: 'boolean',
27
+ label: 'DEI',
26
28
  decode: (): void => {
27
29
  this.instance.dei.setValue(!!this.readBits(0, 2, 3, 1))
28
30
  },
@@ -36,6 +38,7 @@ export class VLAN_802dot1Q extends BaseHeader {
36
38
  type: 'integer',
37
39
  minimum: 0,
38
40
  maximum: 4095,
41
+ label: 'ID',
39
42
  decode: (): void => {
40
43
  this.instance.id.setValue(this.readBits(0, 2, 4, 12))
41
44
  },
@@ -49,6 +52,7 @@ export class VLAN_802dot1Q extends BaseHeader {
49
52
  type: 'string',
50
53
  minLength: 4,
51
54
  maxLength: 4,
55
+ label: 'EtherType',
52
56
  decode: (): void => {
53
57
  this.instance.etherType.setValue(BufferToHex(this.readBytes(2, 2)))
54
58
  },
@@ -9,9 +9,9 @@ async function DecodeAndEncode(packet: string): Promise<void> {
9
9
  const codec = new Codec()
10
10
  const decodeResult = await codec.decode(packetBuffer)
11
11
  // console.log(JSON.stringify(decodeResult, null, 2))
12
- // for (let i = 0; i < 100000; i++) {
13
- // const encodeResult = await codec.encode(decodeResult)
14
- // }
12
+ for (let i = 0; i < 100000; i++) {
13
+ const encodeResult = await codec.encode(decodeResult)
14
+ }
15
15
  const encodeResult = await codec.encode(decodeResult)
16
16
 
17
17
  // const pw=new PcapWriter({filename:`/Users/alex/Desktop/genPcap${Date.now()}.pcap`})
@@ -53,13 +53,17 @@ async function UDP_Codec(packet: string): Promise<void> {
53
53
  await DecodeAndEncode(packet)
54
54
  }
55
55
 
56
+ async function IEC104(packet: string): Promise<void> {
57
+ await DecodeAndEncode(packet)
58
+ }
59
+
56
60
  (async (): Promise<void> => {
57
- console.time('GOOSE')
61
+ // console.time('GOOSE')
58
62
  // await GOOSE_Codec('AaD0CC93AKD0CC93iLgAAQCRAAAAAGGBhoAaR0VEZXZpY2VGNjUwL0xMTjAkR08kZ2NiMDGBAwCcQIIYR0VEZXZpY2VGNjUwL0xMTjAkR09PU0UxgwtGNjUwX0dPT1NFMYQIOG6780IXKAqFAQGGAQuHAQCIAQGJAQCKAQirIIMBAIQDAwAAgwEAhAMDAACDAQCEAwMAAIMBAIQDAwAA')
59
63
  // await GOOSE_Codec('AQzNAQNVABAAAANVgQAABoi4A1UAlgAAAABhgYuAGlBMMTEwMVBJR08wMS9MTE4wJEdPJGdvY2IwgQInEIIZUEwxMTAxUElHTzAxL0xMTjAkZHNHT09TRYMXUEwxMTAxUElHTzAxL0xMTjAuZ28AA1AAAA///wAApdAQcA==')
60
64
  // await GOOSE_Codec('AQzNARACABQ7WwNyiLgQAgDXAAAAAGGBzIAYUENTMDAyUElHTy9MTE4wJEdPJGdvY2IxgQIBkIIYUENTMDAyUElHTy9MTE4wJGRzR09PU0UxgxhQQ1MwMDJQSUdPL0xMTjAkR08kZ29jYjGECGf88cRG/rQAhQMOWIGGAQCHAQCIAQGJAQCKAQ6rWocFCEScQACHBQg+0OVhhQEChwUIAAAAAIcFCEKSmZqHBQhEu4AAhwUIRLuAAIcFCEScQACHBQg+1P30hQEChwUIAAAAAIcFCEJlmZqHBQhEu4AAhwUIRLuAAA==')
61
- await GOOSE_Codec('AQzNAQH/ABEiM0RVgQCgzIi4EjQAcwAAAABhaYASRGV2MS9MTE4wJEdPJGdjYjAxgQEUghFEZXYxL0xMTjAkRGF0U2V0MYMIR1NfZ2NiMDGECAAAAAAAAAAAhQEAhgEAhwEAiAEBiQEAigEDqxeFAQuiC4MBAYkGESIzRFVmhwUIwEhfww==')
62
- console.timeEnd('GOOSE')
65
+ // await GOOSE_Codec('AQzNAQH/ABEiM0RVgQCgzIi4EjQAcwAAAABhaYASRGV2MS9MTE4wJEdPJGdjYjAxgQEUghFEZXYxL0xMTjAkRGF0U2V0MYMIR1NfZ2NiMDGECAAAAAAAAAAAhQEAhgEAhwEAiAEBiQEAigEDqxeFAQuiC4MBAYkGESIzRFVmhwUIwEhfww==')
66
+ // console.timeEnd('GOOSE')
63
67
  //
64
68
  // console.time('IEC61850SampleValues')
65
69
  // await IEC61850SampleValues_Codec('AQzNBAAByv7A/+5piLpAAQBmAAAAAGBcgAEBolcwVYAENDAwMYICCDaDBAAAAAGFAQKHQAADpBwAAAAAAAAgrAAAAAD//DyAAAAAAAAAAUgAACAAAPOi+AAAAAAAC1wyAAAAAP8BRogAAAAAAABFsgAAIAA=')
@@ -91,5 +95,8 @@ async function UDP_Codec(packet: string): Promise<void> {
91
95
  // await IPv6_Codec('MzMAAAAWxAI6RAAAht1uAAAAACQAAf6AAAAAAAAAxgI6//5EAAD/AgAAAAAAAAAAAAAAAAAWOgAFAgAAAQCPAHDCAAAAAQQAAAD/AgAAAAAAAAAAAAAAAAAC')
92
96
  // console.timeEnd('IPv6')
93
97
 
94
-
98
+ console.time('IEC104')
99
+ // await IEC104('ACIVVgtUABbRAAkFCABFAAHcOlYAAP8GoTAKFGRsChRmAQlktU0AnlnKzdq0t1AYCDQZSAAAaB4IAAQABQQUAAoAAQAAAAACAAAAAAMAAAAABAAAAABoKgoABAAHBBQACgABAAAAAAAAAAIAAAAAAAAAAwAAAAAAAAAEAAAAAAAAAGgiDAAEAAkEFAAKAAEAAAAAAAIAAAAAAAMAAAAAAAQAAAAAAGgiDgAEAAsEFAAKAAEAAAAAAAIAAAAAAAMAAAAAAAQAAAAAAGgqEAAEAA0EFAAKAAEAAAAAAAAAAgAAAAAAAAADAAAAAAAAAAQAAAAAAAAAaDYSAAQAHgQUAAoACwAAADEQFwiEBw0MAAAAMRAXCIQHDQ0AAAAxEBcIhAcNDgAAADEQFwiEBw1oNhQABAAfBBQACgALAAAAMRAXCIQHDQwAAAAxEBcIhAcNDQAAADEQFwiEBw0OAAAAMRAXCIQHDWg6FgAEACAEFAAKAAsAAAAAMRAXCIQHDQwAAAAAMRAXCIQHDQ0AAAAAMRAXCIQHDQ4AAAAAMRAXCIQHDWhGGAAEACEEFAAKAAsAAAAAAAAAMRAXCIQHDQwAAAAAAAAAMRAXCIQHDQ0AAAAAAAAAMRAXCIQHDQ4AAAAAAAAAMRAXCIQHDQ==')
100
+ await IEC104('ACIVVgtUABbRAAkFCABFAABwOlUAAP8Gop0KFGRsChRmAQlktU0AnlmCzdq0t1AYCDQZ9gAAaA4CAAIAZAEHAAoAAAAAFGgaBAACAAEEFAAKAAEAAAACAAAAAwAAAAQAAABoGgYAAgADBBQACgABAAAAAgAAAAMAAAAEAAAA')
101
+ console.timeEnd('IEC104')
95
102
  })()