Skip to content

Commit

Permalink
Bump dependencies, update ILSharpCode.Decompiler
Browse files Browse the repository at this point in the history
  • Loading branch information
Windows10CE committed Apr 5, 2023
1 parent 9cc1b6a commit 7be9aa5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
4 changes: 2 additions & 2 deletions CSharpRepl.Tests/CSharpRepl.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.0-rc.2.22476.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0-preview-20221003-04" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.reporters" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
Expand Down
10 changes: 4 additions & 6 deletions CSharpRepl/CSharpRepl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@

<ItemGroup>
<PackageReference Include="AngouriMath" Version="1.3.0" />
<PackageReference Include="ICSharpCode.Decompiler" Version="3.2.0.3856" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.5.0-1.22524.5" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta2" />
<PackageReference Include="NuGet.Packaging" Version="6.5.0-preview.1.35" />
<PackageReference Include="NuGet.Protocol" Version="6.5.0-preview.1.35" />
<PackageReference Include="NuGet.Resolver" Version="6.5.0-preview.1.35" />
<PackageReference Include="ICSharpCode.Decompiler" Version="8.0.0.7313-preview4" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NuGet.Resolver" Version="6.5.0" />
<PackageReference Include="Seq.Extensions.Logging" Version="6.1.0" />
</ItemGroup>
<ItemGroup>
Expand Down
27 changes: 17 additions & 10 deletions CSharpRepl/Eval/DisassemblyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using ICSharpCode.Decompiler.Disassembler;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Mono.Cecil;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
Expand All @@ -15,6 +14,7 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using ICSharpCode.Decompiler.Metadata;

namespace CSDiscordService.Eval
{
Expand Down Expand Up @@ -75,17 +75,21 @@ public object Main()
}}
";

var opts = CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview).WithKind(SourceCodeKind.Regular);
var opts = CSharpParseOptions.Default
.WithLanguageVersion(LanguageVersion.Preview)
.WithKind(SourceCodeKind.Regular);

var scriptSyntaxTree = CSharpSyntaxTree.ParseText(toExecute, opts);
var compOpts = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithOptimizationLevel(OptimizationLevel.Debug).WithAllowUnsafe(true).WithPlatform(Platform.AnyCpu);
var compOpts = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
.WithOptimizationLevel(OptimizationLevel.Debug)
.WithAllowUnsafe(true).WithPlatform(Platform.AnyCpu);

var compilation = CSharpCompilation.Create(Guid.NewGuid().ToString(), options: compOpts, references: References).AddSyntaxTrees(scriptSyntaxTree);
var compilation = CSharpCompilation.Create(Guid.NewGuid().ToString(), options: compOpts, references: References)
.AddSyntaxTrees(scriptSyntaxTree);

var sb = new StringBuilder();
using var pdb = new MemoryStream();
using var dll = new MemoryStream();
var result = compilation.Emit(dll, pdb);
var result = compilation.Emit(dll);
if (!result.Success)
{
sb.AppendLine("Emit Failed");
Expand All @@ -94,19 +98,22 @@ public object Main()
else
{
dll.Seek(0, SeekOrigin.Begin);
using var module = ModuleDefinition.ReadModule(dll);
using var file = new PEFile(compilation.AssemblyName!, dll);
using var writer = new StringWriter(sb);
module.Name = compilation.AssemblyName;
var plainOutput = new PlainTextOutput(writer);
var rd = new ReflectionDisassembler(plainOutput, CancellationToken.None)
{
DetectControlStructure = true
};
var ignoredMethods = new[] { ".ctor" };
var methods = module.Types.SelectMany(a => a.Methods).Where(a => !ignoredMethods.Contains(a.Name));
var methods = file.Metadata.MethodDefinitions.Where(a =>
{
var methodName = file.Metadata.GetString(file.Metadata.GetMethodDefinition(a).Name);
return !ignoredMethods.Contains(methodName);
});
foreach (var method in methods)
{
rd.DisassembleMethod(method);
rd.DisassembleMethod(file, method);
plainOutput.WriteLine();
}
}
Expand Down

0 comments on commit 7be9aa5

Please sign in to comment.