Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wesmaldonado/835338 to your computer and use it in GitHub Desktop.
Save wesmaldonado/835338 to your computer and use it in GitHub Desktop.
Javascript Obfuscation, Minification and why it doesn't really matter.
I'm working on placing some geocaches[http://www.geocaching.com] and they must be 0.1 miles away from other geocaches. Being a programmer I thought, well, let's just write a bookmarklet to augment the geocaching website with a radius around the caches displayed on the map. So I googled for chunk of code that would do this because I'm lazy. The first tool was http://www.freemaptools.com/radius-around-point.htm and its UI was clunky but the output looked good enough to me. So I dig into the source... and *gasp* what is this?
10111010001000010111010000111101010101101101110100010101010100100001...
http://www.freemaptools.com/script/radius-around-point.js
At that point, I could've just looked for the next site but I have a few tricks up my sleeve since I've had to dig into ridiculous javascript for serveral of my jobs... The first trick is just use chrome developer tools, it'll probably get you 90% of the way there... and look, it does!
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.
https://img.skitch.com/20110219-xqbpnjw62ga4jp8jgmy5sq4crx.png
http://www.freemaptools.com/script/radius-around-point.js
So, great... it looks like its been minified/packed... but that isn't going to stop me. The second trick you should know is that javascript functions have a super awesome ability to print themselves out as code. If I can just see how these functions are called I can dig into them. Lucky me, the handlers for clicks were just onclick sections in the link... if these were added via selectors it would've been more difficult but firebug, chrome or safari will let you see what is attached to an element so it'll be possible for that code also.
https://img.skitch.com/20110219-fewbjqi74pj3m7yrrs7q2rdbdw.png
Now I can just follow the function calls down down down to see how it works.
> uselatlng.toString()
"function uselatlng(){var point;point=new google.maps.LatLng(parseFloat(document.getElementById("tb_lat").value),parseFloat(document.getElementById("tb_lng").value));placeMarkerAtPoint(point)}"
placeMarkerAtPoint.toString();
https://img.skitch.com/20110219-qawmppim9bd1ws7gei8cwd7g8j.png
Now you know. And knowing is... something.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment