35

I'd like to have a try on this program but I couldn't figure out how to use it.

I've search on the author's site https://github.com/yck1509/ConfuserEx but the example on this site is not clear enough for someone new to the programming like me.

So I post my question in here in hope that someone would show me how to use it in plain English and along with some examples. It would be so great and appreciated very much.

andrewfam
  • 447
  • 2
  • 5
  • 8
  • 3
    As far as I see, you create a `.crproj` file in the directory where your compiled executable is located (see `ProjectFormat.md` or one of the examples in `additional/`) and then simply call ConfuserEX from the command line. – Appleshell Jun 11 '14 at 04:18

4 Answers4

67

Get the lastest binaries version from here : https://github.com/mkaring/ConfuserEx/releases

For use in command line (Confuser.CLI.exe) :

Confuser.CLI.exe  myProjectFile.crproj

Project file example :

<?xml version="1.0" encoding="utf-8"?>
<project baseDir="c:\" outputDir="c:\Confused" xmlns="http://confuser.codeplex.com">
    <rule preset="none" pattern="true">
        <protection id="anti debug" />
        <protection id="anti dump" />
        <protection id="anti ildasm" />
        <protection id="anti tamper" />
        <protection id="constants" />
        <protection id="ctrl flow" />
        <protection id="invalid metadata" />
        <protection id="ref proxy" />
        <protection id="rename" />
        <protection id="resources" />
    </rule>
    <module path="ICSharpCode.AvalonEdit.dll" />
    <module path="ICSharpCode.Decompiler.dll" />
    <module path="ICSharpCode.NRefactory.dll" />
    <module path="ICSharpCode.NRefactory.CSharp.dll" />
    <module path="ICSharpCode.NRefactory.VB.dll" />
    <module path="ICSharpCode.TreeView.dll" />
    <module path="ILSpy.BamlDecompiler.Plugin.dll" />
    <module path="ILSpy.exe" />
    <module path="ILSpy.SharpDevelop.LGPL.dll" />
    <module path="Mono.Cecil.dll" />
    <module path="Mono.Cecil.Pdb.dll" />
</project>

cmd line

Config file format : https://github.com/yck1509/ConfuserEx/blob/master/docs/ProjectFormat.md

For use with the GUI (ConfuserEx.exe) :

gui

  1. In the Project tab
    1. Choose a base directory
    2. Click on the + button to add DLLs (modules)
  2. In the Settings tab
    1. Click on < Global settings >
    2. Click on the + button. A new rule is added. When the pattern matches, the rule is executed, so "True" mean the rule will always be executed.
    3. Click on Edit button.
    4. Choose the preset "Maximum" then close
  3. In the Protect tab
    1. Click Protect!
TePi
  • 37
  • 6
Adam Paquette
  • 1,243
  • 1
  • 14
  • 28
  • 9
    Until I read this post, I could not realize I had to add a rule. After I added the rule, it nicely Confused the source. – Gabrielius Nov 10 '14 at 16:05
  • 1
    Thanks for this helpful info. In the xml you gave shouldn't the preset be set to "maximum" instead of "none", preset="maximum"? – HCJ Mar 21 '16 at 11:05
  • 1
    Size of the confused file should be greater than the size of the original file ?? – Trilok Pathak Mar 21 '16 at 13:41
  • 2
    When using a preset, you don't have to specify the protections to use in the rule node. Using maximum would be : . The size can be lower. – Adam Paquette Mar 21 '16 at 20:43
  • 1
    I was confused? how do I use `ConfuserEx` ;) – Mohammed Sufian Apr 05 '16 at 19:04
  • After doing obfuscation with ConfuserEx, I am not bale to run that web application. it throws an error – Nisarg Shah May 16 '16 at 09:36
  • project web page is https://yck1509.github.io/ConfuserEx/ and but you do need to download also https://github.com/yck1509/dnlib and move all the files to the dnlib folder; then you can Build the project in VS.net – Roger Deep May 05 '17 at 20:37
  • How to add plugins like KoiVM.Confuser? How to use it, afaik it adds more protection – newbieguy Aug 09 '17 at 22:17
5

This answer cover the cases when you have a solution with (A) multiple projects that may reference each other, and (B) you're looking to automate obfuscation in a Visual Studio Setup project.

1) Add on each of your projects a Confuser.crproj text file, in the project's folder directly. In this folder you should see inside the "bin", "ob", "resources", etc. folders. There is no need to attach these files to your solution in visual studio. The text file should look like this:

<?xml version="1.0" encoding="utf-8"?>
<project baseDir="obj\Release" outputDir="..\Release" xmlns="http://confuser.codeplex.com">
    <rule preset="none" pattern="true">
        <protection id="anti debug" />
        <protection id="anti dump" />
        <protection id="anti ildasm" />
        <protection id="anti tamper" />
        <protection id="constants" />
        <protection id="ctrl flow" />
        <protection id="invalid metadata" />
        <protection id="ref proxy" />
        <protection id="resources" />
    </rule>
    <module path="MyLibrary.dll" />
    <probePath>..\..\bin\Release</probePath>
