There is this awesome online tool, JSNice, that makes a great job of finding names to obfuscated variables.

We make even obfuscated JavaScript code readable. We will rename variables and parameters to names that we learn from thousands of open source projects. Furthermore, often we are also able to guess or infer type annotations.

Answer from cmolina on Stack Overflow
🌐
Unminify
unminify.com
Unminify JS, CSS, HTML, XML and JSON Code
Free tool to unminify (unpack, deobfuscate) JavaScript, CSS, HTML, XML and JSON code, making it readable and pretty.
🌐
GitHub
github.com › eth-sri › UnuglifyJS
GitHub - eth-sri/UnuglifyJS: A simpler open-source version of JavaScript deobfuscator JSNice
UnuglifyJS is a JavaScript tool that renames variables and parameters to names based on statistical model learnt from thousands of open source projects. This is on open-source reimplementation of the JS Nice tool which provides similar functionality.
Starred by 261 users
Forked by 32 users
Languages   JavaScript 99.6% | Python 0.4% | JavaScript 99.6% | Python 0.4%
🌐
GitHub
github.com › davidaq › deuglifyjs
GitHub - davidaq/deuglifyjs: Reverse uglified Javascript code
A utiltiy for reversing minified JS files, not simply formating whitespaces but also tries to make code much more readable.
Starred by 8 users
Forked by 4 users
Languages   JavaScript 100.0% | JavaScript 100.0%
🌐
Skalman
skalman.github.io › UglifyJS-online
UglifyJS 3: Online JavaScript minifier
UglifyJS 3 is an excellent tool to help you minify your JavaScript!
🌐
JS Minify
uglifyjs.net
JS Minify and Beautify - Online
Minify (uglify) your JS data or beautify (prettify) it with advanced formatting options. Our site has an easy to use online tool to convert your data.
🌐
npm
npmjs.com › package › uglify-js
uglify-js - npm
August 29, 2024 - Note: you may want to disable `negate_iife` under compressor options. -O, --output-opts [options] Specify output options (`beautify` disabled by default). -o, --output <file> Output file path (default STDOUT). Specify `ast` or `spidermonkey` to write UglifyJS or SpiderMonkey AST as JSON to STDOUT ...
      » npm install uglify-js
    
Published   Aug 29, 2024
Version   3.19.3
Author   Mihai Bazon
🌐
npm
npmjs.com › package › unuglify-js
unuglify-js - npm
February 20, 2015 - UnuglifyJS is a JavaScript tool that renames variables and parameters to names based on statistical model learnt from thousands of open source projects. This is on open-source reimplementation of the JS Nice tool which provides similar functionality.
      » npm install unuglify-js
    
Published   Feb 20, 2015
Version   0.9.5
🌐
Unminify2
unminify2.com
Unminify JS, CSS, HTML
Free online tool to unminify JS, CSS, HTML compressed code, making it readable again. Unminify, uncompress and beautify any minified JS, CSS, HTML code.
Find elsewhere
🌐
Lisperator
lisperator.net › uglifyjs
UglifyJS — JavaScript parser, compressor, minifier written in JS
Here are some stats showing where UglifyJS2 stands compared to other minifiers. Show charts. JS compressor of world fame.
🌐
GitHub
github.com › meitalbensinai › UnuglifyJS
GitHub - meitalbensinai/UnuglifyJS: A simpler open-source version of JavaScript deobfuscator JSNice
UnuglifyJS is a JavaScript tool that renames variables and parameters to names based on statistical model learnt from thousands of open source projects. This is on open-source reimplementation of the JS Nice tool which provides similar functionality.
Author   meitalbensinai
🌐
GitHub
github.com › mishoo › UglifyJS
GitHub - mishoo/UglifyJS: JavaScript parser / mangler / compressor / beautifier toolkit · GitHub
Note: you may want to disable `negate_iife` under compressor options. -O, --output-opts [options] Specify output options (`beautify` disabled by default). -o, --output <file> Output file path (default STDOUT). Specify `ast` or `spidermonkey` to write UglifyJS or SpiderMonkey AST as JSON to STDOUT ...
Starred by 13.4K users
Forked by 1.2K users
Languages   JavaScript
Top answer
1 of 5
22

I'm specifically looking to unminify a minified JavaScript file. Variable renaming is not a big issue, I want it sufficiently readable to be able to analyze the execution.

Your question title indicates merely reversing minified code, and not necessarily understanding it. But if you are attempting to gain an understanding of it, Opera Dragonfly sounds like a tool you may find very useful...

I have always used Dragonfly for analyzing minified code. In addition to having a pretty printer, it also has incredibly handy analysis functionality.

Here is jQuery.min in all it's minified glory...

The button I circled here is the pretty printer which suddenly turns the code into something like this:

