Skip to content

Commit

Permalink
Fix escaped unicode obfuscated plugins failing to compile
Browse files Browse the repository at this point in the history
  • Loading branch information
0x89A committed Sep 8, 2023
1 parent 9ea012c commit 16a44e5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/CSharp/CSharpLanguage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
using PolySharp.SourceGenerators;
using Sentry;
using System.Collections.Immutable;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;

namespace Oxide.CompilerServices.CSharp
{
Expand Down Expand Up @@ -122,7 +124,13 @@ private async Task<CompilerMessage> SafeCompile(CompilerData data, CompilerMessa
foreach (var source in data.SourceFiles)
{
string fileName = Path.GetFileName(source.Name);
SyntaxTree tree = CSharpSyntaxTree.ParseText(encoding.GetString(source.Data), options, path: fileName, encoding: encoding, cancellationToken: _token);

string sourceString = Regex.Replace(encoding.GetString(source.Data), @"\\[uU]([0-9A-F]{4})", match =>
{
return ((char)int.Parse(match.Value.Substring(2), NumberStyles.HexNumber)).ToString();
});

SyntaxTree tree = CSharpSyntaxTree.ParseText(sourceString, options, path: fileName, encoding: encoding, cancellationToken: _token);
trees.Add(source, tree);
_logger.LogDebug(Events.Compile, "Added C# file {file} to the project", fileName);
}
Expand Down

0 comments on commit 16a44e5

Please sign in to comment.