Is there such a thing as a javascript deminifier (deobfuscator)?

为君一笑 提交于 2019-11-26 13:18:17

问题


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

I want to learn how google does it's loading so I can build my own with non-popular JS toolkits.


回答1:


Try this: JS Beautifier




回答2:


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.




回答3:


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.




回答4:


Chrome Developer tools has this built in




回答5:


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)




回答6:


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.




回答7:


To unminify js files, Unminify would be the best!




回答8:


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?




回答9:


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.



来源:https://stackoverflow.com/questions/1387810/is-there-such-a-thing-as-a-javascript-deminifier-deobfuscator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!