forked from byJoey/cfnew
-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (87 loc) · 3.56 KB
/
obfuscate.yml
File metadata and controls
101 lines (87 loc) · 3.56 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: Generate and Obfuscate Worker Script
on:
workflow_dispatch:
push:
branches:
- '**' # 仅匹配分支推送,排除标签推送
paths:
- '明文源吗'
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: Obfuscate from local source file
run: |
cat > obfuscate.js << 'EOF'
const JavaScriptObfuscator = require('javascript-obfuscator');
const fs = require('fs');
const path = require('path');
const sourceFileName = '明文源吗';
const outputFileName = '少年你相信光吗';
const sourceFilePath = path.join(process.cwd(), sourceFileName);
if (!fs.existsSync(sourceFilePath)) {
console.error('错误:在路径 \'' + sourceFilePath + '\' 未找到源文件。请确保您的仓库根目录有名为 \'明文源吗\' 的文件。');
process.exit(1);
}
const originalCode = fs.readFileSync(sourceFilePath, 'utf8');
if (!originalCode || originalCode.trim().length === 0) {
console.error('错误:源文件 ' + sourceFileName + ' 为空。');
process.exit(1);
}
const obfuscationOptions = {
compact: true,
controlFlowFlattening: false,
controlFlowFlatteningThreshold: 0,
deadCodeInjection: false,
stringArray: true,
stringArrayEncoding: ['base64'],
stringArrayThreshold: 1.0,
stringArrayRotate: true,
stringArrayShuffle: true,
stringArrayWrappersCount: 2,
stringArrayWrappersChainedCalls: false,
stringArrayWrappersParametersMaxCount: 3,
renameGlobals: true,
identifierNamesGenerator: 'mangled-shuffled',
identifierNamesCache: null,
identifiersPrefix: '',
renameProperties: false,
renamePropertiesMode: 'safe',
ignoreImports: false,
target: 'browser',
numbersToExpressions: false,
simplify: false,
splitStrings: true,
splitStringsChunkLength: 1,
transformObjectKeys: false,
unicodeEscapeSequence: true,
selfDefending: false,
debugProtection: false,
debugProtectionInterval: 0,
disableConsoleOutput: true,
domainLock: []
};
const obfuscatedCode = JavaScriptObfuscator.obfuscate(originalCode, obfuscationOptions).getObfuscatedCode();
fs.writeFileSync(path.join(process.cwd(), outputFileName), obfuscatedCode, 'utf8');
console.log('成功将 \'' + sourceFileName + '\' 混淆并保存至 \'' + outputFileName + '\'。');
EOF
node obfuscate.js
- 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 "部署用这个"
git push
fi