上次的DLL在各位使用之后出现了一些不足,下面就对这些地方的更新做一个说明:
其实失误并不在DLL本身,也就是说,DLL的函数YXScrDecode基本是准确无误的,错就错在给他传递
参数的VB这一块,先看下原来的代码
Public Function DCScript(ByVal Script As String) As String Dim s As String, l As Long Dim b As Long, e As Long Dim k As Long l = LenB(Script): s = Space(l) '... b = InStr(Script, "#@~^") '#@~^******== e = InStr(Script, "^#~@") '******==^#~@ If b = 0 Or e = 0 Then If MsgBox("没找到密文开始/结束标识,解密结果可能有误!要继续吗?", vbYesNo) = vbNo Then Exit Function Else If e = 0 Then e = l Else e = e - 8 If b = 0 Then b = 1 Else b = b + 12 End If Else b = b + 12 '为0则全部解密 e = e - 8 '为0则算到末尾 End If frmMain.Caption = "Decoding ..." Script = Mid(Script, b, e - b + 1) 'Script = Replace(Script, "@#", Chr(13)) 'Script = Replace(Script, "@&", Chr(10)) Script = Replace(Script, "@#@&", Chr(13) + Chr(10)) 'vbcCrlf Script = Replace(Script, "@!", "<") Script = Replace(Script, "@*", ">") Script = Replace(Script, "@$", "@") '最后生成@ k = YXScrDecode(Script, s,Len(Script)) DCScript = Left(s, k) End Function
最后那里:Len(Script)或者LenB(Script)
导致了解密有有一部分代码不见了,用LenB则多出很多奇怪的字符,经过检查找出是Len函数
的问题,测试如下
'lpstr(0) = "Hello!" '半角Len = 6;LenB = 12
'lpstr(1) = "Hello!" '全角Len = 6;LenB = 12
'lpstr(2) = "Hello!" & vbCr '回车Len = 7;LenB = 14
'lpstr(3) = "Hello!" & vbCrLf '换行Len = 8;LenB = 16
也就是说Len返回时字符数,LenB返回字节数但是每个字符按2字节算!即Unicode那种。
为了解决这个问题,VB程序员可以用Len和LenB的返回值就算具体的字节数,方法这里就不说了
不然越扯越远,我相信广大程序员都是很聪明的~
YXScript.DLL这次更新 提供了一个函数高效率的处理这个问题,函数YXHowManyBytes
只需要提供一个参数 lpString 返回该参数的字节数(Long)
经过处理后的代码:
Public Function DCScript(ByVal Script As String) As String Dim s As String, l As Long Dim b As Long, e As Long Dim k As Long l = LenB(Script): s = Space(l) '... b = InStr(Script, "#@~^") '#@~^******== e = InStr(Script, "^#~@") '******==^#~@ If b = 0 Or e = 0 Then If MsgBox("没找到密文开始/结束标识,解密结果可能有误!要继续吗?", vbYesNo) = vbNo Then Exit Function Else If e = 0 Then e = l Else e = e - 8 If b = 0 Then b = 1 Else b = b + 12 End If Else b = b + 12 '为0则全部解密 e = e - 8 '为0则算到末尾 End If frmMain.Caption = "Decoding ..." Script = Mid(Script, b, e - b + 1) 'Script = Replace(Script, "@#", Chr(13)) 'Script = Replace(Script, "@&", Chr(10)) Script = Replace(Script, "@#@&", Chr(13) + Chr(10)) 'vbcCrlf Script = Replace(Script, "@!", "<") Script = Replace(Script, "@*", ">") Script = Replace(Script, "@$", "@") '最后生成@ 'k = YXScrDecode(Script, s, Len(Script)) k = YXScrDecoder(Script, s) 's = Replace(s, Chr(13) + Chr(2), vbCrLf)'查出来是0x10和0x0A的原因 '引出另一个问题,为什么char数组第-1个元素为0x02 frmMain.Caption = "碰到我算你倒霉!" DCScript = Left(s, k) End Function
这里提供一个新的函数,YXScrDecoder --多一个r,少一个参数szCount,也就是不必传递字符串的长度
但是lpResult起码有YXHowManyBytes(lpString)长度,否则可能导致内存访问错误
解密CR+LF的时候得到CR 和 0x02 我还不知道是什么原因使C语言字符数组的第-1个元素是0x02,
这次也同时把这个地方解决了,即解码的时候只处理0x09以上的字符,
同时发现在某些计算机上,n会显示为-,正在查原因
下图为解码某个脚本后的效果
更新后的源代码可以在我的下载里找到,不需要分分:
http://download.csdn.net/prsniper
感谢为这次更新提供宝贵意见的朋友,也再次证明,用户的反馈是最有实际意义的!