2

There are many tools to compress a Javascript file (Packer YUI for example).

But how can I decompress them back to a human readable format?

I have compressed a file using a tool like Packer YUI , but I couldn't reach the source back again.

Is there any good software or tricks you can suggest to decompress the JS ?

Mac Taylor
  • 5,020
  • 14
  • 50
  • 73
  • 3
    Hint: Capital letters, proper punctuation and using normal words instead of leet-speak make it easier for people to read your question. – Quentin Feb 12 '10 at 10:13
  • See the Pretty Print features of Chrome or IE Developer Tools. See http://stackoverflow.com/a/7149719/2291 These won't unpack them, but will make them easier to read. – Jon Adams May 10 '12 at 17:18

6 Answers6

4

You can't. Javascript compression is usually a lossy one, and the information is lost forever.

What you can do, is use a source formatter and a good refactoring tool and -- painfully -- reconstruct the original source. Even if you are not familiar with the code it should be possible; Jeff and a few others reverse engineered the WMD javascript code from a minified version.

Finally, you should consider using a version control system and proper backups to keep your source code safe.

David Schmitt
  • 58,259
  • 26
  • 121
  • 165
  • thanks but is there any software to tidy up the mess , so u r telling i lost my script for ever , i always wonder how can i user version control system , any software any online service ? – Mac Taylor Feb 12 '10 at 10:07
  • +1 for mentioning, that JS compression is lossy. Another +1 for the source formatter. And a third +1 for the version control system and backups. Summing it up, taking modulo 2 and finally adding +1 to the answer. – Boldewyn Feb 12 '10 at 10:11
  • @Mac Tylor: If you're a Windows user, take a look at TortoiseSVN. Mac comes with Time Machine (more a backup software than a full featured VCS), and for *NIX you have the most remarkably rich choice of dozens of good command line based systems (and git-gui or gitk, if you choose git and need visible feedback). – Boldewyn Feb 12 '10 at 10:13
  • Online Services: Either you pay, or you publish your soruce code as open source. In the latter case you have the free choice among e.g.: SourceForge, GitHub, Google Code, Codeplex, ... – Boldewyn Feb 12 '10 at 10:15
  • thanks guys , im a windows user and i would give toroise a try – Mac Taylor Feb 12 '10 at 10:23
  • @Mac: not lost. Just a helluva work to get it back. It's still less work to rename all vars and redo the comments than to recode (and re-test and re-debug) the whole script. – David Schmitt Feb 12 '10 at 11:35
3

This website is really cool. You can paste a minified JS, then you get a human readable view.

jacktrades
  • 7,224
  • 13
  • 56
  • 83
3

Try JSMinNpp (now called JSToolNpp) plugin for notepad++ (to compress and decompress). http://www.sunjw.us/jstoolnpp/

Sun Junwen
  • 1,068
  • 10
  • 20
clsturgeon
  • 192
  • 2
  • 11
0

DECOMPRESS JAVASCRIPT

A typical JavaScript compressed with /packer/ starts with the following code:

      `eval(function(p,a,c,k,e,r)`…
      `eval` can simply be replaced by alert.

The eval function evaluates a string argument that contains JavaScript. In most packers, eval is used, followed by document.write.

To decompress JavaScript, replace these methods by one of the following:

1. Replace eval by alert (The alert will simply print the code in a popup-window)

2. If the JavaScript appears after the <body> element, you can add a <textarea> like so:

      `<textarea id="code"></textarea>`

Then, replace eval(…); by document.getElementById("code").value=…;.

0

A linter like ESLint can be handy as well. It can format the code using the "fix all auto-fixable problems" to a point where you can at least start doing manual editing with greater ease.

Wachaga Mwaura
  • 3,310
  • 3
  • 28
  • 31
-1

I never used Packer YUI. But if you use this javascript packer, you can always get your code back using this javascript beautifier which also decompresses the code.

Some javascipt minifier shorten the variable names while compressing the js. In that case you could never get your original code back even if you beautify it.