MalwareSourceCode/MSIL/Virus/Win32/N/Virus.Win32.Nimnul.c-d5c6463b93131b3c485115414cf5809e01323986e3d4274a4868222cbb54aa43/Shared/QuotingUtilities.cs

126 lines
4.2 KiB
C#
Raw Normal View History

2022-08-18 11:28:56 +00:00
// Decompiled with JetBrains decompiler
// Type: Microsoft.Build.Shared.QuotingUtilities
// 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 System.Collections;
using System.Text;
namespace Microsoft.Build.Shared
{
internal static class QuotingUtilities
{
private static readonly char[] splitMarker = new char[1];
internal static ArrayList SplitUnquoted(
string input,
int maxSplits,
bool keepEmptySplits,
bool unquote,
out int emptySplits,
params char[] separator)
{
ErrorUtilities.VerifyThrow(maxSplits >= 2, "There is no point calling this method for less than two splits.");
string str1 = new StringBuilder().Append(separator).ToString();
ErrorUtilities.VerifyThrow(str1.IndexOf('"') == -1, "The double-quote character is not supported as a separator.");
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.EnsureCapacity(input.Length);
bool flag = false;
int num1 = 0;
int num2 = 1;
for (int index = 0; index < input.Length && num2 < maxSplits; ++index)
{
switch (input[index])
{
case char.MinValue:
continue;
case '"':
stringBuilder.Append('"');
if (num1 % 2 == 0)
{
if (flag && index < input.Length - 1 && input[index + 1] == '"')
{
stringBuilder.Append('"');
++index;
}
flag = !flag;
}
num1 = 0;
continue;
case '\\':
stringBuilder.Append('\\');
++num1;
continue;
default:
if (!flag && (str1.Length == 0 && char.IsWhiteSpace(input[index]) || str1.IndexOf(input[index]) != -1))
{
stringBuilder.Append(char.MinValue);
if (++num2 == maxSplits)
stringBuilder.Append(input, index + 1, input.Length - (index + 1));
}
else
stringBuilder.Append(input[index]);
num1 = 0;
continue;
}
}
ArrayList arrayList = new ArrayList();
emptySplits = 0;
foreach (string input1 in stringBuilder.ToString().Split(QuotingUtilities.splitMarker, maxSplits))
{
string str2 = unquote ? QuotingUtilities.Unquote(input1) : input1;
if (str2.Length > 0 || keepEmptySplits)
arrayList.Add((object) str2);
else
++emptySplits;
}
return arrayList;
}
internal static ArrayList SplitUnquoted(string input, params char[] separator) => QuotingUtilities.SplitUnquoted(input, int.MaxValue, false, false, out int _, separator);
internal static string Unquote(string input, out int doubleQuotesRemoved)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.EnsureCapacity(input.Length);
bool flag = false;
int repeatCount = 0;
doubleQuotesRemoved = 0;
for (int index = 0; index < input.Length; ++index)
{
switch (input[index])
{
case '"':
stringBuilder.Append('\\', repeatCount / 2);
if (repeatCount % 2 == 0)
{
if (flag && index < input.Length - 1 && input[index + 1] == '"')
{
stringBuilder.Append('"');
++index;
}
flag = !flag;
++doubleQuotesRemoved;
}
else
stringBuilder.Append('"');
repeatCount = 0;
break;
case '\\':
++repeatCount;
break;
default:
stringBuilder.Append('\\', repeatCount);
stringBuilder.Append(input[index]);
repeatCount = 0;
break;
}
}
return stringBuilder.Append('\\', repeatCount).ToString();
}
internal static string Unquote(string input) => QuotingUtilities.Unquote(input, out int _);
}
}