CyberChef/src/core/operations/DecodeText.mjs

57 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-05-15 17:03:41 +02:00
/**
* @author n1474335 [n1474335@gmail.com]
* @copyright Crown Copyright 2016
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import cptable from "codepage";
import {IO_FORMAT} from "../lib/ChrEnc.mjs";
2018-05-15 17:03:41 +02:00
/**
* Decode text operation
*/
class DecodeText extends Operation {
/**
* DecodeText constructor
*/
constructor() {
super();
this.name = "Decode text";
this.module = "Encodings";
2018-05-15 17:03:41 +02:00
this.description = [
"Decodes text from the chosen character encoding.",
"<br><br>",
"Supported charsets are:",
"<ul>",
Object.keys(IO_FORMAT).map(e => `<li>${e}</li>`).join("\n"),
"</ul>",
].join("\n");
this.infoURL = "https://wikipedia.org/wiki/Character_encoding";
this.inputType = "ArrayBuffer";
2018-05-15 17:03:41 +02:00
this.outputType = "string";
this.args = [
{
"name": "Encoding",
"type": "option",
"value": Object.keys(IO_FORMAT)
}
];
}
/**
* @param {ArrayBuffer} input
2018-05-15 17:03:41 +02:00
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const format = IO_FORMAT[args[0]];
return cptable.utils.decode(format, new Uint8Array(input));
2018-05-15 17:03:41 +02:00
}
}
export default DecodeText;