cyberchef 10.22.1 → 10.24.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 (118) hide show
  1. package/CHANGELOG.md +182 -0
  2. package/CONTRIBUTING.md +40 -0
  3. package/Dockerfile +2 -0
  4. package/Gruntfile.js +2 -28
  5. package/README.md +1 -1
  6. package/babel.config.js +0 -6
  7. package/package.json +64 -63
  8. package/src/core/Chef.mjs +8 -1
  9. package/src/core/Ingredient.mjs +5 -2
  10. package/src/core/Operation.mjs +6 -1
  11. package/src/core/Recipe.mjs +10 -5
  12. package/src/core/config/Categories.json +20 -4
  13. package/src/core/config/OperationConfig.json +550 -26
  14. package/src/core/config/modules/Ciphers.mjs +6 -0
  15. package/src/core/config/modules/Crypto.mjs +6 -0
  16. package/src/core/config/modules/Default.mjs +8 -0
  17. package/src/core/config/modules/Shellcode.mjs +2 -0
  18. package/src/core/config/scripts/fixCryptoApiImports.mjs +54 -0
  19. package/src/core/config/scripts/fixSnackBarMarkup.mjs +28 -0
  20. package/src/core/lib/AudioBytes.mjs +103 -0
  21. package/src/core/lib/AudioMetaSchema.mjs +82 -0
  22. package/src/core/lib/AudioParsers.mjs +630 -0
  23. package/src/core/lib/BigIntUtils.mjs +73 -0
  24. package/src/core/lib/Extract.mjs +5 -0
  25. package/src/core/lib/Modhex.mjs +2 -0
  26. package/src/core/lib/ParityBit.mjs +50 -0
  27. package/src/core/lib/QRCode.mjs +30 -10
  28. package/src/core/lib/RC6.mjs +625 -0
  29. package/src/core/operations/A1Z26CipherDecode.mjs +1 -1
  30. package/src/core/operations/AddTextToImage.mjs +116 -64
  31. package/src/core/operations/AnalyseUUID.mjs +109 -6
  32. package/src/core/operations/BlurImage.mjs +10 -12
  33. package/src/core/operations/ContainImage.mjs +50 -40
  34. package/src/core/operations/ConvertImageFormat.mjs +33 -39
  35. package/src/core/operations/CoverImage.mjs +39 -37
  36. package/src/core/operations/CropImage.mjs +35 -21
  37. package/src/core/operations/DisassembleARM.mjs +193 -0
  38. package/src/core/operations/DitherImage.mjs +8 -8
  39. package/src/core/operations/EscapeUnicodeCharacters.mjs +0 -17
  40. package/src/core/operations/ExtractAudioMetadata.mjs +175 -0
  41. package/src/core/operations/ExtractEmailAddresses.mjs +2 -3
  42. package/src/core/operations/ExtractLSB.mjs +17 -11
  43. package/src/core/operations/ExtractRGBA.mjs +12 -10
  44. package/src/core/operations/FlaskSessionDecode.mjs +80 -0
  45. package/src/core/operations/FlaskSessionSign.mjs +89 -0
  46. package/src/core/operations/FlaskSessionVerify.mjs +136 -0
  47. package/src/core/operations/FlipImage.mjs +14 -10
  48. package/src/core/operations/GenerateImage.mjs +39 -32
  49. package/src/core/operations/ImageBrightnessContrast.mjs +10 -10
  50. package/src/core/operations/ImageFilter.mjs +14 -13
  51. package/src/core/operations/ImageHueSaturationLightness.mjs +22 -20
  52. package/src/core/operations/ImageOpacity.mjs +6 -8
  53. package/src/core/operations/InvertImage.mjs +4 -6
  54. package/src/core/operations/Jq.mjs +12 -4
  55. package/src/core/operations/NormaliseImage.mjs +5 -7
  56. package/src/core/operations/OffsetChecker.mjs +1 -1
  57. package/src/core/operations/ParityBit.mjs +128 -0
  58. package/src/core/operations/ParseEthernetFrame.mjs +112 -0
  59. package/src/core/operations/ParseIPv4Header.mjs +23 -6
  60. package/src/core/operations/ParseQRCode.mjs +13 -13
  61. package/src/core/operations/PseudoRandomIntegerGenerator.mjs +164 -0
  62. package/src/core/operations/RC6Decrypt.mjs +119 -0
  63. package/src/core/operations/RC6Encrypt.mjs +119 -0
  64. package/src/core/operations/RandomizeColourPalette.mjs +11 -11
  65. package/src/core/operations/RegularExpression.mjs +2 -1
  66. package/src/core/operations/RenderMarkdown.mjs +35 -4
  67. package/src/core/operations/ResizeImage.mjs +30 -23
  68. package/src/core/operations/RotateImage.mjs +8 -9
  69. package/src/core/operations/SQLBeautify.mjs +21 -3
  70. package/src/core/operations/SharpenImage.mjs +94 -62
  71. package/src/core/operations/SplitColourChannels.mjs +47 -21
  72. package/src/core/operations/TextIntegerConverter.mjs +123 -0
  73. package/src/core/operations/UnescapeUnicodeCharacters.mjs +17 -0
  74. package/src/core/operations/ViewBitPlane.mjs +16 -20
  75. package/src/core/operations/index.mjs +22 -0
  76. package/src/node/index.mjs +55 -0
  77. package/src/web/HTMLIngredient.mjs +24 -43
  78. package/src/web/HTMLOperation.mjs +8 -2
  79. package/src/web/Manager.mjs +1 -0
  80. package/src/web/html/index.html +6 -6
  81. package/src/web/static/fonts/bmfonts/Roboto72White.fnt +491 -485
  82. package/src/web/static/fonts/bmfonts/RobotoBlack72White.fnt +494 -488
  83. package/src/web/static/fonts/bmfonts/RobotoMono72White.fnt +110 -103
  84. package/src/web/static/fonts/bmfonts/RobotoSlab72White.fnt +498 -492
  85. package/src/web/stylesheets/layout/_banner.css +30 -0
  86. package/src/web/stylesheets/layout/_modals.css +5 -0
  87. package/src/web/stylesheets/utils/_overrides.css +7 -0
  88. package/src/web/waiters/ControlsWaiter.mjs +82 -0
  89. package/src/web/waiters/InputWaiter.mjs +12 -6
  90. package/src/web/waiters/OperationsWaiter.mjs +30 -13
  91. package/src/web/waiters/RecipeWaiter.mjs +2 -2
  92. package/tests/browser/02_ops.js +23 -3
  93. package/tests/node/index.mjs +1 -0
  94. package/tests/node/tests/lib/BigIntUtils.mjs +150 -0
  95. package/tests/node/tests/operations.mjs +11 -10
  96. package/tests/operations/index.mjs +13 -0
  97. package/tests/operations/tests/A1Z26CipherDecode.mjs +33 -0
  98. package/tests/operations/tests/AnalyseUUID.mjs +66 -0
  99. package/tests/operations/tests/DisassembleARM.mjs +377 -0
  100. package/tests/operations/tests/ExtractAudioMetadata.mjs +287 -0
  101. package/tests/operations/tests/ExtractEmailAddresses.mjs +38 -12
  102. package/tests/operations/tests/Fernet.mjs +18 -3
  103. package/tests/operations/tests/FlaskSession.mjs +246 -0
  104. package/tests/operations/tests/GenerateQRCode.mjs +67 -0
  105. package/tests/operations/tests/JWTSign.mjs +83 -8
  106. package/tests/operations/tests/Jq.mjs +32 -0
  107. package/tests/operations/tests/Modhex.mjs +20 -0
  108. package/tests/operations/tests/ParityBit.mjs +147 -0
  109. package/tests/operations/tests/ParseEthernetFrame.mjs +45 -0
  110. package/tests/operations/tests/RC6.mjs +487 -0
  111. package/tests/operations/tests/RegularExpression.mjs +75 -0
  112. package/tests/operations/tests/RenderMarkdown.mjs +110 -0
  113. package/tests/operations/tests/SQLBeautify.mjs +54 -0
  114. package/tests/operations/tests/TextIntegerConverter.mjs +199 -0
  115. package/tests/samples/Audio.mjs +73 -0
  116. package/tests/samples/Images.mjs +0 -12
  117. package/webpack.config.js +10 -7
  118. package/src/core/lib/ImageManipulation.mjs +0 -251
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @author p-leriche [philip.leriche@cantab.net]
3
+ * @copyright Crown Copyright 2025
4
+ * @license Apache-2.0
5
+ */
6
+
7
+ import OperationError from "../errors/OperationError.mjs";
8
+
9
+ /**
10
+ * Number theory utilities used by cryptographic operations.
11
+ *
12
+ * Currently provides:
13
+ * - parseBigInt
14
+ * - Extended Euclidean Algorithm
15
+ * - Modular Exponentiation
16
+ *
17
+ * Additional algorithms may be added as required.
18
+ */
19
+
20
+ /**
21
+ * parseBigInt helper operation
22
+ */
23
+ export function parseBigInt(value, param) {
24
+ const v = (value ?? "").trim();
25
+ if (/^0x[0-9a-f]+$/i.test(v)) return BigInt(v);
26
+ if (/^[+-]?[0-9]+$/.test(v)) return BigInt(v);
27
+ throw new OperationError(param + " must be decimal or hex (0x...)");
28
+ }
29
+
30
+ /**
31
+ * Extended Euclidean Algorithm
32
+ *
33
+ * Returns [g, x, y] such that:
34
+ * a*x + b*y = g = gcd(a, b)
35
+ *
36
+ * (Uses an iterative algorithm to avoid possible stack overflow)
37
+ */
38
+ export function egcd(a, b) {
39
+ let oldR = a, r = b;
40
+ let oldS = 1n, s = 0n;
41
+ let oldT = 0n, t = 1n;
42
+
43
+ while (r !== 0n) {
44
+ const quotient = oldR / r;
45
+
46
+ [oldR, r] = [r, oldR - quotient * r];
47
+ [oldS, s] = [s, oldS - quotient * s];
48
+ [oldT, t] = [t, oldT - quotient * t];
49
+ }
50
+
51
+ // oldR is the gcd
52
+ // oldS and oldT are the Bézout coefficients
53
+ return [oldR, oldS, oldT];
54
+ }
55
+
56
+ /**
57
+ * Modular exponentiation
58
+ */
59
+ export function modPow(base, exponent, modulus) {
60
+ let result = 1n;
61
+ base %= modulus;
62
+
63
+ while (exponent > 0n) {
64
+ if (exponent & 1n) {
65
+ result = (result * base) % modulus;
66
+ }
67
+ base = (base * base) % modulus;
68
+ exponent >>= 1n;
69
+ }
70
+
71
+ return result;
72
+ }
73
+
@@ -45,6 +45,11 @@ export function search(input, searchRegex, removeRegex=null, sortBy=null, unique
45
45
  return results;
46
46
  }
