From ed3d269415a9d3b413c9b1bbf7ada830fa173fb0 Mon Sep 17 00:00:00 2001 From: Andrii Kurdiumov Date: Mon, 9 Mar 2026 10:11:17 +0100 Subject: [PATCH 1/4] Use types from transformed module corelib (#22) and not from Confuser's current runtime corelib --- Confuser.Protections/Compress/Compressor.cs | 8 ++++++-- Confuser.Protections/Constants/EncodePhase.cs | 8 ++++++-- Confuser.Protections/Resources/InjectPhase.cs | 8 +++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Confuser.Protections/Compress/Compressor.cs b/Confuser.Protections/Compress/Compressor.cs index 33c0ea6b7..13c127a64 100644 --- a/Confuser.Protections/Compress/Compressor.cs +++ b/Confuser.Protections/Compress/Compressor.cs @@ -196,8 +196,12 @@ void InjectData(ModuleDef stubModule, MethodDef method, byte[] data) { repl.AddRange(arg); repl.Add(Instruction.Create(OpCodes.Dup)); repl.Add(Instruction.Create(OpCodes.Ldtoken, dataField)); - repl.Add(Instruction.Create(OpCodes.Call, stubModule.Import( - typeof(RuntimeHelpers).GetMethod("InitializeArray")))); + var runtimeHelpers = stubModule.CorLibTypes.GetTypeRef("System.Runtime.CompilerServices", "RuntimeHelpers"); + var arrayTypeRef = stubModule.CorLibTypes.GetTypeRef("System", "Array"); + var runtimeFieldHandle = stubModule.CorLibTypes.GetTypeRef("System", "RuntimeFieldHandle"); + var initialzeArray = new MemberRefUser(stubModule, "InitializeArray", + MethodSig.CreateStatic(stubModule.CorLibTypes.Void, arrayTypeRef.ToTypeSig(), runtimeFieldHandle.ToTypeSig()), runtimeHelpers); + repl.Add(Instruction.Create(OpCodes.Call, stubModule.Import(initialzeArray))); return repl.ToArray(); }); } diff --git a/Confuser.Protections/Constants/EncodePhase.cs b/Confuser.Protections/Constants/EncodePhase.cs index 4eba9118e..6dc7ba2b5 100644 --- a/Confuser.Protections/Constants/EncodePhase.cs +++ b/Confuser.Protections/Constants/EncodePhase.cs @@ -121,8 +121,12 @@ protected override void Execute(ConfuserContext context, ProtectionParameters pa repl.AddRange(arg); repl.Add(Instruction.Create(OpCodes.Dup)); repl.Add(Instruction.Create(OpCodes.Ldtoken, moduleCtx.DataField)); - repl.Add(Instruction.Create(OpCodes.Call, moduleCtx.Module.Import( - typeof(RuntimeHelpers).GetMethod("InitializeArray")))); + var runtimeHelpers = moduleCtx.Module.CorLibTypes.GetTypeRef("System.Runtime.CompilerServices", "RuntimeHelpers"); + var arrayTypeRef = moduleCtx.Module.CorLibTypes.GetTypeRef("System", "Array"); + var runtimeFieldHandle = moduleCtx.Module.CorLibTypes.GetTypeRef("System", "RuntimeFieldHandle"); + var initialzeArray = new MemberRefUser(moduleCtx.Module, "InitializeArray", + MethodSig.CreateStatic(moduleCtx.Module.CorLibTypes.Void, arrayTypeRef.ToTypeSig(), runtimeFieldHandle.ToTypeSig()), runtimeHelpers); + repl.Add(Instruction.Create(OpCodes.Call, moduleCtx.Module.Import(initialzeArray))); return repl.ToArray(); }); } diff --git a/Confuser.Protections/Resources/InjectPhase.cs b/Confuser.Protections/Resources/InjectPhase.cs index 540591750..b78ff12f7 100644 --- a/Confuser.Protections/Resources/InjectPhase.cs +++ b/Confuser.Protections/Resources/InjectPhase.cs @@ -138,9 +138,15 @@ void MutateInitializer(REContext moduleCtx, MethodDef decomp) { repl.Add(Instruction.Create(OpCodes.Ldtoken, moduleCtx.DataField)); repl.Add(Instruction.Create(OpCodes.Call, moduleCtx.Module.Import( typeof(RuntimeHelpers).GetMethod("InitializeArray")))); + var runtimeHelpers = moduleCtx.Module.CorLibTypes.GetTypeRef("System.Runtime.CompilerServices", "RuntimeHelpers"); + var arrayTypeRef = moduleCtx.Module.CorLibTypes.GetTypeRef("System", "Array"); + var runtimeFieldHandle = moduleCtx.Module.CorLibTypes.GetTypeRef("System", "RuntimeFieldHandle"); + var initialzeArray = new MemberRefUser(moduleCtx.Module, "InitializeArray", + MethodSig.CreateStatic(moduleCtx.Module.CorLibTypes.Void, arrayTypeRef.ToTypeSig(), runtimeFieldHandle.ToTypeSig()), runtimeHelpers); + repl.Add(Instruction.Create(OpCodes.Call, moduleCtx.Module.Import(initialzeArray))); return repl.ToArray(); }); moduleCtx.Context.Registry.GetService().ExcludeMethod(moduleCtx.Context, moduleCtx.InitMethod); } } -} \ No newline at end of file +} From 3250483e11d15d6a14d1f85a2f994fab3f77595f Mon Sep 17 00:00:00 2001 From: Andrii Kurdiumov Date: Sat, 14 Mar 2026 15:07:06 +0100 Subject: [PATCH 2/4] Remove duplicate transformation (#23) Fixed leftover from #22 --- Confuser.Protections/Resources/InjectPhase.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Confuser.Protections/Resources/InjectPhase.cs b/Confuser.Protections/Resources/InjectPhase.cs index b78ff12f7..9dd6fff20 100644 --- a/Confuser.Protections/Resources/InjectPhase.cs +++ b/Confuser.Protections/Resources/InjectPhase.cs @@ -136,8 +136,6 @@ void MutateInitializer(REContext moduleCtx, MethodDef decomp) { repl.AddRange(arg); repl.Add(Instruction.Create(OpCodes.Dup)); repl.Add(Instruction.Create(OpCodes.Ldtoken, moduleCtx.DataField)); - repl.Add(Instruction.Create(OpCodes.Call, moduleCtx.Module.Import( - typeof(RuntimeHelpers).GetMethod("InitializeArray")))); var runtimeHelpers = moduleCtx.Module.CorLibTypes.GetTypeRef("System.Runtime.CompilerServices", "RuntimeHelpers"); var arrayTypeRef = moduleCtx.Module.CorLibTypes.GetTypeRef("System", "Array"); var runtimeFieldHandle = moduleCtx.Module.CorLibTypes.GetTypeRef("System", "RuntimeFieldHandle"); From 8501b20c303e92130e7afcb16a423b3d60127882 Mon Sep 17 00:00:00 2001 From: Andrii Kurdiumov Date: Sat, 14 Mar 2026 15:55:32 +0100 Subject: [PATCH 3/4] Remove not needed dependency on net8.0 (#24) --- Confuser.Runtime/Confuser.Runtime.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Confuser.Runtime/Confuser.Runtime.csproj b/Confuser.Runtime/Confuser.Runtime.csproj index 9de368049..be1448112 100644 --- a/Confuser.Runtime/Confuser.Runtime.csproj +++ b/Confuser.Runtime/Confuser.Runtime.csproj @@ -14,7 +14,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive From f5d57f1fdff4cf84a607ea36c6ee3072be56e3df Mon Sep 17 00:00:00 2001 From: Andrii Kurdiumov Date: Sat, 14 Mar 2026 19:35:31 +0100 Subject: [PATCH 4/4] Update dependencies --- .gitignore | 4 +++- Confuser.Core/Confuser.Core.csproj | 2 +- Confuser.Protections/Confuser.Protections.csproj | 2 +- Confuser.Renamer/Confuser.Renamer.csproj | 3 +-- Confuser2.slnx | 1 - ConfuserEx.Common.props | 4 ++-- ConfuserEx.Common.targets | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 6ea345e51..1f8a9c523 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,6 @@ packages/ gh-pages/ .idea/ -artifacts/ \ No newline at end of file +artifacts/ +/Confuser.Protections/runtime +/Confuser.Protections/runtime diff --git a/Confuser.Core/Confuser.Core.csproj b/Confuser.Core/Confuser.Core.csproj index 2a99c6b54..2e7042530 100644 --- a/Confuser.Core/Confuser.Core.csproj +++ b/Confuser.Core/Confuser.Core.csproj @@ -13,7 +13,7 @@ - + diff --git a/Confuser.Protections/Confuser.Protections.csproj b/Confuser.Protections/Confuser.Protections.csproj index 17787687c..4a2625df8 100644 --- a/Confuser.Protections/Confuser.Protections.csproj +++ b/Confuser.Protections/Confuser.Protections.csproj @@ -13,7 +13,7 @@ - + diff --git a/Confuser.Renamer/Confuser.Renamer.csproj b/Confuser.Renamer/Confuser.Renamer.csproj index dcfa68970..417ecb18e 100644 --- a/Confuser.Renamer/Confuser.Renamer.csproj +++ b/Confuser.Renamer/Confuser.Renamer.csproj @@ -17,9 +17,8 @@ - + - diff --git a/Confuser2.slnx b/Confuser2.slnx index 0628fb98c..c3ee62254 100644 --- a/Confuser2.slnx +++ b/Confuser2.slnx @@ -85,7 +85,6 @@ - diff --git a/ConfuserEx.Common.props b/ConfuserEx.Common.props index b0802a2f2..4c1bc948c 100644 --- a/ConfuserEx.Common.props +++ b/ConfuserEx.Common.props @@ -9,7 +9,7 @@ <_CurrentYear>$([System.DateTime]::Now.ToString(yyyy)) Ki;Martin Karing;Andrii Kurdiumov Copyright © 2014 Ki, 2018 - 2022 Martin Karing, 2016 - $(_CurrentYear) Andrii Kurdiumov - https://github.com/mkaring/ConfuserEx.git + https://github.com/kant2002/ConfuserEx.git git @@ -26,4 +26,4 @@ false - \ No newline at end of file + diff --git a/ConfuserEx.Common.targets b/ConfuserEx.Common.targets index df1c5a3d6..f6553b0c7 100644 --- a/ConfuserEx.Common.targets +++ b/ConfuserEx.Common.targets @@ -1,7 +1,7 @@ - +