myobfuscate_unpacker.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // simple unpacker/deobfuscator for scripts messed up with myobfuscate.com
  3. // You really don't want to obfuscate your scripts there: they're tracking
  4. // your unpackings, your script gets turned into something like this,
  5. // as of 2011-04-25:
  6. /*
  7. var _escape = 'your_script_escaped';
  8. var _111 = document.createElement('script');
  9. _111.src = 'http://api.www.myobfuscate.com/?getsrc=ok' +
  10. '&ref=' + encodeURIComponent(document.referrer) +
  11. '&url=' + encodeURIComponent(document.URL);
  12. var 000 = document.getElementsByTagName('head')[0];
  13. 000.appendChild(_111);
  14. document.write(unescape(_escape));
  15. */
  16. //
  17. // written by Einar Lielmanis <einar@jsbeautifier.org>
  18. //
  19. // usage:
  20. //
  21. // if (MyObfuscate.detect(some_string)) {
  22. // var unpacked = MyObfuscate.unpack(some_string);
  23. // }
  24. //
  25. //
  26. var MyObfuscate = {
  27. detect: function (str) {
  28. if (/^var _?[0O1lI]{3}\=('|\[).*\)\)\);/.test(str)) {
  29. return true;
  30. }
  31. if (/^function _?[0O1lI]{3}\(_/.test(str) && /eval\(/.test(str)) {
  32. return true;
  33. }
  34. return false;
  35. },
  36. unpack: function (str) {
  37. if (MyObfuscate.detect(str)) {
  38. var __eval = eval;
  39. try {
  40. eval = function (unpacked) {
  41. if (MyObfuscate.starts_with(unpacked, 'var _escape')) {
  42. // fetch the urlencoded stuff from the script,
  43. var matches = /'([^']*)'/.exec(unpacked);
  44. var unescaped = unescape(matches[1]);
  45. if (MyObfuscate.starts_with(unescaped, '<script>')) {
  46. unescaped = unescaped.substr(8, unescaped.length - 8);
  47. }
  48. if (MyObfuscate.ends_with(unescaped, '</script>')) {
  49. unescaped = unescaped.substr(0, unescaped.length - 9);
  50. }
  51. unpacked = unescaped;
  52. }
  53. // throw to terminate the script
  54. unpacked = "// Unpacker warning: be careful when using myobfuscate.com for your projects:\n" +
  55. "// scripts obfuscated by the free online version may call back home.\n" +
  56. "\n//\n" + unpacked;
  57. throw unpacked;
  58. };
  59. __eval(str); // should throw
  60. } catch (e) {
  61. // well, it failed. we'll just return the original, instead of crashing on user.
  62. if (typeof e === "string") {
  63. str = e;
  64. }
  65. }
  66. eval = __eval;
  67. }
  68. return str;
  69. },
  70. starts_with: function (str, what) {
  71. return str.substr(0, what.length) === what;
  72. },
  73. ends_with: function (str, what) {
  74. return str.substr(str.length - what.length, what.length) === what;
  75. },
  76. run_tests: function (sanity_test) {
  77. var t = sanity_test || new SanityTest();
  78. return t;
  79. }
  80. };