MalwareSourceCode/MSIL/Virus/Win32/S/Virus.Win32.Sality.sil-4e552874df8b99a0969b07ded909051569fdb84478f01dd750d0323cc3573f48/JScriptCompiler.cs

947 lines
41 KiB
C#
Raw Normal View History

2022-08-18 11:28:56 +00:00
// Decompiled with JetBrains decompiler
// Type: JScriptCompiler
// Assembly: jsc, Version=7.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// MVID: 64FE9439-6D79-4C3B-BBDD-9D73A741F992
// Assembly location: C:\Users\Administrateur\Downloads\Virusshare.00004-msil\Virus.Win32.Sality.sil-4e552874df8b99a0969b07ded909051569fdb84478f01dd750d0323cc3573f48.exe
using Microsoft.JScript;
using Microsoft.JScript.Vsa;
using Microsoft.Vsa;
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Globalization;
using System.IO;
using System.Reflection.Emit;
using System.Resources;
using System.Text;
using System.Text.RegularExpressions;
internal class JScriptCompiler : MarshalByRefObject
{
private bool fPrintBanner;
private bool fBannerPrinted;
private bool fPrintTargets;
private int exitCode;
private bool fHelp;
private bool fUtf8Output;
private ArrayList targets;
private CompilerOptions currentTarget;
private int codeItemCounter = 0;
internal static readonly string ContextStringDelimiter = ";;";
private static int LCID = CultureInfo.CurrentUICulture.LCID;
private static readonly ResourceManager resourceManager = new ResourceManager("JSC", typeof (JScriptCompiler).Module.Assembly);
public int Run(string[] args)
{
this.exitCode = 0;
try
{
this.fPrintBanner = true;
this.fBannerPrinted = false;
this.fPrintTargets = false;
this.fHelp = false;
this.fUtf8Output = false;
this.targets = new ArrayList();
this.currentTarget = (CompilerOptions) null;
if (args.Length == 0)
{
this.PrintUsage();
return 0;
}
this.ParseArguments(args, false);
if (this.fUtf8Output)
Console.SetOut(TextWriter.Synchronized((TextWriter) new StreamWriter(Console.OpenStandardOutput(), (Encoding) new UTF8Encoding(false))
{
AutoFlush = true
}));
if (this.fHelp)
{
this.PrintUsage();
return 0;
}
foreach (CompilerOptions target in this.targets)
{
if (target.SourceFileNames.Count == 0)
throw new CmdLineException(CmdLineError.NoInputSourcesSpecified, JScriptCompiler.GetCultureInfo());
}
if (this.targets.Count > 1)
this.fPrintTargets = true;
this.PrintBanner();
foreach (CompilerOptions target in this.targets)
{
if (!target.fForceCodepage)
target.codepage = JScriptCompiler.GetCultureInfo().TextInfo.ANSICodePage;
if (target.strOutputFileName == null)
{
string withoutExtension = Path.GetFileNameWithoutExtension((string) target.SourceFileNames[0]);
target.strOutputFileName = withoutExtension + (target.PEFileKind == PEFileKinds.Dll ? ".dll" : ".exe");
}
if (!this.Compile(target))
this.exitCode = 10;
}
}
catch (CmdLineException ex)
{
this.PrintBanner();
Console.WriteLine(ex.Message);
this.exitCode = 10;
}
catch (Exception ex)
{
this.PrintBanner();
Console.WriteLine("fatal error JS2999: " + ex.Message);
this.exitCode = 10;
}
return this.exitCode;
}
private void ParseArguments(string[] args, bool fromResponseFile)
{
int start = 0;
while (start < args.Length)
{
if (this.currentTarget == null)
this.currentTarget = new CompilerOptions();
int options = this.ParseOptions(args, start, fromResponseFile);
start = this.ParseSources(args, options);
if (!fromResponseFile || start < args.Length - 1)
{
this.targets.Add((object) this.currentTarget);
this.currentTarget = (CompilerOptions) null;
}
}
}
private int ParseOptions(string[] args, int start, bool fromResponseFile)
{
int options;
for (options = start; options < args.Length; ++options)
{
string str1 = args[options];
if (str1 != null && str1.Length != 0)
{
if ('@' == str1[0])
{
if (fromResponseFile)
throw new CmdLineException(CmdLineError.NestedResponseFiles, JScriptCompiler.GetCultureInfo());
string str2 = str1.Substring(1);
if (str2.Length == 0)
throw new CmdLineException(CmdLineError.NoFileName, args[options], JScriptCompiler.GetCultureInfo());
string[] args1 = File.Exists(str2) ? this.ReadResponseFile(str2) : throw new CmdLineException(CmdLineError.SourceNotFound, str2, JScriptCompiler.GetCultureInfo());
if (args1 != null)
this.ParseArguments(args1, true);
}
else
{
if ('-' == str1[0] || '/' == str1[0])
{
string option = str1.Substring(1);
if (option.Length >= 1)
{
switch (option[0])
{
case '?':
case 'H':
case 'h':
if (CmdLineOptionParser.IsSimpleOption(option, "?") || CmdLineOptionParser.IsSimpleOption(option, "help"))
{
this.fHelp = true;
continue;
}
break;
case 'A':
case 'a':
object obj1 = CmdLineOptionParser.IsBooleanOption(option, "autoref");
if (obj1 != null)
{
if ((bool) obj1)
{
this.currentTarget.autoRef = true;
this.currentTarget.autoRefSetExplicitly = true;
continue;
}
this.currentTarget.autoRef = false;
continue;
}
object obj2 = (object) CmdLineOptionParser.IsArgumentOption(option, "a.version", "assembly.version");
if (obj2 != null)
{
if (((string) obj2).Length == 0)
throw new CmdLineException(CmdLineError.MissingVersionInfo, JScriptCompiler.GetCultureInfo());
try
{
this.currentTarget.versionInfo = new Version((string) obj2);
continue;
}
catch (Exception ex)
{
throw new CmdLineException(CmdLineError.InvalidVersion, (string) obj2, JScriptCompiler.GetCultureInfo());
}
}
else
break;
case 'C':
case 'c':
object obj3 = (object) CmdLineOptionParser.IsArgumentOption(option, "codepage");
if (obj3 != null)
{
if (((string) obj3).Length == 0)
throw new CmdLineException(CmdLineError.NoCodePage, args[options], JScriptCompiler.GetCultureInfo());
try
{
this.currentTarget.codepage = int.Parse((string) obj3, (IFormatProvider) CultureInfo.InvariantCulture);
this.currentTarget.fForceCodepage = true;
continue;
}
catch (Exception ex)
{
throw new CmdLineException(CmdLineError.InvalidCodePage, (string) obj3, JScriptCompiler.GetCultureInfo());
}
}
else
break;
case 'D':
case 'd':
object obj4 = CmdLineOptionParser.IsBooleanOption(option, "debug");
if (obj4 != null)
{
this.currentTarget.fDebug = (bool) obj4;
continue;
}
object definitionList = (object) CmdLineOptionParser.IsArgumentOption(option, "d", "define");
if (definitionList != null)
{
IDictionaryEnumerator enumerator = this.GetAllDefines((string) definitionList).GetEnumerator();
try
{
while (enumerator.MoveNext())
{
DictionaryEntry current = (DictionaryEntry) enumerator.Current;
this.currentTarget.Defines[current.Key] = current.Value;
}
continue;
}
finally
{
if (enumerator is IDisposable disposable)
disposable.Dispose();
}
}
else
break;
case 'F':
case 'f':
object obj5 = CmdLineOptionParser.IsBooleanOption(option, "fast");
if (obj5 != null)
{
this.currentTarget.fFast = (bool) obj5;
continue;
}
break;
case 'L':
case 'l':
object obj6 = (object) CmdLineOptionParser.IsArgumentOption(option, "lcid");
if (obj6 != null)
{
if (((string) obj6).Length == 0)
throw new CmdLineException(CmdLineError.NoLocaleID, args[options], JScriptCompiler.GetCultureInfo());
try
{
int culture = int.Parse((string) obj6, (IFormatProvider) CultureInfo.InvariantCulture);
CultureInfo cultureInfo = new CultureInfo(culture);
JScriptCompiler.LCID = culture;
continue;
}
catch (Exception ex)
{
throw new CmdLineException(CmdLineError.InvalidLocaleID, (string) obj6, JScriptCompiler.GetCultureInfo());
}
}
else
{
object obj7 = (object) CmdLineOptionParser.IsArgumentOption(option, "lib");
if (obj7 != null)
{
string str3 = (string) obj7;
if (str3.Length == 0)
throw new CmdLineException(CmdLineError.MissingLibArgument, JScriptCompiler.GetCultureInfo());
this.currentTarget.libpath = str3.Replace(',', Path.PathSeparator) + (object) Path.PathSeparator + this.currentTarget.libpath;
continue;
}
object resinfo = (object) CmdLineOptionParser.IsArgumentOption(option, "linkres", "linkresource");
if (resinfo != null)
{
this.AddResourceFile(new ResInfo((string) resinfo, true));
continue;
}
break;
}
case 'N':
case 'n':
if (CmdLineOptionParser.IsSimpleOption(option, "nologo"))
{
this.fPrintBanner = false;
continue;
}
object obj8 = CmdLineOptionParser.IsBooleanOption(option, "nostdlib");
if (obj8 != null)
{
this.currentTarget.fNoStdlib = (bool) obj8;
if ((bool) obj8 && !this.currentTarget.autoRefSetExplicitly)
{
this.currentTarget.autoRef = false;
continue;
}
continue;
}
break;
case 'O':
case 'o':
object path1 = (object) CmdLineOptionParser.IsArgumentOption(option, "out");
if (path1 != null)
{
try
{
if (Path.GetFileName((string) path1) == "")
throw new CmdLineException(CmdLineError.NoFileName, args[options], JScriptCompiler.GetCultureInfo());
}
catch (ArgumentException ex)
{
throw new CmdLineException(CmdLineError.NoFileName, args[options], JScriptCompiler.GetCultureInfo());
}
if (Path.GetExtension((string) path1) == "")
throw new CmdLineException(CmdLineError.MissingExtension, args[options], JScriptCompiler.GetCultureInfo());
this.currentTarget.strOutputFileName = this.currentTarget.strOutputFileName == null ? (string) path1 : throw new CmdLineException(CmdLineError.MultipleOutputNames, JScriptCompiler.GetCultureInfo());
continue;
}
break;
case 'P':
case 'p':
object obj9 = CmdLineOptionParser.IsBooleanOption(option, "print");
if (obj9 != null)
{
this.currentTarget.fPrint = (bool) obj9;
this.currentTarget.fPrintSetExplicitly = (bool) obj9;
continue;
}
break;
case 'R':
case 'r':
object fileList = (object) CmdLineOptionParser.IsArgumentOption(option, "r", "reference");
if (fileList != null)
{
StringEnumerator stringEnumerator = ((string) fileList).Length != 0 ? this.GetAllReferences((string) fileList).GetEnumerator() : throw new CmdLineException(CmdLineError.NoFileName, args[options], JScriptCompiler.GetCultureInfo());
try
{
while (stringEnumerator.MoveNext())
{
string current = stringEnumerator.Current;
bool flag = false;
foreach (string importFileName in this.currentTarget.ImportFileNames)
{
if (string.Compare(importFileName, current, true, CultureInfo.InvariantCulture) == 0)
{
flag = true;
break;
}
}
if (!flag)
this.currentTarget.ImportFileNames.Add((object) current);
}
continue;
}
finally
{
if (stringEnumerator is IDisposable disposable)
disposable.Dispose();
}
}
else
{
object resinfo = (object) CmdLineOptionParser.IsArgumentOption(option, "res", "resource");
if (resinfo != null)
{
this.AddResourceFile(new ResInfo((string) resinfo, false));
continue;
}
break;
}
case 'T':
case 't':
object obj10 = (object) CmdLineOptionParser.IsArgumentOption(option, "t", "target");
if (obj10 != null)
{
if (this.currentTarget.fTargetSpecified)
throw new CmdLineException(CmdLineError.MultipleTargets, JScriptCompiler.GetCultureInfo());
if (string.Compare((string) obj10, "exe", true, CultureInfo.InvariantCulture) == 0)
{
this.currentTarget.fTargetSpecified = true;
this.currentTarget.PEFileKind = PEFileKinds.ConsoleApplication;
continue;
}
if (string.Compare((string) obj10, "winexe", true, CultureInfo.InvariantCulture) == 0)
{
this.currentTarget.fTargetSpecified = true;
this.currentTarget.PEFileKind = PEFileKinds.WindowApplication;
this.currentTarget.fPrint = this.currentTarget.fPrintSetExplicitly;
continue;
}
if (string.Compare((string) obj10, "library", true, CultureInfo.InvariantCulture) != 0)
throw new CmdLineException(CmdLineError.InvalidTarget, (string) obj10, JScriptCompiler.GetCultureInfo());
this.currentTarget.fTargetSpecified = true;
this.currentTarget.PEFileKind = PEFileKinds.Dll;
continue;
}
break;
case 'U':
case 'u':
object obj11 = CmdLineOptionParser.IsBooleanOption(option, "utf8output");
if (obj11 != null)
{
this.fUtf8Output = (bool) obj11;
continue;
}
break;
case 'V':
case 'v':
object obj12 = CmdLineOptionParser.IsBooleanOption(option, "VersionSafe");
if (obj12 != null)
{
this.currentTarget.fVersionSafe = (bool) obj12;
continue;
}
break;
case 'W':
case 'w':
object obj13 = (object) CmdLineOptionParser.IsArgumentOption(option, "w", "warn");
if (obj13 != null)
{
if (((string) obj13).Length == 0)
throw new CmdLineException(CmdLineError.NoWarningLevel, args[options], JScriptCompiler.GetCultureInfo());
if (1 == ((string) obj13).Length)
{
switch (((string) obj13)[0])
{
case '0':
this.currentTarget.nWarningLevel = 0;
continue;
case '1':
this.currentTarget.nWarningLevel = 1;
continue;
case '2':
this.currentTarget.nWarningLevel = 2;
continue;
case '3':
this.currentTarget.nWarningLevel = 3;
continue;
case '4':
this.currentTarget.nWarningLevel = 4;
continue;
}
}
throw new CmdLineException(CmdLineError.InvalidWarningLevel, args[options], JScriptCompiler.GetCultureInfo());
}
object obj14 = CmdLineOptionParser.IsBooleanOption(option, "warnaserror");
if (obj14 != null)
{
this.currentTarget.fTreatWarningsAsErrors = (bool) obj14;
continue;
}
object obj15 = (object) CmdLineOptionParser.IsArgumentOption(option, "win32res");
if (obj15 != null)
{
string path2 = (string) obj15;
if (path2.Length == 0)
throw new CmdLineException(CmdLineError.NoFileName, args[options], JScriptCompiler.GetCultureInfo());
if (!File.Exists(path2))
throw new CmdLineException(CmdLineError.ResourceNotFound, args[options], JScriptCompiler.GetCultureInfo());
this.currentTarget.Win32Resource = this.currentTarget.Win32Resource == null ? path2 : throw new CmdLineException(CmdLineError.MultipleWin32Resources, JScriptCompiler.GetCultureInfo());
continue;
}
break;
}
}
throw new CmdLineException(CmdLineError.UnknownOption, args[options], JScriptCompiler.GetCultureInfo());
}
break;
}
}
}
return options;
}
private int ParseSources(string[] args, int start)
{
int sources;
for (sources = start; sources < args.Length; ++sources)
{
if (args[sources].Length != 0)
{
if ('-' != args[sources][0])
{
if ('/' != args[sources][0])
{
try
{
if (Path.GetFileName(args[sources]) == "")
throw new CmdLineException(CmdLineError.InvalidSourceFile, args[sources], JScriptCompiler.GetCultureInfo());
}
catch (ArgumentException ex)
{
throw new CmdLineException(CmdLineError.InvalidSourceFile, args[sources], JScriptCompiler.GetCultureInfo());
}
foreach (string importFileName in this.currentTarget.ImportFileNames)
{
if (string.Compare(importFileName, args[sources], true, CultureInfo.InvariantCulture) == 0)
throw new CmdLineException(CmdLineError.DuplicateFileAsSourceAndAssembly, args[sources], JScriptCompiler.GetCultureInfo());
}
foreach (string sourceFileName in this.currentTarget.SourceFileNames)
{
if (string.Compare(sourceFileName, args[sources], true, CultureInfo.InvariantCulture) == 0)
throw new CmdLineException(CmdLineError.DuplicateSourceFile, args[sources], JScriptCompiler.GetCultureInfo());
}
this.currentTarget.SourceFileNames.Add((object) args[sources]);
}
else
break;
}
else
break;
}
}
return sources;
}
private bool Compile(CompilerOptions options)
{
if (this.fPrintTargets)
Console.WriteLine(JScriptCompiler.Localize("Compiling", options.strOutputFileName));
VsaEngine engine = new VsaEngine();
if (engine == null)
throw new CmdLineException(CmdLineError.CannotCreateEngine, JScriptCompiler.GetCultureInfo());
engine.InitVsaEngine("JSC://Microsoft.JScript.Vsa.VsaEngine", (IVsaSite) new EngineSite(options));
((BaseVsaEngine) engine).LCID = JScriptCompiler.LCID;
((BaseVsaEngine) engine).GenerateDebugInfo = options.fDebug;
((BaseVsaEngine) engine).SetOption("AutoRef", (object) options.autoRef);
((BaseVsaEngine) engine).SetOption("fast", (object) options.fFast);
((BaseVsaEngine) engine).SetOption("output", (object) options.strOutputFileName);
((BaseVsaEngine) engine).SetOption("PEFileKind", (object) options.PEFileKind);
((BaseVsaEngine) engine).SetOption("print", (object) options.fPrint);
((BaseVsaEngine) engine).SetOption("libpath", (object) options.libpath);
if (options.versionInfo != (Version) null)
((BaseVsaEngine) engine).SetOption("version", (object) options.versionInfo);
((BaseVsaEngine) engine).SetOption("VersionSafe", (object) options.fVersionSafe);
((BaseVsaEngine) engine).SetOption("defines", (object) options.Defines);
((BaseVsaEngine) engine).SetOption("warnaserror", (object) options.fTreatWarningsAsErrors);
((BaseVsaEngine) engine).SetOption("WarningLevel", (object) options.nWarningLevel);
if (options.Win32Resource != null)
((BaseVsaEngine) engine).SetOption("win32resource", (object) options.Win32Resource);
if (options.ManagedResources.Count > 0)
((BaseVsaEngine) engine).SetOption("managedResources", (object) options.ManagedResources.Values);
bool flag1 = false;
bool flag2 = false;
foreach (string importFileName in options.ImportFileNames)
{
this.AddAssemblyReference((IVsaEngine) engine, importFileName);
string fileName = Path.GetFileName(importFileName);
if (string.Compare(fileName, "mscorlib.dll", true, CultureInfo.InvariantCulture) == 0)
flag1 = true;
else if (string.Compare(fileName, "System.Windows.Forms.dll", true, CultureInfo.InvariantCulture) == 0)
flag2 = true;
}
if (!options.fNoStdlib && !flag1)
this.AddAssemblyReference((IVsaEngine) engine, "mscorlib.dll");
if (options.PEFileKind == PEFileKinds.WindowApplication && !options.fNoStdlib && !flag2)
this.AddAssemblyReference((IVsaEngine) engine, "System.Windows.Forms.dll");
for (int index = 0; index < options.SourceFileNames.Count; ++index)
this.AddSourceFile((IVsaEngine) engine, (string) options.SourceFileNames[index], options.codepage, options.fForceCodepage);
try
{
return ((BaseVsaEngine) engine).Compile();
}
catch (VsaException ex)
{
if (ex.ErrorCode == -2146226172)
{
if (((Exception) ex).InnerException != null && ((Exception) ex).InnerException is BadImageFormatException)
Console.WriteLine(new CmdLineException(CmdLineError.InvalidAssembly, ((Exception) ex).Message, JScriptCompiler.GetCultureInfo()).Message);
else if (((Exception) ex).InnerException != null && (((Exception) ex).InnerException is FileNotFoundException || ((Exception) ex).InnerException is FileLoadException))
Console.WriteLine(new CmdLineException(CmdLineError.AssemblyNotFound, ((Exception) ex).Message, JScriptCompiler.GetCultureInfo()).Message);
else
Console.WriteLine(new CmdLineException(CmdLineError.InvalidAssembly, JScriptCompiler.GetCultureInfo()).Message);
}
else if (ex.ErrorCode == -2146226123)
Console.WriteLine(new CmdLineException(CmdLineError.ErrorSavingCompiledState, ((Exception) ex).Message, JScriptCompiler.GetCultureInfo()).Message);
else if (ex.ErrorCode == -2146226171 && ((Exception) ex).InnerException != null)
{
Console.WriteLine(new CmdLineException(CmdLineError.InvalidCharacters, ((Exception) ex).Message, JScriptCompiler.GetCultureInfo()).Message);
}
else
{
Console.WriteLine(JScriptCompiler.Localize("INTERNAL COMPILER ERROR"));
Console.WriteLine((object) ex);
}
return false;
}
catch (Exception ex)
{
Console.WriteLine(JScriptCompiler.Localize("INTERNAL COMPILER ERROR"));
Console.WriteLine((object) ex);
return false;
}
}
private void AddAssemblyReference(IVsaEngine engine, string fileName) => ((IVsaReferenceItem) engine.Items.CreateItem(fileName, (VsaItemType) 0, (VsaItemFlag) 0)).AssemblyName = fileName;
private void AddSourceFile(
IVsaEngine engine,
string fileName,
int codepage,
bool fForceCodepage)
{
string str = "$SourceFile_" + (object) this.codeItemCounter++;
IVsaCodeItem ivsaCodeItem = (IVsaCodeItem) engine.Items.CreateItem(str, (VsaItemType) 2, (VsaItemFlag) 0);
((IVsaItem) ivsaCodeItem).SetOption("codebase", (object) fileName);
ivsaCodeItem.SourceText = this.ReadFile(fileName, codepage, fForceCodepage);
}
private void AddResourceFile(ResInfo resinfo)
{
if (!File.Exists(resinfo.fullpath))
throw new CmdLineException(CmdLineError.ManagedResourceNotFound, resinfo.filename, JScriptCompiler.GetCultureInfo());
if (this.currentTarget.ManagedResourceFileNames[(object) resinfo.fullpath] != null)
throw new CmdLineException(CmdLineError.DuplicateResourceFile, resinfo.filename, JScriptCompiler.GetCultureInfo());
if (this.currentTarget.ManagedResources[(object) resinfo.name] != null)
throw new CmdLineException(CmdLineError.DuplicateResourceName, resinfo.name, JScriptCompiler.GetCultureInfo());
this.currentTarget.ManagedResources[(object) resinfo.name] = (object) resinfo;
this.currentTarget.ManagedResourceFileNames[(object) resinfo.fullpath] = (object) resinfo;
}
internal void PrintBanner() => this.PrintBanner((CultureInfo) null);
internal void PrintBanner(CultureInfo culture)
{
if (this.fBannerPrinted || !this.fPrintBanner)
return;
string str1 = 7.ToString() + "." + 10.ToString((IFormatProvider) CultureInfo.InvariantCulture).PadLeft(2, '0') + "." + 3052.ToString((IFormatProvider) CultureInfo.InvariantCulture).PadLeft(4, '0');
Version version = Environment.Version;
object[] objArray1 = new object[5]
{
(object) version.Major,
(object) ".",
null,
null,
null
};
object[] objArray2 = objArray1;
int num = version.Minor;
string str2 = num.ToString((IFormatProvider) CultureInfo.InvariantCulture);
objArray2[2] = (object) str2;
objArray1[3] = (object) ".";
object[] objArray3 = objArray1;
num = version.Build;
string str3 = num.ToString((IFormatProvider) CultureInfo.InvariantCulture).PadLeft(4, '0');
objArray3[4] = (object) str3;
string str4 = string.Concat(objArray1);
this.fBannerPrinted = true;
Console.WriteLine(string.Format(JScriptCompiler.Localize("Banner line 1", culture), (object) str1));
Console.WriteLine(string.Format(JScriptCompiler.Localize("Banner line 2", culture), (object) str4));
Console.WriteLine(JScriptCompiler.Localize("Banner line 3", culture) + "\r\n");
}
internal void PrintUsage()
{
CultureInfo cultureInfo = JScriptCompiler.GetCultureInfo();
this.PrintBanner(cultureInfo);
Console.WriteLine(JScriptCompiler.Localize("Usage format", cultureInfo));
Console.WriteLine();
Console.Write(" ");
Console.WriteLine(JScriptCompiler.Localize("Usage options", cultureInfo));
Console.WriteLine("");
Console.Write(" ");
Console.WriteLine(JScriptCompiler.Localize("Output Files", cultureInfo));
Console.Write(" /out:<file> ");
Console.WriteLine(JScriptCompiler.Localize("Usage /out", cultureInfo));
Console.Write(" /t[arget]:exe ");
Console.WriteLine(JScriptCompiler.Localize("Usage /t:exe", cultureInfo));
Console.Write(" /t[arget]:winexe ");
Console.WriteLine(JScriptCompiler.Localize("Usage /t:winexe", cultureInfo));
Console.Write(" /t[arget]:library ");
Console.WriteLine(JScriptCompiler.Localize("Usage /t:library", cultureInfo));
Console.WriteLine();
Console.Write(" ");
Console.WriteLine(JScriptCompiler.Localize("Input Files", cultureInfo));
Console.Write(" /autoref[+|-] ");
Console.WriteLine(JScriptCompiler.Localize("Usage /autoref", cultureInfo));
Console.Write(" /lib:<path> ");
Console.WriteLine(JScriptCompiler.Localize("Usage /lib", cultureInfo));
Console.Write(" /r[eference]:<file list> ");
Console.WriteLine(JScriptCompiler.Localize("Usage /reference", cultureInfo));
Console.Write(" ");
Console.WriteLine("<file list>: <assembly name>[;<assembly name>...]");
Console.WriteLine();
Console.Write(" ");
Console.WriteLine(JScriptCompiler.Localize("Resources", cultureInfo));
Console.Write(" /win32res:<file> ");
Console.WriteLine(JScriptCompiler.Localize("Usage /win32res", cultureInfo));
Console.Write(" /res[ource]:<info> ");
Console.WriteLine(JScriptCompiler.Localize("Usage /resource", cultureInfo));
Console.WriteLine(" <info>: <filename>[,<name>[,public|private]]");
Console.Write(" /linkres[ource]:<info> ");
Console.WriteLine(JScriptCompiler.Localize("Usage /linkresource", cultureInfo));
Console.WriteLine(" <info>: <filename>[,<name>[,public|private]]");
Console.WriteLine();
Console.Write(" ");
Console.WriteLine(JScriptCompiler.Localize("Code Generation", cultureInfo));
Console.Write(" /debug[+|-] ");
Console.WriteLine(JScriptCompiler.Localize("Usage /debug", cultureInfo));
Console.Write(" /fast[+|-] ");
Console.WriteLine(JScriptCompiler.Localize("Usage /fast", cultureInfo));
Console.Write(" /warnaserror[+|-] ");
Console.WriteLine(JScriptCompiler.Localize("Usage /warnaserror", cultureInfo));
Console.Write(" /w[arn]:<level> ");
Console.WriteLine(JScriptCompiler.Localize("Usage /warn", cultureInfo));
Console.WriteLine();
Console.Write(" ");
Console.WriteLine(JScriptCompiler.Localize("Miscellaneous", cultureInfo));
Console.Write(" @<filename> ");
Console.WriteLine(JScriptCompiler.Localize("Usage @file", cultureInfo));
Console.Write(" /? ");
Console.WriteLine(JScriptCompiler.Localize("Usage /?", cultureInfo));
Console.Write(" /help ");
Console.WriteLine(JScriptCompiler.Localize("Usage /?", cultureInfo));
Console.Write(" /d[efine]:<symbols> ");
Console.WriteLine(JScriptCompiler.Localize("Usage /define", cultureInfo));
Console.Write(" /nologo ");
Console.WriteLine(JScriptCompiler.Localize("Usage /nologo", cultureInfo));
Console.Write(" /print[+|-] ");
Console.WriteLine(JScriptCompiler.Localize("Usage /print", cultureInfo));
Console.WriteLine();
Console.Write(" ");
Console.WriteLine(JScriptCompiler.Localize("Advanced", cultureInfo));
Console.Write(" /codepage:<id> ");
Console.WriteLine(JScriptCompiler.Localize("Usage /codepage", cultureInfo));
Console.Write(" /lcid:<id> ");
Console.WriteLine(JScriptCompiler.Localize("Usage /lcid", cultureInfo));
Console.Write(" /nostdlib[+|-] ");
Console.WriteLine(JScriptCompiler.Localize("Usage /nostdlib", cultureInfo));
Console.Write(" /utf8output[+|-] ");
Console.WriteLine(JScriptCompiler.Localize("Usage /utf8output", cultureInfo));
Console.Write(" /versionsafe[+|-] ");
Console.WriteLine(JScriptCompiler.Localize("Usage /versionsafe", cultureInfo));
Console.WriteLine();
}
internal static void PrintError(
string sourceFile,
int line,
int column,
bool fIsWarning,
int number,
string message)
{
string str = (10000 + (number & (int) ushort.MaxValue)).ToString((IFormatProvider) CultureInfo.InvariantCulture).Substring(1);
if (string.Compare(sourceFile, "no source") != 0)
Console.Write(sourceFile + "(" + (object) line + "," + (object) column + ") : ");
Console.WriteLine((fIsWarning ? "warning JS" : "error JS") + str + ": " + message);
}
private int GetArgumentSeparatorIndex(string argList, int startIndex)
{
int num1 = argList.IndexOf(",", startIndex);
int num2 = argList.IndexOf(";", startIndex);
return num1 == -1 || num2 != -1 && num1 >= num2 ? num2 : num1;
}
private Hashtable GetAllDefines(string definitionList)
{
Hashtable definitions = new Hashtable();
int startIndex = 0;
int argumentSeparatorIndex;
do
{
argumentSeparatorIndex = this.GetArgumentSeparatorIndex(definitionList, startIndex);
this.AddDefinition(argumentSeparatorIndex != -1 ? definitionList.Substring(startIndex, argumentSeparatorIndex - startIndex) : definitionList.Substring(startIndex), definitions);
startIndex = argumentSeparatorIndex + 1;
}
while (argumentSeparatorIndex > -1);
return definitions;
}
private StringCollection GetAllReferences(string fileList)
{
StringCollection allReferences = new StringCollection();
int startIndex = 0;
int argumentSeparatorIndex;
do
{
argumentSeparatorIndex = this.GetArgumentSeparatorIndex(fileList, startIndex);
string str = argumentSeparatorIndex != -1 ? fileList.Substring(startIndex, argumentSeparatorIndex - startIndex).Trim() : fileList.Substring(startIndex).Trim();
if (str.Length == 0)
throw new CmdLineException(CmdLineError.MissingReference, fileList, JScriptCompiler.GetCultureInfo());
allReferences.Add(str);
startIndex = argumentSeparatorIndex + 1;
}
while (argumentSeparatorIndex > -1);
return allReferences;
}
private void AddDefinition(string def, Hashtable definitions)
{
int length = def.IndexOf("=");
string str1;
object obj;
if (length == -1)
{
str1 = def.Trim();
obj = (object) true;
}
else
{
str1 = def.Substring(0, length).Trim();
string str2 = def.Substring(length + 1).Trim();
if (string.Compare(str2, "true", true, CultureInfo.InvariantCulture) == 0)
obj = (object) true;
else if (string.Compare(str2, "false", true, CultureInfo.InvariantCulture) == 0)
{
obj = (object) false;
}
else
{
try
{
obj = (object) int.Parse(str2, (IFormatProvider) CultureInfo.InvariantCulture);
}
catch (Exception ex)
{
throw new CmdLineException(CmdLineError.InvalidDefinition, str1, JScriptCompiler.GetCultureInfo());
}
}
}
if (str1.Length == 0)
throw new CmdLineException(CmdLineError.MissingDefineArgument, JScriptCompiler.GetCultureInfo());
if (str1[0] == '_' && (str1.CompareTo("_debug") == 0 || str1.CompareTo("_fast") == 0 || str1.CompareTo("_jscript") == 0 || str1.CompareTo("_jscript_build") == 0 || str1.CompareTo("_jscript_version") == 0 || str1.CompareTo("_microsoft") == 0 || str1.CompareTo("_win32") == 0 || str1.CompareTo("_x86") == 0))
throw new CmdLineException(CmdLineError.CompilerConstant, str1, JScriptCompiler.GetCultureInfo());
definitions[(object) str1] = obj;
}
internal string ReadFile(string fileName, int codepage, bool fForceCodepage)
{
FileStream fileStream;
try
{
fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
}
catch (ArgumentException ex)
{
throw new CmdLineException(CmdLineError.InvalidCharacters, fileName, JScriptCompiler.GetCultureInfo());
}
catch (DirectoryNotFoundException ex)
{
throw new CmdLineException(CmdLineError.SourceNotFound, fileName, JScriptCompiler.GetCultureInfo());
}
catch (FileNotFoundException ex)
{
throw new CmdLineException(CmdLineError.SourceNotFound, fileName, JScriptCompiler.GetCultureInfo());
}
long length = fileStream.Length;
if (length == 0L)
return "";
Encoding encoding;
try
{
encoding = Encoding.GetEncoding(codepage);
}
catch (ArgumentException ex)
{
throw new CmdLineException(CmdLineError.InvalidCodePage, codepage.ToString((IFormatProvider) CultureInfo.InvariantCulture), JScriptCompiler.GetCultureInfo());
}
StreamReader streamReader = new StreamReader((Stream) fileStream, encoding, true);
if (length > (long) int.MaxValue)
throw new CmdLineException(CmdLineError.SourceFileTooBig, JScriptCompiler.GetCultureInfo());
return streamReader.ReadToEnd();
}
private string[] ReadResponseFile(string strFileName)
{
FileStream fileStream = new FileStream(strFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
if (fileStream.Length == 0L)
return (string[]) null;
StreamReader streamReader = new StreamReader((Stream) fileStream);
string input = streamReader.ReadLine();
Regex regex = new Regex("\\s*([^\\s\\\"]|(\\\"[^\\\"\\n]*\\\"))+");
StringCollection stringCollection = new StringCollection();
for (; input != null; input = streamReader.ReadLine())
{
if (!input.Trim().StartsWith("#"))
{
MatchCollection matchCollection = regex.Matches(input);
if (matchCollection != null && matchCollection.Count != 0)
{
foreach (Capture capture in matchCollection)
{
string str = capture.ToString().Trim();
int startIndex = 0;
while ((startIndex = str.IndexOf("\"", startIndex)) != -1)
{
if (startIndex == 0)
str = str.Substring(1);
else if (str[startIndex - 1] == '\\')
++startIndex;
else
str = str.Remove(startIndex, 1);
}
stringCollection.Add(str);
}
}
}
}
if (stringCollection.Count == 0)
return (string[]) null;
string[] array = new string[stringCollection.Count];
stringCollection.CopyTo(array, 0);
return array;
}
internal static string Localize(string s) => JScriptCompiler.Localize(s, (string) null, (CultureInfo) null);
internal static string Localize(string s, string context) => JScriptCompiler.Localize(s, context, (CultureInfo) null);
internal static string Localize(string s, CultureInfo culture) => JScriptCompiler.Localize(s, (string) null, culture);
internal static string Localize(string s, string context, CultureInfo culture)
{
try
{
if (culture == null)
culture = JScriptCompiler.GetCultureInfo();
string str = JScriptCompiler.resourceManager.GetString(s, culture);
if (str != null)
{
int length = str.IndexOf(JScriptCompiler.ContextStringDelimiter);
if (length == -1)
return str;
return context != null ? string.Format(str.Substring(length + 2), (object) context) : str.Substring(0, length);
}
}
catch (MissingManifestResourceException ex)
{
}
return s;
}
internal static CultureInfo GetCultureInfo()
{
CultureInfo cultureInfo = (CultureInfo) null;
try
{
cultureInfo = new CultureInfo(JScriptCompiler.LCID);
}
catch (ArgumentException ex)
{
}
return cultureInfo ?? CultureInfo.CurrentUICulture;
}
}