下面这段代码,我想问的是
1.ascii和unascii没有地方引用啊,这两个function是在那个地方起作用的
2.ascii中function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\\u$2")}这一段是什么意思,不懂,特别是&0和&2,不知道这是什么
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body><script style="text/javascript">
function ascii(str){
return str.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\\u$2")});
}
function unascii(str){
return unescape(str.replace(/\\u/g,"%u"));
}
document.write("\u6ca1\u6709");</script>
</body>
</html>document.write("\u6e05\u534e\u5927\u5b66");</script>
</body>
</html>
1.ascii和unascii没有地方引用啊,这两个function是在那个地方起作用的
2.ascii中function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\\u$2")}这一段是什么意思,不懂,特别是&0和&2,不知道这是什么
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body><script style="text/javascript">
function ascii(str){
return str.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\\u$2")});
}
function unascii(str){
return unescape(str.replace(/\\u/g,"%u"));
}
document.write("\u6ca1\u6709");</script>
</body>
</html>document.write("\u6e05\u534e\u5927\u5b66");</script>
</body>
</html>
document.write(test);看到画面上打的一串字符\u4F60\u597D
再执行代码
alert("\u4F60\u597D");你就知道是怎么回事了这个技术常用来代码混淆
document.write("\u6ca1\u6709"); ---没有
document.write(unascii("\u6ca1\u6709"));---没有
document.write(ascii("\u6ca1\u6709"));---\u6ca1\u6709
能不能给我解释下ascii后面一段,完全摸不着头脑,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\\u$2")}这一段....
$0 是变量
/gi 是正则全部匹配
刚才测试了下,原来这个函数功能不全,不能达到完全代码混淆的功能。而只是对汉字等特殊字符进行了编码。<script>
var a = 'alert("I am a boy 君")';
function ascii(str){
return str.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\\u$2")});}
document.write(ascii(a));</script>而lz给出的代码,只是调用了他的结果,而没有调用它的函数
<script>
eval("\u0061\u006c\u0065\u0072\u0074\u0028\u0027\u0042\u006c\u0075\u0065\u0069\u0064\u0065\u0061\u0027\u0029");
</script>javascript支持用unicode码来执行代码。而你的ascii,恰好完成了其中的对汉字进行加密的功能。但是感觉意义不是很大记得当年攻击google服务器的代码全部经由unicode进行加密,打开js源文件,全部都是这种代码下面给出完整的加密代码
/**
* 代码unicode加密
*
* @param target
*/
function unicodeEncipher(target) { var value = "";
for (var index = 0; index < target.length; index++) {
var temp = target.charCodeAt(index).toString(16);
value += "\\u" + new Array(5 - String(temp).length).join("0") + temp;
}
return value;
}
alert(unicodeEncipher("你好啊,你家多少人啊.I "));