47
47
 
48
+ /**
49
+ * Email regular expression
50
+ */
51
+ export const EMAIL_REGEX = /(?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9](?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9-]*[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9])?\.)+[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9](?:[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9-]*[\u00A0-\uD7FF\uE000-\uFFFFa-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\])/ig;
52
+
48
53
 
49
54
  /**
50
55
  * URL regular expression
@@ -50,6 +50,7 @@ const HEX_ALPHABET_MAP = HEX_ALPHABET.split("");
50
50
  export function toModhex(data, delim=" ", padding=2, extraDelim="", lineSize=0) {
51
51
  if (!data) return "";
52
52
  if (data instanceof ArrayBuffer) data = new Uint8Array(data);
53
+ if (data.length === 0) return "";
53
54
 
54
55
  const regularHexString = toHex(data, "", padding, "", 0);
55
56
 
@@ -100,6 +101,7 @@ export function toModhex(data, delim=" ", padding=2, extraDelim="", lineSize=0)
100
101
  export function toModhexFast(data) {
101
102
  if (!data) return "";
102
103
  if (data instanceof ArrayBuffer) data = new Uint8Array(data);
104
+ if (data.length === 0) return "";
103
105
 
104
106
  const output = [];
105
107
 
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Parity Bit functions.
3
+ *
4
+ * @author j83305 [awz22@protonmail.com]
5
+ * @copyright Crown Copyright 2020
6
+ * @license Apache-2.0
7
+ *
8
+ */
9
+
10
+ import OperationError from "../errors/OperationError.mjs";
11
+
12
+ /**
13
+ * Function to take the user input and encode using the given arguments
14
+ * @param input string of binary
15
+ * @param args array
16
+ */
17
+ export function calculateParityBit(input, args) {
18
+ let count1s = 0;
19
+ for (let i = 0; i < input.length; i++) {
20
+ const character = input.charAt(i);
21
+ if (character === "1") {
22
+ count1s++;
23
+ } else if (character !== args[3] && character !== "0" && character !== " ") {
24
+ throw new OperationError("unexpected character encountered: \"" + character + "\"");
25
+ }
26
+ }
27
+ let parityBit = "1";
28
+ const flipflop = args[0] === "Even Parity" ? 0 : 1;
29
+ if (count1s % 2 === flipflop) {
30
+ parityBit = "0";
31
+ }
32
+ if (args[1] === "End") {
33
+ return input + parityBit;
34
+ } else {
35
+ return parityBit + input;
36
+ }
37
+ }
38
+
39
+ /**
40
+ * just removes the parity bit to return the original data
41
+ * @param input string of binary, encoded
42
+ * @param args array
43
+ */
44
+ export function decodeParityBit(input, args) {
45
+ if (args[1] === "End") {
46
+ return input.slice(0, -1);
47
+ } else {
48
+ return input.slice(1);
49
+ }
50
+ }
@@ -10,7 +10,7 @@ import OperationError from "../errors/OperationError.mjs";
10
10
  import jsQR from "jsqr";
