Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ConfuserEx?

Tags:

obfuscation

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.

like image 641
andrewfam Avatar asked Jun 11 '14 04:06

andrewfam


2 Answers

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!
like image 55
Naster Avatar answered Nov 19 '22 09:11

Naster


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.

like image 5
cat_in_hat Avatar answered Nov 19 '22 08:11

cat_in_hat