screnc.exe (Microsoft Script Encoder) 產出的編碼腳本 (.vbe, .jse, .asp, .hta 等) 可用此 VBScript 解碼器還原為原始碼。支援單檔多段編碼、cscript 輸出至 stdout、wscript 彈窗顯示。
Option Explicit
Dim args, filePath
Set args = WScript.Arguments
Select Case args.Count
Case 0: filePath = BrowseForFolder("Choose an encoded file", &H4031, &H0011)
Case 1: If InStr(args(0), "?") = 0 Then filePath = args(0)
Case Else: WScript.Echo "Too many parameters": WScript.Quit(1)
End Select
Set args = Nothing
If filePath <> "" Then
Dim fso, f, content
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(filePath) Then
Set f = fso.OpenTextFile(filePath, 1)
content = f.ReadAll: f.Close: Set f = Nothing
Const TagInit = "#@~^", TagFin = "==^#~@"
Dim posB, posE
Do
posE = 0
posB = InStr(content, TagInit)
If posB > 0 Then
If InStr(posB, content, "==") - posB = 10 Then
posE = InStr(posB, content, TagFin)
If posE > 0 Then
content = Left(content, posB-1) & _
Decode(Mid(content, posB+12, posE-posB-12-6)) & _
Mid(content, posE+6)
End If
End If
End If
Loop Until posE = 0
WScript.Echo content
Else
WScript.Echo filePath & " not found"
End If
Set fso = Nothing
Else
WScript.Echo "Usage: " & WScript.FullName & " " & WScript.ScriptFullName & " "
End If
' ===== 核心解碼函式 =====
Function Decode(str)
Dim encoder, map(127), i, j, c, temp, idx, comb
comb = "1231232332321323132311233213233211323231311231321323112331123132"
Set encoder = CreateObject("Scripting.Encoder")
' 建立逆向映射表
For i = 9 To 127: map(i) = "JLA": Next
For i = 9 To 127
temp = Mid(encoder.EncodeScriptFile(".vbs", String(3, Chr(i)), 0, ""), 13, 3)
For j = 1 To 3
c = Asc(Mid(temp, j, 1))
map(c) = Left(map(c), j-1) & Chr(i) & Mid(map(c), j+1)
Next
Next
map(42) = Left(map(42),1) & ")" & Right(map(42),1) ' 修正 ')' 誤解為 '>'
Set encoder = Nothing
' 還原逸出序列
str = Replace(Replace(str, "@&", Chr(10)), "@#", Chr(13))
str = Replace(Replace(str, "@*", ">"), "@!", "<")
str = Replace(str, "@$", "@")
idx = -1
For i = 1 To Len(str)
c = Asc(Mid(str, i, 1))
If c < 128 Then idx = idx + 1
If (c = 9) Or (c > 31 And c < 128) Then
If c <> 60 And c <> 62 And c <> 64 Then
str = Left(str, i-1) & Mid(map(c), Mid(comb, (idx Mod 64)+1, 1), 1) & Mid(str, i+1)
End If
End If
Next
Decode = str
End Function
Function BrowseForFolder(prompt, browseType, location)
Dim shell, folder
Set shell = CreateObject("Shell.Application")
On Error Resume Next
Set folder = shell.BrowseForFolder(0, prompt, browseType, location)
BrowseForFolder = folder.ParentFolder.ParseName(folder.Title).Path
If Err.Number <> 0 Then BrowseForFolder = ""
Set folder = Nothing: Set shell = Nothing
End Function
REM 命令列模式 (輸出到 stdout,可重導向)
cscript //nologo decovbe.vbs encoded.vbe > decoded.vbs
REM 互動模式 (無參數執行,彈出選檔對話框)
wscript decovbe.vbs
.vbe (VBScript Encoded).jse (JScript Encoded).asp, .asa (ASP 編碼頁面).hta (HTML Application)