diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index 49654858..efe9254c 100644 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -501,7 +501,8 @@ "Generate Lorem Ipsum", "Numberwang", "XKCD Random Number", - "GootLoader Decode" + "Gootloader Decode", + "Gootloader Code Parser" ] }, { diff --git a/src/core/operations/GootLoaderDecode.mjs b/src/core/operations/GootLoaderDecode.mjs index d077016e..e9ebcbc8 100644 --- a/src/core/operations/GootLoaderDecode.mjs +++ b/src/core/operations/GootLoaderDecode.mjs @@ -7,15 +7,15 @@ import Operation from "../Operation.mjs"; /** * Gootloader decode operation */ -class GootLoaderDecode extends Operation { +class GootloaderDecode extends Operation { /** - * GootLoader constructor + * Gootloader constructor */ constructor() { super(); - this.name = "GootLoader Decode"; + this.name = "Gootloader Decode"; this.module = "Code"; - this.description = "Decodes GootLoader JScript code block obfuscation"; + this.description = "Decodes Gootloader JScript code block obfuscation"; this.inputType = "string"; this.outputType = "string"; this.args = []; @@ -41,4 +41,4 @@ class GootLoaderDecode extends Operation { } } -export default GootLoaderDecode; +export default GootloaderDecode; diff --git a/src/core/operations/GootloaderCodeParser.mjs b/src/core/operations/GootloaderCodeParser.mjs new file mode 100644 index 00000000..f4306093 --- /dev/null +++ b/src/core/operations/GootloaderCodeParser.mjs @@ -0,0 +1,50 @@ +/** + * @copyright Crown Copyright 2016 + * @license Apache-2.0 + */ +import Operation from "../Operation.mjs"; + /** + * Gootloader code parser operation + */ +class GootloaderCodeParser extends Operation { + /** + * GootLoader constructor + */ + constructor() { + super(); + this.name = "Gootloader Code Parser"; + this.module = "Code"; + this.description = "Parse the actual code of Gootloader from JS"; + this.inputType = "string"; + this.outputType = "string"; + this.args = []; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + if (!input) return ""; + input = input.split("\n"); + + const mainRegex = /^[a-z0-9]+\(/; + const variableRegex = /^[a-z0-9]+\s*=\s*/; + const functionRegex = /^function [a-z]/; + + const main = input.filter(line => mainRegex.test(line)); + const variables = input.filter(line => variableRegex.test(line)); + const functionIndices = input + .map((line, index) => (functionRegex.test(line) ? index : -1)) + .filter(index => index !== -1); + const functions = functionIndices.map(fStart => { + const fEnd = input.slice(fStart).findIndex(line => line === "}"); + return input.slice(fStart, fStart + fEnd + 1).join(""); + }); + + return variables.join("\n") + "\n\n" + functions.join("\n") + "\n\n" + main.join("\n"); + } +} + +export default GootloaderCodeParser;