Skip to content

Commit

Permalink
Update Utils.cs
Browse files Browse the repository at this point in the history
This pull request is related to the issue EricZimmerman#7
  • Loading branch information
SteAmeR authored Nov 17, 2022
1 parent 3b97a64 commit fd30061
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions ExtensionBlocks/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4100,52 +4100,58 @@ private static string[] MultistringToStringArray(ref char[] arg)

public static List<string> GetStringsFromMultistring(byte[] rawBytes)
{
var outstrings = new List<string>();
var outstrings = new List<string>();

//drop last 2 bytes
rawBytes = rawBytes.Take(rawBytes.Length - 2).ToArray();

var bytestring = BitConverter.ToString(rawBytes);

if (bytestring.EndsWith("-00-00-00") == false)
if (bytestring.StartsWith("00-00-00-") == false)
{
bytestring = bytestring + "-00";
}
if (bytestring.EndsWith("-00-00-00") == false)
{
bytestring = bytestring + "-00";
}

var index = 0;
var index = 0;

try
{
var regexObj = new Regex("00-00-", RegexOptions.IgnoreCase);
var matchResults = regexObj.Match(bytestring);
while (matchResults.Success)
try
{
// matched text: matchResults.Value
// match start: matchResults.Index
var regexObj = new Regex("00-00-", RegexOptions.IgnoreCase);
var matchResults = regexObj.Match(bytestring);
while (matchResults.Success)
{
// matched text: matchResults.Value
// match start: matchResults.Index

var instancePosition = (matchResults.Index + 3)/3;
var instancePosition = (matchResults.Index + 3) / 3;

if (instancePosition + 2 < rawBytes.Length)
{
outstrings.Add(
ReplaceNulls(Encoding.Unicode.GetString(rawBytes, index, instancePosition - index)));
if (instancePosition + 2 < rawBytes.Length)
{
outstrings.Add(
ReplaceNulls(Encoding.Unicode.GetString(rawBytes, index, instancePosition - index)));

index += instancePosition + 2;
}
index += instancePosition + 2;
}

// match length: matchResults.Length
matchResults = matchResults.NextMatch();
// match length: matchResults.Length
matchResults = matchResults.NextMatch();
}
if (index + 4 <= rawBytes.Length)
{
outstrings.Add(ReplaceNulls(Encoding.Unicode.GetString(rawBytes, index, rawBytes.Length - index)));
}
}
if (index + 4 <= rawBytes.Length)
catch (ArgumentException)
{
outstrings.Add(ReplaceNulls(Encoding.Unicode.GetString(rawBytes, index, rawBytes.Length - index)));
throw;
}
}
catch (ArgumentException)
else
{
throw;
outstrings.Add(string.Empty);
}

return outstrings;
}

Expand Down Expand Up @@ -4246,4 +4252,4 @@ public static string GetFolderNameFromGuid(string guid)
return thedate;
}
}
}
}

0 comments on commit fd30061

Please # to comment.