Merge 884b0b94d856da73c60f8b2923f348ddfe59ae07 into 4290ea753912378913b1f3f54e0fc5720afeda5d

This commit is contained in:
Willi Ballenthin 2026-08-08 22:54:24 +05:30 committed by GitHub
commit db780a854b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 4 deletions

View File

@ -32,7 +32,7 @@ class TextEncodingBruteForce extends Operation {
"</ul>" "</ul>"
].join("\n"); ].join("\n");
this.infoURL = "https://wikipedia.org/wiki/Character_encoding"; this.infoURL = "https://wikipedia.org/wiki/Character_encoding";
this.inputType = "string"; this.inputType = "byteArray";
this.outputType = "json"; this.outputType = "json";
this.presentType = "html"; this.presentType = "html";
this.args = [ this.args = [
@ -45,21 +45,22 @@ class TextEncodingBruteForce extends Operation {
} }
/** /**
* @param {string} input * @param {byteArray} input
* @param {Object[]} args * @param {Object[]} args
* @returns {json} * @returns {json}
*/ */
run(input, args) { run(input, args) {
const output = {}, const output = {},
charsets = Object.keys(CHR_ENC_CODE_PAGES), charsets = Object.keys(CHR_ENC_CODE_PAGES),
mode = args[0]; mode = args[0],
stringInput = Utils.arrayBufferToStr(input);
charsets.forEach(charset => { charsets.forEach(charset => {
try { try {
if (mode === "Decode") { if (mode === "Decode") {
output[charset] = cptable.utils.decode(CHR_ENC_CODE_PAGES[charset], input); output[charset] = cptable.utils.decode(CHR_ENC_CODE_PAGES[charset], input);
} else { } 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) { } catch (err) {
output[charset] = "Could not decode."; output[charset] = "Could not decode.";

View File

@ -30,6 +30,21 @@ TestRegister.addTests([
args: ["Decode"], 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"],
},
],
} }
]); ]);