Geeks With Blogs

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

Lorin Thwaits A geek says what?

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.)

Posted on Monday, July 17, 2006 7:39 AM ASP.NET , AJAX | Back to top


Comments on this post: Now you can read between the lines of obfuscated Javascript

# translated to JavaScript/PSPad
Requesting Gravatar...
I wanted to use the beautifier in the PSPad editor, so I translated the cs-code to JavaScript:

http://triess.de/download/format.zip
Left by Stefan Triess on Jul 17, 2006 12:46 PM

# re: Now you can read between the lines of obfuscated Javascript
Requesting Gravatar...
The above link / web site is not available :-(
Left by Pete on Aug 15, 2006 12:53 PM

# re: Now you can read between the lines of obfuscated Javascript
Requesting Gravatar...
Works great!

Thanks
/Jonas
Left by Jonas on Oct 04, 2006 8:46 PM

# re: Now you can read between the lines of obfuscated Javascript
Requesting Gravatar...
Excellent! Thanks Lorin.
Left by Andrew on Oct 18, 2006 7:33 AM

# re: Now you can read between the lines of obfuscated Javascript
Requesting Gravatar...
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/?
Left by Olivier Dony on Jul 19, 2007 2:31 AM

# re: Now you can read between the lines of obfuscated Javascript
Requesting Gravatar...
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.
Left by oa on Nov 07, 2007 1:42 AM

# re: Now you can read between the lines of obfuscated Javascript
Requesting Gravatar...
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
Left by oa on Nov 08, 2007 12:59 AM

# re: Now you can read between the lines of obfuscated Javascript
Requesting Gravatar...
The follow link :http://hdvforever.com/blog/beautifier.zip
is broken,
Can who send me the beautifier.zip?

jrt324@gmial.com

Thanks!
Left by JIm on Jan 21, 2008 9:20 PM

# re: Now you can read between the lines of obfuscated Javascript
Requesting Gravatar...
"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
Left by Bill on Nov 12, 2008 5:55 AM

# re: Now you can read between the lines of obfuscated Javascript
Requesting Gravatar...
I'll try the solenoid disconnect and see what happens.
Left by DDos Protection on Nov 06, 2009 11:34 PM

# re: Now you can read between the lines of obfuscated Javascript
Requesting Gravatar...
could you send me your source code;
my email: yaoancheng@gmail.com
your source download link http://hdvforever.com/blog/beautifier.zip doesnt work;
Left by cya on Mar 20, 2010 3:12 AM

# re: Now you can read between the lines of obfuscated Javascript
Requesting Gravatar...
ditto on the broken source link.

Stefan's link is working, though. Thanks, Stefan.

And Thanks, Lorin.
Left by Jay C on May 06, 2010 11:45 PM

# re: Now you can read between the lines of obfuscated Javascript
Requesting Gravatar...
Tried downloading source; file invalid
Left by Rich on Aug 29, 2010 6:39 PM

Your comment:
 (will show your gravatar)


Copyright © Lorin Thwaits | Powered by: GeeksWithBlogs.net