11
11
  import qr from "qr-image";
12
12
  import Utils from "../Utils.mjs";
13
- import Jimp from "jimp/es/index.js";
13
+ import { Jimp, JimpMime } from "jimp";
14
14
 
15
15
  /**
16
16
  * Parses a QR code image from an image
@@ -29,18 +29,31 @@ export async function parseQrCode(input, normalise) {
29
29
 
30
30
  try {
31
31
  if (normalise) {
32
- image.rgba(false);
33
- image.background(0xFFFFFFFF);
34
- image.normalize();
35
32
  image.greyscale();
36
- image = await image.getBufferAsync(Jimp.MIME_JPEG);
37
- image = await Jimp.read(image);
33
+ image.normalize();
38
34
  }
39
35
  } catch (err) {
40
36
  throw new OperationError(`Error normalising image. (${err})`);
41
37
  }
42
38
 
43
- const qrData = jsQR(image.bitmap.data, image.getWidth(), image.getHeight());
39
+ // Remove transparency which jsQR cannot handle
40
+ image.scan((x, y, idx) => {
41
+ // If pixel is fully transparent, make it opaque white
42
+ if (image.bitmap.data[idx + 3] === 0x00) {
43
+ image.bitmap.data[idx + 0] = 0xff;
44
+ image.bitmap.data[idx + 1] = 0xff;
45
+ image.bitmap.data[idx + 2] = 0xff;
46
+ }
47
+ // Otherwise, make it fully opaque at its existing colour
48
+ image.bitmap.data[idx + 3] = 0xff;
49
+ });
50
+ image = await Jimp.read(await image.getBuffer(JimpMime.jpeg));
51
+
52
+ const qrData = jsQR(
53
+ new Uint8ClampedArray(image.bitmap.data),
54
+ image.width,
55
+ image.height,
56
+ );
44
57
  if (qrData) {
45
58
  return qrData.data;
46
59
  } else {
@@ -58,7 +71,13 @@ export async function parseQrCode(input, normalise) {
58
71
  * @param {string} errorCorrection
59
72
  * @returns {ArrayBuffer}
60
73
  */
