I've recently had to move build servers as we are advancing our codebase from .NET 4 to 4.6.1. The problem I'm having right now is that we use a lot of Classic ASP pages that we obfuscate with the scrrun.dll scripting.encoder object. Our old build server, a Windows 2003 box, had no problem with this. The current box can't seem to manage modifying the <%@ Language=VBScript %>
tags. When I call the scripting.encoder.EncodeScriptFile
using a cflag
of 0
or 1
I get an exception code of
c00000005 on the module msvcrt.dll.
When I use a cflag
of 2
the script obfuscates fine but that flag turns off the modification of the language tag to <%@ Language=VBScript.Encode %>
, or in a couple of cases where there isn't a language tag, a cflag
of 0
inserts the <%@ Language=VBScript.Encode %>
tag, but 2
does not.
Is there a way to get the scripting.encoder.EncodeScriptFile
to work properly in Windows Server 2008 R2? Is there another way to do the same function?
I'm using this script as a tester:
Option Explicit
dim oEncoder, oFilesToEncode, file, sDest
dim sFileOut, oFile, oEncFile, oFSO, i
dim oStream, sSourceFile
set oFilesToEncode = WScript.Arguments
set oEncoder = CreateObject("Scripting.Encoder")
For i = 0 to oFilesToEncode.Count - 1
set oFSO = CreateObject("Scripting.FileSystemObject")
file = oFilesToEncode(i)
set oFile = oFSO.GetFile(file)
Set oStream = oFile.OpenAsTextStream(1)
sSourceFile=oStream.ReadAll
oStream.Close
sDest = oEncoder.EncodeScriptFile(".asp",sSourceFile,1,"")
sFileOut = Left(file, Len(file) - 3) & "aspe"
Set oEncFile = oFSO.CreateTextFile(sFileOut)
oEncFile.Write sDest
oEncFile.Close
if i = 1 then
exit for
end if
Next
EDIT: Revised section since code didn't format well in comments
set oFSO = CreateObject("ADODB.Stream")
oFSO.CharSet = "utf-8"
file = oFilesToEncode(i)
oFSO.open
oFSO.LoadFromFile(file)
sSourceFile=oFSO.ReadText()
sDest = oEncoder.EncodeScriptFile(".asp",sSourceFile,0,"")
sFileOut = Left(file, Len(file) - 3) & "aspe"
oFSO.WriteText(sFileOut)
oFSO.SaveToFile sDest
oEncFile.Close