当前位置: 移动技术网 > IT编程>脚本编程>VBScript > 邪恶的eval和new Function使用介绍

邪恶的eval和new Function使用介绍

2017年12月08日  | 移动技术网IT编程  | 我要评论

ktv转让,镓,伊拉克足球

代码:

复制代码 代码如下:

// 友善提醒:为了你的手指安全,请在chrome下运行
'alert("hello")'.replace(/.+/, eval);
'alert("hello")'.replace(/.+/, function(m){new function(m)();});

var i = 0; eval(new array(101).join('alert(++i);'));
var i = 0; new function(new array(101).join('alert(++i);'))();


解释:
1、string.replace(regexp, replacement): replacement可以是function. in this case, the function is invoked for each match, and the string it returns is used as the replacement text.

2、new function(argument_names..., body): 注意参数中的body. 这样,用new function('body')()
, 也可以像eval一样动态执行代码。

3、array.join(separator): 这个最简单,不多说。在这里,巧妙的用来解决了一个无聊问题:写段代码,运行后打印出从1到100的整数,不允许使用循环、跳转和递归。

这些代码可以干什么?可以肯定的是可以干很多猥琐的事。具体是啥呢,自己想啰。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网