|
|
@@ -0,0 +1,38 @@
|
|
|
+const fs = require('fs');
|
|
|
+const path = require('path');
|
|
|
+const JavaScriptObfuscator = require('javascript-obfuscator');
|
|
|
+
|
|
|
+// 指定要混淆的文件
|
|
|
+const mainFilePath = path.join(__dirname, 'electron.js');
|
|
|
+const distFilePath = path.join(__dirname, 'build', 'electron.js');
|
|
|
+
|
|
|
+// 读取 `main.js` 文件内容
|
|
|
+const fileContent = fs.readFileSync(mainFilePath, 'utf8');
|
|
|
+
|
|
|
+// 配置混淆选项
|
|
|
+const obfuscationResult = JavaScriptObfuscator.obfuscate(fileContent, {
|
|
|
+ compact: true,
|
|
|
+ controlFlowFlattening: true,
|
|
|
+ controlFlowFlatteningThreshold: 0.75,
|
|
|
+ deadCodeInjection: true,
|
|
|
+ deadCodeInjectionThreshold: 0.4,
|
|
|
+ debugProtection: true,
|
|
|
+ debugProtectionInterval: 3000,
|
|
|
+ disableConsoleOutput: true,
|
|
|
+ identifierNamesGenerator: 'hexadecimal',
|
|
|
+ renameGlobals: false,
|
|
|
+ selfDefending: true,
|
|
|
+ stringArray: true,
|
|
|
+ stringArrayEncoding: ['base64'],
|
|
|
+ stringArrayThreshold: 0.75,
|
|
|
+ transformObjectKeys: true,
|
|
|
+ unicodeEscapeSequence: false,
|
|
|
+});
|
|
|
+
|
|
|
+if (!fs.existsSync(path.dirname(distFilePath))) {
|
|
|
+ fs.mkdirSync(path.dirname(distFilePath), { recursive: true });
|
|
|
+}
|
|
|
+
|
|
|
+// 将混淆后的代码写入 `dist/main.js`
|
|
|
+fs.writeFileSync(distFilePath, obfuscationResult.getObfuscatedCode());
|
|
|
+console.log(`Successfully obfuscated ${mainFilePath} to ${distFilePath}`);
|