Humanify: Deobfuscate JS with AI & Babel
In the world of web development, minified and obfuscated JavaScript code can be a significant hurdle for understanding and debugging. Fortunately, innovative open-source projects are emerging to tackle this challenge. One such project is Humanify, a versatile tool that leverages the power of Large Language Models (LLMs) like ChatGPT and Gemini, combined with sophisticated Babel plugins, to transform complex, unreadable JavaScript into a human-friendly format.
Humanify aims to deobfuscate, unminify, transpile, and unpack JavaScript code. While LLMs primarily assist in renaming variables and functions for better clarity, the core heavy lifting of structural code transformation is handled by Babel at the Abstract Syntax Tree (AST) level, ensuring that the code's functionality remains perfectly intact (1-to-1 equivalent).
Key Features and Benefits:
- AI-Powered Renaming: Utilizes LLMs to intelligently suggest descriptive names for variables and functions, vastly improving code readability.
- AST-Level Transformation: Employs custom and off-the-shelf Babel plugins to perform unmangling and code restructuring at a fundamental level.
- Webpack Unbundling: Includes support for
Webcrack
to effectively unbundle Webpack-bundled JavaScript applications. - Flexible Execution Modes: Offers flexibility in how you run the tool:
- OpenAI/Gemini Mode: Connects to cloud-based AI services (requiring API keys) for potentially higher accuracy and convenience, though with associated costs depending on code size.
- Local Mode: Allows you to run the deobfuscation process entirely on your machine, utilizing either your CPU or GPU. This mode is free and offers excellent performance, especially on Apple Silicon Macs, though the accuracy can sometimes be influenced by the local model used.
- Cross-Platform Compatibility: Designed to run on Node.js, making it accessible to a wide range of developers.
- Ease of Installation: Installable globally via npm (
npm install -g humanifyjs
) or usable directly vianpx
for quick testing (npx humanifyjs
).
Getting Started with Humanify:
- Installation: Ensure you have Node.js (version 20 or higher) installed. Then, install Humanify globally using
npm install -g humanifyjs
. - Usage: You can run the tool from your terminal. For example, to deobfuscate a file named
obfuscated-script.js
using OpenAI's API:Or using Gemini:humanify openai --apiKey="your-api-key" obfuscated-script.js
For local processing, you'll first need to download a model (e.g.,humanify gemini --apiKey="your-google-api-key" obfuscated-script.js
humanify download 2b
) and then run:humanify local obfuscated-script.js
Humanify represents a significant step forward in making JavaScript code more transparent and understandable. Whether you're dealing with third-party scripts, legacy code, or simply want to improve the maintainability of your own projects, this open-source tool provides a powerful and adaptable solution. Its combination of AI intelligence and robust code transformation capabilities makes it a must-have in any developer's toolkit.