HTML outputs can now be selected and handle control characters correctly

This commit is contained in:
n1474335 2022-07-18 18:39:41 +01:00
parent 0dc2322269
commit 7c8a185a3d
16 changed files with 319 additions and 124 deletions

View file

@ -149,7 +149,7 @@ class Magic extends Operation {
output += `<tr>
<td><a href="#${recipeURL}">${Utils.generatePrettyRecipe(option.recipe, true)}</a></td>
<td>${Utils.escapeHtml(Utils.printable(Utils.truncate(option.data, 99)))}</td>
<td>${Utils.escapeHtml(Utils.escapeWhitespace(Utils.truncate(option.data, 99)))}</td>
<td>${language}${fileType}${matchingOps}${useful}${validUTF8}${entropy}</td>
</tr>`;
});

View file

@ -86,12 +86,12 @@ class ROT13BruteForce extends Operation {
}
const rotatedString = Utils.byteArrayToUtf8(rotated);
if (rotatedString.toLowerCase().indexOf(cribLower) >= 0) {
const rotatedStringPrintable = Utils.printable(rotatedString, false);
const rotatedStringEscaped = Utils.escapeWhitespace(rotatedString);
if (printAmount) {
const amountStr = "Amount = " + (" " + amount).slice(-2) + ": ";
result.push(amountStr + rotatedStringPrintable);
result.push(amountStr + rotatedStringEscaped);
} else {
result.push(rotatedStringPrintable);
result.push(rotatedStringEscaped);
}
}
}

View file

@ -66,12 +66,12 @@ class ROT47BruteForce extends Operation {
}
const rotatedString = Utils.byteArrayToUtf8(rotated);
if (rotatedString.toLowerCase().indexOf(cribLower) >= 0) {
const rotatedStringPrintable = Utils.printable(rotatedString, false);
const rotatedStringEscaped = Utils.escapeWhitespace(rotatedString);
if (printAmount) {
const amountStr = "Amount = " + (" " + amount).slice(-2) + ": ";
result.push(amountStr + rotatedStringPrintable);
result.push(amountStr + rotatedStringEscaped);
} else {
result.push(rotatedStringPrintable);
result.push(rotatedStringEscaped);
}
}
}

View file

@ -79,7 +79,7 @@ class TextEncodingBruteForce extends Operation {
let table = "<table class='table table-hover table-sm table-bordered table-nonfluid'><tr><th>Encoding</th><th>Value</th></tr>";
for (const enc in encodings) {
const value = Utils.escapeHtml(Utils.printable(encodings[enc], true));
const value = Utils.escapeHtml(Utils.escapeWhitespace(encodings[enc]));
table += `<tr><td>${enc}</td><td>${value}</td></tr>`;
}

View file

@ -63,33 +63,32 @@ class ToHexdump extends Operation {
if (length < 1 || Math.round(length) !== length)
throw new OperationError("Width must be a positive integer");
let output = "";
const lines = [];
for (let i = 0; i < data.length; i += length) {
const buff = data.slice(i, i+length);
let hexa = "";
for (let j = 0; j < buff.length; j++) {
hexa += Utils.hex(buff[j], padding) + " ";
}
let lineNo = Utils.hex(i, 8);
const buff = data.slice(i, i+length);
const hex = [];
buff.forEach(b => hex.push(Utils.hex(b, padding)));
let hexStr = hex.join(" ").padEnd(length*(padding+1), " ");
const ascii = Utils.printable(Utils.byteArrayToChars(buff), false, unixFormat);
const asciiStr = ascii.padEnd(buff.length, " ");
if (upperCase) {
hexa = hexa.toUpperCase();
hexStr = hexStr.toUpperCase();
lineNo = lineNo.toUpperCase();
}
output += lineNo + " " +
hexa.padEnd(length*(padding+1), " ") +
" |" +
Utils.printable(Utils.byteArrayToChars(buff), false, unixFormat).padEnd(buff.length, " ") +
"|\n";
lines.push(`${lineNo} ${hexStr} |${asciiStr}|`);
if (includeFinalLength && i+buff.length === data.length) {
output += Utils.hex(i+buff.length, 8) + "\n";
lines.push(Utils.hex(i+buff.length, 8));
}
}
return output.slice(0, -1);
return lines.join("\n");
}
/**

View file

@ -126,11 +126,7 @@ class XORBruteForce extends Operation {
if (crib && resultUtf8.toLowerCase().indexOf(crib) < 0) continue;
if (printKey) record += "Key = " + Utils.hex(key, (2*keyLength)) + ": ";
if (outputHex) {
record += toHex(result);
} else {
record += Utils.printable(resultUtf8, false);
}
record += outputHex ? toHex(result) : Utils.escapeWhitespace(resultUtf8);
output.push(record);
}