mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-06 22:47:11 -04:00
Added operation: "JavaScript"
Operation "JavaScript" is added under category "Utils" and it adds option to write JS code to manipulate data.
This commit is contained in:
parent
8b0112229e
commit
6c269dd204
3 changed files with 36 additions and 1 deletions
|
@ -162,6 +162,7 @@ var Categories = [
|
|||
"Parse UNIX file permissions",
|
||||
"Swap endianness",
|
||||
"Parse colour code",
|
||||
"JavaScript",
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -2782,5 +2782,19 @@ var OperationConfig = {
|
|||
input_type: "string",
|
||||
output_type: "string",
|
||||
args: []
|
||||
}
|
||||
},
|
||||
"JavaScript": {
|
||||
description: "Script in JavaScript",
|
||||
run: StrUtils.run_javascript,
|
||||
manual_bake: true,
|
||||
input_type: "string",
|
||||
output_type: "string",
|
||||
args: [
|
||||
{
|
||||
name: "@param {string} input, @returns {string}",
|
||||
type: "text",
|
||||
value: "return input;"
|
||||
},
|
||||
]
|
||||
},
|
||||
};
|
|
@ -508,5 +508,25 @@ var StrUtils = {
|
|||
|
||||
return output;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Script JS.
|
||||
*
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run_javascript: function (input, args) {
|
||||
try {
|
||||
/*jshint -W061 */
|
||||
var fn = Function("input", args);
|
||||
/*jshint +W061 */
|
||||
return fn(input);
|
||||
}
|
||||
catch (err) {
|
||||
return "JavaScript error: " + err.message;
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue