Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

break javascript one line code to readable code

I have seen people put all their JS code into one single line. (something like this: http://www.drasticdata.nl/DrasticTreemap/Examples/js/swfobject.js) I know they are trying to protect their IP. But I want to read the code and study it.

Is there a way to make those one-line code readable? For example, break it down to multiple lines?

Thanks.

like image 634
JJ Liu Avatar asked Sep 29 '11 23:09

JJ Liu


1 Answers

A quick google search for "JavaScript de-obfuscator" will return you multiple online parsers that format obfuscated code into something formatted and readable.

The following works pretty well:

http://jsbeautifier.org/

There is no way to rename variable names to their, once semantic, forms. Something you'll have to tread through...

A couple of terms to note minification and obfuscation:

Minification (Wikipedia)

Minification (also minimisation or minimization), in computer programming languages and especially JavaScript, is the process of removing all unnecessary characters from source code, without changing its functionality.

Obfuscation (Wikipedia)

Obfuscated code is source or machine code that has been made difficult to understand for humans. Programmers may deliberately obfuscate code to conceal its purpose (security through obscurity) or its logic to prevent tampering, deter reverse engineering, or as a puzzle or recreational challenge for someone reading the source code. Programs known as obfuscators transform readable code into obfuscated code using various techniques.

References

http://en.wikipedia.org/wiki/Obfuscated_code

http://en.wikipedia.org/wiki/Minification_(programming)

like image 126
Alex Avatar answered Sep 25 '22 01:09

Alex