diff --git a/src/core/operations/TextEncodingBruteForce.mjs b/src/core/operations/TextEncodingBruteForce.mjs index ae96fd0a29..1f76fc2146 100644 --- a/src/core/operations/TextEncodingBruteForce.mjs +++ b/src/core/operations/TextEncodingBruteForce.mjs @@ -32,7 +32,7 @@ class TextEncodingBruteForce extends Operation { "" ].join("\n"); this.infoURL = "https://wikipedia.org/wiki/Character_encoding"; - this.inputType = "string"; + this.inputType = "byteArray"; this.outputType = "json"; this.presentType = "html"; this.args = [ @@ -45,21 +45,22 @@ class TextEncodingBruteForce extends Operation { } /** - * @param {string} input + * @param {byteArray} input * @param {Object[]} args * @returns {json} */ run(input, args) { const output = {}, charsets = Object.keys(CHR_ENC_CODE_PAGES), - mode = args[0]; + mode = args[0], + stringInput = Utils.arrayBufferToStr(input); charsets.forEach(charset => { try { if (mode === "Decode") { output[charset] = cptable.utils.decode(CHR_ENC_CODE_PAGES[charset], input); } else { - output[charset] = Utils.arrayBufferToStr(cptable.utils.encode(CHR_ENC_CODE_PAGES[charset], input)); + output[charset] = Utils.arrayBufferToStr(cptable.utils.encode(CHR_ENC_CODE_PAGES[charset], stringInput)); } } catch (err) { output[charset] = "Could not decode."; diff --git a/tests/operations/tests/TextEncodingBruteForce.mjs b/tests/operations/tests/TextEncodingBruteForce.mjs index dfc5073b47..32b56e299c 100644 --- a/tests/operations/tests/TextEncodingBruteForce.mjs +++ b/tests/operations/tests/TextEncodingBruteForce.mjs @@ -30,6 +30,21 @@ TestRegister.addTests([ args: ["Decode"], }, ], + }, + { + name: "Text Encoding Brute Force - Decode preserves raw UTF-8 bytes", + input: "63 61 66 c3 a9", + expectedMatch: /UTF-8 Unicode \(65001\).{1,10}café/, + recipeConfig: [ + { + op: "From Hex", + args: ["Auto"], + }, + { + op: "Text Encoding Brute Force", + args: ["Decode"], + }, + ], } ]);