0

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 
peg_leg
  • 73
  • 1
  • 7
  • The Error Code `C00000005` refers to a [`Buffer Overrun`](https://blogs.msdn.microsoft.com/calvin_hsia/2004/06/30/what-is-a-c0000005-crash/) in the C Runtime Library, it's likely that something is wrong with the characters being passed so that it isn't seeing them correctly terminated in memory. Is the source file correctly encoded? *(UTF-8, Windows-1252 etc)*. Could it also possibly be that the run architecture version of `Scripting.Encoder` is being run? *(is 32 Bit or 64 Bit)*. – user692942 Mar 17 '16 at 13:17
  • I get the same result from the SysWow64 cscript as I do with the x64 one. Notepad++ says the encoding of the target file is UTF-8. – peg_leg Mar 17 '16 at 14:07
  • It it's UTF-8 encoded why you opening it with the [`TextStream` object](https://msdn.microsoft.com/en-us/library/312a5kbt(v=vs.84).aspx) as it won't open UTF-8 encoded files correctly, you should use it's big brother [`ADODB.Stream`](https://msdn.microsoft.com/en-us/library/ms675032(v=vs.85).aspx) setting the [`Charset = "UTF-8"`](https://msdn.microsoft.com/en-us/library/ms681424(v=vs.85).aspx). – user692942 Mar 17 '16 at 14:17
  • Is there a method in adodb.Stream to obfuscate code like scripting.encoder does? or any other encode function that will do it? I can bring the text in using ADODB.Stream but then I have scripting.encoder and bam the error I indicated above. – peg_leg Mar 17 '16 at 17:55
  • Can you show the `ADODB.Stream` attempted code?, `TextStream` is not the same and more limited as you are finding out. – user692942 Mar 17 '16 at 19:04
  • 'For i = 0 to oFilesToEncode.Count - 1' '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 – peg_leg Mar 18 '16 at 14:02

0 Answers0