@netkitty/codec 1.2.1 → 2.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.
Files changed (176) hide show
  1. package/CHANGELOG.md +159 -0
  2. package/README.md +58 -10
  3. package/README.zh-CN.md +52 -9
  4. package/dist/Codec.d.ts +3 -2
  5. package/dist/Codec.js +106 -10
  6. package/dist/abstracts/BaseHeader.d.ts +28 -2
  7. package/dist/abstracts/BaseHeader.js +132 -43
  8. package/dist/errors/CodecSchemaValidateError.d.ts +34 -1
  9. package/dist/errors/CodecSchemaValidateError.js +26 -3
  10. package/dist/headers/ADSAMS.js +2 -0
  11. package/dist/headers/AH.js +1 -0
  12. package/dist/headers/AMQP.js +2 -1
  13. package/dist/headers/ARP.js +16 -10
  14. package/dist/headers/BACnetIP.js +1 -0
  15. package/dist/headers/BGP.js +1 -0
  16. package/dist/headers/Babel.js +2 -1
  17. package/dist/headers/BitTorrent.d.ts +2 -0
  18. package/dist/headers/BitTorrent.js +4 -2
  19. package/dist/headers/C37118.js +1 -0
  20. package/dist/headers/CAPWAP.js +1 -0
  21. package/dist/headers/CDP.js +1 -1
  22. package/dist/headers/CMS.js +2 -2
  23. package/dist/headers/COTP.d.ts +2 -0
  24. package/dist/headers/COTP.js +6 -1
  25. package/dist/headers/CassandraCQL.js +1 -0
  26. package/dist/headers/Codesys.js +1 -0
  27. package/dist/headers/Collectd.js +1 -1
  28. package/dist/headers/DCCP.js +1 -0
  29. package/dist/headers/DHCPFailover.js +1 -0
  30. package/dist/headers/DNS.js +3 -3
  31. package/dist/headers/DTLS.js +1 -0
  32. package/dist/headers/Diameter.js +3 -2
  33. package/dist/headers/EAPOL.js +1 -1
  34. package/dist/headers/EIGRP.js +1 -1
  35. package/dist/headers/ENIP.js +1 -0
  36. package/dist/headers/Elasticsearch.js +1 -0
  37. package/dist/headers/EtherCAT.js +1 -0
  38. package/dist/headers/EthernetII.js +6 -0
  39. package/dist/headers/FTP.js +6 -6
  40. package/dist/headers/Finger.js +3 -3
  41. package/dist/headers/FoundationFieldbusHSE.js +1 -0
  42. package/dist/headers/GELF.js +7 -1
  43. package/dist/headers/GENEVE.js +1 -1
  44. package/dist/headers/GLBP.js +1 -1
  45. package/dist/headers/GTPU.js +1 -0
  46. package/dist/headers/GTPv2C.js +1 -0
  47. package/dist/headers/GitProtocol.js +2 -2
  48. package/dist/headers/Goose.js +20 -8
  49. package/dist/headers/Gopher.js +6 -6
  50. package/dist/headers/HARTIP.js +1 -0
  51. package/dist/headers/HSR.js +2 -0
  52. package/dist/headers/HTTP.js +6 -6
  53. package/dist/headers/HTTP2.js +1 -0
  54. package/dist/headers/ICMP.js +1 -0
  55. package/dist/headers/ICMPv6.js +1 -0
  56. package/dist/headers/IEC104_I_Frame.js +26 -3
  57. package/dist/headers/IEC104_S_Frame.js +7 -2
  58. package/dist/headers/IEC104_U_Frame.js +14 -3
  59. package/dist/headers/IEC61850SampledValues.js +2 -1
  60. package/dist/headers/IGMP.js +1 -0
  61. package/dist/headers/IMAP.js +5 -5
  62. package/dist/headers/IPFIX.js +2 -1
  63. package/dist/headers/IPv4.js +18 -1
  64. package/dist/headers/IPv6.js +1 -0
  65. package/dist/headers/IPv6HopByHopOptions.js +12 -11
  66. package/dist/headers/IRC.js +4 -4
  67. package/dist/headers/ISAKMP.js +2 -1
  68. package/dist/headers/ISCSI.js +2 -0
  69. package/dist/headers/ISIS.js +2 -1
  70. package/dist/headers/ISOSession.d.ts +2 -0
  71. package/dist/headers/ISOSession.js +14 -10
  72. package/dist/headers/Ident.js +8 -8
  73. package/dist/headers/KNXnetIP.js +1 -0
  74. package/dist/headers/Kafka.js +1 -0
  75. package/dist/headers/Kerberos.js +1 -0
  76. package/dist/headers/L2TP.js +2 -2
  77. package/dist/headers/LACP.js +1 -1
  78. package/dist/headers/LDAP.js +2 -3
  79. package/dist/headers/LDP.js +1 -0
  80. package/dist/headers/LLC.d.ts +2 -0
  81. package/dist/headers/LLC.js +2 -0
  82. package/dist/headers/LPD.js +3 -3
  83. package/dist/headers/MGCP.js +7 -7
  84. package/dist/headers/MMS.d.ts +2 -0
  85. package/dist/headers/MMS.js +10 -6
  86. package/dist/headers/MQTT.js +1 -0
  87. package/dist/headers/MQTTSN.js +1 -0
  88. package/dist/headers/MarkerProtocol.js +1 -1
  89. package/dist/headers/Megaco.js +3 -3
  90. package/dist/headers/Memcached.js +3 -2
  91. package/dist/headers/ModbusTCP.js +1 -0
  92. package/dist/headers/ModbusUDP.js +1 -0
  93. package/dist/headers/MongoDB.js +1 -0
  94. package/dist/headers/MySQL.js +1 -0
  95. package/dist/headers/NATS.js +2 -2
  96. package/dist/headers/NBDS.js +1 -0
  97. package/dist/headers/NBSS.js +1 -0
  98. package/dist/headers/NFS.js +1 -0
  99. package/dist/headers/NHRP.js +1 -0
  100. package/dist/headers/NNTP.js +6 -6
  101. package/dist/headers/NetFlowV5.js +1 -0
  102. package/dist/headers/OLSR.js +2 -1
  103. package/dist/headers/OPCUA.js +1 -0
  104. package/dist/headers/OpenFlow.js +1 -0
  105. package/dist/headers/OpenVPN.js +1 -0
  106. package/dist/headers/PCWorx.js +1 -0
  107. package/dist/headers/POP3.js +5 -5
  108. package/dist/headers/PPPoEDiscovery.js +2 -1
  109. package/dist/headers/PPPoESession.js +1 -0
  110. package/dist/headers/PPTP.js +1 -0
  111. package/dist/headers/PTP.js +1 -0
  112. package/dist/headers/PostgreSQL.js +2 -0
  113. package/dist/headers/QUIC.js +2 -0
  114. package/dist/headers/RADIUS.js +1 -0
  115. package/dist/headers/RDP.d.ts +2 -0
  116. package/dist/headers/RDP.js +4 -1
  117. package/dist/headers/RFB.js +4 -4
  118. package/dist/headers/RGoose.js +6 -1
  119. package/dist/headers/RSVP.js +3 -2
  120. package/dist/headers/RTCP.js +1 -0
  121. package/dist/headers/RTP.js +2 -1
  122. package/dist/headers/RTPS.d.ts +2 -0
  123. package/dist/headers/RTPS.js +4 -1
  124. package/dist/headers/RTSP.js +7 -7
  125. package/dist/headers/RawData.js +1 -1
  126. package/dist/headers/Redis.js +4 -4
  127. package/dist/headers/Rlogin.js +5 -5
  128. package/dist/headers/Rsync.js +2 -2
  129. package/dist/headers/S7comm.d.ts +2 -0
  130. package/dist/headers/S7comm.js +5 -1
  131. package/dist/headers/SCTP.js +2 -2
  132. package/dist/headers/SFlow.js +2 -1
  133. package/dist/headers/SIP.js +6 -6
  134. package/dist/headers/SLMP.js +1 -0
  135. package/dist/headers/SLP.js +2 -0
  136. package/dist/headers/SLPv1.js +1 -0
  137. package/dist/headers/SMB1.js +1 -0
  138. package/dist/headers/SMB2.js +1 -0
  139. package/dist/headers/SMPP.js +1 -0
  140. package/dist/headers/SMTP.js +6 -6
  141. package/dist/headers/SNAP.js +18 -5
  142. package/dist/headers/SNMP.js +4 -4
  143. package/dist/headers/SOCKS4.js +11 -5
  144. package/dist/headers/SSDP.js +7 -7
  145. package/dist/headers/SSH.js +5 -4
  146. package/dist/headers/STOMP.js +5 -5
  147. package/dist/headers/STUN.js +2 -0
  148. package/dist/headers/Skinny.js +1 -0
  149. package/dist/headers/StatsD.js +4 -4
  150. package/dist/headers/SunRPC.js +1 -0
  151. package/dist/headers/Syslog.js +2 -2
  152. package/dist/headers/TCP.js +18 -6
  153. package/dist/headers/TLS_Alert.js +23 -11
  154. package/dist/headers/TLS_ApplicationData.js +9 -4
  155. package/dist/headers/TLS_ChangeCipherSpec.js +10 -5
  156. package/dist/headers/TLS_Handshake.js +41 -26
  157. package/dist/headers/TLS_Heartbeat.js +10 -1
  158. package/dist/headers/TPKT.js +3 -1
  159. package/dist/headers/TacacsPlus.js +1 -0
  160. package/dist/headers/Telnet.js +2 -1
  161. package/dist/headers/Teredo.js +2 -2
  162. package/dist/headers/UDP.js +8 -0
  163. package/dist/headers/VLAN_802dot1Q.js +7 -0
  164. package/dist/headers/WCCP.js +1 -0
  165. package/dist/headers/WHOIS.js +3 -3
  166. package/dist/headers/WSDiscovery.js +2 -2
  167. package/dist/headers/XMPP.js +3 -3
  168. package/dist/headers/Zabbix.js +1 -0
  169. package/dist/index.d.ts +3 -3
  170. package/dist/lib/SchemaValidator.d.ts +31 -0
  171. package/dist/lib/SchemaValidator.js +137 -0
  172. package/dist/schema/ProtocolFieldJSONSchema.d.ts +4 -1
  173. package/dist/schema/ProtocolJSONSchema.d.ts +1 -1
  174. package/dist/types/CodecErrorInfo.d.ts +11 -0
  175. package/dist/types/LayerGraph.d.ts +14 -1
  176. package/package.json +2 -2