</project>

Replace MyLibrary.dll for the output of your project. (And replace .dll for .exe if it's an executable.)

ConfuserEX chooses different starting points for relative paths so that's why the paths look weird in the file.

The key element of this step is to obfuscate the "obj" output of each of your projects. This is to help your Windows Setup project to pick up the obfuscated versions.

2) In the post-build event of each of your projects, add a post-build event like the following:

if "$(ConfigurationName)" == "Release" $(SolutionDir)..\ConfuserEX\Confuser.CLI.exe $(ProjectDir)Confuser.crproj

The first condition is to obfuscate only when building in Release. Here you will need to adjust the paths to match the path of your Confuser.CLI.exe. I have my ConfuserEX folder alongside the solution's root folder.

3) In your Setup project, the issue we need to address is to make sure that packaging picks up your obfuscated versions. Setup has some obscure logic to decide from which folder each assembly is picked up. We will force it to pick up the right ones. For this, you have to:

(3a) add all your projects as "Project Output", this makes sure the obfuscated files in your "obj" folders make it to the package.

(3b) check the "detected dependencies" section of your Setup project. Whenever you see a dependency that is generated by one of your projects, go to its Properties and mark it as Exclude=True. This makes sure your obfuscated versions in the package aren't replaced by non-obfuscated versions due to the inference process.

cat_in_hat
  • 635
  • 9
  • 15
  • Update: I ended up throwing away Visual Studio Setup projects and using Wix instead, like everyone on StackOverflow says you should do. Then it becomes much more easier to obfuscate and sign assemblies. – cat_in_hat Jun 04 '18 at 13:51
2

For anyone else struggling with problems: I downloaded it and the master is missing the dnlib. You can separately download the dnlib copy it into the dnlib folder and then would compile.

That should work for most, however for me against my exe it gave a "improper dos format" error on any exe. Thought maybe since I had updated to vs2015 and 4.5.3 (.net 5 or 6 or whatever they want to call it now). I figured maybe that was it. but it wasn't (Highest compile was 4.5).

Looking on google my assumption was it couldn't update the files so spent 1 hour + converting the tuples from your class to .net 4 tuples. and updating all the projects to 4.5.

If you can, you guys need to check your github fork and hit download then then compile.. it should compile from the site and does not. I am sure this is a great product. Just a bit rough since it isn't made for Juniors to use. Maybe you could just have a link to an EXE? That may help so people aren't dealing with the compile issues.

Btw really good stuff, looks like this does a lot of stuff even the paid ones don't just a bit of a curve on learning.

Another note it looks like you have a RuntimeEnvironment.GetSystemVersion()[1] == 4 in there it should probably be (with some parsing) RuntimeEnvironment.GetSystemVersion()[1] > 3.9 so you get 4 and 4.5

**update. Updated to 4.5 and drag and drop stopped working, still works as you described above. was going with 4.5.3 but you aren't using any of the new functionality.

What I ended up with, I will edit later to state if it's working. https://onedrive.live.com/redir?resid=88D92E4D40C0593C%21105

Going with above.

Graviton
  • 81,782
  • 146
  • 424
  • 602
Mark Rowe
  • 919
  • 9
  • 7
  • 1
    the project is using git submodules. To obtain dnlib do `git submodule init` and then `git submodule update` – codingdave Nov 03 '16 at 09:02
1

For me, this method works the best:

define a crproj:

<?xml version="1.0" encoding="utf-8"?>
<project baseDir="c:\program files\confuserex" outputDir="c:\program files\confuserex\Confused" xmlns="http://confuser.codeplex.com">
    <rule preset="none" pattern="true">
        <protection id="anti debug" />
        <protection id="anti dump" />
        <protection id="anti ildasm" />
        <protection id="anti tamper" />
        <protection id="constants" />
        <protection id="ctrl flow" />
        <protection id="invalid metadata" />
        <protection id="ref proxy" />
        <protection id="rename" />
        <protection id="resources" />
    </rule>
    <module path="C:\Temp\dlhsoft\DlhSoft.HierarchicalData.LightWPF.Controls.dll" />
    <module path="C:\Temp\dlhsoft\DlhSoft.ProjectData.GanttChart.LightWPF.Controls.dll" />
    <module path="C:\Temp\dlhsoft\DlhSoft.ProjectData.PertChart.LightWPF.Controls.dll" />
</project>

and call this file from the commandline using this:

"c:\program files\confuserex\confuserex.exe" "c:\program files\confuserex\myprojectfile.crproj"
real_yggdrasil
  • 1,213
  • 4
  • 14
  • 27