Generate and Obfuscate Worker Script #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |