Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erroneous and unused assembly referred to in XAML xmlns causes ConfuserEx to crash #536

Open
DaveInCaz opened this issue Jun 7, 2023 · 0 comments
Labels
enhancement New feature or request triage This issue needs some initial analysis.

Comments

@DaveInCaz
Copy link

DaveInCaz commented Jun 7, 2023

I had a C# DLL with a WPF XAML file that had a line like the following:

<ResourceDictionary
      ...
      xmlns:SomeNamespace="clr-namespace:SomeNamespace;assembly=Bogus"
      ...
>

The problem was that the Bogus assembly did not exist - however this xmlns was not actually used in XAML and so the file still compiled OK in Visual Studio. (If it had been in use I believe VS would have flagged an error.) Because of that, it slips through to obfuscation later on.

Apparently when ConfuserEx finds the nonsense reference to Bogus it tries to load bogus.dll which it cannot find. This leads to a crash:

[ERROR] Failed to resolve an assembly, check if all dependencies are present in the correct version.
Exception: dnlib.DotNet.AssemblyResolveException: Could not resolve assembly: Bogus
   at dnlib.DotNet.Extensions.ResolveThrow(IAssemblyResolver self, String asmFullName, ModuleDef sourceModule)
   at Confuser.Renamer.BAML.BAMLAnalyzer.PopulateReferences(BamlDocument document)
   at Confuser.Renamer.BAML.BAMLAnalyzer.Analyze(ModuleDefMD module, String bamlName, Byte[] data)
   at Confuser.Renamer.Analyzers.WPFAnalyzer.AnalyzeResources(ConfuserContext context, INameService service, ModuleDefMD module)
   at Confuser.Renamer.Analyzers.WPFAnalyzer.Analyze(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def)
   at Confuser.Renamer.AnalyzePhase.Analyze(NameService service, ConfuserContext context, ProtectionParameters parameters, IDnlibDef def, Boolean runAnalyzer)
   at Confuser.Renamer.AnalyzePhase.Execute(ConfuserContext context, ProtectionParameters parameters)
   at Confuser.Core.ProtectionPipeline.ExecuteStage(PipelineStage stage, Action`1 func, Func`1 targets, ConfuserContext context)
   at Confuser.Core.ConfuserEngine.RunPipeline(ProtectionPipeline pipeline, ConfuserContext context)
   at Confuser.Core.ConfuserEngine.RunInternal(ConfuserParameters parameters, CancellationToken token)

Although the crash itself might be considered a bug, the root problem is bad XAML. So ideally it would be nice if ConfuserEx could handle this. But if not, at least this post may be a useful debugging signpost for others.

@DaveInCaz DaveInCaz added enhancement New feature or request triage This issue needs some initial analysis. labels Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triage This issue needs some initial analysis.
Projects
None yet
Development

No branches or pull requests

1 participant