Skip to content

openapphub/code-obfuscator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

code-obfuscator 🛡️

npm version License: MIT

A powerful HTML and JavaScript obfuscator tool built with Bun runtime. Supports advanced code obfuscation, HTML minification, and external JavaScript file processing.

强大的基于 Bun 运行时的 HTML 和 JavaScript 混淆工具。支持高级代码混淆、HTML 压缩以及外部 JavaScript 文件处理。

✨ Features

English

  • 🚀 High Performance: Built with Bun runtime for lightning-fast processing
  • 🛡️ Advanced Obfuscation: Multiple layers of code protection including control flow flattening, dead code injection, and string array encoding
  • 📄 HTML Support: Process HTML files with inline and external JavaScript
  • 🔧 Flexible Configuration: Extensive obfuscation options for different protection levels
  • 🎯 CLI Tool: Easy-to-use command-line interface
  • 📦 Global Installation: Install globally for system-wide usage

中文

  • 🚀 高性能:基于 Bun 运行时,处理速度极快
  • 🛡️ 高级混淆:多层代码保护,包括控制流扁平化、死代码注入和字符串数组编码
  • 📄 HTML 支持:处理包含内联和外部 JavaScript 的 HTML 文件
  • 🔧 灵活配置:丰富的混淆选项,适用于不同保护级别
  • 🎯 CLI 工具:易用的命令行界面
  • 📦 全局安装:支持全局安装,系统级使用

📦 Installation

Global Installation (Recommended)

npm install -g code-obfuscator

Local Installation

npm install code-obfuscator
# or
bun add code-obfuscator

Development Setup

git clone https://github.com/openapphub/code-obfuscator.git
cd code-obfuscator
bun install

🚀 Usage

Command Line Interface

code-obfuscator --input <input-file> --output <output-file>

# Examples
code-obfuscator --input index.html --output obfuscated.html
code-obfuscator --input script.js --output obfuscated.js
code-obfuscator --input ./src/app.html --output ./dist/app.html

Options

Option Short Description Required
--input -i Input HTML or JS file path Yes
--output -o Output file path Yes
--help -h Show help information No
--version Show version number No

使用示例

混淆 HTML 文件

code-obfuscator --input index.html --output dist/index.html

混淆 JavaScript 文件

code-obfuscator --input app.js --output dist/app.js

批量处理

# Process multiple files
for file in *.html; do
  code-obfuscator --input "$file" --output "dist/$file"
done

⚙️ Obfuscation Features

The tool uses JavaScript Obfuscator with the following protection features:

代码混淆特性

  • 压缩 (Compaction): Remove unnecessary whitespace and comments
  • 控制流扁平化 (Control Flow Flattening): Transform code structure
  • 死代码注入 (Dead Code Injection): Add meaningless code to confuse analysis
  • 字符串数组 (String Array): Encode strings in arrays with transformations
  • 标识符重命名 (Identifier Renaming): Use hexadecimal names
  • 数字表达式 (Numbers to Expressions): Convert numbers to expressions
  • 字符串分割 (String Splitting): Split strings into chunks
  • 自我保护 (Self-Defending): Prevent code beautification
  • 控制台禁用 (Console Output Disabled): Remove console statements

HTML 处理特性

  • 内联 JavaScript 混淆: Obfuscate <script> tags without src
  • 外部 JavaScript 处理: Process external JS files referenced in HTML
  • HTML 压缩: Minify HTML structure
  • 路径保持: Maintain relative paths for external resources

📁 File Structure After Processing

your-project/
├── index.html          # Original HTML file
├── js/
│   ├── app.js         # Original JS file
│   └── utils.js       # Original JS file
└── dist/              # Output directory
    ├── index.html     # Obfuscated HTML
    └── js/
        ├── app.js     # Obfuscated JS
        └── utils.js   # Obfuscated JS

🔧 Configuration

The obfuscator uses optimized default settings, but you can modify obfuscator.ts for custom configurations:

const jsObfuscatorOptions = {
  compact: true,
  controlFlowFlattening: true,
  deadCodeInjection: true,
  stringArray: true,
  // ... other options
};

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

👨‍💻 Author

jinxiaoman

🙏 Acknowledgments

  • Bun - The blazing fast JavaScript runtime
  • JavaScript Obfuscator - The core obfuscation library
  • Cheerio - Fast, flexible, and lean implementation of core jQuery designed for the server

Made with ❤️ using Bun

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published