欢迎来到山村网

VBS 加解密 For MS Script Encode

2019-03-02 10:32:37浏览:651 来源:山村网   
核心摘要:这篇文章主要介绍了微软自己的代码加解密实现方法,需要的朋友可以参考下一、加密复制代码 代码如下:Dim ObjectFSOIf (lcase(rig
这篇文章主要介绍了微软自己的代码加解密实现方法,需要的朋友可以参考下

一、加密

复制代码 代码如下:
Dim ObjectFSO

If (lcase(right(wscript.fullname,11))="wscript.exe") Then
Wscript.Quit(0)
End If

If wscript.arguments.count<2 Then
Wscript.Echo "VBS Code Encoder v1.0 Powered by ENUN. http://www.enun.net/"
Wscript.Echo "Notes: dFileName Must be '*.vbe'!"
Wscript.Echo "Usage: cscript.exe //nologo sFileName dFileName"
Wscript.Echo " eg: cscript.exe //nologo test.vbs enc.vbe"
Wscript.Quit(0)
End If

sFileName = Wscript.Arguments(0)
dFileName = Wscript.Arguments(1)

Set ObjectFSO = CreateObject("scripting.FileSystemObject")
Set ReadData = ObjectFSO.OpenTextFile(sFileName, 1)

ObjectFSO.OpenTextFile(dFileName, 8, true).Write(Encoder(ReadData.Readall))

Function Encoder(data)
Encoder = CreateObject("scripting.Encoder").EncodescriptFile(".vbs", data, 0, "VBscript")
End Function

二、解密

复制代码 代码如下:
option explicit

Dim oArgs, NomFichier

'Optional argument : the encoded filename

NomFichier=""
Set oArgs = Wscript.Arguments
Select Case oArgs.Count

Case 0 'No Arg, popup a dialog box to choose the file
NomFichier=BrowseForFolder("Choose an encoded file", &H4031, &H0011)
Case 1
If Instr(oArgs(0),"?")=0 Then '-? ou /? => aide
NomFichier=oArgs(0)
End If
Case Else
Wscript.Echo "Too many parameters"
End Select

Set oArgs = Nothing

If NomFichier<>"" Then
Dim fso
Set fso=Wscript.CreateObject("scripting.FileSystemObject")
If fso.FileExists(NomFichier) Then
Dim fic,contenu
Set fic = fso.OpenTextFile(NomFichier, 1)
Contenu=fic.readAll
fic.close
Set fic=Nothing
Const TagInit="#@~^" '#@~^awQAAA==
Const TagFin="==^#~@" '& chr(0)
Dim DebutCode, FinCode
Do
FinCode=0
DebutCode=Instr(Contenu,TagInit)
If DebutCode>0 Then
If (Instr(DebutCode,Contenu,"==")-DebutCode)=10 Then 'If "==" follows the tag
FinCode=Instr(DebutCode,Contenu,TagFin)
If FinCode>0 Then
Contenu=Left(Contenu,DebutCode-1) & _
Decode(Mid(Contenu,DebutCode+12,FinCode-DebutCode-12-6)) & _
Mid(Contenu,FinCode+6)
End If
End If
End If
Loop Until FinCode=0
Wscript.Echo Contenu
Else
Wscript.Echo Nomfichier & " not found"
End If
Set fso=Nothing

Else
Wscript.Echo "Please give a filename"
Wscript.Echo "Usage : " & wscript.fullname & " " & Wscript.scriptFullName & " <filename>"

End If

Function Decode(Chaine)
Dim se,i,c,j,index,ChaineTemp
Dim tDecode(127)
Const Combinaison="1231232332321323132311233213233211323231311231321323112331123132"
Set se=Wscript.CreateObject("scripting.Encoder")
For i=9 to 127
tDecode(i)="JLA"
Next

For i=9 to 127
ChaineTemp=Mid(se.EncodescriptFile(".vbs",string(3,i),0,""),13,3)
For j=1 to 3
c=Asc(Mid(ChaineTemp,j,1))
tDecode(c)=Left(tDecode(c),j-1) & chr(i) & Mid(tDecode(c),j+1)
Next
Next

'Next line we correct a bug, otherwise a ")" could be decoded to a ">"
tDecode(42)=Left(tDecode(42),1) & ")" & Right(tDecode(42),1)
Set se=Nothing
Chaine=Replace(Replace(Chaine,"@&",chr(10)),"@#",chr(13))
Chaine=Replace(Replace(Chaine,"@*",">"),"@!","<")
Chaine=Replace(Chaine,"@$","@")
index=-1
For i=1 to Len(Chaine)
c=asc(Mid(Chaine,i,1))
If c<128 Then index=index+1
If (c=9) or ((c>31) and (c<128)) Then
If (c<>60) and (c<>62) and (c<>64) Then
Chaine=Left(Chaine,i-1) & Mid(tDecode(c),Mid(Combinaison,(index mod 64)+1,1),1) & Mid(Chaine,i+1)
End If
End If
Next
Decode=Chaine
End Function

Function BrowseForFolder(ByVal pstrprompt, ByVal pintBrowseType, ByVal pintLocation)
Dim ShellObject, pstrTempFolder, x
Set ShellObject=Wscript.CreateObject("Shell.Application")
On Error Resume Next
Set pstrTempFolder=ShellObject.BrowseForFolder(&H0,pstrprompt,pintBrowseType,pintLocation)
BrowseForFolder=pstrTempFolder.ParentFolder.ParseName(pstrTempFolder.Title).Path
If Err.Number<>0 Then BrowseForFolder=""
Set pstrTempFolder=Nothing
Set ShellObject=Nothing
End Function



原文: http://www.enun.net/?p=866

(责任编辑:豆豆)
下一篇:

VBS 加解密 For CAPICOM

上一篇:

C#.NET发送邮件的实例代码

  • 信息二维码

    手机看新闻

  • 分享到
打赏
免责声明
• 
本文仅代表作者个人观点,本站未对其内容进行核实,请读者仅做参考,如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除,作者需自行承担相应责任。涉及到版权或其他问题,请及时联系我们 xfptx@outlook.com