手机
当前位置:查字典教程网 >脚本专栏 >vbs >邪恶的eval和new Function使用介绍
邪恶的eval和new Function使用介绍
摘要:代码:复制代码代码如下://友善提醒:为了你的手指安全,请在Chrome下运行'alert("hello")'.replace(/.+/,e...

代码:

复制代码 代码如下:

// 友善提醒:为了你的手指安全,请在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的整数,不允许使用循环、跳转和递归。

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

【邪恶的eval和new Function使用介绍】相关文章:

VBScript 打造自己的远程CMDShell附使用教程

VBS教程:函数-CStr 函数

可以得到当前系统信息的脚本sysinfo.vbs

用vbs实现更改计算机的说明的代码

VBS通过WMI获取CPU使用率的代码

WMI 创建系统服务的实现代码(Automatic)

VBS教程:属性-Name 属性

VBScript 文件操作代码小结

用vbs确定用户的登录名的代码

VBS教程:VBscript语句-Private 语句

精品推荐
分类导航