Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
<input type="hidden" id='code-2' value="" />xcode = document.getElementById('code-2').value.split("\n");document.getElementById('code').value = result;
document.getElementById('code-2').value = result;$ js example_js_eval.txt | indent<+html>
<+head>
<+title>MyEncrypi0nK3y<+/title>
<+/head>
<+script>
function decrypt(key, input) {
var output = “”;
return output;
}
eval(decrypt(document.title, “258ff2c006e9bd6”));
<+/script>
<+/html><+/code>
(плюсы добавлены в теги, что отобразить их в комментах, Хабр блокирует).
Понятно, что суть обфускации - закриптовать код, но надо ведь ещё и скрыть процедуру декрипта.
Всё вышесказанное касается js в html, но нельзя забывать о js в pdf и swf, где возможности ещё шире и интереснее.<html>
<head>
<style>textarea {width: 100%; height: 50%}</style>
</head>
<body>
<script>
simpleEncoder = {
regex : /[^a-z]/g,
/*
*
*/
encode : function(js)
{
var hash = this.decode.toString().replace(this.regex, '');
var s = escape(this.xorStrings(js, hash));
return "_=" + this.decode.toString() + "('" + s + "', " + this.regex + ")";
},
/*
*
*/
decode : function(code, regex)
{
xorStrings = function (str1, str2)
{
var s=new String();
for(var i=0; i < str1.length; i++)
{
var c1=str1[i].charCodeAt(0);
var c2=str2[i % str2.length].charCodeAt(0);
s+=String.fromCharCode((c1 ^ c2 ^ str2.length));
}
return s;
}
code = unescape(code);
hash = arguments.callee.toString().replace(regex, '');
eval(xorStrings(code, hash));
},
/*
*
*/
xorChars : function (char1, char2)
{
return String.fromCharCode((char1.charCodeAt(0) ^ char2.charCodeAt(0)) % 255);
},
/*
*
*/
xorStrings : function (str1, str2)
{
var s=new String();
for(var i=0; i < str1.length; i++)
{
var c1=str1[i].charCodeAt(0);
var c2=str2[i % str2.length].charCodeAt(0);
s+=String.fromCharCode((c1 ^ c2 ^ str2.length));
}
return s;
}
}
var encoded_js = simpleEncoder.encode("alert('Hello World! Привет, мир!');");
document.write("<textarea><script>" + encoded_js + "</script></textarea>");
</script>
</body>
</html>
* This source code was highlighted with Source Code Highlighter.hash_decode_fn = you_decode_fn.toString().replace(/[^a-z]/g, ''); str_js = xorStrings(unescape(you_code), hash_decode_fn);
никакой из обфускаторов так не сможет
function выдёргивается через []["filter"], а сами символы f-i-l-t-e-r берутся из true и false, которые в свою очередь !![] и ![].
Обфускация JavaScript