您的位置:程序门 -> vb -> vba



关于vbs脚本的加密 请高手帮忙~


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


关于vbs脚本的加密 请高手帮忙~
发表于:2008-01-22 23:03:03 楼主
        我学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=(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
'全部代码就到这了,好长~

书上说,把要加密的vbs脚本拖到这个脚本上就行了,不过我没有成功,不知道那里有问题,请帮帮我,谢谢~

发表于:2008-01-23 09:27:371楼 得分:0
整个代码全部有问题
1.str2hex中strhex把每个字符转为十六后,字符串长度有一位,有两位,有四位,而你没有做限制区分
2.hextostr中也涉及到以上问题,所以解密肯定不对
3.主代码中问题更多
4.没人给你回复,是因为你没给分   0


快速检索

最新资讯
热门点击