@@ -136,8 +136,9 @@ class RSVP extends BaseHeader_1.BaseHeader {
136
136
  reserved: this.fieldUInt('reserved', 5, 1, 'Reserved'),
137
137
  length: {
138
138
  type: 'integer',
139
+ autoCalculated: true,
139
140
  label: 'Length',
140
- minimum: 8,
141
+ minimum: 0,
141
142
  maximum: 65535,
142
143
  decode: function () {
143
144
  this.instance.length.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(6, 2)));
@@ -180,7 +181,7 @@ class RSVP extends BaseHeader_1.BaseHeader {
180
181
  items: {
181
182
  type: 'object',
182
183
  properties: {
183
- length: { type: 'integer', label: 'Length', minimum: 0, maximum: 65535 },
184
+ length: { type: 'integer', label: 'Length', autoCalculated: true, minimum: 0, maximum: 65535 },
184
185
  classNum: { type: 'integer', label: 'Class-Num', minimum: 0, maximum: 255 },
185
186
  cType: { type: 'integer', label: 'C-Type', minimum: 0, maximum: 255 },
186
187
  data: { type: 'string', label: 'Data', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX }
@@ -121,6 +121,7 @@ class RTCP extends BaseHeader_1.BaseHeader {
121
121
  packetType: this.fieldUInt('packetType', 1, 1, 'Packet Type'),
122
122
  length: {
123
123
  type: 'integer',
124
+ autoCalculated: true,
124
125
  label: 'Length',
125
126
  minimum: 0,
126
127
  maximum: 65535,
@@ -113,6 +113,7 @@ class RTP extends BaseHeader_1.BaseHeader {
113
113
  //packet may lie), else derived from the CSRC list length; written into byte 0 bits 4-7.
114
114
  csrcCount: {
115
115
  type: 'integer',
116
+ autoCalculated: true,
116
117
  label: 'CSRC Count',
117
118
  minimum: 0,
118
119
  maximum: 15,
@@ -160,7 +161,7 @@ class RTP extends BaseHeader_1.BaseHeader {
160
161
  label: 'Header Extension',
161
162
  properties: {
162
163
  profile: { type: 'integer', label: 'Profile', minimum: 0, maximum: 65535 },
163
- length: { type: 'integer', label: 'Length (32-bit words)', minimum: 0, maximum: 65535 },
164
+ length: { type: 'integer', label: 'Length (32-bit words)', autoCalculated: true, minimum: 0, maximum: 65535 },
164
165
  data: { type: 'string', label: 'Data', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX }
165
166
  }
166
167
  },
@@ -1,4 +1,5 @@
1
1
  import { BaseHeader } from '../abstracts/BaseHeader';
2
+ import { HeuristicParent } from '../types/LayerGraph';
2
3
  import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
3
4
  import { DemuxProducer } from '../types/DemuxProducer';
4
5
  /**
@@ -27,6 +28,7 @@ export declare class RTPS extends BaseHeader {
27
28
  readonly name: string;
28
29
  readonly nickname: string;
29
30
  readonly matchKeys: string[];
31
+ readonly heuristicParents: HeuristicParent[];
30
32
  readonly heuristicFallback: boolean;
31
33
  match(): boolean;
32
34
  readonly demuxProducers: DemuxProducer[];
@@ -33,6 +33,8 @@ class RTPS extends BaseHeader_1.BaseHeader {
33
33
  //No demux keys: RTPS uses dynamically negotiated UDP ports, so it is a content-heuristic child
34
34
  //recognized by its 'RTPS' magic rather than a well-known port.
35
35
  this.matchKeys = [];
36
+ //Editor graph: matched by content, so list it under these parents in allowedNextLayers().
37
+ this.heuristicParents = ['udp'];
36
38
  this.heuristicFallback = true;
37
39
  //A leaf header — submessage bodies are QoS/type-dependent and kept verbatim, decoded later.
38
40
  this.demuxProducers = [];
@@ -52,7 +54,7 @@ class RTPS extends BaseHeader_1.BaseHeader {
52
54
  properties: {
53
55
  //The 4-byte magic 'RTPS' (0x52545053). Kept verbatim so any variant round-trips; it is
54
56
  //also the content signature match() gates on.
55
- magic: this.fieldHex('magic', 0, 4, 'Magic'),
57
+ magic: { ...this.fieldHex('magic', 0, 4, 'Magic'), default: '52545053' },
56
58
  //Protocol version (major.minor), e.g. 0x0201 = RTPS 2.1. Two opaque octets.
57
59
  protocolVersion: this.fieldHex('protocolVersion', 4, 2, 'Protocol Version'),
58
60
  //Vendor ID (OMG-assigned), e.g. 0x0101 = RTI Connext. Two opaque octets.
@@ -84,6 +86,7 @@ class RTPS extends BaseHeader_1.BaseHeader {
84
86
  },
85
87
  submessageLength: {
86
88
  type: 'integer',
89
+ autoCalculated: true,
87
90
  label: 'Submessage Length',
88
91
  minimum: 0,
89
92
  maximum: 65535
@@ -138,13 +138,13 @@ class RTSP extends BaseHeader_1.BaseHeader {
138
138
  //message field above, never read back). isRequest distinguishes a Request-Line from a
139
139
  //Status-Line; method/requestUri are for requests, statusCode/reasonPhrase for responses;
140
140
  //cseq is RTSP's request/response sequence number (one per message).
141
- isRequest: { type: 'boolean', label: 'Is Request' },
142
- method: { type: 'string', label: 'Method' },
143
- requestUri: { type: 'string', label: 'Request URI' },
144
- version: { type: 'string', label: 'Version' },
145
- statusCode: { type: 'integer', label: 'Status Code', minimum: 0, maximum: 999 },
146
- reasonPhrase: { type: 'string', label: 'Reason Phrase' },
147
- cseq: { type: 'integer', label: 'CSeq', minimum: 0 }
141
+ isRequest: { type: 'boolean', label: 'Is Request', readOnly: true },
142
+ method: { type: 'string', label: 'Method', readOnly: true },
143
+ requestUri: { type: 'string', label: 'Request URI', readOnly: true },
144
+ version: { type: 'string', label: 'Version', readOnly: true },
145
+ statusCode: { type: 'integer', label: 'Status Code', readOnly: true, minimum: 0, maximum: 999 },
146
+ reasonPhrase: { type: 'string', label: 'Reason Phrase', readOnly: true },
147
+ cseq: { type: 'integer', label: 'CSeq', readOnly: true, minimum: 0 }
148
148
  }
149
149
  };
150
150
  }
@@ -26,7 +26,7 @@ class RawData extends BaseHeader_1.BaseHeader {
26
26
  this.instance.data.setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(0, dataLength)));
27
27
  },
28
28
  encode: () => {
29
- this.writeBytes(0, Buffer.from(this.instance.data.getValue().toString(), 'hex'));
29
+ this.writeBytes(0, Buffer.from(this.instance.data.getValue('').toString(), 'hex'));
30
30
  }
31
31
  }
32
32
  }
@@ -162,10 +162,10 @@ class Redis extends BaseHeader_1.BaseHeader {
162
162
  //never read back). respType names the leading type byte; isRequest flags the `*` array shape
163
163
  //that client commands use; command is the array's first bulk string (the verb); preview is the
164
164
  //first line as latin1 text.
165
- respType: { type: 'string', label: 'RESP Type' },
166
- isRequest: { type: 'boolean', label: 'Is Request' },
167
- command: { type: 'string', label: 'Command' },
168
- preview: { type: 'string', label: 'Preview' }
165
+ respType: { type: 'string', label: 'RESP Type', readOnly: true },
166
+ isRequest: { type: 'boolean', label: 'Is Request', readOnly: true },
167
+ command: { type: 'string', label: 'Command', readOnly: true },
168
+ preview: { type: 'string', label: 'Preview', readOnly: true }
169
169
  }
170
170
  };
171
171
  }
@@ -92,12 +92,12 @@ class Rlogin extends BaseHeader_1.BaseHeader {
92
92
  //Display-only metadata parsed from the startup message on decode (no encode — populated by
93
93
  //the `message` field below, never read back). isStartup flags a payload that opens with a
94
94
  //0x00 byte; clientUser/serverUser/terminalType are the leading null-separated fields.
95
- isStartup: { type: 'boolean', label: 'Is Startup', default: false },
96
- clientUser: { type: 'string', label: 'Client User', default: '' },
97
- serverUser: { type: 'string', label: 'Server User', default: '' },
98
- terminalType: { type: 'string', label: 'Terminal Type', default: '' },
95
+ isStartup: { type: 'boolean', label: 'Is Startup', readOnly: true, default: false },
96
+ clientUser: { type: 'string', label: 'Client User', readOnly: true, default: '' },
97
+ serverUser: { type: 'string', label: 'Server User', readOnly: true, default: '' },
98
+ terminalType: { type: 'string', label: 'Terminal Type', readOnly: true, default: '' },
99
99
  //Drives the one-line summary: "clientUser/serverUser" for a startup, else 'data'.
100
- summaryInfo: { type: 'string', label: 'Summary', hidden: true, default: '' },
100
+ summaryInfo: { type: 'string', label: 'Summary', readOnly: true, hidden: true, default: '' },
101
101
  //The whole raw payload is the single source of truth: decoded verbatim to hex and re-emitted
102
102
  //untouched (byte-perfect for any Rlogin payload). The startup fields are parsed into the
103
103
  //display-only metadata above, which carry no codec of their own.
@@ -99,8 +99,8 @@ class Rsync extends BaseHeader_1.BaseHeader {
99
99
  //Display-only metadata parsed from the first line on decode (no encode — populated by the
100
100
  //message field above, never read back). isGreeting is true only for a `@RSYNCD:` line;
101
101
  //version is the token after `@RSYNCD:` (empty for a binary/non-greeting segment).
102
- isGreeting: { type: 'boolean', label: 'Is Greeting' },
103
- version: { type: 'string', label: 'Version' }
102
+ isGreeting: { type: 'boolean', label: 'Is Greeting', readOnly: true },
103
+ version: { type: 'string', label: 'Version', readOnly: true }
104
104
  }
105
105
  };
106
106
  }
@@ -1,4 +1,5 @@
1
1
  import { BaseHeader } from '../abstracts/BaseHeader';
2
+ import { HeuristicParent } from '../types/LayerGraph';
2
3
  import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
3
4
  import { DemuxProducer } from '../types/DemuxProducer';
4
5
  /**
@@ -30,6 +31,7 @@ export declare class S7comm extends BaseHeader {
30
31
  readonly name: string;
31
32
  readonly nickname: string;
32
33
  readonly matchKeys: string[];
34
+ readonly heuristicParents: HeuristicParent[];
33
35
  readonly heuristicFallback: boolean;
34
36
  match(): boolean;
35
37
  readonly demuxProducers: DemuxProducer[];
@@ -39,6 +39,8 @@ class S7comm extends BaseHeader_1.BaseHeader {
39
39
  //with no matchKeys), selection is by content: heuristicFallback lists it in the heuristic chain and
40
40
  //match() gates on the COTP parent plus the 0x32 signature.
41
41
  this.matchKeys = [];
42
+ //Editor graph: matched by content, so list it under these parents in allowedNextLayers().
43
+ this.heuristicParents = [{ parent: 'cotp', discriminator: { field: 'pduType', value: 0xf0 } }];
42
44
  this.heuristicFallback = true;
43
45
  //A leaf for now — the Parameter/Data sections require per-function, cross-PDU parsing.
44
46
  this.demuxProducers = [];
@@ -79,6 +81,7 @@ class S7comm extends BaseHeader_1.BaseHeader {
79
81
  static #lengthField(name, offset, sectionName, label) {
80
82
  return {
81
83
  type: 'integer',
84
+ autoCalculated: true,
82
85
  label: label,
83
86
  minimum: 0,
84
87
  maximum: 65535,
@@ -111,7 +114,8 @@ class S7comm extends BaseHeader_1.BaseHeader {
111
114
  properties: {
112
115
  //Protocol Id: always 0x32 for S7comm. A plain uint (no enum) so a crafted/off-spec value
113
116
  //still round-trips; the 0x32 signature gates selection in match(), not the schema.
114
- protocolId: this.fieldUInt('protocolId', 0, 1, 'Protocol Id'),
117
+ //Default 0x32: the S7comm Protocol Id, and the signature match() requires.
118
+ protocolId: { ...this.fieldUInt('protocolId', 0, 1, 'Protocol Id'), default: 0x32 },
115
119
  //ROSCTR (message class): 1 Job, 2 Ack, 3 Ack_Data, 7 Userdata. Kept as a plain uint —
116
120
  //an unknown class must still decode and re-encode, so no enum constraint is applied.
117
121
  rosctr: this.fieldUInt('rosctr', 1, 1, 'ROSCTR'),
@@ -84,9 +84,9 @@ class SCTP extends BaseHeader_1.BaseHeader {
84
84
  properties: {
85
85
  type: { type: 'integer', label: 'Chunk Type', minimum: 0, maximum: 255 },
86
86
  flags: { type: 'integer', label: 'Chunk Flags', minimum: 0, maximum: 255 },
87
- length: { type: 'integer', label: 'Chunk Length', minimum: 0, maximum: 65535 },
87
+ length: { type: 'integer', label: 'Chunk Length', autoCalculated: true, minimum: 0, maximum: 65535 },
88
88
  value: { type: 'string', label: 'Value', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX },
89
- padding: { type: 'string', label: 'Padding', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX }
89
+ padding: { type: 'string', label: 'Padding', autoCalculated: true, contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX }
90
90
  }
91
91
  },
92
92
  decode: function () {
@@ -143,6 +143,7 @@ class SFlow extends BaseHeader_1.BaseHeader {
143
143
  }, 'System Uptime'),
144
144
  numSamples: {
145
145
  type: 'integer',
146
+ autoCalculated: true,
146
147
  label: 'Number of Samples',
147
148
  minimum: 0,
148
149
  maximum: 4294967295,
@@ -177,7 +178,7 @@ class SFlow extends BaseHeader_1.BaseHeader {
177
178
  label: 'Sample',
178
179
  properties: {
179
180
  sampleType: { type: 'integer', label: 'Sample Type', minimum: 0, maximum: 4294967295 },
180
- sampleLength: { type: 'integer', label: 'Sample Length', minimum: 0, maximum: 4294967295 },
181
+ sampleLength: { type: 'integer', label: 'Sample Length', autoCalculated: true, minimum: 0, maximum: 4294967295 },
181
182
  sampleData: { type: 'string', label: 'Sample Data', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX }
182
183
  }
183
184
  },
@@ -113,12 +113,12 @@ class SIP extends BaseHeader_1.BaseHeader {
113
113
  //Display-only metadata parsed from the start-line on decode (no encode — populated by the
114
114
  //message field above, never read back). isRequest distinguishes a Request-Line from a
115
115
  //Status-Line; method/requestUri are for requests, statusCode/reasonPhrase for responses.
116
- isRequest: { type: 'boolean', label: 'Is Request' },
117
- method: { type: 'string', label: 'Method' },
118
- requestUri: { type: 'string', label: 'Request URI' },
119
- version: { type: 'string', label: 'Version' },
120
- statusCode: { type: 'integer', label: 'Status Code', minimum: 0, maximum: 999 },
121
- reasonPhrase: { type: 'string', label: 'Reason Phrase' }
116
+ isRequest: { type: 'boolean', label: 'Is Request', readOnly: true },
117
+ method: { type: 'string', label: 'Method', readOnly: true },
118
+ requestUri: { type: 'string', label: 'Request URI', readOnly: true },
119
+ version: { type: 'string', label: 'Version', readOnly: true },
120
+ statusCode: { type: 'integer', label: 'Status Code', readOnly: true, minimum: 0, maximum: 999 },
121
+ reasonPhrase: { type: 'string', label: 'Reason Phrase', readOnly: true }
122
122
  }
123
123
  };
124
124
  }
@@ -90,6 +90,7 @@ class SLMP extends BaseHeader_1.BaseHeader {
90
90
  //may lie); else derived from the encoded `data` length.
91
91
  requestDataLength: {
92
92
  type: 'integer',
93
+ autoCalculated: true,
93
94
  label: 'Request Data Length',
94
95
  minimum: 0,
95
96
  maximum: 65535,
@@ -92,6 +92,7 @@ class SLP extends BaseHeader_1.BaseHeader {
92
92
  functionId: this.fieldUInt('functionId', 1, 1, 'Function-ID'),
93
93
  length: {
94
94
  type: 'integer',
95
+ autoCalculated: true,
95
96
  label: 'Length',
96
97
  minimum: 0,
97
98
  maximum: 16777215,
@@ -124,6 +125,7 @@ class SLP extends BaseHeader_1.BaseHeader {
124
125
  xid: this.fieldUInt('xid', 10, 2, 'XID'),
125
126
  langTagLen: {
126
127
  type: 'integer',
128
+ autoCalculated: true,
127
129
  label: 'Language Tag Length',
128
130
  minimum: 0,
129
131
  maximum: 65535,
@@ -57,6 +57,7 @@ class SLPv1 extends BaseHeader_1.BaseHeader {
57
57
  functionId: this.fieldUInt('functionId', 1, 1, 'Function'),
58
58
  length: {
59
59
  type: 'integer',
60
+ autoCalculated: true,
60
61
  label: 'Length',
61
62
  minimum: 0,
62
63
  maximum: 65535,
@@ -112,6 +112,7 @@ class SMB1 extends BaseHeader_1.BaseHeader {
112
112
  //else derived as 32 + body bytes.
113
113
  streamProtocolLength: {
114
114
  type: 'integer',
115
+ autoCalculated: true,
115
116
  label: 'Stream Protocol Length',
116
117
  minimum: 0,
117
118
  maximum: 16777215,
@@ -110,6 +110,7 @@ class SMB2 extends BaseHeader_1.BaseHeader {
110
110
  //else derived as 64 + body bytes.
111
111
  streamProtocolLength: {
112
112
  type: 'integer',
113
+ autoCalculated: true,
113
114
  label: 'Stream Protocol Length',
114
115
  minimum: 0,
115
116
  maximum: 16777215,
@@ -48,6 +48,7 @@ class SMPP extends BaseHeader_1.BaseHeader {
48
48
  properties: {
49
49
  commandLength: {
50
50
  type: 'integer',
51
+ autoCalculated: true,
51
52
  label: 'Command Length',
52
53
  //minimum 0 (not 16): a crafted/corrupt PDU may carry a command_length below the 16-byte
53
54
  //header, and that value must round-trip (honored verbatim) rather than being rejected by
@@ -125,12 +125,12 @@ class SMTP extends BaseHeader_1.BaseHeader {
125
125
  //message field above, never read back). isReply distinguishes a server reply from a
126
126
  //client command; replyCode/isMultiline/replyText describe a reply, command/argument a
127
127
  //command.
128
- isReply: { type: 'boolean', label: 'Is Reply' },
129
- replyCode: { type: 'integer', label: 'Reply Code', minimum: 0, maximum: 999 },
130
- isMultiline: { type: 'boolean', label: 'Is Multiline' },
131
- replyText: { type: 'string', label: 'Reply Text' },
132
- command: { type: 'string', label: 'Command' },
133
- argument: { type: 'string', label: 'Argument' }
128
+ isReply: { type: 'boolean', label: 'Is Reply', readOnly: true },
129
+ replyCode: { type: 'integer', label: 'Reply Code', readOnly: true, minimum: 0, maximum: 999 },
130
+ isMultiline: { type: 'boolean', label: 'Is Multiline', readOnly: true },
131
+ replyText: { type: 'string', label: 'Reply Text', readOnly: true },
132
+ command: { type: 'string', label: 'Command', readOnly: true },
133
+ argument: { type: 'string', label: 'Argument', readOnly: true }
134
134
  }
135
135
  };
136
136
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SNAP = void 0;
4
4
  const BaseHeader_1 = require("../abstracts/BaseHeader");
5
+ const HexToBuffer_1 = require("../helper/HexToBuffer");
5
6
  /**
6
7
  * SNAP — Sub-Network Access Protocol (IEEE 802.2), the 5-byte header that follows an LLC header whose
7
8
  * DSAP/SSAP are 0xAA. It carries a 3-byte OUI (Organizationally Unique Identifier) and a 2-byte Protocol
@@ -34,14 +35,26 @@ class SNAP extends BaseHeader_1.BaseHeader {
34
35
  type: 'object',
35
36
  summary: 'SNAP oui=${oui} type=${etherType}',
36
37
  properties: {
37
- oui: this.fieldHex('oui', 0, 3, 'OUI'),
38
+ //When oui / etherType are left out they are taken from ouiProtocol — the field the editor
39
+ //graph sets to route a vendor child (snap→cdp is ouiProtocol '00000c2000').
40
+ oui: { ...this.fieldHex('oui', 0, 3, 'OUI'), encode: function () {
41
+ const ouiProtocol = this.instance.ouiProtocol.getValue('');
42
+ const oui = this.instance.oui.getValue(ouiProtocol.length === 10 ? ouiProtocol.substring(0, 6) : '000000');
43
+ this.instance.oui.setValue(oui);
44
+ this.writeBytes(0, (0, HexToBuffer_1.HexToBuffer)(oui));
45
+ } },
38
46
  //Named `etherType` (not `pid`) so the existing ethertype demux + IPv4/ARP/IPv6 match() —
39
47
  //which read the parent's `etherType` field literally — route through SNAP unchanged, exactly
40
48
  //as they do through Ethernet II and 802.1Q.
41
- etherType: this.fieldHex('etherType', 3, 2, 'Protocol Type'),
42
- //Display/demux-only: OUI+PID concatenated, the `snapoui` key for vendor protocols (CDP/VTP
43
- //under Cisco 0x00000C). No encode closure — the bytes are written by oui + etherType, this
44
- //is derived — so it never affects the re-emitted frame.
49
+ etherType: { ...this.fieldHex('etherType', 3, 2, 'Protocol Type'), encode: function () {
50
+ const ouiProtocol = this.instance.ouiProtocol.getValue('');
51
+ const etherType = this.instance.etherType.getValue(ouiProtocol.length === 10 ? ouiProtocol.substring(6, 10) : '0000');
52
+ this.instance.etherType.setValue(etherType);
53
+ this.writeBytes(3, (0, HexToBuffer_1.HexToBuffer)(etherType));
54
+ } },
55
+ //Demux key: OUI+PID concatenated, the `snapoui` key for vendor protocols (CDP/VTP under Cisco
56
+ //0x00000C). No encode closure — the bytes are written by oui + etherType — but it supplies
57
+ //them when they are left out (see oui), so the editor can route a child by setting it.
45
58
  ouiProtocol: {
46
59
  type: 'string',
47
60
  label: 'OUI Protocol',
@@ -164,8 +164,8 @@ class SNMP extends BaseHeader_1.BaseHeader {
164
164
  version: {
165
165
  type: 'integer',
166
166
  label: 'Version',
167
- minimum: 0,
168
- maximum: 3,
167
+ //A BER INTEGER (0 v1, 1 v2c, 3 v3): any decoded value must re-encode, so the bounds
168
+ //are left open (a long INTEGER decodes to a large number), not the defined versions.
169
169
  decode: function () {
170
170
  const available = this.packet.length - this.startPos;
171
171
  if (available <= 0)
@@ -277,8 +277,8 @@ class SNMP extends BaseHeader_1.BaseHeader {
277
277
  //empty for the common request/response PDUs, which use the structured fields below.
278
278
  pduRaw: { type: 'string', label: 'PDU Body', contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX, hidden: true },
279
279
  requestId: { type: 'integer', label: 'Request ID' },
280
- errorStatus: { type: 'integer', label: 'Error Status', minimum: 0 },
281
- errorIndex: { type: 'integer', label: 'Error Index', minimum: 0 },
280
+ errorStatus: { type: 'integer', label: 'Error Status' },
281
+ errorIndex: { type: 'integer', label: 'Error Index' },
282
282
  variableBindings: {
283
283
  type: 'array',
284
284
  label: 'Variable Bindings',
@@ -6,6 +6,7 @@ const BufferToNumber_1 = require("../helper/BufferToNumber");
6
6
  const NumberToBuffer_1 = require("../helper/NumberToBuffer");
7
7
  const BufferToIP_1 = require("../helper/BufferToIP");
8
8
  const IPToBuffer_1 = require("../helper/IPToBuffer");
9
+ const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
9
10
  /**
10
11
  * SOCKS4 — the SOCKS Protocol Version 4 (and the SOCKS4a extension), carried over TCP well-known
11
12
  * port 1080. Only two message shapes travel on the wire, discriminated by their leading octet:
@@ -62,6 +63,11 @@ class SOCKS4 extends BaseHeader_1.BaseHeader {
62
63
  #isRequest() {
63
64
  return this.instance.messageType.getValue('request') === 'request';
64
65
  }
66
+ /** True for a SOCKS4a request: dstIp is 0.0.0.x with x != 0, so a domain follows the user-id. */
67
+ #isSocks4a() {
68
+ const octets = this.instance.dstIp.getValue('').split('.');
69
+ return octets.length === 4 && octets[0] === '0' && octets[1] === '0' && octets[2] === '0' && octets[3] !== '0';
70
+ }
65
71
  /**
66
72
  * Read a null-terminated latin1 string at `offset` (bounded by the captured length); returns its
67
73
  * value plus the offset one past the terminator (or the end of buffer if never terminated).
@@ -133,7 +139,6 @@ class SOCKS4 extends BaseHeader_1.BaseHeader {
133
139
  command: {
134
140
  type: 'integer',
135
141
  label: 'Command',
136
- enum: [1, 2],
137
142
  minimum: 0,
138
143
  maximum: 255,
139
144
  default: 1,
@@ -166,7 +171,6 @@ class SOCKS4 extends BaseHeader_1.BaseHeader {
166
171
  status: {
167
172
  type: 'integer',
168
173
  label: 'Status',
169
- enum: [0x5a, 0x5b, 0x5c, 0x5d],
170
174
  minimum: 0,
171
175
  maximum: 255,
172
176
  default: 0x5a,
@@ -227,6 +231,7 @@ class SOCKS4 extends BaseHeader_1.BaseHeader {
227
231
  type: 'string',
228
232
  label: 'Destination IP',
229
233
  default: '0.0.0.0',
234
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.IPv4,
230
235
  decode: function () {
231
236
  this.instance.dstIp.setValue(this.#payloadLength() >= 8 ? (0, BufferToIP_1.BufferToIPv4)(this.readBytes(4, 4)) : '0.0.0.0');
232
237
  },
@@ -256,14 +261,15 @@ class SOCKS4 extends BaseHeader_1.BaseHeader {
256
261
  }
257
262
  },
258
263
  //REQUEST shape (SOCKS4a): the null-terminated destination domain that follows the
259
- //user-id when the client could not resolve the host (dstIp 0.0.0.x). Structured
260
- //whenever bytes remain after the user-id terminator, so SOCKS4a round-trips exactly.
264
+ //user-id when the client could not resolve the host (dstIp 0.0.0.x, x != 0). Only
265
+ //decoded for such a SOCKS4a request, so bytes trailing a plain SOCKS4 request (e.g.
266
+ //padding) fall to raw instead of being misread as a domain; SOCKS4a round-trips exactly.
261
267
  domain: {
262
268
  type: 'string',
263
269
  label: 'Domain',
264
270
  default: '',
265
271
  decode: function () {
266
- if (!this.#isRequest()) {
272
+ if (!this.#isRequest() || !this.#isSocks4a()) {
267
273
  this.instance.domain.setValue('');
268
274
  return;
269
275
  }
@@ -124,15 +124,15 @@ class SSDP extends BaseHeader_1.BaseHeader {
124
124
  //Display-only metadata parsed from the start-line on decode (no encode — populated by the
125
125
  //message field above, never read back). isRequest distinguishes a Request-Line from a
126
126
  //Status-Line; method/requestUri are for requests, statusCode/reasonPhrase for responses.
127
- isRequest: { type: 'boolean', label: 'Is Request' },
127
+ isRequest: { type: 'boolean', label: 'Is Request', readOnly: true },
128
128
  //Display-only Info-column text ("M-SEARCH *" / "200 OK"), set on decode; no encode, so it
129
129
  //never affects the re-emitted bytes.
130
- info: { type: 'string', label: 'Info' },
131
- method: { type: 'string', label: 'Method' },
132
- requestUri: { type: 'string', label: 'Request URI' },
133
- version: { type: 'string', label: 'Version' },
134
- statusCode: { type: 'integer', label: 'Status Code', minimum: 0, maximum: 999 },
135
- reasonPhrase: { type: 'string', label: 'Reason Phrase' }
130
+ info: { type: 'string', label: 'Info', readOnly: true },
131
+ method: { type: 'string', label: 'Method', readOnly: true },
132
+ requestUri: { type: 'string', label: 'Request URI', readOnly: true },
133
+ version: { type: 'string', label: 'Version', readOnly: true },
134
+ statusCode: { type: 'integer', label: 'Status Code', readOnly: true, minimum: 0, maximum: 999 },
135
+ reasonPhrase: { type: 'string', label: 'Reason Phrase', readOnly: true }
136
136
  }
137
137
  };
138
138
  }
@@ -109,11 +109,11 @@ class SSH extends BaseHeader_1.BaseHeader {
109
109
  },
110
110
  //Display-only metadata parsed from the identification line on decode (no encode —
111
111
  //populated by `message` below for the identification shape, empty for a binary packet).
112
- protoVersion: { type: 'string', label: 'Protocol Version', default: '' },
113
- softwareVersion: { type: 'string', label: 'Software Version', default: '' },
114
- identString: { type: 'string', label: 'Identification String', default: '' },
112
+ protoVersion: { type: 'string', label: 'Protocol Version', readOnly: true, default: '' },
113
+ softwareVersion: { type: 'string', label: 'Software Version', readOnly: true, default: '' },
114
+ identString: { type: 'string', label: 'Identification String', readOnly: true, default: '' },
115
115
  //Drives the one-line summary: the software version for an identification, else 'packet'.
116
- summaryInfo: { type: 'string', label: 'Summary', hidden: true, default: '' },
116
+ summaryInfo: { type: 'string', label: 'Summary', readOnly: true, hidden: true, default: '' },
117
117
  //IDENTIFICATION shape: the whole line kept verbatim (byte-perfect) and re-emitted
118
118
  //untouched. The display metadata above is parsed from it on decode; encode never
119
119
  //reconstructs the line from that metadata.
@@ -148,6 +148,7 @@ class SSH extends BaseHeader_1.BaseHeader {
148
148
  //whole message spans packet_length + 4 bytes. Big-endian (unlike ENIP's CIP order).
149
149
  packetLength: {
150
150
  type: 'integer',
151
+ autoCalculated: true,
151
152
  label: 'Packet Length',
152
153
  minimum: 0,
153
154
  maximum: 4294967295,
@@ -124,12 +124,12 @@ class STOMP extends BaseHeader_1.BaseHeader {
124
124
  //`message` field below, never read back). command is the frame's COMMAND line;
125
125
  //destination/content-type/content-length are the common headers, present when the frame
126
126
  //carries them.
127
- command: { type: 'string', label: 'Command', default: '' },
128
- destination: { type: 'string', label: 'Destination', default: '' },
129
- contentType: { type: 'string', label: 'Content Type', default: '' },
130
- contentLength: { type: 'integer', label: 'Content Length', minimum: 0, default: 0 },
127
+ command: { type: 'string', label: 'Command', readOnly: true, default: '' },
128
+ destination: { type: 'string', label: 'Destination', readOnly: true, default: '' },
129
+ contentType: { type: 'string', label: 'Content Type', readOnly: true, default: '' },
130
+ contentLength: { type: 'integer', label: 'Content Length', readOnly: true, minimum: 0, default: 0 },
131
131
  //Drives the one-line summary (COMMAND + destination when present).
132
- summaryInfo: { type: 'string', label: 'Summary', hidden: true, default: '' },
132
+ summaryInfo: { type: 'string', label: 'Summary', readOnly: true, hidden: true, default: '' },
133
133
  //The whole raw payload is the single source of truth: decoded verbatim to hex and
134
134
  //re-emitted untouched (byte-perfect for any STOMP frame). The COMMAND line and common
135
135
  //headers are parsed into the display-only metadata above, which carry no codec of their own.
@@ -48,6 +48,7 @@ class STUN extends BaseHeader_1.BaseHeader {
48
48
  //from the encoded attributes after they are written.
49
49
  messageLength: {
50
50
  type: 'integer',
51
+ autoCalculated: true,
51
52
  label: 'Message Length',
52
53
  minimum: 0,
53
54
  maximum: 65535,
@@ -90,6 +91,7 @@ class STUN extends BaseHeader_1.BaseHeader {
90
91
  },
91
92
  value: {
92
93
  type: 'string',
94
+ byteAlignment: 4,
93
95
  label: 'Value',
94
96
  contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX
95
97
  },
@@ -73,6 +73,7 @@ class Skinny extends BaseHeader_1.BaseHeader {
73
73
  //All multi-byte Skinny fields are LITTLE-ENDIAN.
74
74
  dataLength: {
75
75
  type: 'integer',
76
+ autoCalculated: true,
76
77
  label: 'Data Length',
77
78
  minimum: 0,
78
79
  maximum: 4294967295,
@@ -108,10 +108,10 @@ class StatsD extends BaseHeader_1.BaseHeader {
108
108
  },
109
109
  //Display-only metadata parsed from the first metric line on decode (no encode — populated
110
110
  //by the message field above, never read back). sampleRate is empty when absent.
111
- metricName: { type: 'string', label: 'Metric Name' },
112
- metricValue: { type: 'string', label: 'Metric Value' },
113
- metricType: { type: 'string', label: 'Metric Type' },
114
- sampleRate: { type: 'string', label: 'Sample Rate' }
111
+ metricName: { type: 'string', label: 'Metric Name', readOnly: true },
112
+ metricValue: { type: 'string', label: 'Metric Value', readOnly: true },
113
+ metricType: { type: 'string', label: 'Metric Type', readOnly: true },
114
+ sampleRate: { type: 'string', label: 'Sample Rate', readOnly: true }
115
115
  }
116
116
  };
117
117
  }
@@ -133,6 +133,7 @@ class SunRPC extends BaseHeader_1.BaseHeader {
133
133
  },
134
134
  fragmentLength: {
135
135
  type: 'integer',
136
+ autoCalculated: true,
136
137
  label: 'Fragment Length',
137
138
  minimum: 0,
138
139
  maximum: 2147483647,
@@ -78,8 +78,8 @@ class Syslog extends BaseHeader_1.BaseHeader {
78
78
  },
79
79
  //Derived from PRI (display only; encode reconstructs PRI, not these): facility = PRI>>3,
80
80
  //severity = PRI&7.
81
- facility: { type: 'integer', label: 'Facility', minimum: 0, maximum: 23 },
82
- severity: { type: 'integer', label: 'Severity', minimum: 0, maximum: 7 },
81
+ facility: { type: 'integer', label: 'Facility', readOnly: true, minimum: 0, maximum: 23 },
82
+ severity: { type: 'integer', label: 'Severity', readOnly: true, minimum: 0, maximum: 7 },
83
83
  message: { type: 'string', label: 'Message' }
84
84
  }
85
85
  };