mirror of
https://github.com/vxunderground/MalwareSourceCode.git
synced 2024-12-23 03:46:10 +00:00
394 lines
16 KiB
C#
394 lines
16 KiB
C#
|
// Decompiled with JetBrains decompiler
|
|||
|
// Type: Microsoft.Build.CommandLine.CommandLineSwitches
|
|||
|
// Assembly: MSBuild, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
|
|||
|
// MVID: E42BAB90-704E-4C03-B5C0-D4E3A6B884E3
|
|||
|
// Assembly location: C:\Users\Administrateur\Downloads\Virusshare-00001-msil\Virus.Win32.Nimnul.c-d5c6463b93131b3c485115414cf5809e01323986e3d4274a4868222cbb54aa43.exe
|
|||
|
|
|||
|
using Microsoft.Build.Shared;
|
|||
|
using System;
|
|||
|
using System.Collections;
|
|||
|
|
|||
|
namespace Microsoft.Build.CommandLine
|
|||
|
{
|
|||
|
internal sealed class CommandLineSwitches
|
|||
|
{
|
|||
|
private static readonly CommandLineSwitches.ParameterlessSwitchInfo[] parameterlessSwitchesMap = new CommandLineSwitches.ParameterlessSwitchInfo[5]
|
|||
|
{
|
|||
|
new CommandLineSwitches.ParameterlessSwitchInfo(new string[3]
|
|||
|
{
|
|||
|
"help",
|
|||
|
"h",
|
|||
|
"?"
|
|||
|
}, CommandLineSwitches.ParameterlessSwitch.Help, (string) null),
|
|||
|
new CommandLineSwitches.ParameterlessSwitchInfo(new string[2]
|
|||
|
{
|
|||
|
"version",
|
|||
|
"ver"
|
|||
|
}, CommandLineSwitches.ParameterlessSwitch.Version, (string) null),
|
|||
|
new CommandLineSwitches.ParameterlessSwitchInfo(new string[1]
|
|||
|
{
|
|||
|
"nologo"
|
|||
|
}, CommandLineSwitches.ParameterlessSwitch.NoLogo, (string) null),
|
|||
|
new CommandLineSwitches.ParameterlessSwitchInfo(new string[2]
|
|||
|
{
|
|||
|
"noautoresponse",
|
|||
|
"noautorsp"
|
|||
|
}, CommandLineSwitches.ParameterlessSwitch.NoAutoResponse, (string) null),
|
|||
|
new CommandLineSwitches.ParameterlessSwitchInfo(new string[2]
|
|||
|
{
|
|||
|
"noconsolelogger",
|
|||
|
"noconlog"
|
|||
|
}, CommandLineSwitches.ParameterlessSwitch.NoConsoleLogger, (string) null)
|
|||
|
};
|
|||
|
private static readonly CommandLineSwitches.ParameterizedSwitchInfo[] parameterizedSwitchesMap = new CommandLineSwitches.ParameterizedSwitchInfo[7]
|
|||
|
{
|
|||
|
new CommandLineSwitches.ParameterizedSwitchInfo(new string[1], CommandLineSwitches.ParameterizedSwitch.Project, "DuplicateProjectSwitchError", false, (string) null, true),
|
|||
|
new CommandLineSwitches.ParameterizedSwitchInfo(new string[2]
|
|||
|
{
|
|||
|
"target",
|
|||
|
"t"
|
|||
|
}, CommandLineSwitches.ParameterizedSwitch.Target, (string) null, true, "MissingTargetError", true),
|
|||
|
new CommandLineSwitches.ParameterizedSwitchInfo(new string[2]
|
|||
|
{
|
|||
|
"property",
|
|||
|
"p"
|
|||
|
}, CommandLineSwitches.ParameterizedSwitch.Property, (string) null, true, "MissingPropertyError", true),
|
|||
|
new CommandLineSwitches.ParameterizedSwitchInfo(new string[2]
|
|||
|
{
|
|||
|
"logger",
|
|||
|
"l"
|
|||
|
}, CommandLineSwitches.ParameterizedSwitch.Logger, (string) null, false, "MissingLoggerError", false),
|
|||
|
new CommandLineSwitches.ParameterizedSwitchInfo(new string[2]
|
|||
|
{
|
|||
|
"verbosity",
|
|||
|
"v"
|
|||
|
}, CommandLineSwitches.ParameterizedSwitch.Verbosity, (string) null, false, "MissingVerbosityError", true),
|
|||
|
new CommandLineSwitches.ParameterizedSwitchInfo(new string[2]
|
|||
|
{
|
|||
|
"validate",
|
|||
|
"val"
|
|||
|
}, CommandLineSwitches.ParameterizedSwitch.Validate, (string) null, false, (string) null, true),
|
|||
|
new CommandLineSwitches.ParameterizedSwitchInfo(new string[2]
|
|||
|
{
|
|||
|
"consoleloggerparameters",
|
|||
|
"clp"
|
|||
|
}, CommandLineSwitches.ParameterizedSwitch.ConsoleLoggerParameters, (string) null, false, (string) null, true)
|
|||
|
};
|
|||
|
private CommandLineSwitches.DetectedParameterlessSwitch[] parameterlessSwitches;
|
|||
|
private CommandLineSwitches.DetectedParameterizedSwitch[] parameterizedSwitches;
|
|||
|
private static readonly char[] parameterSeparators = new char[2]
|
|||
|
{
|
|||
|
',',
|
|||
|
';'
|
|||
|
};
|
|||
|
private static readonly string[] noParameters = new string[0];
|
|||
|
private string errorMessage;
|
|||
|
private string badCommandLineArg;
|
|||
|
private Exception innerException;
|
|||
|
private bool isParameterError;
|
|||
|
|
|||
|
internal static bool IsParameterlessSwitch(
|
|||
|
string switchName,
|
|||
|
out CommandLineSwitches.ParameterlessSwitch parameterlessSwitch,
|
|||
|
out string duplicateSwitchErrorMessage)
|
|||
|
{
|
|||
|
parameterlessSwitch = CommandLineSwitches.ParameterlessSwitch.Invalid;
|
|||
|
duplicateSwitchErrorMessage = (string) null;
|
|||
|
foreach (CommandLineSwitches.ParameterlessSwitchInfo parameterlessSwitches in CommandLineSwitches.parameterlessSwitchesMap)
|
|||
|
{
|
|||
|
foreach (string switchName1 in parameterlessSwitches.switchNames)
|
|||
|
{
|
|||
|
if (string.Compare(switchName, switchName1, StringComparison.OrdinalIgnoreCase) == 0)
|
|||
|
{
|
|||
|
parameterlessSwitch = parameterlessSwitches.parameterlessSwitch;
|
|||
|
duplicateSwitchErrorMessage = parameterlessSwitches.duplicateSwitchErrorMessage;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return parameterlessSwitch != CommandLineSwitches.ParameterlessSwitch.Invalid;
|
|||
|
}
|
|||
|
|
|||
|
internal static bool IsParameterizedSwitch(
|
|||
|
string switchName,
|
|||
|
out CommandLineSwitches.ParameterizedSwitch parameterizedSwitch,
|
|||
|
out string duplicateSwitchErrorMessage,
|
|||
|
out bool multipleParametersAllowed,
|
|||
|
out string missingParametersErrorMessage,
|
|||
|
out bool unquoteParameters)
|
|||
|
{
|
|||
|
parameterizedSwitch = CommandLineSwitches.ParameterizedSwitch.Invalid;
|
|||
|
duplicateSwitchErrorMessage = (string) null;
|
|||
|
multipleParametersAllowed = false;
|
|||
|
missingParametersErrorMessage = (string) null;
|
|||
|
unquoteParameters = false;
|
|||
|
foreach (CommandLineSwitches.ParameterizedSwitchInfo parameterizedSwitches in CommandLineSwitches.parameterizedSwitchesMap)
|
|||
|
{
|
|||
|
foreach (string switchName1 in parameterizedSwitches.switchNames)
|
|||
|
{
|
|||
|
if (string.Compare(switchName, switchName1, StringComparison.OrdinalIgnoreCase) == 0)
|
|||
|
{
|
|||
|
parameterizedSwitch = parameterizedSwitches.parameterizedSwitch;
|
|||
|
duplicateSwitchErrorMessage = parameterizedSwitches.duplicateSwitchErrorMessage;
|
|||
|
multipleParametersAllowed = parameterizedSwitches.multipleParametersAllowed;
|
|||
|
missingParametersErrorMessage = parameterizedSwitches.missingParametersErrorMessage;
|
|||
|
unquoteParameters = parameterizedSwitches.unquoteParameters;
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
return parameterizedSwitch != CommandLineSwitches.ParameterizedSwitch.Invalid;
|
|||
|
}
|
|||
|
|
|||
|
internal CommandLineSwitches()
|
|||
|
{
|
|||
|
this.parameterlessSwitches = new CommandLineSwitches.DetectedParameterlessSwitch[5];
|
|||
|
this.parameterizedSwitches = new CommandLineSwitches.DetectedParameterizedSwitch[7];
|
|||
|
}
|
|||
|
|
|||
|
internal void SetParameterlessSwitch(
|
|||
|
CommandLineSwitches.ParameterlessSwitch parameterlessSwitch,
|
|||
|
string commandLineArg)
|
|||
|
{
|
|||
|
this.parameterlessSwitches[(int) parameterlessSwitch].commandLineArg = commandLineArg;
|
|||
|
}
|
|||
|
|
|||
|
internal bool SetParameterizedSwitch(
|
|||
|
CommandLineSwitches.ParameterizedSwitch parameterizedSwitch,
|
|||
|
string commandLineArg,
|
|||
|
string switchParameters,
|
|||
|
bool multipleParametersAllowed,
|
|||
|
bool unquoteParameters)
|
|||
|
{
|
|||
|
bool flag = false;
|
|||
|
if (this.parameterizedSwitches[(int) parameterizedSwitch].commandLineArg == null)
|
|||
|
this.parameterizedSwitches[(int) parameterizedSwitch].parameters = new ArrayList();
|
|||
|
this.parameterizedSwitches[(int) parameterizedSwitch].commandLineArg = commandLineArg;
|
|||
|
if (multipleParametersAllowed)
|
|||
|
{
|
|||
|
int emptySplits;
|
|||
|
this.parameterizedSwitches[(int) parameterizedSwitch].parameters.AddRange((ICollection) QuotingUtilities.SplitUnquoted(switchParameters, int.MaxValue, false, unquoteParameters, out emptySplits, CommandLineSwitches.parameterSeparators));
|
|||
|
flag = emptySplits == 0;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (unquoteParameters)
|
|||
|
switchParameters = QuotingUtilities.Unquote(switchParameters);
|
|||
|
if (switchParameters.Length > 0)
|
|||
|
{
|
|||
|
this.parameterizedSwitches[(int) parameterizedSwitch].parameters.Add((object) switchParameters);
|
|||
|
flag = true;
|
|||
|
}
|
|||
|
}
|
|||
|
return flag;
|
|||
|
}
|
|||
|
|
|||
|
internal bool IsParameterlessSwitchSet(
|
|||
|
CommandLineSwitches.ParameterlessSwitch parameterlessSwitch)
|
|||
|
{
|
|||
|
return this.parameterlessSwitches[(int) parameterlessSwitch].commandLineArg != null;
|
|||
|
}
|
|||
|
|
|||
|
internal bool this[
|
|||
|
CommandLineSwitches.ParameterlessSwitch parameterlessSwitch]
|
|||
|
{
|
|||
|
return this.parameterlessSwitches[(int) parameterlessSwitch].commandLineArg != null;
|
|||
|
}
|
|||
|
|
|||
|
internal string GetParameterlessSwitchCommandLineArg(
|
|||
|
CommandLineSwitches.ParameterlessSwitch parameterlessSwitch)
|
|||
|
{
|
|||
|
return this.parameterlessSwitches[(int) parameterlessSwitch].commandLineArg;
|
|||
|
}
|
|||
|
|
|||
|
internal bool IsParameterizedSwitchSet(
|
|||
|
CommandLineSwitches.ParameterizedSwitch parameterizedSwitch)
|
|||
|
{
|
|||
|
return this.parameterizedSwitches[(int) parameterizedSwitch].commandLineArg != null;
|
|||
|
}
|
|||
|
|
|||
|
internal string[] this[
|
|||
|
CommandLineSwitches.ParameterizedSwitch parameterizedSwitch]
|
|||
|
{
|
|||
|
return this.parameterizedSwitches[(int) parameterizedSwitch].commandLineArg == null ? CommandLineSwitches.noParameters : (string[]) this.parameterizedSwitches[(int) parameterizedSwitch].parameters.ToArray(typeof (string));
|
|||
|
}
|
|||
|
|
|||
|
internal string GetParameterizedSwitchCommandLineArg(
|
|||
|
CommandLineSwitches.ParameterizedSwitch parameterizedSwitch)
|
|||
|
{
|
|||
|
return this.parameterizedSwitches[(int) parameterizedSwitch].commandLineArg;
|
|||
|
}
|
|||
|
|
|||
|
internal bool HaveAnySwitchesBeenSet()
|
|||
|
{
|
|||
|
for (int index = 0; index < 5; ++index)
|
|||
|
{
|
|||
|
if (this.IsParameterlessSwitchSet((CommandLineSwitches.ParameterlessSwitch) index))
|
|||
|
return true;
|
|||
|
}
|
|||
|
for (int index = 0; index < 7; ++index)
|
|||
|
{
|
|||
|
if (this.IsParameterizedSwitchSet((CommandLineSwitches.ParameterizedSwitch) index))
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
internal void SetUnknownSwitchError(string badCommandLineArgValue) => this.SetSwitchError("UnknownSwitchError", badCommandLineArgValue);
|
|||
|
|
|||
|
internal void SetUnexpectedParametersError(string badCommandLineArgValue) => this.SetSwitchError("UnexpectedParametersError", badCommandLineArgValue);
|
|||
|
|
|||
|
internal void SetSwitchError(string messageResourceNameValue, string badCommandLineArgValue) => this.SetError(messageResourceNameValue, badCommandLineArgValue, (Exception) null, false);
|
|||
|
|
|||
|
internal void SetParameterError(string messageResourceNameValue, string badCommandLineArgValue) => this.SetParameterError(messageResourceNameValue, badCommandLineArgValue, (Exception) null);
|
|||
|
|
|||
|
internal void SetParameterError(
|
|||
|
string messageResourceNameValue,
|
|||
|
string badCommandLineArgValue,
|
|||
|
Exception innerExceptionValue)
|
|||
|
{
|
|||
|
this.SetError(messageResourceNameValue, badCommandLineArgValue, innerExceptionValue, true);
|
|||
|
}
|
|||
|
|
|||
|
private void SetError(
|
|||
|
string messageResourceNameValue,
|
|||
|
string badCommandLineArgValue,
|
|||
|
Exception innerExceptionValue,
|
|||
|
bool isParameterErrorValue)
|
|||
|
{
|
|||
|
if (this.HaveErrors())
|
|||
|
return;
|
|||
|
this.errorMessage = messageResourceNameValue;
|
|||
|
this.badCommandLineArg = badCommandLineArgValue;
|
|||
|
this.innerException = innerExceptionValue;
|
|||
|
this.isParameterError = isParameterErrorValue;
|
|||
|
}
|
|||
|
|
|||
|
internal bool HaveErrors() => this.errorMessage != null;
|
|||
|
|
|||
|
internal void ThrowErrors()
|
|||
|
{
|
|||
|
if (!this.HaveErrors())
|
|||
|
return;
|
|||
|
if (this.isParameterError)
|
|||
|
InitializationException.Throw(this.errorMessage, this.badCommandLineArg, this.innerException, false);
|
|||
|
else
|
|||
|
CommandLineSwitchException.Throw(this.errorMessage, this.badCommandLineArg);
|
|||
|
}
|
|||
|
|
|||
|
internal void Append(CommandLineSwitches switchesToAppend)
|
|||
|
{
|
|||
|
if (!this.HaveErrors() && switchesToAppend.HaveErrors())
|
|||
|
{
|
|||
|
this.errorMessage = switchesToAppend.errorMessage;
|
|||
|
this.badCommandLineArg = switchesToAppend.badCommandLineArg;
|
|||
|
this.innerException = switchesToAppend.innerException;
|
|||
|
this.isParameterError = switchesToAppend.isParameterError;
|
|||
|
}
|
|||
|
for (int index = 0; index < 5; ++index)
|
|||
|
{
|
|||
|
if (switchesToAppend.IsParameterlessSwitchSet((CommandLineSwitches.ParameterlessSwitch) index))
|
|||
|
{
|
|||
|
if (!this.IsParameterlessSwitchSet((CommandLineSwitches.ParameterlessSwitch) index) || CommandLineSwitches.parameterlessSwitchesMap[index].duplicateSwitchErrorMessage == null)
|
|||
|
this.parameterlessSwitches[index].commandLineArg = switchesToAppend.parameterlessSwitches[index].commandLineArg;
|
|||
|
else
|
|||
|
this.SetSwitchError(CommandLineSwitches.parameterlessSwitchesMap[index].duplicateSwitchErrorMessage, switchesToAppend.GetParameterlessSwitchCommandLineArg((CommandLineSwitches.ParameterlessSwitch) index));
|
|||
|
}
|
|||
|
}
|
|||
|
for (int index = 0; index < 7; ++index)
|
|||
|
{
|
|||
|
if (switchesToAppend.IsParameterizedSwitchSet((CommandLineSwitches.ParameterizedSwitch) index))
|
|||
|
{
|
|||
|
if (!this.IsParameterizedSwitchSet((CommandLineSwitches.ParameterizedSwitch) index) || CommandLineSwitches.parameterizedSwitchesMap[index].duplicateSwitchErrorMessage == null)
|
|||
|
{
|
|||
|
if (this.parameterizedSwitches[index].commandLineArg == null)
|
|||
|
this.parameterizedSwitches[index].parameters = new ArrayList();
|
|||
|
this.parameterizedSwitches[index].commandLineArg = switchesToAppend.parameterizedSwitches[index].commandLineArg;
|
|||
|
this.parameterizedSwitches[index].parameters.AddRange((ICollection) switchesToAppend.parameterizedSwitches[index].parameters);
|
|||
|
}
|
|||
|
else
|
|||
|
this.SetSwitchError(CommandLineSwitches.parameterizedSwitchesMap[index].duplicateSwitchErrorMessage, switchesToAppend.GetParameterizedSwitchCommandLineArg((CommandLineSwitches.ParameterizedSwitch) index));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
internal enum ParameterlessSwitch
|
|||
|
{
|
|||
|
Invalid = -1, // 0xFFFFFFFF
|
|||
|
Help = 0,
|
|||
|
Version = 1,
|
|||
|
NoLogo = 2,
|
|||
|
NoAutoResponse = 3,
|
|||
|
NoConsoleLogger = 4,
|
|||
|
NumberOfParameterlessSwitches = 5,
|
|||
|
}
|
|||
|
|
|||
|
internal enum ParameterizedSwitch
|
|||
|
{
|
|||
|
Invalid = -1, // 0xFFFFFFFF
|
|||
|
Project = 0,
|
|||
|
Target = 1,
|
|||
|
Property = 2,
|
|||
|
Logger = 3,
|
|||
|
Verbosity = 4,
|
|||
|
Validate = 5,
|
|||
|
ConsoleLoggerParameters = 6,
|
|||
|
NumberOfParameterizedSwitches = 7,
|
|||
|
}
|
|||
|
|
|||
|
private struct ParameterlessSwitchInfo
|
|||
|
{
|
|||
|
internal string[] switchNames;
|
|||
|
internal string duplicateSwitchErrorMessage;
|
|||
|
internal CommandLineSwitches.ParameterlessSwitch parameterlessSwitch;
|
|||
|
|
|||
|
internal ParameterlessSwitchInfo(
|
|||
|
string[] switchNames,
|
|||
|
CommandLineSwitches.ParameterlessSwitch parameterlessSwitch,
|
|||
|
string duplicateSwitchErrorMessage)
|
|||
|
{
|
|||
|
this.switchNames = switchNames;
|
|||
|
this.duplicateSwitchErrorMessage = duplicateSwitchErrorMessage;
|
|||
|
this.parameterlessSwitch = parameterlessSwitch;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private struct ParameterizedSwitchInfo
|
|||
|
{
|
|||
|
internal string[] switchNames;
|
|||
|
internal string duplicateSwitchErrorMessage;
|
|||
|
internal bool multipleParametersAllowed;
|
|||
|
internal string missingParametersErrorMessage;
|
|||
|
internal bool unquoteParameters;
|
|||
|
internal CommandLineSwitches.ParameterizedSwitch parameterizedSwitch;
|
|||
|
|
|||
|
internal ParameterizedSwitchInfo(
|
|||
|
string[] switchNames,
|
|||
|
CommandLineSwitches.ParameterizedSwitch parameterizedSwitch,
|
|||
|
string duplicateSwitchErrorMessage,
|
|||
|
bool multipleParametersAllowed,
|
|||
|
string missingParametersErrorMessage,
|
|||
|
bool unquoteParameters)
|
|||
|
{
|
|||
|
this.switchNames = switchNames;
|
|||
|
this.duplicateSwitchErrorMessage = duplicateSwitchErrorMessage;
|
|||
|
this.multipleParametersAllowed = multipleParametersAllowed;
|
|||
|
this.missingParametersErrorMessage = missingParametersErrorMessage;
|
|||
|
this.unquoteParameters = unquoteParameters;
|
|||
|
this.parameterizedSwitch = parameterizedSwitch;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private struct DetectedParameterlessSwitch
|
|||
|
{
|
|||
|
internal string commandLineArg;
|
|||
|
}
|
|||
|
|
|||
|
private struct DetectedParameterizedSwitch
|
|||
|
{
|
|||
|
internal string commandLineArg;
|
|||
|
internal ArrayList parameters;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|