refactor and rename 'Gootkit' to 'Gootloader' & added Gootloader Code Parser operator

This commit is contained in:
Rodel Mendrez 2023-08-14 10:39:08 +12:00
parent ef3e8eb3b0
commit c166e0b6a9
3 changed files with 57 additions and 6 deletions

View file

@ -501,7 +501,8 @@
"Generate Lorem Ipsum",
"Numberwang",
"XKCD Random Number",
"GootLoader Decode"
"Gootloader Decode",
"Gootloader Code Parser"
]
},
{

View file

@ -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;

View file

@ -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;