PDA

View Full Version : Parsing, obfuscating and compressing scripts


krycek
11-04-2002, 04:59 PM
Scenario:

I have lots of javascripts, all of which I have written myself. Some of them are going to have to be installed onto a client's server soon, and the last thing I want is for them to be able to muck around with the scripts!

There is always some insecurity, but I think the first thing I need to do is to parse the files and remove all comments, unneccessary whitespace, and also carriage returns. I have seen a couple of scripts to do this but they are in Perl, and I have no idea how to run them! :o Does anyone know a script written in PHP that would do this???

Second, I would like to obfuscate the files, that is, change every variable and function name into letters starting a, b, c... etc. so that they take up less space and also are a lot harder to understand! :D

Again I have found Perl scripts to do this but no PHP ones... also, I would like the script to be as reliable, comprehensive, and automatic as possible - so I do not mind paying for a commercial one. :)

Now, the next thing is, is there any way to prevent people reading the scripts? I am pretty certain the answer is no, and tbh, the parsing and obfuscating will most likely be enough. But, I have seen some sites (ukreg for example) that have .exe files sat on the server handling requests, and I have no idea how etc. I assume they will be written in VB or C or summat, not JavaScript or PHP, but can anyone shed any light onto how to make these babies? If they are not cross-platform don't worry though ;) I think a much better idea would be to somehow compile my scripts into a DLL or summat, but I have no idea...

...any suggestions? :)

Cheers!

::] krycek [::

mordred
11-04-2002, 06:01 PM
I don't know of a PHP script that's explicitly designed to obfuscate JavaScripts (though that would make for an interesting project), but I know of some compression/uglification scripts written in JS to squeeze the size of the scripts and by doing that, replacing repeating code sequences.

http://www.crockford.com/javascript/jsmin.html
http://www.dithered.com/experiments/compression/index.html

Maybe they provide a first help for your purpose. It should not pose a great problem to convert the logic of these scripts to PHP and to add some flavor by opening, modifying and saving the files automatically. File handling with PHP is no voodoo, that should be easy to extend.

Of course obfuscation is no secure thing, but I guess I don't tell you anything new in this sentence. The MS approach with the ScriptEncoder technology is also in vain because a trivial search on Google reveals to many scripts that decode those scripts in seconds.

Anyway, if you've found Perl scripts to satisfy your needs, what speaks against using them (or porting them to PHP if that suits you better)? :)

Socraties
11-04-2002, 07:48 PM
I do know that zend has made a few cool php tools. If I understatnd it correctly, zend has made a tool that will safeguard your code by essentially encrypting the code. The same product that does this will also create a license. It is not a free product and I am not sure if it will work for JS or other languages but it might be worth checking inot the link to is is:

http://www.zend.com/store/products/zend-safeguard-suite.php

Hope this is some help to you.