ConfuserEx icon indicating copy to clipboard operation
ConfuserEx copied to clipboard

Obfuscate - Class Library (Universal Windows)

Open kubakista opened this issue 6 years ago • 2 comments

Hello,

I develop C#/XAML library for UWP apps. In Visual Studio 2017 it is known as "Class Library (Universal Windows)".

If I set min version of the SDK to 15063 or lower, obfuscating works. However, I need to use at least 16299 and it causes problems. The difference between 15063 and 16299 is support of .NET Standard which is available from 16299. https://devblogs.microsoft.com/dotnet/announcing-uwp-support-for-net-standard-2-0/

Config <?xml version="1.0" encoding="utf-8"?> <project baseDir="." outputDir="Confused" xmlns="http://confuser.codeplex.com"> <rule preset="none" pattern="true"> <protection id="anti ildasm" /> <protection id="ctrl flow" /> </rule> <module path="ClassLibrary1.dll" /> </project>

Result info: core[0] Discovered 13 protections, 1 packers. info: core[0] Confuser.Core 2.0.0-alpha.232+b2780c3b3d Copyright c 2018 - 2019 Martin Karing info: core[0] Running on Microsoft Windows NT 6.2.9200.0, .NET Framework v4.0.30319.42000, 64 bits info: core[0] Loading input modules... info: core[0] Loading 'ClassLibrary1.dll'... info: core[0] Resolving dependencies... crit: core[0] Failed to resolve a type, check if all dependencies are present in the correct version. dnlib.DotNet.TypeResolveException: Could not resolve type: System.Threading.Tasks.Task (System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a) at dnlib.DotNet.TypeRef.ResolveThrow(ModuleDef sourceModule) at dnlib.DotNet.Extensions.ResolveTypeDefThrow(ITypeDefOrRef tdr) at Confuser.Renamer.Analyzers.InterReferenceAnalyzer.Analyze(IConfuserContext context, INameService service, IProtectionParameters parameters, IDnlibDef def) in C:\projects\confuserex\Confuser.Renamer\Analyzers\InterReferenceAnalyzer.cs:line 39 at Confuser.Renamer.AnalyzePhase.Analyze(NameService service, IConfuserContext context, IProtectionPara

It complains about missing System.Runtime. I checked which .dll is used in the project and it is the following one: #region Assembly System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a // C:\Users\jakub\.nuget\packages\microsoft.netcore.universalwindowsplatform\6.2.9\ref\uap10.0.15138\System.Runtime.dll #endregion

I copied the .dll into the folder with the executable file and ran it again.

info: core[0] Discovered 13 protections, 1 packers. info: core[0] Confuser.Core 2.0.0-alpha.232+b2780c3b3d Copyright c 2018 - 2019 Martin Karing info: core[0] Running on Microsoft Windows NT 6.2.9200.0, .NET Framework v4.0.30319.42000, 64 bits info: core[0] Loading input modules... info: core[0] Loading 'ClassLibrary1.dll'... info: core[0] Resolving dependencies... crit: core[0] Failed to resolve a type, check if all dependencies are present in the correct version. dnlib.DotNet.TypeResolveException: Could not resolve type: System.Threading.Tasks.Task (System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a) at dnlib.DotNet.TypeRef.ResolveThrow(ModuleDef sourceModule) at dnlib.DotNet.Extensions.ResolveTypeDefThrow(ITypeDefOrRef tdr) at Confuser.Renamer.Analyzers.InterReferenceAnalyzer.Analyze(IConfuserContext context, INameService service, IProtectionParameters parameters, IDnlibDef def) in C:\projects\confuserex\Confuser.Renamer\Analyzers\InterReferenceAnalyzer.cs:line 39 at Confuser.Renamer.AnalyzePhase.Analyze(NameService service, IConfuserContext context, IProtectionParameters parameters, IDnlibDef def, Boolean runAnalyzer) in C:\projects\confuserex\Confuser.Renamer\AnalyzePhase.cs:line 153 at Confuser.Renamer.AnalyzePhase.Confuser.Core.IProtectionPhase.Execute(IConfuserContext context, IProtectionParameters parameter

I checked details of the System.Runtime.dll file and it actually shows different version, which is weird. image

I am not sure what to do right now. Was anybody successful with protecting UWP lib targeting min 16299?

Best Regards, Jakub

kubakista avatar Sep 04 '19 10:09 kubakista

Confuser isn't resolving to local assemblies, in case it finds a matching one in the GAC, unless you REALLY force it to. Please add the assemblies from the universal windows to the the *.crproj file like so:

<module path="C:\Users\jakub\.nuget\packages\microsoft.netcore.universalwindowsplatform\6.2.9\ref\uap10.0.15138\System.Runtime.dll" external="true" />

This will force ConfuserEx to load that assemblies from this specific location. As of right now this is the only way to get .NET Core obfuscation working properly. You can also use relative paths in case you copied the files into the same directory.

mkaring avatar Sep 05 '19 21:09 mkaring

Unfortunately it did not help, still the same error.

kubakista avatar Sep 06 '19 06:09 kubakista