1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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();
|