mkaring / ConfuserEx

An open-source, free protector for .NET applications
https://mkaring.github.io/ConfuserEx/
MIT License
2.34k stars 365 forks source link

Some Protections don't work #244

Closed rafak360 closed 3 years ago

rafak360 commented 4 years ago

I'm using the GUI ConfuserEx.exe.

My Project is a CLR Windows Forms C++/CLI .NET Framework 4.5 Windows 10

Preset: Maximum

Protections:

typescramble throws the following exception:

[ERROR] Failed to calcuate maxstack.

anti tamper throws the following exception:

[ERROR] Unknown error occurred.
Exception: System.InvalidOperationException: Reusing old body locations is enabled. Can't remove bodies.
   at dnlib.DotNet.Writer.MethodBodyChunks.Remove(MethodBody methodBody)
   at Confuser.Protections.AntiTamper.NormalMode.CreateSections(ModuleWriterBase writer)
   at Confuser.Protections.AntiTamper.NormalMode.WriterEvent(Object sender, ModuleWriterEventArgs e)
   at dnlib.DotNet.Writer.EventHandler2`1.Invoke(Object sender, TEventArgs e)
   at dnlib.DotNet.Writer.ModuleWriterOptionsBase.RaiseEvent(Object sender, ModuleWriterEventArgs e)
   at dnlib.DotNet.Writer.ModuleWriterBase.OnWriterEvent(ModuleWriterEvent evt)
   at dnlib.DotNet.Writer.ModuleWriterBase.Metadata_MetadataEvent(Object sender, MetadataWriterEventArgs e)
   at dnlib.DotNet.Writer.Metadata.OnMetadataEvent(MetadataEvent evt)
   at dnlib.DotNet.Writer.NativeModuleWriter.Write()
   at dnlib.DotNet.Writer.NativeModuleWriter.WriteImpl()
   at dnlib.DotNet.Writer.ModuleWriterBase.Write(Stream dest)
   at Confuser.Core.ConfuserEngine.WriteModule(ConfuserContext context)
   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)

resources makes my application not able to launch.

The rest of the Protections seem to be working fine.

Is there a fix for these issues though?

mkaring commented 3 years ago

The typescramble protection is unlikely to work in a mixed-mode assembly. The resource protection got some bugfixes since the last version, maybe it works with the current snapshot.

For the anti tamper protection, I found the cause for your issue and fixed it in the #292 pull request. It would you great if you could check with this build if your issue has been resolved.

rafak360 commented 3 years ago

The typescramble protection is unlikely to work in a mixed-mode assembly. The resource protection got some bugfixes since the last version, maybe it works with the current snapshot.

For the anti tamper protection, I found the cause for your issue and fixed it in the #292 pull request. It would you great if you could check with this build if your issue has been resolved.

Thanks @mkaring that build solved the anti tamper issue in my CLR Project, however typescramble and resource still a problem.

mkaring commented 3 years ago

@rafak360: I'm looking into the issue with the resource protection. As for the typescamble: Don't get your hopes up. This isn't a protection that should be enabled for the entire assembly …

ElektroKill commented 3 years ago

I could look into the typescramble problem but I would need a small program to reproduce the error. If you are able to provide that I would be thankful!

rafak360 commented 3 years ago

I could look into the typescramble problem but I would need a small program to reproduce the error. If you are able to provide that I would be thankful!

@ElektroKill I made a simple program to expose that error in typescramble, it's just an Empty CLR Project generated by Visual Studio, here it is: Small Program

mkaring commented 3 years ago

@ElektroKill: The linked pull request, now contains two failing tests. One for the resources protection and one for the typescramble. The second is all yours.

ElektroKill commented 3 years ago

I've identified the TypeScrambler issue to be caused by improper detection of whether the method has a return type. The C++/CLI runtime contains a lot of modifier signatures over the actual return types which cause the detection to fail. I am working on a fix right now.

mkaring commented 3 years ago

@rafak360: @ElektroKill and I sorted all this out.

antitamper, typescrambler and resources are, work now for the basic unit test I created. Could you give the new build a shot with your project? You can download the new build here

rafak360 commented 3 years ago

@rafak360: @ElektroKill and I sorted all this out.

antitamper, typescrambler and resources are, work now for the basic unit test I created. Could you give the new build a shot with your project? You can download the new build here

@mkaring Tested that build and what I found out: anti tamper, typescramble and resources do work individually, but when anti tamper and resources are ON so application doesn't even launch.

mkaring commented 3 years ago

@rafak360: Good catch. The change for the anti tamper protection conflicted with the way the resources protection works. It's now changed to work properly with all other protections.

Find the new build here.

rafak360 commented 3 years ago

@rafak360: Good catch. The change for the anti tamper protection conflicted with the way the resources protection works. It's now changed to work properly with all other protections.

Find the new build here.

@mkaring Tested that build and problem solved! Good job. It's working fine with all protections ON plus Preset set to Maximum, however I noticed the following warning: [WARN] Could not find backing code for resource type 'SmallProgram.Resource', protections may not apply to that type.

That happens when a CLR project has an Assembly Resource File (.resx).

mkaring commented 3 years ago

This warning is generated, because ConfuserEx is unable to determine how the resx file is accessed. This is something that can't be changed right now, because this function relies on detecting the default access code that is generated for VB.NET and C#. Since there is no code generation in C++/CLI, this feature won't work.

Treat this warning as an information that ConfuserEx is unable to protect the resource file.

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.