Which is a nice start, but it is still very difficult to understand without some idea of what it looks like during execution.

First you need to determine what part of a minified file's functionality you are trying to understand. Event breakpoints are incredibly handy for this because you can set them for almost any user input, or on an element's load. For example, if I wanted to see what happens in jQuery when a mouseover event occurs, I could add an event breakpoint for "mouseover". That way I can see where the entry point into the code is when I move my mouse over a specific element.

When your code hits a breakpoint, you get into a mode where you can, like in many DOM debuggers, interact with the current state of the code you are inspecting. But you are able to do it by hovering the mouse over sections of code so it's really quite easy to keep the code context in mind.

You can also inspect scope and who references what from the "State" sub-tab in the Scripts tab in the same way as you can with the source window. So you can see if a variable overrides another, or if fancy closure magic is happening somewhere, or what scope a variable actually originated from. Also if you look at a DOM element, you can mouse over that to highlight it on the page. (See last picture.)

The Dragonfly console also has this mouseover functionality... Also everything has tab completion, so you can execute any code from any state, inspect at any level of execution, reassign variables, run tests, or just navigate around with [Tab] completion to do just about anything to figure out what the code you are looking at does.

Opera's inspector will definitely aid in reversing and understanding minified or obfuscated code.

2 of 5
16

I prefer to use the pretty printer inbuilt in Google Chrome's Developer Tools.

Here is the minified Code:

On pressing the pretty print button, you get the following:

Top answer
1 of 3
36

There isn't any real distinction between the two. Even UglifyJS calls itself a minification toolkit.

The distinction could be more relevant when comparing JavaScript minification to CSS minification—CSS minification involves only removing whitespace—the original code remains intact.

With JavaScript, it is possible to not only remove whitespace, but also to make transformations to the code, such as truncating variable names to single characters.

Minifying JavaScript not only makes the source smaller; it also makes the code less readable, or obfuscates it. But do not operate under the assumption that minification or uglification, or whatever you want to call it, is a security measure. It isn't encryption. The code is harder to read, but it is not impossible to read, and while it's not usually possible to return minified code back to its original form, it is possible to 'beautify' it and make it more readable.

It doesn't make sense to both minify and uglify, because most minifiers will both remove whitespace and unnecessary characters, as well as obfuscate the code. All you're doing is introducing another build step.

2 of 3
21

Minifying is just removing unnecessary white-space and redundant like comments and semicolons. And it can be reversed back when needed.

Uglifying is transforming the code into an "unreadable" form by changing variable names, function names, etc., to hide the original content. Once it is used, there isn't any way to reverse it back.

Some libraries, like UglifyJS, does minification when used, by removing unnecessary parts. But in general, uglifying is making the code unreadable.

Minifying your code speeds up your page loading, making visitors and search engines happy, and it is also readable. Most major browsers minify the code before execution.

🌐
GitHub
github.com › cadorn › uglify-js
GitHub - cadorn/uglify-js: JavaScript parser / mangler / compressor / beautifier library for NodeJS
Update: please read the section on unsafe transformations. This package implements a general-purpose JavaScript parser/compressor/beautifier toolkit. It is developed on NodeJS, but it should work on any JavaScript platform supporting the CommonJS module system (and if your platform of choice doesn’t support CommonJS, you can easily implement it, or discard the exports.* lines from UglifyJS sources). The tokenizer/parser generates an abstract syntax tree from JS ...
Author   cadorn
🌐
npm
npmjs.com › package › uglifyjs
uglifyjs - npm
Author message:uglifyjs is deprecated - use uglify-js instead.
      » npm install uglifyjs
    
Published   May 15, 2017
Version   2.4.11
🌐
Quora
quora.com › Is-there-a-way-to-de-minify-JavaScript-code
Is there a way to de-minify JavaScript code? - Quora
Answer (1 of 5): I am guessing that you want to see your original source code even after minification. In such cases, it is appropriate to generate source maps while minifying. Most build tools provide an uglify/minify plugin which comes with an option to generate sourcemaps. For example, the gr...
🌐
CodeSandbox
codesandbox.io › examples › package › unuglify-js
unuglify-js examples - CodeSandbox
Use this online unuglify-js playground to view and fork unuglify-js example apps and templates on CodeSandbox.
🌐
GitHub
github.com › gruntjs › grunt-contrib-uglify
GitHub - gruntjs/grunt-contrib-uglify: Minify files with UglifyJS.
In this example, running grunt uglify:my_target will prepend a banner created by interpolating the banner template string with the config object. Here, those properties are the values imported from the package.json file (which are available via the pkg config property) plus today's date.
Starred by 1.5K users
Forked by 347 users
Languages   JavaScript 100.0% | JavaScript 100.0%