user2976086
user2976086

Reputation: 53

obfuscation of javascript and browsers

If I obfuscate javascript code how does the browser process/understand it?

Second if I want to obfuscate a short script in an HTML what are the steps I need to take to do that as I've never doen this before? Do I paste javascript into some sort of tool and which 'scrambles' it and then I paste the results back into my html page?

Thanks

Upvotes: 0

Views: 2695

Answers (1)

Ira Baxter
Ira Baxter

Reputation: 95420

The secret to obfuscation is the browser never "understood" the original pretty program in the first place, and in fact does not need to understand it. All it does is execute the individual bits of the program in the order the program says. This is the point of Turing machines; mere local symbol manipulation is enough to do any computation.

So, your pretty program is executed as little bits, each of which does something specific; e.g.

   x = y + z;  // sum the elements
   if (p)  q = 1; // handle special condition
   print(x+q);  // produce the answer

An obfuscator tool scrambles the names used by the bits in consistent way, and may shuffle the bits of computation about in a way that don't affect the result, e.g.,

   if (r7)  p52= 1; // handle special condition
   c17 = n9 + b12; // sum the elements
   print(p52+c17); // produce the answer

Often comments and whitespace that are key help to readability are removed:

   if(r7)p52=1;c17=n9+b12;print(p52+c17); 

So when the obfuscated program is run, it computes the same results, and puts them in equivalent places.

Net result: the obfuscated program does the same thing as the original.

Yes, you need a tool to do this; you can't do this by hand to any program of any real size reliably. Good obfuscators will obfuscate javascript embedded in HTML pages directly; you don't need to do any hand cutting and pasting. They are easy find with Google; you can also find a variety of them via my bio.

Upvotes: 6

Related Questions