2010-04-10 50 views
1

我需要一些帮助来理解这段代码是如何混淆。该代码是:的JavaScript混淆帮助

<a id="suggest" href="#" ajaxify="/ajax/social_graph/invite_dialog.php?class=FanManager&amp;node_id=108463912505356" class=" profile_action actionspro_a" rel="dialog-post">Suggest to Friends</a> 

而困惑是:

\x3c\x61\x20\x69\x64\x3d\x22\x73\x75\x67\x67\x65\x73\x74\x22\x20\x68\x72\x65\x66\x3d\x22\x23\x22\x20\x61\x6a\x61\x78\x69\x66\x79\x3d\x22\x2f\x61\x6a\x61\x78\x2f\x73\x6f\x63\x69\x61\x6c\x5f\x67\x72\x61\x70\x68\x2f\x69\x6e\x76\x69\x74\x65\x5f\x64\x69\x61\x6c\x6f\x67\x2e\x70\x68\x70\x3f\x63\x6c\x61\x73\x73\x3d\x46\x61\x6e\x4d\x61\x6e\x61\x67\x65\x72\x26\x61\x6d\x70\x3b\x6e\x6f\x64\x65\x5f\x69\x64\x3d\x31\x30\x38\x34\x36\x33\x39\x31\x32\x35\x30\x35\x33\x35\x36\x22\x20\x63\x6c\x61\x73\x73\x3d\x22\x20\x70\x72\x6f\x66\x69\x6c\x65\x5f\x61\x63\x74\x69\x6f\x6e\x20\x61\x63\x74\x69\x6f\x6e\x73\x70\x72\x6f\x5f\x61\x22\x20\x72\x65\x6c\x3d\x22\x64\x69\x61\x6c\x6f\x67\x2d\x70\x6f\x73\x74\x22\x3e\x53\x75\x67\x67\x65\x73\x74\x20\x74\x6f\x20\x46\x72\x69\x65\x6e\x64\x73\x3c\x2f\x61\x3e","\x73\x75\x67\x67\x65\x73\x74 

现在我用上面的混淆代码UNESCAPE读它。我想知道什么是用来混淆这样的代码?基本上,我需要将可读代码自定义为相同的混淆。

任何帮助将不胜感激。

+0

您不需要使用'unescape '来“解码”一个像这样的字符串。只是警告/打印字符串会显示它的未混淆状态。 'unescape'用于解码HTML编码的字符串,甚至为此目的不推荐使用。 – 2010-04-10 21:36:44

回答

0

类型在地址栏下面的代码:

javascript:alert("\x3c\x61\x20\x69\x64\x3d\x22\x73\x75\x67\x67\x65\x73\x74\x22\x20\x68\x72\x65\x66\x3d\x22\x23\x22\x20\x61\x6a\x61\x78\x69\x66\x79\x3d\x22\x2f\x61\x6a\x61\x78\x2f\x73\x6f\x63\x69\x61\x6c\x5f\x67\x72\x61\x70\x68\x2f\x69\x6e\x76\x69\x74\x65\x5f\x64\x69\x61\x6c\x6f\x67\x2e\x70\x68\x70\x3f\x63\x6c\x61\x73\x73\x3d\x46\x61\x6e\x4d\x61\x6e\x61\x67\x65\x72\x26\x61\x6d\x70\x3b\x6e\x6f\x64\x65\x5f\x69\x64\x3d\x31\x30\x38\x34\x36\x33\x39\x31\x32\x35\x30\x35\x33\x35\x36\x22\x20\x63\x6c\x61\x73\x73\x3d\x22\x20\x70\x72\x6f\x66\x69\x6c\x65\x5f\x61\x63\x74\x69\x6f\x6e\x20\x61\x63\x74\x69\x6f\x6e\x73\x70\x72\x6f\x5f\x61\x22\x20\x72\x65\x6c\x3d\x22\x64\x69\x61\x6c\x6f\x67\x2d\x70\x6f\x73\x74\x22\x3e\x53\x75\x67\x67\x65\x73\x74\x20\x74\x6f\x20\x46\x72\x69\x65\x6e\x64\x73\x3c\x2f\x61\x3e","\x73\x75\x67\x67\x65\x73\x74") 

,它会得到解码。

+0

是的我知道,我想学习如何做到这一点,定制可读代码,然后以相同的方式对其进行伪装 – Victor 2010-04-10 21:24:06

1

你不应该使用什么严重混淆,但它可以很有趣玩弄:如果您正在使用高于255 Unicode字符

var readable = '<a id="suggest" href="#" ajaxify="/ajax/social_graph/invite_dialog.php?class=FanManager&amp;node_id=108463912505356" class=" profile_action actionspro_a" rel="dialog-post">Suggest to Friends</a>'; 

Array.prototype.map.call(readable, 
function(c){ 
    return "\\x" + c.charCodeAt().toString(16); 
}).join(""); 
+0

请注意,'map'方法在ECMAScript第5版的实现中可用(以及大多数Firefox版本)。例如,它不在IE8中。 – 2010-04-10 21:38:30

+0

没关系。这段代码并不打算在现实生活中使用。 – 2010-04-10 21:42:44

2

,你将需要一些特殊的处理。您还需要确保十六进制代码正确填充0,否则该函数将在16以下的字符(如\ n和\ t)中断开:

function obfuscate(str) { 
    var escaped = []; 
    for (var i = 0; i < str.length; i++) { 
    var c = str.charCodeAt(i); 
    var cs = "0000" + c.toString(16); 
    if (c < 256) { 
     cs = "\\x" + cs.substr(-2); 
    } else { 
     cs = "\\u" + cs.substr(-4); 
    } 
    escaped.push(cs); 
    } 
    return escaped.join(''); 
} 

var ob = obfuscate("Hello world!"); 
alert(ob);