From 46e43f4bde4a35785b4997b81e86cd19f046b69b Mon Sep 17 00:00:00 2001 From: Minteck Date: Tue, 21 Dec 2021 16:52:28 +0100 Subject: Commit --- src/build/index.js | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/build/index.js (limited to 'src/build/index.js') diff --git a/src/build/index.js b/src/build/index.js new file mode 100644 index 0000000..6370574 --- /dev/null +++ b/src/build/index.js @@ -0,0 +1,73 @@ +console.log("LangDetect Compiler v1"); +console.log("Loading, step 1"); +const fs = require('fs'); +console.log("Loading, step 2"); +var JavaScriptObfuscator = require('../node_modules/javascript-obfuscator'); +console.log("Loading, step 3"); +if (fs.existsSync("./keys.bin")) { + fs.unlinkSync("./keys.bin"); +} + +console.log("Building project..."); +console.log("Getting files list..."); +files = fs.readdirSync(".."); + +console.log("Compiling " + files.length + " files..."); +total = files.length; +global.current = 0; + +function compile(file) { + if (file.endsWith(".js")) { + cnt = fs.readFileSync("../" + file).toString(); + if (file == "../trust.js" || file == "trust.js") { + console.log(current + "/" + total + " - " + file + " - Trusted Platform Monitor"); + cnt = cnt.replaceAll("/*!!obdef!!*/_ob=false;/*!!obdef!!*/", "/*!!obdef!!*/_ob=true;/*!!obdef!!*/") + } + if (file != "index.js") { + console.log(current + "/" + total + " - " + file + " - Security"); + cnt = "if (require.main === module) { process.exit(255); };" + cnt; + } + console.log(current + "/" + total + " - " + file + " - Minify"); + sml = cnt; // TODO: Do REAL minify + console.log(current + "/" + total + " - " + file + " - Compile"); + obf = JavaScriptObfuscator.obfuscate( + sml, + { + compact: true, + controlFlowFlattening: true, + controlFlowFlatteningThreshold: 1, + numbersToExpressions: true, + simplify: true, + shuffleStringArray: true, + splitStrings: true, + stringArrayThreshold: 1, + selfDefending: true, + deadCodeInjection: true, + deadCodeInjectionThreshold: 0.25, + stringArray: true, + target: "node", + } + ); + obr = obf.getObfuscatedCode() + console.log(current + "/" + total + " - " + file + " - Save"); + fs.writeFileSync("../../" + file, obr); + console.log(current + "/" + total + " - " + file + " - Sign"); + const trust = require("../../trust.js"); + trust.add("../../" + file, "LangDetect Continuous Integration (compil86:1.0)", "./" + file); + } else { + console.log(current + "/" + total + " - " + file + " - Ignore"); + } +} + +function run() { + compile("../trust.js"); + for (var i = 0; i < total; i++) { + file = files[i]; + compile(file); + current++; + } + console.log("Copying certificate keys..."); + fs.copyFileSync("./keys.bin", "../../keys.bin"); +} + +run(); -- cgit