-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfu.js
48 lines (42 loc) · 1.49 KB
/
confu.js
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
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
const inputDir = path.resolve(__dirname, 'aaa');
const outputDir = path.resolve(__dirname, 'src');
// 遍历目录获取所有 .js 文件
function getAllJsFiles(dir, files = []) {
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
getAllJsFiles(fullPath, files);
} else if (entry.isFile() && fullPath.endsWith('.js')) {
files.push(fullPath);
}
}
return files;
}
// 创建输出目录
function ensureDirectoryExistence(filePath) {
const dirname = path.dirname(filePath);
if (!fs.existsSync(dirname)) {
fs.mkdirSync(dirname, { recursive: true });
}
}
// 混淆并保存文件
function obfuscateAndSave(inputFile, outputFile) {
ensureDirectoryExistence(outputFile);
const command = `javascript-obfuscator "${inputFile}" --output "${outputFile}"`;
execSync(command, { stdio: 'inherit' });
}
// 主函数
function main() {
const jsFiles = getAllJsFiles(inputDir);
jsFiles.forEach(file => {
const relativePath = path.relative(inputDir, file);
const outputFilePath = path.join(outputDir, relativePath);
obfuscateAndSave(file, outputFilePath);
});
console.log(`混淆完成,文件已存储到 ${outputDir}`);
}
main();