cyberchef 9.37.3 → 9.38.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -2
- package/Gruntfile.js +2 -1
- package/package.json +4 -2
- package/src/core/config/Categories.json +1 -0
- package/src/core/config/OperationConfig.json +30 -2
- package/src/core/config/modules/Default.mjs +2 -0
- package/src/core/config/scripts/newMinorVersion.mjs +144 -0
- package/src/core/lib/Binary.mjs +9 -5
- package/src/core/lib/FileSignatures.mjs +12 -12
- package/src/core/lib/Protocol.mjs +47 -0
- package/src/core/lib/Stream.mjs +22 -12
- package/src/core/operations/ParseTCP.mjs +245 -0
- package/src/core/operations/ParseUDP.mjs +29 -24
- package/src/core/operations/Substitute.mjs +5 -5
- package/src/core/operations/ToBase45.mjs +4 -0
- package/src/core/operations/ToHex.mjs +2 -2
- package/src/core/operations/index.mjs +2 -0
- package/src/node/index.mjs +5 -0
- package/src/web/App.mjs +10 -5
- package/src/web/html/index.html +12 -10
- package/src/web/stylesheets/components/_pane.css +11 -4
- package/src/web/stylesheets/layout/_controls.css +4 -0
- package/src/web/stylesheets/layout/_io.css +1 -2
- package/src/web/stylesheets/layout/_structure.css +2 -2
- package/src/web/waiters/OperationsWaiter.mjs +5 -1
- package/src/web/waiters/OutputWaiter.mjs +2 -0
- package/src/web/waiters/WindowWaiter.mjs +2 -2
- package/tests/operations/index.mjs +1 -0
- package/tests/operations/tests/ParseTCP.mjs +44 -0
- package/tests/operations/tests/ParseUDP.mjs +5 -18
- package/webpack.config.js +11 -0
package/CHANGELOG.md
CHANGED
|
@@ -13,6 +13,9 @@ All major and minor version changes will be documented in this file. Details of
|
|
|
13
13
|
|
|
14
14
|
## Details
|
|
15
15
|
|
|
16
|
+
### [9.38.0] - 2022-05-30
|
|
17
|
+
- Added 'Parse TCP' operation [@n1474335] | [a895d1d]
|
|
18
|
+
|
|
16
19
|
### [9.37.0] - 2022-03-29
|
|
17
20
|
- 'SM4 Encrypt' and 'SM4 Decrypt' operations added [@swesven] | [#1189]
|
|
18
21
|
- NoPadding options added for CBC and ECB modes in AES, DES and Triple DES Decrypt operations [@swesven] | [#1189]
|
|
@@ -135,7 +138,7 @@ All major and minor version changes will be documented in this file. Details of
|
|
|
135
138
|
|
|
136
139
|
<details>
|
|
137
140
|
<summary>Click to expand v8 minor versions</summary>
|
|
138
|
-
|
|
141
|
+
|
|
139
142
|
### [8.38.0] - 2019-07-03
|
|
140
143
|
- 'Streebog' and 'GOST hash' operations added [@MShwed] [@n1474335] | [#530]
|
|
141
144
|
|
|
@@ -288,6 +291,7 @@ All major and minor version changes will be documented in this file. Details of
|
|
|
288
291
|
|
|
289
292
|
|
|
290
293
|
|
|
294
|
+
[9.38.0]: https://github.com/gchq/CyberChef/releases/tag/v9.38.0
|
|
291
295
|
[9.37.0]: https://github.com/gchq/CyberChef/releases/tag/v9.37.0
|
|
292
296
|
[9.36.0]: https://github.com/gchq/CyberChef/releases/tag/v9.36.0
|
|
293
297
|
[9.35.0]: https://github.com/gchq/CyberChef/releases/tag/v9.35.0
|
|
@@ -416,6 +420,7 @@ All major and minor version changes will be documented in this file. Details of
|
|
|
416
420
|
[289a417]: https://github.com/gchq/CyberChef/commit/289a417dfb5923de5e1694354ec42a08d9395bfe
|
|
417
421
|
[e9ca4dc]: https://github.com/gchq/CyberChef/commit/e9ca4dc9caf98f33fd986431cd400c88082a42b8
|
|
418
422
|
[dd18e52]: https://github.com/gchq/CyberChef/commit/dd18e529939078b89867297b181a584e8b2cc7da
|
|
423
|
+
[a895d1d]: https://github.com/gchq/CyberChef/commit/a895d1d82a2f92d440a0c5eca2bc7c898107b737
|
|
419
424
|
|
|
420
425
|
[#95]: https://github.com/gchq/CyberChef/pull/299
|
|
421
426
|
[#173]: https://github.com/gchq/CyberChef/pull/173
|
|
@@ -502,4 +507,4 @@ All major and minor version changes will be documented in this file. Details of
|
|
|
502
507
|
[#1242]: https://github.com/gchq/CyberChef/pull/1242
|
|
503
508
|
[#1244]: https://github.com/gchq/CyberChef/pull/1244
|
|
504
509
|
[#1313]: https://github.com/gchq/CyberChef/pull/1313
|
|
505
|
-
[#1326]: https://github.com/gchq/CyberChef/pull/1326
|
|
510
|
+
[#1326]: https://github.com/gchq/CyberChef/pull/1326
|
package/Gruntfile.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cyberchef",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.38.2",
|
|
4
4
|
"description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.",
|
|
5
5
|
"author": "n1474335 <n1474335@gmail.com>",
|
|
6
6
|
"homepage": "https://gchq.github.io/CyberChef",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"autoprefixer": "^10.4.4",
|
|
49
49
|
"babel-loader": "^8.2.4",
|
|
50
50
|
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
51
|
-
"chromedriver": "^
|
|
51
|
+
"chromedriver": "^101.0.0",
|
|
52
52
|
"cli-progress": "^3.10.0",
|
|
53
53
|
"colors": "^1.4.0",
|
|
54
54
|
"copy-webpack-plugin": "^10.2.4",
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"html-webpack-plugin": "^5.5.0",
|
|
70
70
|
"imports-loader": "^3.1.1",
|
|
71
71
|
"mini-css-extract-plugin": "2.6.0",
|
|
72
|
+
"modify-source-webpack-plugin": "^3.0.0",
|
|
72
73
|
"nightwatch": "^2.0.10",
|
|
73
74
|
"postcss": "^8.4.12",
|
|
74
75
|
"postcss-css-variables": "^0.18.0",
|
|
@@ -174,6 +175,7 @@
|
|
|
174
175
|
"lint": "npx grunt lint",
|
|
175
176
|
"postinstall": "npx grunt exec:fixCryptoApiImports",
|
|
176
177
|
"newop": "node --experimental-modules --experimental-json-modules src/core/config/scripts/newOperation.mjs",
|
|
178
|
+
"minor": "node --experimental-modules --experimental-json-modules src/core/config/scripts/newMinorVersion.mjs",
|
|
177
179
|
"getheapsize": "node -e 'console.log(`node heap limit = ${require(\"v8\").getHeapStatistics().heap_size_limit / (1024 * 1024)} Mb`)'",
|
|
178
180
|
"setheapsize": "export NODE_OPTIONS=--max_old_space_size=2048"
|
|
179
181
|
}
|
|
@@ -9518,6 +9518,25 @@
|
|
|
9518
9518
|
}
|
|
9519
9519
|
]
|
|
9520
9520
|
},
|
|
9521
|
+
"Parse TCP": {
|
|
9522
|
+
"module": "Default",
|
|
9523
|
+
"description": "Parses a TCP header and payload (if present).",
|
|
9524
|
+
"infoURL": "https://wikipedia.org/wiki/Transmission_Control_Protocol",
|
|
9525
|
+
"inputType": "string",
|
|
9526
|
+
"outputType": "html",
|
|
9527
|
+
"flowControl": false,
|
|
9528
|
+
"manualBake": false,
|
|
9529
|
+
"args": [
|
|
9530
|
+
{
|
|
9531
|
+
"name": "Input format",
|
|
9532
|
+
"type": "option",
|
|
9533
|
+
"value": [
|
|
9534
|
+
"Hex",
|
|
9535
|
+
"Raw"
|
|
9536
|
+
]
|
|
9537
|
+
}
|
|
9538
|
+
]
|
|
9539
|
+
},
|
|
9521
9540
|
"Parse TLV": {
|
|
9522
9541
|
"module": "Default",
|
|
9523
9542
|
"description": "Converts a Type-Length-Value (TLV) encoded string into a JSON object. Can optionally include a <code>Key</code> / <code>Type</code> entry. <br><br>Tags: Key-Length-Value, KLV, Length-Value, LV",
|
|
@@ -9548,11 +9567,20 @@
|
|
|
9548
9567
|
"module": "Default",
|
|
9549
9568
|
"description": "Parses a UDP header and payload (if present).",
|
|
9550
9569
|
"infoURL": "https://wikipedia.org/wiki/User_Datagram_Protocol",
|
|
9551
|
-
"inputType": "
|
|
9570
|
+
"inputType": "string",
|
|
9552
9571
|
"outputType": "html",
|
|
9553
9572
|
"flowControl": false,
|
|
9554
9573
|
"manualBake": false,
|
|
9555
|
-
"args": [
|
|
9574
|
+
"args": [
|
|
9575
|
+
{
|
|
9576
|
+
"name": "Input format",
|
|
9577
|
+
"type": "option",
|
|
9578
|
+
"value": [
|
|
9579
|
+
"Hex",
|
|
9580
|
+
"Raw"
|
|
9581
|
+
]
|
|
9582
|
+
}
|
|
9583
|
+
]
|
|
9556
9584
|
},
|
|
9557
9585
|
"Parse UNIX file permissions": {
|
|
9558
9586
|
"module": "Default",
|
|
@@ -97,6 +97,7 @@ import ParseIPRange from "../../operations/ParseIPRange.mjs";
|
|
|
97
97
|
import ParseIPv4Header from "../../operations/ParseIPv4Header.mjs";
|
|
98
98
|
import ParseIPv6Address from "../../operations/ParseIPv6Address.mjs";
|
|
99
99
|
import ParseSSHHostKey from "../../operations/ParseSSHHostKey.mjs";
|
|
100
|
+
import ParseTCP from "../../operations/ParseTCP.mjs";
|
|
100
101
|
import ParseTLV from "../../operations/ParseTLV.mjs";
|
|
101
102
|
import ParseUDP from "../../operations/ParseUDP.mjs";
|
|
102
103
|
import ParseUNIXFilePermissions from "../../operations/ParseUNIXFilePermissions.mjs";
|
|
@@ -263,6 +264,7 @@ OpModules.Default = {
|
|
|
263
264
|
"Parse IPv4 header": ParseIPv4Header,
|
|
264
265
|
"Parse IPv6 address": ParseIPv6Address,
|
|
265
266
|
"Parse SSH Host Key": ParseSSHHostKey,
|
|
267
|
+
"Parse TCP": ParseTCP,
|
|
266
268
|
"Parse TLV": ParseTLV,
|
|
267
269
|
"Parse UDP": ParseUDP,
|
|
268
270
|
"Parse UNIX file permissions": ParseUNIXFilePermissions,
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This script updates the CHANGELOG when a new minor version is created.
|
|
3
|
+
*
|
|
4
|
+
* @author n1474335 [n1474335@gmail.com]
|
|
5
|
+
* @copyright Crown Copyright 2022
|
|
6
|
+
* @license Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/* eslint no-console: ["off"] */
|
|
10
|
+
|
|
11
|
+
import prompt from "prompt";
|
|
12
|
+
import colors from "colors";
|
|
13
|
+
import path from "path";
|
|
14
|
+
import fs from "fs";
|
|
15
|
+
import process from "process";
|
|
16
|
+
|
|
17
|
+
const dir = path.join(process.cwd() + "/src/core/config/");
|
|
18
|
+
if (!fs.existsSync(dir)) {
|
|
19
|
+
console.log("\nCWD: " + process.cwd());
|
|
20
|
+
console.log("Error: newMinorVersion.mjs should be run from the project root");
|
|
21
|
+
console.log("Example> node --experimental-modules src/core/config/scripts/newMinorVersion.mjs");
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let changelogData = fs.readFileSync(path.join(process.cwd(), "CHANGELOG.md"), "utf8");
|
|
26
|
+
const lastVersion = changelogData.match(/## Details\s+### \[(\d+)\.(\d+)\.(\d+)\]/);
|
|
27
|
+
const newVersion = [
|
|
28
|
+
parseInt(lastVersion[1], 10),
|
|
29
|
+
parseInt(lastVersion[2], 10) + 1,
|
|
30
|
+
0
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
let knownContributors = changelogData.match(/^\[@([^\]]+)\]/gm);
|
|
34
|
+
knownContributors = knownContributors.map(c => c.slice(2, -1));
|
|
35
|
+
|
|
36
|
+
const date = (new Date()).toISOString().split("T")[0];
|
|
37
|
+
|
|
38
|
+
const schema = {
|
|
39
|
+
properties: {
|
|
40
|
+
message: {
|
|
41
|
+
description: "A short but descriptive summary of a feature in this version",
|
|
42
|
+
example: "Added 'Op name' operation",
|
|
43
|
+
prompt: "Feature description",
|
|
44
|
+
type: "string",
|
|
45
|
+
required: true,
|
|
46
|
+
},
|
|
47
|
+
author: {
|
|
48
|
+
description: "The author of the feature (only one supported, edit manually to add more)",
|
|
49
|
+
example: "n1474335",
|
|
50
|
+
prompt: "Author",
|
|
51
|
+
type: "string",
|
|
52
|
+
default: "n1474335"
|
|
53
|
+
},
|
|
54
|
+
id: {
|
|
55
|
+
description: "The PR number or full commit hash for this feature.",
|
|
56
|
+
example: "1200",
|
|
57
|
+
prompt: "Pull request or commit ID",
|
|
58
|
+
type: "string"
|
|
59
|
+
},
|
|
60
|
+
another: {
|
|
61
|
+
description: "y/n",
|
|
62
|
+
example: "y",
|
|
63
|
+
prompt: "Add another feature?",
|
|
64
|
+
type: "string",
|
|
65
|
+
pattern: /^[yn]$/,
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// Build schema
|
|
71
|
+
for (const prop in schema.properties) {
|
|
72
|
+
const p = schema.properties[prop];
|
|
73
|
+
p.description = "\n" + colors.white(p.description) + colors.cyan("\nExample: " + p.example) + "\n" + colors.green(p.prompt);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
prompt.message = "";
|
|
77
|
+
prompt.delimiter = ":".green;
|
|
78
|
+
|
|
79
|
+
const features = [];
|
|
80
|
+
const authors = [];
|
|
81
|
+
const prIDs = [];
|
|
82
|
+
const commitIDs = [];
|
|
83
|
+
|
|
84
|
+
prompt.start();
|
|
85
|
+
|
|
86
|
+
const getFeature = function() {
|
|
87
|
+
prompt.get(schema, (err, result) => {
|
|
88
|
+
if (err) {
|
|
89
|
+
console.log("\nExiting script.");
|
|
90
|
+
process.exit(0);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
features.push(result);
|
|
94
|
+
|
|
95
|
+
if (result.another === "y") {
|
|
96
|
+
getFeature();
|
|
97
|
+
} else {
|
|
98
|
+
let message = `### [${newVersion[0]}.${newVersion[1]}.${newVersion[2]}] - ${date}\n`;
|
|
99
|
+
|
|
100
|
+
features.forEach(feature => {
|
|
101
|
+
const id = feature.id.length > 10 ? feature.id.slice(0, 7) : "#" + feature.id;
|
|
102
|
+
message += `- ${feature.message} [@${feature.author}] | [${id}]\n`;
|
|
103
|
+
|
|
104
|
+
if (!knownContributors.includes(feature.author)) {
|
|
105
|
+
authors.push(`[@${feature.author}]: https://github.com/${feature.author}`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (feature.id.length > 10) {
|
|
109
|
+
commitIDs.push(`[${id}]: https://github.com/gchq/CyberChef/commit/${feature.id}`);
|
|
110
|
+
} else {
|
|
111
|
+
prIDs.push(`[#${feature.id}]: https://github.com/gchq/CyberChef/pull/${feature.id}`);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Message
|
|
116
|
+
changelogData = changelogData.replace(/## Details\n\n/, "## Details\n\n" + message + "\n");
|
|
117
|
+
|
|
118
|
+
// Tag
|
|
119
|
+
const newTag = `[${newVersion[0]}.${newVersion[1]}.${newVersion[2]}]: https://github.com/gchq/CyberChef/releases/tag/v${newVersion[0]}.${newVersion[1]}.${newVersion[2]}\n`;
|
|
120
|
+
changelogData = changelogData.replace(/\n\n(\[\d+\.\d+\.\d+\]: https)/, "\n\n" + newTag + "$1");
|
|
121
|
+
|
|
122
|
+
// Author
|
|
123
|
+
authors.forEach(author => {
|
|
124
|
+
changelogData = changelogData.replace(/(\n\[@[^\]]+\]: https:\/\/github\.com\/[^\n]+\n)\n/, "$1" + author + "\n\n");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Commit IDs
|
|
128
|
+
commitIDs.forEach(commitID => {
|
|
129
|
+
changelogData = changelogData.replace(/(\n\[[^\].]+\]: https:\/\/github.com\/gchq\/CyberChef\/commit\/[^\n]+\n)\n/, "$1" + commitID + "\n\n");
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// PR IDs
|
|
133
|
+
prIDs.forEach(prID => {
|
|
134
|
+
changelogData = changelogData.replace(/(\n\[#[^\]]+\]: https:\/\/github.com\/gchq\/CyberChef\/pull\/[^\n]+\n)\n/, "$1" + prID + "\n\n");
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
fs.writeFileSync(path.join(process.cwd(), "CHANGELOG.md"), changelogData);
|
|
138
|
+
|
|
139
|
+
console.log("Written CHANGELOG.md");
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
getFeature();
|
package/src/core/lib/Binary.mjs
CHANGED
|
@@ -13,7 +13,7 @@ import OperationError from "../errors/OperationError.mjs";
|
|
|
13
13
|
/**
|
|
14
14
|
* Convert a byte array into a binary string.
|
|
15
15
|
*
|
|
16
|
-
* @param {Uint8Array|byteArray} data
|
|
16
|
+
* @param {Uint8Array|byteArray|number} data
|
|
17
17
|
* @param {string} [delim="Space"]
|
|
18
18
|
* @param {number} [padding=8]
|
|
19
19
|
* @returns {string}
|
|
@@ -26,13 +26,17 @@ import OperationError from "../errors/OperationError.mjs";
|
|
|
26
26
|
* toBinary([10,20,30], ":");
|
|
27
27
|
*/
|
|
28
28
|
export function toBinary(data, delim="Space", padding=8) {
|
|
29
|
-
if (!data) return "";
|
|
30
|
-
|
|
31
29
|
delim = Utils.charRep(delim);
|
|
32
30
|
let output = "";
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
if (data.length) { // array
|
|
33
|
+
for (let i = 0; i < data.length; i++) {
|
|
34
|
+
output += data[i].toString(2).padStart(padding, "0") + delim;
|
|
35
|
+
}
|
|
36
|
+
} else if (typeof data === "number") { // Single value
|
|
37
|
+
return data.toString(2).padStart(padding, "0");
|
|
38
|
+
} else {
|
|
39
|
+
return "";
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
if (delim.length) {
|
|
@@ -3778,8 +3778,8 @@ function parseDEFLATE(stream) {
|
|
|
3778
3778
|
|
|
3779
3779
|
while (!finalBlock) {
|
|
3780
3780
|
// Read header
|
|
3781
|
-
finalBlock = stream.readBits(1);
|
|
3782
|
-
const blockType = stream.readBits(2);
|
|
3781
|
+
finalBlock = stream.readBits(1, "le");
|
|
3782
|
+
const blockType = stream.readBits(2, "le");
|
|
3783
3783
|
|
|
3784
3784
|
if (blockType === 0) {
|
|
3785
3785
|
/* No compression */
|
|
@@ -3798,16 +3798,16 @@ function parseDEFLATE(stream) {
|
|
|
3798
3798
|
/* Dynamic Huffman */
|
|
3799
3799
|
|
|
3800
3800
|
// Read the number of liternal and length codes
|
|
3801
|
-
const hlit = stream.readBits(5) + 257;
|
|
3801
|
+
const hlit = stream.readBits(5, "le") + 257;
|
|
3802
3802
|
// Read the number of distance codes
|
|
3803
|
-
const hdist = stream.readBits(5) + 1;
|
|
3803
|
+
const hdist = stream.readBits(5, "le") + 1;
|
|
3804
3804
|
// Read the number of code lengths
|
|
3805
|
-
const hclen = stream.readBits(4) + 4;
|
|
3805
|
+
const hclen = stream.readBits(4, "le") + 4;
|
|
3806
3806
|
|
|
3807
3807
|
// Parse code lengths
|
|
3808
3808
|
const codeLengths = new Uint8Array(huffmanOrder.length);
|
|
3809
3809
|
for (let i = 0; i < hclen; i++) {
|
|
3810
|
-
codeLengths[huffmanOrder[i]] = stream.readBits(3);
|
|
3810
|
+
codeLengths[huffmanOrder[i]] = stream.readBits(3, "le");
|
|
3811
3811
|
}
|
|
3812
3812
|
|
|
3813
3813
|
// Parse length table
|
|
@@ -3819,16 +3819,16 @@ function parseDEFLATE(stream) {
|
|
|
3819
3819
|
code = readHuffmanCode(stream, codeLengthsTable);
|
|
3820
3820
|
switch (code) {
|
|
3821
3821
|
case 16:
|
|
3822
|
-
repeat = 3 + stream.readBits(2);
|
|
3822
|
+
repeat = 3 + stream.readBits(2, "le");
|
|
3823
3823
|
while (repeat--) lengthTable[i++] = prev;
|
|
3824
3824
|
break;
|
|
3825
3825
|
case 17:
|
|
3826
|
-
repeat = 3 + stream.readBits(3);
|
|
3826
|
+
repeat = 3 + stream.readBits(3, "le");
|
|
3827
3827
|
while (repeat--) lengthTable[i++] = 0;
|
|
3828
3828
|
prev = 0;
|
|
3829
3829
|
break;
|
|
3830
3830
|
case 18:
|
|
3831
|
-
repeat = 11 + stream.readBits(7);
|
|
3831
|
+
repeat = 11 + stream.readBits(7, "le");
|
|
3832
3832
|
while (repeat--) lengthTable[i++] = 0;
|
|
3833
3833
|
prev = 0;
|
|
3834
3834
|
break;
|
|
@@ -3886,11 +3886,11 @@ function parseHuffmanBlock(stream, litTab, distTab) {
|
|
|
3886
3886
|
if (code < 256) continue;
|
|
3887
3887
|
|
|
3888
3888
|
// Length code
|
|
3889
|
-
stream.readBits(lengthExtraTable[code - 257]);
|
|
3889
|
+
stream.readBits(lengthExtraTable[code - 257], "le");
|
|
3890
3890
|
|
|
3891
3891
|
// Dist code
|
|
3892
3892
|
code = readHuffmanCode(stream, distTab);
|
|
3893
|
-
stream.readBits(distanceExtraTable[code]);
|
|
3893
|
+
stream.readBits(distanceExtraTable[code], "le");
|
|
3894
3894
|
}
|
|
3895
3895
|
}
|
|
3896
3896
|
|
|
@@ -3948,7 +3948,7 @@ function readHuffmanCode(stream, table) {
|
|
|
3948
3948
|
const [codeTable, maxCodeLength] = table;
|
|
3949
3949
|
|
|
3950
3950
|
// Read max length
|
|
3951
|
-
const bitsBuf = stream.readBits(maxCodeLength);
|
|
3951
|
+
const bitsBuf = stream.readBits(maxCodeLength, "le");
|
|
3952
3952
|
const codeWithLength = codeTable[bitsBuf & ((1 << maxCodeLength) - 1)];
|
|
3953
3953
|
const codeLength = codeWithLength >>> 16;
|
|
3954
3954
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protocol parsing functions.
|
|
3
|
+
*
|
|
4
|
+
* @author n1474335 [n1474335@gmail.com]
|
|
5
|
+
* @copyright Crown Copyright 2022
|
|
6
|
+
* @license Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import BigNumber from "bignumber.js";
|
|
10
|
+
import {toHexFast} from "../lib/Hex.mjs";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Recursively displays a JSON object as an HTML table
|
|
14
|
+
*
|
|
15
|
+
* @param {Object} obj
|
|
16
|
+
* @returns string
|
|
17
|
+
*/
|
|
18
|
+
export function objToTable(obj, nested=false) {
|
|
19
|
+
let html = `<table
|
|
20
|
+
class='table table-sm table-nonfluid ${nested ? "mb-0 table-borderless" : "table-bordered"}'
|
|
21
|
+
style='table-layout: fixed; ${nested ? "margin: -1px !important;" : ""}'>`;
|
|
22
|
+
if (!nested)
|
|
23
|
+
html += `<tr>
|
|
24
|
+
<th>Field</th>
|
|
25
|
+
<th>Value</th>
|
|
26
|
+
</tr>`;
|
|
27
|
+
|
|
28
|
+
for (const key in obj) {
|
|
29
|
+
html += `<tr><td style='word-wrap: break-word'>${key}</td>`;
|
|
30
|
+
if (typeof obj[key] === "object")
|
|
31
|
+
html += `<td style='padding: 0'>${objToTable(obj[key], true)}</td>`;
|
|
32
|
+
else
|
|
33
|
+
html += `<td>${obj[key]}</td>`;
|
|
34
|
+
html += "</tr>";
|
|
35
|
+
}
|
|
36
|
+
html += "</table>";
|
|
37
|
+
return html;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Converts bytes into a BigNumber string
|
|
42
|
+
* @param {Uint8Array} bs
|
|
43
|
+
* @returns {string}
|
|
44
|
+
*/
|
|
45
|
+
export function bytesToLargeNumber(bs) {
|
|
46
|
+
return BigNumber(toHexFast(bs), 16).toString();
|
|
47
|
+
}
|
package/src/core/lib/Stream.mjs
CHANGED
|
@@ -27,15 +27,17 @@ export default class Stream {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* Get a number of bytes from the current position.
|
|
30
|
+
* Get a number of bytes from the current position, or all remaining bytes.
|
|
31
31
|
*
|
|
32
|
-
* @param {number} numBytes
|
|
32
|
+
* @param {number} [numBytes=null]
|
|
33
33
|
* @returns {Uint8Array}
|
|
34
34
|
*/
|
|
35
|
-
getBytes(numBytes) {
|
|
35
|
+
getBytes(numBytes=null) {
|
|
36
36
|
if (this.position > this.length) return undefined;
|
|
37
37
|
|
|
38
|
-
const newPosition =
|
|
38
|
+
const newPosition = numBytes !== null ?
|
|
39
|
+
this.position + numBytes :
|
|
40
|
+
this.length;
|
|
39
41
|
const bytes = this.bytes.slice(this.position, newPosition);
|
|
40
42
|
this.position = newPosition;
|
|
41
43
|
this.bitPos = 0;
|
|
@@ -91,34 +93,40 @@ export default class Stream {
|
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
/**
|
|
94
|
-
* Reads a number of bits from the buffer.
|
|
95
|
-
*
|
|
96
|
-
* @TODO Add endianness
|
|
96
|
+
* Reads a number of bits from the buffer in big or little endian.
|
|
97
97
|
*
|
|
98
98
|
* @param {number} numBits
|
|
99
|
+
* @param {string} [endianness="be"]
|
|
99
100
|
* @returns {number}
|
|
100
101
|
*/
|
|
101
|
-
readBits(numBits) {
|
|
102
|
+
readBits(numBits, endianness="be") {
|
|
102
103
|
if (this.position > this.length) return undefined;
|
|
103
104
|
|
|
104
105
|
let bitBuf = 0,
|
|
105
106
|
bitBufLen = 0;
|
|
106
107
|
|
|
107
108
|
// Add remaining bits from current byte
|
|
108
|
-
bitBuf =
|
|
109
|
+
bitBuf = this.bytes[this.position++] & bitMask(this.bitPos);
|
|
110
|
+
if (endianness !== "be") bitBuf >>>= this.bitPos;
|
|
109
111
|
bitBufLen = 8 - this.bitPos;
|
|
110
112
|
this.bitPos = 0;
|
|
111
113
|
|
|
112
114
|
// Not enough bits yet
|
|
113
115
|
while (bitBufLen < numBits) {
|
|
114
|
-
|
|
116
|
+
if (endianness === "be")
|
|
117
|
+
bitBuf = (bitBuf << bitBufLen) | this.bytes[this.position++];
|
|
118
|
+
else
|
|
119
|
+
bitBuf |= this.bytes[this.position++] << bitBufLen;
|
|
115
120
|
bitBufLen += 8;
|
|
116
121
|
}
|
|
117
122
|
|
|
118
123
|
// Reverse back to numBits
|
|
119
124
|
if (bitBufLen > numBits) {
|
|
120
125
|
const excess = bitBufLen - numBits;
|
|
121
|
-
|
|
126
|
+
if (endianness === "be")
|
|
127
|
+
bitBuf >>>= excess;
|
|
128
|
+
else
|
|
129
|
+
bitBuf &= (1 << numBits) - 1;
|
|
122
130
|
bitBufLen -= excess;
|
|
123
131
|
this.position--;
|
|
124
132
|
this.bitPos = 8 - excess;
|
|
@@ -133,7 +141,9 @@ export default class Stream {
|
|
|
133
141
|
* @returns {number} The bit mask
|
|
134
142
|
*/
|
|
135
143
|
function bitMask(bitPos) {
|
|
136
|
-
return
|
|
144
|
+
return endianness === "be" ?
|
|
145
|
+
(1 << (8 - bitPos)) - 1 :
|
|
146
|
+
256 - (1 << bitPos);
|
|
137
147
|
}
|
|
138
148
|
}
|
|
139
149
|
|