From afd8717819a47a7cbbe8eebf51b7723f44438add Mon Sep 17 00:00:00 2001 From: RomaRoma? Date: Mon, 4 May 2026 11:30:08 +0200 Subject: [PATCH] Add From JSFuck operation --- src/core/config/Categories.json | 3 +- src/core/operations/FromJSFuck.mjs | 53 +++++++++++++++++++++++++++ tests/operations/tests/FromJSFuck.mjs | 0 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/core/operations/FromJSFuck.mjs create mode 100644 tests/operations/tests/FromJSFuck.mjs diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index ab1dafb0..9fea4054 100644 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -501,7 +501,8 @@ "BSON deserialise", "To MessagePack", "From MessagePack", - "Render Markdown" + "Render Markdown", + "From JSFuck" ] }, { diff --git a/src/core/operations/FromJSFuck.mjs b/src/core/operations/FromJSFuck.mjs new file mode 100644 index 00000000..b50c1973 --- /dev/null +++ b/src/core/operations/FromJSFuck.mjs @@ -0,0 +1,53 @@ +/** + * @author Roma476 [friciu.robert09@gmail.com] + * @copyright Crown Copyright 2026 + * @license Apache-2.0 + */ + +import Operation from "../Operation.mjs"; +import OperationError from "../errors/OperationError.mjs"; + +/** + * From JSFuck operation + */ +class FromJSFuck extends Operation { + + /** + * FromJSFuck constructor + */ + constructor() { + super(); + + this.name = "From JSFuck"; + this.module = "Default"; + this.description = "Decodes JSFuck encoded JavaScript. JSFuck uses only 6 characters: [, ], (, ), ! and +.

e.g. [][(![]+[])[+[]]+...] becomes alert(1)"; + this.infoURL = "https://wikipedia.org/wiki/JSFuck"; + this.inputType = "string"; + this.outputType = "string"; + this.args = []; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + // Input Validation + for (let i = 0; i < input.length; i++) { + const char = input[i]; + if (!["[", "]", "(", ")", "!", "+"].includes(char)) { + throw new OperationError(`Invalid character at position ${i}: ${char}`); + } + } + + try { + return String(Function('"use strict"; return (' + input + ')')()); + } catch (err) { + throw new OperationError("Unable to decode JSFuck: " + err.message); + } + } + +} + +export default FromJSFuck; diff --git a/tests/operations/tests/FromJSFuck.mjs b/tests/operations/tests/FromJSFuck.mjs new file mode 100644 index 00000000..e69de29b