-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcompresser.mjs
73 lines (73 loc) · 2.53 KB
/
compresser.mjs
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
import fs from 'fs';
import path from 'path';
import obfuscator from 'javascript-obfuscator';
import progressBar from 'progress';
/**
* @author jasonlaubb
* @contributors https://github.com/jasonlaubb/Matrix-AntiCheat?tab=readme-ov-file#developers
* @license AGPLv3
* @link https://github.com/jasonlaubb/Matrix-AntiCheat
*/
const directoryPath = './Matrix_BP/scripts';
const whiteList = ['',]
async function traverseDirectory(directoryPath) {
const files = await fs.promises.readdir(directoryPath, {
withFileTypes: true
});
for (const file of files) {
const filePath = path.join(directoryPath, file.name);
if (file.isDirectory()) {
if (file.name.includes('node_modules') || file.name.includes('data')) continue;
await traverseDirectory(filePath);
} else if (file.isFile() && file.name.endsWith('.js') && !whiteList.includes(file.name)) {
bar.tick({
file: file.name
});
bar.render();
await obfuscateFile(filePath);
}
}
}
async function obfuscateFile(filePath) {
const fileContent = await fs.promises.readFile(filePath, 'utf8');
// Only do dead code injection to prevent slow running
const obfuscatedCode = obfuscator.obfuscate(fileContent, {
compact: true,
stringArray: false,
deadCodeInjection: false,
renameProperties: false,
renameGlobals: true,
stringArrayIndexShift: false,
numbersToExpressions: false,
});
await fs.promises.writeFile(filePath, obfuscatedCode.getObfuscatedCode());
}
let bar;
async function onStart() {
const count = await countLoopIterations(directoryPath);
bar = new progressBar('Compresser: [:bar] :percent :file', {
complete: '=',
incomplete: '.',
width: 30,
total: count
});
await traverseDirectory(directoryPath);
console.log('\nCompresser: Obfuscation process finished.');
}
onStart();
async function countLoopIterations(directoryPath) {
const files = await fs.promises.readdir(directoryPath, {
withFileTypes: true
});
let count = 0;
for (const file of files) {
const filePath = path.join(directoryPath, file.name);
if (file.isDirectory()) {
if (file.name.includes('node_modules')) continue;
count += await countLoopIterations(filePath);
} else if (file.isFile() && file.name.endsWith('.js') && !whiteList.includes(file.name)) {
count++;
}
}
return count; // +1 for the current directory
}