Now you can read between the lines of obfuscated Javascript

A few months ago I wrote a simple Javascript beautifier, which suited my needs at the time.  But since then while dissecting longer AJAX-centric scripts in various websites, I found some things that were giving the beautifier some trouble.  So I took some time this morning to fix a few bugs and improve overall performance.

Some of you may be asking, “What is a beautifier?”  Put in nasty obfuscated code that is all run together, and it spits out something that's nicely formatted and very readable:

function layoutmouseup() {if ((moving != 0) && (target != 0)) {rearrange(
moving, movingcol, target, targetcol);var targ = target;if (movingcol == targetcol
&& target > moving) {targ = targ - 1;}displaylayout();}moving = 0;movingcol =
0;target = 0;targetcol = 0;}

function layoutmouseup()
{
 if ((moving != 0) && (target != 0))
 {
  rearrange(moving, movingcol...
  var targ = target;
  if (movingcol == targetcol ...
  {
   targ = targ - 1;
  }
  displaylayout();
 }
moving = 0; movingcol = 0; target = 0; targetcol = 0; }
 

I've now tested it with all kinds of crazy obfuscated Javascript, and the only thing it doesn't handle properly at this point is RegEx.  I'll have to save that update for the next revision.  For the moment it's a pretty good way to quickly get a handle on obfuscated code.  Pull some crazy code out from any compacted .js file out there and give it a try:
 
http://hdvforever.com/beautify.aspx
 
This will always remain 100% free and open-source.  I hope the developer community at large can benefit from it.

(My post about the original version is here.  The links there point to the updated code.)


Feedback

# translated to JavaScript/PSPad

I wanted to use the beautifier in the PSPad editor, so I translated the cs-code to JavaScript:

http://triess.de/download/format.zip
7/17/2006 12:46 PM | Stefan Triess

# re: Now you can read between the lines of obfuscated Javascript

The above link / web site is not available :-( 8/15/2006 12:53 PM | Pete

# re: Now you can read between the lines of obfuscated Javascript

Works great!

Thanks
/Jonas 10/4/2006 8:46 PM | Jonas

# re: Now you can read between the lines of obfuscated Javascript

Excellent! Thanks Lorin. 10/18/2006 7:33 AM | Andrew

# re: Now you can read between the lines of obfuscated Javascript

I've tried your beautifier but ended up on a cryptic indexOutOfBoundsException, and I don't have the time to have a look at the source code and/or fix it.

However I found this excellent other beautifier (written in PHP apparently) and it worked very well!
You might want to try it, since you were looking for one in the first place: http://elfz.laacz.lv/beautify/? 7/19/2007 2:31 AM | Olivier Dony

# re: Now you can read between the lines of obfuscated Javascript

To solve the RegExp detection you can check:
if current char = "/" and previous non-space char = "(" --> it's a RegExp.

Please fix the comments bug as well, Keep double line breaks and keep inline comments on their original line (breaking after the comment rather than after semicolon).

I'll try to do all of that myself, and if i prevail i'll post the code in here.
11/7/2007 1:42 AM | oa

# re: Now you can read between the lines of obfuscated Javascript

ok, try this version, and tell me what you think.
it supports comments and regular expressions.
but it's still bogus.
someone here wanna fix them...? :*)
http://www.megiadam.com/oria/files/pspad.addon.format.0.2b1.zip
11/8/2007 12:59 AM | oa

# re: Now you can read between the lines of obfuscated Javascript

The follow link :http://hdvforever.com/blog/beautifier.zip
is broken,
Can who send me the beautifier.zip?

jrt324@gmial.com

Thanks!
1/21/2008 9:20 PM | JIm

# re: Now you can read between the lines of obfuscated Javascript

"The follow link :http://hdvforever.com/blog/beautifier.zip
is broken,
Can who send me the beautifier.zip?"

Could this be uploaded again or emailed to me please 11/12/2008 5:55 AM | Bill

# ed hardy shop

I'll try to do all of that myself, and if i prevail i'll post the code in here.
10/23/2009 3:23 AM | ed hardy

# re: Now you can read between the lines of obfuscated Javascript

I'll try the solenoid disconnect and see what happens. 11/6/2009 11:34 PM | DDos Protection

Post a comment





 

News


Welcome to my blog.
Here's what we've got on the menu today:

Tag Cloud


Article Categories

Archives

Post Categories

Image Galleries

Syndication: