CyberChef/src/core/operations/ParseQRCode.mjs

67 lines
1.8 KiB
JavaScript
Raw Normal View History

2018-12-20 15:45:23 +01:00
/**
* @author j433866 [j433866@gmail.com]
* @copyright Crown Copyright 2018
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
2019-03-13 10:20:13 +01:00
import { isImage } from "../lib/FileType.mjs";
import { parseQrCode } from "../lib/QRCode.mjs";
2018-12-20 15:45:23 +01:00
/**
* Parse QR Code operation
*/
class ParseQRCode extends Operation {
/**
* ParseQRCode constructor
*/
constructor() {
super();
this.name = "Parse QR Code";
this.module = "Image";
2018-12-25 22:54:38 +01:00
this.description = "Reads an image file and attempts to detect and read a Quick Response (QR) code from the image.<br><br><u>Normalise Image</u><br>Attempts to normalise the image before parsing it to improve detection of a QR code.";
2018-12-20 15:45:23 +01:00
this.infoURL = "https://wikipedia.org/wiki/QR_code";
this.inputType = "ArrayBuffer";
2018-12-20 15:45:23 +01:00
this.outputType = "string";
2018-12-21 12:24:31 +01:00
this.args = [
{
"name": "Normalise image",
"type": "boolean",
2018-12-25 22:54:38 +01:00
"value": false
2018-12-21 12:24:31 +01:00
}
];
2020-02-25 12:33:35 +01:00
this.checks = {
input: {
regex: [
{
"match": "^(?:\\xff\\xd8\\xff|\\x89\\x50\\x4e\\x47|\\x47\\x49\\x46|.{8}\\x57\\x45\\x42\\x50|\\x42\\x4d)",
"flags": "",
"args": [false],
"useful": true
}
]
}
2020-02-25 12:33:35 +01:00
};
2018-12-20 15:45:23 +01:00
}
/**
* @param {ArrayBuffer} input
2018-12-20 15:45:23 +01:00
* @param {Object[]} args
* @returns {string}
*/
async run(input, args) {
2018-12-21 12:24:31 +01:00
const [normalise] = args;
2018-12-25 22:54:38 +01:00
if (!isImage(input)) {
2018-12-20 15:45:23 +01:00
throw new OperationError("Invalid file type.");
}
return await parseQrCode(input, normalise);
2018-12-20 15:45:23 +01:00
}
}
export default ParseQRCode;