2018-12-12 17:34:45 +00:00
|
|
|
/**
|
|
|
|
* @author Cynser
|
|
|
|
* @copyright Crown Copyright 2018
|
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Operation from "../Operation";
|
|
|
|
import Utils from "../Utils";
|
|
|
|
import cptable from "../vendor/js-codepage/cptable.js";
|
|
|
|
import {IO_FORMAT} from "../lib/ChrEnc";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Text Encoding Brute Force operation
|
|
|
|
*/
|
|
|
|
class TextEncodingBruteForce extends Operation {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TextEncodingBruteForce constructor
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.name = "Text Encoding Brute Force";
|
|
|
|
this.module = "CharEnc";
|
|
|
|
this.description = "Enumerate all possible text encodings for input.";
|
|
|
|
this.infoURL = "https://wikipedia.org/wiki/Character_encoding";
|
|
|
|
this.inputType = "string";
|
|
|
|
this.outputType = "string";
|
2018-12-17 19:39:12 +00:00
|
|
|
this.args = [
|
|
|
|
{
|
|
|
|
name: "Mode",
|
|
|
|
type: "option",
|
|
|
|
value: ["Encode", "Decode"]
|
|
|
|
}
|
|
|
|
];
|
2018-12-12 17:34:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} input
|
|
|
|
* @param {Object[]} args
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
run(input, args) {
|
|
|
|
const output = [],
|
2018-12-17 19:39:12 +00:00
|
|
|
charSets = Object.keys(IO_FORMAT),
|
|
|
|
mode = args[0];
|
2018-12-12 17:34:45 +00:00
|
|
|
|
|
|
|
for (let i = 0; i < charSets.length; i++) {
|
2018-12-17 19:39:12 +00:00
|
|
|
let currentEncoding = charSets[i] + ": ";
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (mode === "Decode") {
|
|
|
|
currentEncoding += cptable.utils.decode(IO_FORMAT[charSets[i]], input);
|
|
|
|
} else {
|
|
|
|
currentEncoding += cptable.utils.encode(IO_FORMAT[charSets[i]], input);
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
currentEncoding += "Could not decode.";
|
|
|
|
}
|
|
|
|
|
|
|
|
output.push(Utils.printable(currentEncoding, true));
|
2018-12-12 17:34:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return output.join("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default TextEncodingBruteForce;
|