61
- export function generateQrCode(input, format, moduleSize, margin, errorCorrection) {
74
+ export function generateQrCode(
75
+ input,
76
+ format,
77
+ moduleSize,
78
+ margin,
79
+ errorCorrection,
80
+ ) {
62
81
  const formats = ["SVG", "EPS", "PDF", "PNG"];
63
82
  if (!formats.includes(format.toUpperCase())) {
64
83
  throw new OperationError("Unsupported QR code format.");
@@ -70,7 +89,8 @@ export function generateQrCode(input, format, moduleSize, margin, errorCorrectio
70
89
  type: format,
71
90
  size: moduleSize,
72
91
  margin: margin,
73
- "ec_level": errorCorrection.charAt(0).toUpperCase()
92
+ // eslint-disable-next-line camelcase
93
+ ec_level: errorCorrection.charAt(0).toUpperCase(),
74
94
  });
75
95
  } catch (err) {
76
96
  throw new OperationError(`Error generating QR code. (${err})`);
@@ -86,7 +106,7 @@ export function generateQrCode(input, format, moduleSize, margin, errorCorrectio
86
106
  case "PDF":
87
107
  return Utils.strToArrayBuffer(qrImage);
88
108
  case "PNG":
89
- return qrImage.buffer;
109
+ return qrImage.buffer.slice(qrImage.byteOffset, qrImage.byteLength + qrImage.byteOffset);
90
110
  default:
91
111
  throw new OperationError("Unsupported QR code format.");
92
112
  }