Skip to content

Commit 9eb95ed

Browse files
committed
Select .NET 8 variant based on entry point selection
1 parent 575f1a5 commit 9eb95ed

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

Confuser.Core/CoreComponent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected internal override void Initialize(ConfuserContext context) {
7878
context.Registry.RegisterService(_RandomServiceId, typeof(IRandomService), new RandomService(_context.Project.Seed));
7979
context.Registry.RegisterService(_MarkerServiceId, typeof(IMarkerService), new MarkerService(context, marker));
8080
context.Registry.RegisterService(_TraceServiceId, typeof(ITraceService), new TraceService());
81-
context.Registry.RegisterService(_RuntimeServiceId, typeof(IRuntimeService), new RuntimeService());
81+
context.Registry.RegisterService(_RuntimeServiceId, typeof(IRuntimeService), new RuntimeService(context));
8282
context.Registry.RegisterService(_CompressionServiceId, typeof(ICompressionService), new CompressionService(context));
8383
context.Registry.RegisterService(_APIStoreId, typeof(IAPIStore), new APIStore(context));
8484
}

Confuser.Core/Services/RuntimeService.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44
using dnlib.DotNet;
55

66
namespace Confuser.Core.Services {
7-
internal class RuntimeService : IRuntimeService {
7+
internal class RuntimeService : IRuntimeService {
8+
private readonly ConfuserContext context;
89
ModuleDef rtModule;
910

11+
public RuntimeService(ConfuserContext context) {
12+
this.context = context;
13+
}
14+
1015
/// <inheritdoc />
1116
public TypeDef GetRuntimeType(string fullName) {
1217
if (rtModule == null) {
@@ -16,7 +21,9 @@ public TypeDef GetRuntimeType(string fullName) {
1621
}
1722

1823
private void LoadConfuserRuntimeModule() {
19-
const string runtimeDllName = "runtime\\net472\\Confuser.Runtime.dll";
24+
var entryPoint = this.context.Project[0].Resolve(this.context.Project.BaseDirectory);
25+
var hasMscorlib = entryPoint.GetAssemblyRef("mscorlib") != null;
26+
var runtimeDllName = hasMscorlib ? "runtime\\net472\\Confuser.Runtime.dll" : "runtime\\net8.0\\Confuser.Runtime.dll";
2027

2128
var module = typeof(RuntimeService).Assembly.ManifestModule;
2229
string rtPath = runtimeDllName;

0 commit comments

Comments
 (0)