-
Notifications
You must be signed in to change notification settings - Fork 6.2k
81 lines (65 loc) · 2.74 KB
/
obfuscate.yml
File metadata and controls
81 lines (65 loc) · 2.74 KB
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
74
75
76
77
78
79
80
81
name: Generate and Obfuscate Worker Script
on:
workflow_dispatch:
schedule:
- cron: '0 * * * *'
jobs:
build-and-obfuscate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install Obfuscator
run: npm install javascript-obfuscator
- name: Create source file and obfuscate
run: |
node -e "
const JavaScriptObfuscator = require('javascript-obfuscator');
const fs = require('fs');
const originalCode = process.env.SOURCE_CODE;
if (!originalCode || originalCode.length < 50) {
console.error('Error: Source code from secrets is missing or empty.');
process.exit(1);
}
// --- 最终平衡型混淆配置 ---
const obfuscationOptions = {
compact: true,
// 启用轻度的逻辑混淆,以平衡安全与性能
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 0.75,
deadCodeInjection: true,
deadCodeInjectionThreshold: 0.4,
// 借鉴自新配置的高效保护功能
stringArray: true,
stringArrayEncoding: ['base64'],
stringArrayThreshold: 0.75,
renameGlobals: true,
identifierNamesGenerator: 'mangled', // 使用更短的混淆名称
numbersToExpressions: true, // 数字转为表达式
splitStrings: true, // 分割字符串
splitStringsChunkLength: 10,
transformObjectKeys: true,
// 禁用对性能影响最大的选项
selfDefending: false,
debugProtection: false
};
const obfuscatedCode = JavaScriptObfuscator.obfuscate(originalCode, obfuscationOptions).getObfuscatedCode();
fs.writeFileSync('./少年你相信光吗', obfuscatedCode, 'utf8');
"
env:
SOURCE_CODE: ${{ secrets.WORKER_SOURCE_CODE }}
- name: Commit and push the obfuscated file
run: |
git config --global user.name 'GitHub Actions Bot'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add '少年你相信光吗'
if git diff --staged --quiet; then
echo "No changes to commit, the obfuscated file is already up-to-date."
else
git commit -m "build: Generate and obfuscate worker script"
git push
fi