mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-09 07:45:00 -04:00
add custom js code operation
This commit is contained in:
parent
7c19be7710
commit
826da61c6a
1 changed files with 54 additions and 0 deletions
54
src/core/operations/CustomCode.mjs
Normal file
54
src/core/operations/CustomCode.mjs
Normal file
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* @author kjcain [kyler@kylercain.com]
|
||||
* @copyright Crown Copyright 2022
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
|
||||
/**
|
||||
* Custom Code operation
|
||||
*/
|
||||
class CustomCode extends Operation {
|
||||
|
||||
/**
|
||||
* CustomCode constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Custom Code";
|
||||
this.module = "Default";
|
||||
this.description = "Execute custom javascript code.";
|
||||
this.infoURL = "";
|
||||
this.inputType = "JSON";
|
||||
this.outputType = "JSON";
|
||||
this.args = [
|
||||
{
|
||||
name: "Code",
|
||||
type: "text",
|
||||
value: "return input;"
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {JSON} input
|
||||
* @param {Object[]} args
|
||||
* @returns {JSON}
|
||||
*/
|
||||
run(input, args) {
|
||||
const [customCode] = args;
|
||||
|
||||
try {
|
||||
const wrappedCode = new Function("input", customCode);
|
||||
return wrappedCode(input);
|
||||
} catch (error) {
|
||||
throw new OperationError(error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default CustomCode;
|
Loading…
Add table
Add a link
Reference in a new issue