This script will encode or decode files containing VBScript or Jscript. Simply drag-and-drop file(s) on to script icon. It uses the Scripting.Encoder.

Download ScriptDEcoder (vbs file)

  1. '==============================================
  2. 'NAME: ScriptDEcoder.vbs
  3. '
  4. 'AUTHOR:  Scott Greenberg
  5. 'COMPANY: SG Technology
  6. 'WEBSITE: http://gogogadgetscott.info
  7. 'Date :    4/23/2004
  8. 'VERSION: 1.0
  9. '
  10. 'COMMENT:
  11. 'Recognized file extensions:
  12. 'vbs vbe js jse htm html asa asp cdx
  13. 'Decode procces derived from VBE decoder
  14. 'by: Jean-Luc Antoine
  15. 'http://www.interclasse.com/scripts/decovbe.php
  16. '
  17. 'Copyright© 2004. SG Technology. All rights reserved.
  18. '==============================================
  19. Const TagInit = "#@~^"
  20. Const TagFin = "==^#~@"
  21. 'Get And check command arguments
  22. Set oArgs = WScript.Arguments
  23. If oArgs.Count = 0 Then
  24.   DisplayHelp ""
  25.   WScript.Quit
  26. End If
  27. 'Check If user requests help
  28. For Each Arg In oArgs
  29.   If InStr (Arg, "?") > 0 Then
  30.     DisplayHelp ""
  31.     WScript.Quit
  32.   End If
  33. Next
  34. Set oFSO = CreateObject ("Scripting.FileSystemObject")
  35. 'Create encoder object
  36. Set oEncoder = CreateObject ("Scripting.Encoder")
  37. For Each Arg In oArgs
  38.   'Check If argument contains path To a valid file
  39.   If oFSO.FileExists(Arg) Then
  40.     sFileExt = oFSO.GetExtensionName(Arg)
  41.     ValidExts = Array ("vbs", "js", "jse", "vbe", "htm", "html", "asa", "asp", "cdx")
  42.     For Each Ext In ValidExts
  43.       If Ext = sFileExt Then
  44.         DisplayHelp Process(Arg)
  45.         Exit For
  46.       End If
  47.     Next
  48.   Else
  49.     DisplayHelp "Argument Is Not a valid file."
  50.   End If
  51. Next
  52. DisplayHelp "Process Is complete"
  53. 'Clean up
  54. Set oEncoder = Nothing
  55. Set oFSO = Nothing
  56. Set oArgs = Nothing
  57. 'Process file
  58. Function Process(sFileIn)
  59.   'Get In file extension
  60.   sSourceExt = "." & oFSO.GetExtensionName(sFileIn)
  61.   sSourceFile = oFSO.GetBaseName(sFileIn)
  62.   'Read file into buffer
  63.   Set fIn = oFSO.OpenTextFile(sFileIn)
  64.   sSource = fIn.ReadAll
  65.   fIn.Close : Set fIn = Nothing
  66.   'Run process
  67.   If InStr (sSource, TagInit) = 0 Then
  68.     Decoded = True
  69.   End If
  70.   If Decoded = True Then
  71.     sOut = Encode(sSource, sSourceExt)
  72.     Select Case sSourceExt
  73.     Case ".vbs"
  74.       sOutExt = ".vbe"
  75.     Case ".js"
  76.       sOutExt = ".jse"
  77.     Case Else
  78.       sOutExt = sSourceExt
  79.     End Select
  80.     Process = "File "&sSourceFile&sSourceExt&" encoded And saved As "&sSourceFile&sOutExt&"."
  81.   Else
  82.     sOut = Decode(sSource, sSourceExt)
  83.     Select Case sSourceExt
  84.     Case ".vbe"
  85.       sOutExt = ".vbs"
  86.     Case ".jse"
  87.       sOutExt = ".js"
  88.     Case Else
  89.       sOutExt = sSourceExt
  90.     End Select
  91.     Process = "File "&sSourceFile&sSourceExt&" decoded And saved As "&sSourceFile&sOutExt&"."
  92.   End If
  93.   'Write New file
  94.   sFileOut = oFSO.GetParentFolderName(sFileIn) & "\" & _
  95.   sSourceFile & sOutExt
  96.   '* Fix To overwrite file
  97.   Set fOut = oFSO.OpenTextFile(sFileOut, 2, True )
  98.   fOut.Write sOut
  99.   fOut.close : Set fOut = Nothing
  100. End Function
  101. 'Encode buffer
  102. Function Encode(sSource, sSourceExt)
  103.   'Encode source
  104.   Encode = oEncoder.EncodeScriptFile(sSourceExt, sSource, 0, 0)
  105.   Set oEncoder = Nothing
  106. End Function
  107. 'Decode helper
  108. Function Decode(sSource, sSourceExt)
  109.   Do
  110.     FinCode = 0
  111.     'Find the start positon of encoded data
  112.     StartCode = InStr (sSource, TagInit)
  113.     If StartCode > 0 Then
  114.       'If "==" the marker follows
  115.       If (InStr (StartCode, sSource, "==") - StartCode) = 10 Then
  116.         'Find the End positon of encoded data
  117.         FinCode = InStr (StartCode, sSource, TagFin)
  118.         If FinCode > 0 Then
  119.           'Decode encoded data
  120.           sSource = Left (sSource, StartCode - 1) & _
  121.           DecodeH(Mid (sSource, StartCode + 12, FinCode - StartCode - 12 - 6)) & _
  122.           Mid (sSource, FinCode + 6)
  123.         End If
  124.       End If
  125.     End If
  126.   Loop Until FinCode = 0
  127.   If Asc (Right (sSource, 1)) = 0 Then sSource = Left (sSource, Len (sSource) - 1)
  128.   sSource = Replace (sSource,".Encode","")
  129.   Decode = sSource
  130. End Function
  131. 'Decode buffer
  132. Function DecodeH(Chain)
  133.   Dim tDecode(127)
  134.   Const Combination = "1231232332321323132311233213233211323231311231321323112331123132"
  135.   For i = 9 To 127
  136.     tDecode(i) = "JLA"
  137.   Next
  138.   For i = 9 To 127
  139.     ChainsTemp = Mid (oEncoder.EncodeScriptFile(".vbs", String (3, i), 0, ""), 13, 3)
  140.     For j = 1 To 3
  141.       c = Asc (Mid (ChainsTemp, j, 1))
  142.       If Not ((c = 42) And (i = 62)) Then
  143.         tDecode(c) = Left (tDecode(c), j - 1) & Chr (i) & Mid (tDecode(c), j + 1)
  144.       End If
  145.     Next
  146.   Next
  147.   Chain = Replace (Replace (Chain, "@&", Chr (10)), "@#", Chr (13))
  148.   Chain = Replace (Replace (Chain,"@*",">"), "@!", "<")
  149.   Chain = Replace (Chain,"@$","@")
  150.   index = -1
  151.   For i = 1 To Len (Chain)
  152.     c = Asc (Mid (Chain, i, 1))
  153.     If c < 128 Then index = index + 1
  154.     If (c = 9) Or ((c > 31) And (c < 128)) Then
  155.       If (c <> 60) And (c <> 62) And (c <> 64) Then
  156.         Chain = Left (Chain,i - 1) & _
  157.         Mid (tDecode(c), Mid (Combination, (index Mod 64) + 1, 1), 1) & _
  158.         Mid (Chain,i + 1)
  159.       End If
  160.     End If
  161.   Next
  162.   DecodeH = Chain
  163. End Function
  164. 'Sub To display help message And any exceptions
  165. Sub DisplayHelp(msg)
  166.   CRLF = Chr (13) + Chr (10)
  167.   If msg = "" Then msg = msg & " --- About this script ---" & CRLF & _
  168.   "Recognized file extensions: " & CRLF & _
  169.   " vbs vbe js jse htm html asa asp cdx" & CRLF & CRLF & _
  170.   "<file(s) To encode/decode>" & CRLF & _
  171.   "? <help>"
  172.   MsgBox msg, vbInformation , "ScriptDEcoder"
  173. End Sub

Download ScriptDEcoder (vbs file)