Is there such a thing as a JavaScript deminifier (deobfuscator)? [closed]
Asked Answered
B

10

22

This question is exactly the opposite of Which JavaScript minifier (cruncher) does the same things that the one Google uses for its JavaScript APIs?.

I want to learn how Google does its loading, so I can build my own with non-popular JavaScript toolkits.

Busk answered 7/9, 2009 at 6:25 Comment(4)
I just found I didn't search for "unminify" #822619, although I still think this is valid as neither of the answers works to "undo the variable renaming"Busk
You are using the wrong term in your question. What you are really interested in reversing "obfuscation" (identifier renaming). THus you've gotten a bunch of answers correct for your question but not for your apparant purpose.Reign
If there's no sourcemap, the best you can do is beautify it. If the variable names were all shortened, there's no way to... unshorten them without having the source. (and if you had the source, there's no point in deobfuscating it.)Precocious
Possible duplicate of How to deminify javascriptWatters
A
33

Try this: JS Beautifier

Abba answered 7/9, 2009 at 6:28 Comment(4)
This is just a code formatter, very good at it but not what I'm look for here.Busk
It doesn't just format youy code, it's supposed to do the "deminifier" thing .. had you tried actually?Abba
@Yoda: How can it dobfuscate? It appears to know nothing about identifiers.Reign
JavaScript Obfuscator You can paste your code to the "Obfuscated Output" textarea and press "decode"Vapor
L
23

Try http://www.jsnice.org/

I just stumbled on it and it is great. It expands the code. It has statistical variable renaming. for example, if you have this code:

var g = f.originalEvent.targetTouches[0];

Then it it turns your code into:

var touches = event.originalEvent.targetTouches[0];

Pretty good guess, methinks.

It turned this:

d.slide.hasClass("selected") ? (e.onSlideOpen.call(d.prev.children("div")[0]), q ? (e.rtl && d.slide.position().left > i.w / 2 || d.slide.position().left < i.w / 2) && h.animateSlide.call(d) : t && d.index ? (h.animateGroup(d, !0), h.fitToContent(d.prev)) : d.slide.position().top < i.h / 2 && h.animateSlide.call(d)) : (setTimeout(function() { e.onSlideOpen.call(d.slide.children("div")[0]) }, e.slideSpeed), h.animateGroup(d), t && h.fitToContent(d.slide)), e.autoPlay && (f.stop(), f.play(l.index(j.filter(".selected"))))

Into this:

if (e.slide.hasClass("selected")) {
    settings.onSlideOpen.call(e.prev.children("div")[0]);
    if (val) {
      if (settings.rtl && e.slide.position().left > box.w / 2 || e.slide.position().left < box.w / 2) {
        self.animateSlide.call(e);
      }
    } else {
      if (isMac && e.index) {
        self.animateGroup(e, true);
        self.fitToContent(e.prev);
      } else {
        if (e.slide.position().top < box.h / 2) {
          self.animateSlide.call(e);
        }
      }
    }
  } else {
    setTimeout(function() {
      settings.onSlideOpen.call(e.slide.children("div")[0]);
    }, settings.slideSpeed);
    self.animateGroup(e);
    if (isMac) {
      self.fitToContent(e.slide);
    }
  }
  if (settings.autoPlay) {
    node.stop();
    node.play(tabs.index(options.filter(".selected")));
  }

A library I'm working on has a couple of bugs, and after spending hours trying to decipher the code, finding this is going to save me a bunch of time.

Seriously, this tool wipes the floor with JS Beautifier.

Leptophyllous answered 3/12, 2014 at 15:3 Comment(3)
Very nice. Automatic type detection too. Three years after this comment, this still looks like the best de-minimizer.Shipentine
Times out on large files unfortunatelyDagnah
Any alternative for this one? Looked really great, now offPlumcot
B
15

Uhhh, it would be impossible to restore variable names unless there was a mapping of minified -> original variable names available. Otherwise, I think the authors of that tool could win the Randi prize for psychic feats.

Bronchus answered 7/9, 2009 at 7:10 Comment(2)
Of course you will not be able to regain the original names. But if it at least get you better names you can later find&replace, in other word the tool will know JS syntax and replace the variable a with method_named_a but will not replace it in ba() because that will generate a syntax errorBusk
You specifically complained that the beautifiers didn't "undo the variable renaming", implying you wanted the original symbols back.Bronchus
K
7

Chrome Developer tools has this built in

Kizzee answered 1/4, 2014 at 14:40 Comment(0)
A
2

You will not be able to reconstruct method name or variable names. The best you can hope for is a simple JS code formater (like those previously mentioned), and then to go through the file method by method, line by line, working out what each part does.

Perhaps using a good JS refactoring tool would make this easier as well (being able to rename/document methods)

Arieariel answered 7/9, 2009 at 7:11 Comment(2)
Ok this seems like a better lead, so which is a good JS refractoring tool?Busk
Intellij IDEA can do method/variable renaming on Javascript files. Apparantly CodeRush / Refactor Pro will do the same in Visual StudioArieariel
R
0

See our SD ECMAScript Formatter for a tool that will nicely format code.

EDIT: If you want to reverse the renaming process you need something can rename the obfuscated names back to the originals.

This tool can technically do that: SD Thicket ECMAScript Obfuscator.

It does so by applying a renaming map over which you have precise control. Typically you implicitly construct such a map during the obfuscation process by choosing which names to obfuscate and which to preserve, and the obfuscator applies that map to produce the obfuscated code.

The Thicket obfuscator generates this map as side effect when you obfuscate in the form essentially of a set of pairs (originalname,obfuscatedname) for reference and debugging purposes.

Swapping elements gives the map (obfuscatedname,originalname). That inverted map can be applied by Thicket to recover the code with the original names, from the obfuscated code. And the Thicket obfuscator includes the Formatter to let you make it look nice again.

The catch to "reversing minification" (as you put it poorly, you are trying to reverse obfuscation), is that you need the map. Since people doing obfuscation don't give away the map, you, as a recipient of obfuscated code, have nothing to apply. A would-be pirate would have to reconstruct the map presumably by painful reverse engineering.

The "reversing" process also can't recover comments. They're gone forever.

This is all by design, so the real question is why are you looking to reverse obfuscation?

Reign answered 7/9, 2009 at 7:5 Comment(5)
@Jorge: that's because your original question misused the term "minification" when you meant "obfuscation". I've expanded the answer to tell you exactly how to reverse the obfuscation process to the extent possible. The tools will do it if you have the right data. You are unlikely to have that data.Reign
This is not a deobfuscator too. It just maps identifer names and pretty prints.Frenulum
That's exactly what I said, and that you'd couldn't do better than that.Reign
@Ira, I do not agree variable renaming is not obfuscation, it's simply minification of "letters" rather than "whitespace". Obfuscation of variable names is to add variables/methods that are not needed or to replace 1 call with 2 calls one to a dummy method that simply redirects.Busk
Most users/victims of such tools think they are fine obfuscators even if you have a different definition. It is true that one could do more to obfuscate code. I could claim that adding useless method calls isn't obfuscation, and that I was satisfied only if you scrambled control flow, data flow, and converted the result to a 3 state 7 symbol Turing machine, but this is disingenuous. The issue here is degree of obfuscation, not whether obfuscated. YMMV.Reign
F
0

You can use the \b (word boundary) feature in regular expressions to find single-letter variable names in a file.

for i in "abcdefghij..z"; do
    sed -i "s/\b$i\b/$(random /usr/share/dict/words)/g" somefile.js
done

You can also use this in vim with something like :%s/\<a\>/truesaiyanpower/g.

Foregather answered 13/7, 2012 at 21:59 Comment(0)
H
0

To unminify JavaScript files, Unminify would be the best!

Heim answered 15/1, 2016 at 12:4 Comment(1)
Why would it be the best?Impute
A
0

To unminify CSS, HTML and JavaScript files, you can use the Unminify or Unminify JS online tools!

Armilda answered 3/3, 2020 at 10:54 Comment(2)
How is this any different to the one posted by Shafizadeh? I can see the actual link is different, is it just someone else's online implementation of unminify?Polycotyledon
There are multiple tools are available to format and convert into read only formats. I am not sure all tools are same, but it help you to format all your web elements like JS, html and CSS in effective manner. Thanks.Armilda
G
-2

A JavaScript minifier and JavaScript obfuscator are two different things.

Minifier - removes the comments, unnecessary whitespace and newlines from a program.

Obfuscator - make modifications to the program, changing the names of variables, functions, and members, making the program much harder to understand. Some obfuscators are quite aggressive in their modifications to code.

This JavaScript obfuscator will obfuscate your code.

If you want to deobfuscate your code, try JavaScript Beautifier. It will deobfuscate if obfuscation is found and then beautify the code.

Gudren answered 30/11, 2015 at 19:19 Comment(1)
minifiers may also obfuscate with the purpose of making the code smaller, it being hard to read is just a side effect.Precocious

© 2022 - 2024 — McMap. All rights reserved.