复制代码 代码如下: dxy: 你好! 我学vbs也有一小段时间了,最近看到一本书上讲vbs脚本的加密,就自己试了试,可是有一点问题,低级的语法错误我都自己修正了,可脚本运行后不起作用.所以想请教你一下.脚本的原理是这样的:它把代码转换成16进制,然后再写个解密代码,通过这个解密来执行加密的代码,将字符串成16进制的代码如下: Function str2hex (Byval strHex) For i=1 to Len(strHex) sHex = sHex & Hex(Asc(mid(strHex,i,1))) next str2Hex = sHex end Function
解密的代码如下:
Function hextostr(data) Hextostr = "Execute""""" C= "&Chr(&H" N= ")" Do while Len(data) 1 if IsNumeric (Left(data,1)) then Hextostr=Hextostr&c&Left(data,2)&N data=mid(data,3) else Hextostr=HextoStr&C&Left(data,4)&N data=mid(data,5) end if loop end Function
解密代码好象有点问题,请帮忙指正,我实在找不出
整个成品就是:
on error resume next set arg=wscript.arguement '声明外部参数 if arg.count=0 Then wscript.quit '若无参数则退出脚本 set fso=creatobject("Scripting.Filesystem Object") '声明fso组件 when fso.opentextfile(arg(0),1,flase) data = readall:.close'读取文本内容 if err.number 0 then wscript.quit '如果发生错误,则退出 with fso.opentextfile(arg(0)&"*.vbs",2,true) '将转换好的写到一个新的vbs中 if err.number 0 then wscript.quit '如果发生错误,则退出 .writeline "Execute(Hextostr("""&str2hex(data)&"""))" '执行解密并执行解密后的代码 .writeline "Function hextostr(data)" .writeline "Hextostr=""Execute""""""""""" .writeline "C=""&CHR(&H""" .writeline "N= )" .writeline "Do while Len(data) 1" .writeline "if IsNumeric (Left(data,1)) then" .writeline "Hextostr=Hextostr&c&Left(data,2)&N" .writeline "data = (data,3)" .writeline "else" .writeline "Hextostr=Hex to str&c&Left(data,4)&N" .writeline "data=mid(data,5)" .writeline "end if" .writeline "loop" .writeline "end function" '把解密函数写进去 .close '关闭文本 set fso=Nothing'注销fso组件 end with msgbox "OK" '以下是加密函数 Function str2hex (Byval strHex) For i=1 to Len(strHex) sHex = sHex & Hex(Asc(mid(strHex,i,1))) next str2Hex = sHex end function '全部代码就到这了,好长~