Generate and Obfuscate Worker Script #5
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: false, | |
| debugProtection: false, | |
| selfDefending: false, | |
| // 保留少量僵尸代码增加分析难度 | |
| deadCodeInjection: true, | |
| deadCodeInjectionThreshold: 0.2, | |
| // 保留的核心保护功能 | |
| disableConsoleOutput: true, | |
| identifierNamesGenerator: 'hexadecimal', | |
| renameGlobals: true, | |
| stringArray: true, | |
| stringArrayEncoding: ['base64'], | |
| stringArrayThreshold: 1, // 100% 隐藏字符串 | |
| transformObjectKeys: true, | |
| unicodeEscapeSequence: 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 |