VBS十年未解之谜

标签: , ,

今天有人加我QQ,请教一个困扰了他近十年的VBS问题。

先上代码,加密.vbs

function script_path()
on error resume next
full_path=wscript.ScriptFullname
filename=wscript.scriptname
lenstr=len(full_path)-len(filename)
script_path=left(full_path,lenstr)
end function

jiami  script_path,"longkey.txt"
 function jiami(path,filename)
 jm_file=filename
 jm_path=path
 Dim key1,key2,key3,key4,key(4) 
ttime=time()
 
Key(0)=1
key(1)=10
key(2)=11
key(3)=23

Set WS = CreateObject("WScript.Shell")
Set FSO= Createobject("scripting.filesystemobject")
Set InF=FSO.OpenTextFile(WScript.ScriptFullname,1) 
set fso2=fso.createTextFile(script_path&jm_file)
Do While InF.AtEndOfStream<>True
 
dm=InF.ReadLine
for I=1 to len(dm)
  dqchar= Mid(dm, I, 1)
if j<3 then
  j=j+1
  dqchar= Chr(Asc(dqchar) -key(j))
else
  j=-1
end if
 dqstr=dqstr&dqchar
Next
 
fso2.writeline dqstr
dqstr=""
Loop
Set fso=Nothing 
end function 

解密.vbs

'注释:根据加密的算法解密longkey.txt 得到的longkey.vbs就是源代码。

function script_path()
on error resume next
full_path=wscript.ScriptFullname
filename=wscript.scriptname
lenstr=len(full_path)-len(filename)
script_path=left(full_path,lenstr)
end function

'-30 可以保证没有其他的乱码
jiemi script_path,"longkey.txt"
function jiemi(path,filename)
jm_path=path
jm_file=filename
Dim key1,key2,key3,key4,key(4) 
ttime=time()
'Key(0) = CInt(Month(Date))
'key(1)=cint(Day(Date))
'key(2)=cint(hour(time))
'key(3)=cint(minute(time))
Key(0) =1
key(1)=10
key(2)=11
key(3)=23


Set FSO= Createobject("scripting.filesystemobject")
Set WS = CreateObject("WScript.Shell")
Set InF=FSO.OpenTextFile(jm_path&jm_file) 
set fso2=fso.createTextFile(script_path&"longkey.vbs")

Do While InF.AtEndOfStream<>True
dm=InF.ReadLine
for I=1 to len(dm) 
dqchar= Mid(dm, I, 1)
if j<3 then
j=j+1
dqchar= Chr(Asc(dqchar) +key(j))
else
j=-1
end if
dqstr=dqstr&dqchar
Next
'if len(dqstr)>0 then
'msgbox dqstr
fso2.writeline dqstr
dqstr=""
'end if
Loop
'msgbox dqstr
Set fso2=Nothing 
end function

撇开代码写得很难看不说(毕竟是十年前写的,情有可原),上面的VBS是可以工作的,“加密.vbs”把自身按照一定的算法加密成longkey.txt,“解密.vbs”按照逆向算法把longkey.txt解密成longkey.vbs,还原成原始代码。

到目前为止,一切都还算顺利,但是如果在“加密.vbs”第一行加上’)!三个字符(注意除此之外两者没有任何区别),也就是变成这样:

')!
function script_path()
on error resume next
full_path=wscript.ScriptFullname
filename=wscript.scriptname
lenstr=len(full_path)-len(filename)
script_path=left(full_path,lenstr)
end function

jiami  script_path,"longkey.txt"
 function jiami(path,filename)
 jm_file=filename
 jm_path=path
 Dim key1,key2,key3,key4,key(4) 
ttime=time()
 
Key(0)=1
key(1)=10
key(2)=11
key(3)=23

Set WS = CreateObject("WScript.Shell")
Set FSO= Createobject("scripting.filesystemobject")
Set InF=FSO.OpenTextFile(WScript.ScriptFullname,1) 
set fso2=fso.createTextFile(script_path&jm_file)
Do While InF.AtEndOfStream<>True
 
dm=InF.ReadLine
for I=1 to len(dm)
  dqchar= Mid(dm, I, 1)
if j<3 then
  j=j+1
  dqchar= Chr(Asc(dqchar) -key(j))
else
  j=-1
end if
 dqstr=dqstr&dqchar
Next
 
fso2.writeline dqstr
dqstr=""
Loop
Set fso=Nothing 
end function 

“加密.vbs”改成这样之后,加密自身得到的longkey.txt用“解密.vbs”解密出来是乱码,也就是无法还原。

他的疑问:理论上注释是不影响代码运行结果的,同样的代码为什么不一样的结果?这是不是VBS的BUG?

你说呢?

赞赏

微信赞赏支付宝赞赏

随机文章:

  1. NDS上的NeoGeo模拟器NeoDS
  2. WScript.Shell对象SpecialFolders属性未公开文档
  3. Workbooks.Open中的相对路径
  4. JCreator打包JAR可执行文档
  5. VBS调用WMI搜索文件

3 条评论 发表在“VBS十年未解之谜”上

  1. 乱码说道:

    !的ascii码正好被 23 减掉 无故多出 \n 导致BUG出现、
    也就是说无论在脚本哪,连续出现四个!此BUG必现。

  2. 艳文说道:

    编程小菜鸟。。我也不知道。。求原答案是啥?。。

  3. ○郑斯彬○说道:

    啊哈,我也留个脚印吧。
    十分感谢Demon!必须的。因为….上述难看的代码(除了script_path函数)都是我敲键盘写的。
    什么时候我做了程序猿,代码也就规范了。惭愧的是那么多年了,VBS还是那个水平。也许因为我本身就不打算深入VBS吧。 之所以用VBS就是看中它的潇洒,随意涂鸦,哈哈:)

留下回复