From 8097ab770648c04d56f59517b954a226ee730875 Mon Sep 17 00:00:00 2001 From: Andrii Kurdiumov Date: Sun, 8 Mar 2026 18:36:23 +0100 Subject: [PATCH 1/4] Package two variants of runtime One for .NET Framework, and second for .NET applications Right now this is get rid of System.Runtime dependency when .NET FW app obfuscated by .NET application, and there 3 types which are used from S.P.CoreLib - System.Array - System.RuntimeFieldHandle - System.RuntimeHelpers Right now always used .NET FW version when building. This is does not solve problem with obfuscation of .NET apps using .NET Confuser, and introduce issue with building .NET application using Confuser integration --- .gitignore | 1 - Confuser.Core/Services/RuntimeService.cs | 2 +- .../Confuser.Protections.csproj | 53 ++++++++++++++++--- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 1f8a9c523..fbdab9cbd 100644 --- a/.gitignore +++ b/.gitignore @@ -41,4 +41,3 @@ gh-pages/ .idea/ artifacts/ /Confuser.Protections/runtime -/Confuser.Protections/runtime diff --git a/Confuser.Core/Services/RuntimeService.cs b/Confuser.Core/Services/RuntimeService.cs index 4d4edae4a..d5a6f6db0 100644 --- a/Confuser.Core/Services/RuntimeService.cs +++ b/Confuser.Core/Services/RuntimeService.cs @@ -16,7 +16,7 @@ public TypeDef GetRuntimeType(string fullName) { } private void LoadConfuserRuntimeModule() { - const string runtimeDllName = "Confuser.Runtime.dll"; + const string runtimeDllName = "runtime\\net472\\Confuser.Runtime.dll"; var module = typeof(RuntimeService).Assembly.ManifestModule; string rtPath = runtimeDllName; diff --git a/Confuser.Protections/Confuser.Protections.csproj b/Confuser.Protections/Confuser.Protections.csproj index 4a2625df8..386dda8d7 100644 --- a/Confuser.Protections/Confuser.Protections.csproj +++ b/Confuser.Protections/Confuser.Protections.csproj @@ -5,6 +5,7 @@ net472;net8.0 + ..\Confuser.Runtime\Confuser.Runtime.csproj @@ -12,16 +13,56 @@ Protections and packers of ConfuserEx - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + runtime\net8.0\%(Filename)%(Extension) + PreserveNewest + + + runtime\net472\%(Filename)%(Extension) + PreserveNewest + + + + + + \ No newline at end of file From 0f82b6ad4ff0cdfec7a5325b011aa6a4248bf641 Mon Sep 17 00:00:00 2001 From: Andrii Kurdiumov Date: Sun, 8 Mar 2026 18:42:30 +0100 Subject: [PATCH 2/4] Add dependency --- Confuser.Protections/Confuser.Protections.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Confuser.Protections/Confuser.Protections.csproj b/Confuser.Protections/Confuser.Protections.csproj index 386dda8d7..87585226b 100644 --- a/Confuser.Protections/Confuser.Protections.csproj +++ b/Confuser.Protections/Confuser.Protections.csproj @@ -16,6 +16,7 @@ + @@ -65,4 +66,4 @@ - \ No newline at end of file + From 575f1a5ef08f1e73664c9e713bd9c6fd63906409 Mon Sep 17 00:00:00 2001 From: Andrii Kurdiumov Date: Sun, 8 Mar 2026 18:55:58 +0100 Subject: [PATCH 3/4] Prebuild all Runtime TFMs --- .gitignore | 1 + .../Confuser.Protections.csproj | 27 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index fbdab9cbd..ae12b8e6d 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ gh-pages/ .idea/ artifacts/ /Confuser.Protections/runtime +*.binlog diff --git a/Confuser.Protections/Confuser.Protections.csproj b/Confuser.Protections/Confuser.Protections.csproj index 87585226b..ed84a3ac5 100644 --- a/Confuser.Protections/Confuser.Protections.csproj +++ b/Confuser.Protections/Confuser.Protections.csproj @@ -25,13 +25,18 @@ - + + + + + + + - + @@ -40,18 +45,12 @@ - - + + - + From 9eb95ed9bfef775619147b7697597286e37293f3 Mon Sep 17 00:00:00 2001 From: Andrii Kurdiumov Date: Thu, 19 Mar 2026 17:03:20 +0100 Subject: [PATCH 4/4] Select .NET 8 variant based on entry point selection --- Confuser.Core/CoreComponent.cs | 2 +- Confuser.Core/Services/RuntimeService.cs | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Confuser.Core/CoreComponent.cs b/Confuser.Core/CoreComponent.cs index 7ae6d7a82..d39ad7fe8 100644 --- a/Confuser.Core/CoreComponent.cs +++ b/Confuser.Core/CoreComponent.cs @@ -78,7 +78,7 @@ protected internal override void Initialize(ConfuserContext context) { context.Registry.RegisterService(_RandomServiceId, typeof(IRandomService), new RandomService(_context.Project.Seed)); context.Registry.RegisterService(_MarkerServiceId, typeof(IMarkerService), new MarkerService(context, marker)); context.Registry.RegisterService(_TraceServiceId, typeof(ITraceService), new TraceService()); - context.Registry.RegisterService(_RuntimeServiceId, typeof(IRuntimeService), new RuntimeService()); + context.Registry.RegisterService(_RuntimeServiceId, typeof(IRuntimeService), new RuntimeService(context)); context.Registry.RegisterService(_CompressionServiceId, typeof(ICompressionService), new CompressionService(context)); context.Registry.RegisterService(_APIStoreId, typeof(IAPIStore), new APIStore(context)); } diff --git a/Confuser.Core/Services/RuntimeService.cs b/Confuser.Core/Services/RuntimeService.cs index d5a6f6db0..fe94c9ca0 100644 --- a/Confuser.Core/Services/RuntimeService.cs +++ b/Confuser.Core/Services/RuntimeService.cs @@ -4,9 +4,14 @@ using dnlib.DotNet; namespace Confuser.Core.Services { - internal class RuntimeService : IRuntimeService { + internal class RuntimeService : IRuntimeService { + private readonly ConfuserContext context; ModuleDef rtModule; + public RuntimeService(ConfuserContext context) { + this.context = context; + } + /// public TypeDef GetRuntimeType(string fullName) { if (rtModule == null) { @@ -16,7 +21,9 @@ public TypeDef GetRuntimeType(string fullName) { } private void LoadConfuserRuntimeModule() { - const string runtimeDllName = "runtime\\net472\\Confuser.Runtime.dll"; + var entryPoint = this.context.Project[0].Resolve(this.context.Project.BaseDirectory); + var hasMscorlib = entryPoint.GetAssemblyRef("mscorlib") != null; + var runtimeDllName = hasMscorlib ? "runtime\\net472\\Confuser.Runtime.dll" : "runtime\\net8.0\\Confuser.Runtime.dll"; var module = typeof(RuntimeService).Assembly.ManifestModule; string rtPath = runtimeDllName;