| 1 |
/* |
| 2 |
|
| 3 |
The MIT License (MIT) |
| 4 |
|
| 5 |
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors. |
| 6 |
|
| 7 |
Permission is hereby granted, free of charge, to any person |
| 8 |
obtaining a copy of this software and associated documentation files |
| 9 |
(the "Software"), to deal in the Software without restriction, |
| 10 |
including without limitation the rights to use, copy, modify, merge, |
| 11 |
publish, distribute, sublicense, and/or sell copies of the Software, |
| 12 |
and to permit persons to whom the Software is furnished to do so, |
| 13 |
subject to the following conditions: |
| 14 |
|
| 15 |
The above copyright notice and this permission notice shall be |
| 16 |
included in all copies or substantial portions of the Software. |
| 17 |
|
| 18 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 19 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 21 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 22 |
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 23 |
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 24 |
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 25 |
SOFTWARE. |
| 26 |
*/ |
| 27 |
|
| 28 |
// |
| 29 |
// simple unpacker/deobfuscator for scripts messed up with myobfuscate.com |
| 30 |
// You really don't want to obfuscate your scripts there: they're tracking |
| 31 |
// your unpackings, your script gets turned into something like this, |
| 32 |
// as of 2011-04-25: |
| 33 |
/* |
| 34 |
|
| 35 |
var _escape = 'your_script_escaped'; |
| 36 |
var _111 = document.createElement('script'); |
| 37 |
_111.src = 'http://api.www.myobfuscate.com/?getsrc=ok' + |
| 38 |
'&ref=' + encodeURIComponent(document.referrer) + |
| 39 |
'&url=' + encodeURIComponent(document.URL); |
| 40 |
var 000 = document.getElementsByTagName('head')[0]; |
| 41 |
000.appendChild(_111); |
| 42 |
document.write(unescape(_escape)); |
| 43 |
|
| 44 |
*/ |
| 45 |
// |
| 46 |
// written by Einar Lielmanis <[email protected]> |
| 47 |
// |
| 48 |
// usage: |
| 49 |
// |
| 50 |
// if (MyObfuscate.detect(some_string)) { |
| 51 |
// var unpacked = MyObfuscate.unpack(some_string); |
| 52 |
// } |
| 53 |
// |
| 54 |
// |
| 55 |
|
| 56 |
/*jshint strict:false */ |
| 57 |
|
| 58 |
var MyObfuscate = { |
| 59 |
detect: function(str) { |
| 60 |
if (/^var _?[0O1lI]{3}\=('|\[).*\)\)\);/.test(str)) { |
| 61 |
return true; |
| 62 |
} |
| 63 |
if (/^function _?[0O1lI]{3}\(_/.test(str) && /eval\(/.test(str)) { |
| 64 |
return true; |
| 65 |
} |
| 66 |
return false; |
| 67 |
}, |
| 68 |
|
| 69 |
unpack: function(str) { |
| 70 |
if (MyObfuscate.detect(str)) { |
| 71 |
var __eval = eval; |
| 72 |
try { |
| 73 |
eval = function(unpacked) { // jshint ignore:line |
| 74 |
if (MyObfuscate.starts_with(unpacked, 'var _escape')) { |
| 75 |
// fetch the urlencoded stuff from the script, |
| 76 |
var matches = /'([^']*)'/.exec(unpacked); |
| 77 |
var unescaped = unescape(matches[1]); |
| 78 |
if (MyObfuscate.starts_with(unescaped, '<script>')) { |
| 79 |
unescaped = unescaped.substr(8, unescaped.length - 8); |
| 80 |
} |
| 81 |
if (MyObfuscate.ends_with(unescaped, '</script>')) { |
| 82 |
unescaped = unescaped.substr(0, unescaped.length - 9); |
| 83 |
} |
| 84 |
unpacked = unescaped; |
| 85 |
} |
| 86 |
// throw to terminate the script |
| 87 |
unpacked = "// Unpacker warning: be careful when using myobfuscate.com for your projects:\n" + |
| 88 |
"// scripts obfuscated by the free online version may call back home.\n" + |
| 89 |
"\n//\n" + unpacked; |
| 90 |
throw unpacked; |
| 91 |
}; // jshint ignore:line |
| 92 |
__eval(str); // should throw |
| 93 |
} catch (e) { |
| 94 |
// well, it failed. we'll just return the original, instead of crashing on user. |
| 95 |
if (typeof e === "string") { |
| 96 |
str = e; |
| 97 |
} |
| 98 |
} |
| 99 |
eval = __eval; // jshint ignore:line |
| 100 |
} |
| 101 |
return str; |
| 102 |
}, |
| 103 |
|
| 104 |
starts_with: function(str, what) { |
| 105 |
return str.substr(0, what.length) === what; |
| 106 |
}, |
| 107 |
|
| 108 |
ends_with: function(str, what) { |
| 109 |
return str.substr(str.length - what.length, what.length) === what; |
| 110 |
}, |
| 111 |
|
| 112 |
run_tests: function(sanity_test) { |
| 113 |
var t = sanity_test || new SanityTest(); |
| 114 |
|
| 115 |
return t; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
}; |