2

Is there code I can include in my CSharp project file to check if ConfuserEx executed properly, and kill the compile process if not? Maybe use reflection to check if a class name still exists (i.e. has not been obfuscated)?

Update: This is the code in the .csproj file that calls the obfuscation routine:

<Target Name="AfterCompile">
    <Exec Command="if &quot;$(PlatformName)&quot; == &quot;AnyCPU&quot; (if &quot;$(ConfigurationName)&quot; == &quot;Release&quot; (powershell.exe  -ExecutionPolicy Bypass -File  &quot;$(ProjectDir)confuserEx\confuserps.ps1&quot; &quot;'C:\Program Files\ConfuserEx\Confuser.CLI.exe'&quot; &quot;'$(ProjectDir)confuserEx\confuser.crproj'&quot; &quot;'$(ProjectDir)obj\$(ConfigurationName)\'&quot; &quot;'$(ProjectDir)obj\$(ConfigurationName)\$(TargetFileName)'&quot; &quot;'normal'&quot; )&#xD;&#xA;) else (if &quot;$(ConfigurationName)&quot; == &quot;Release&quot; (powershell.exe  -ExecutionPolicy Bypass -File  &quot;$(ProjectDir)confuserEx\confuserps.ps1&quot; &quot;'C:\Program Files\ConfuserEx\Confuser.CLI.exe'&quot; &quot;'$(ProjectDir)confuserEx\confuser.crproj'&quot; &quot;'$(ProjectDir)obj\$(PlatformName)\$(ConfigurationName)\'&quot; &quot;'$(ProjectDir)obj\$(PlatformName)\$(ConfigurationName)\$(TargetFileName)'&quot; &quot;'normal'&quot; )&#xD;&#xA;)" />
  </Target>
dashnick
  • 2,020
  • 19
  • 34
  • Running a pre- or post-build task is one way to do it, which one depends on when the obfuscation takes place. – stuartd Aug 02 '17 at 13:50

1 Answers1

0

You can write your own utility to verify whether obfuscation executes successfully, via libraries such as Cecil, or simply use existing tools, such as Red-Gate Obfuscation Checker.

Lex Li
  • 60,503
  • 9
  • 116
  • 147
  • Is there a way to script Cecil in the project file to check if a class exists? – dashnick Aug 02 '17 at 15:47
  • Also, does Red-Gate Obfuscation checker work for other obfuscators besides its own? – dashnick Aug 02 '17 at 15:50
  • 1
    @dashnick To the first question, within your project file, you can [define a build task with inline C#](https://learn.microsoft.com/en-us/visualstudio/msbuild/walkthrough-creating-an-inline-task) that uses Mono.Cecil and outputs whether obfuscation was detected. Then, within the `AfterCompile` target, you can call the task and then run the Error task if your task said obfuscation was not present. – Joe Sewell Aug 02 '17 at 18:35
  • Awesome, did not know about inline tasks. I think that should work! I'll post my solution here if I figure it out. – dashnick Aug 02 '17 at 18:38
  • Oh, though there may be an issue [if you're using Mono.Cecil, a non-Microsoft assembly, for inline tasks](https://stackoverflow.com/questions/9455354/msbuild-inline-task-reference-non-standard-microsoft-assemblies). I would still try it and see if it works, but otherwise you might have to just use Base Class Library types. – Joe Sewell Aug 02 '17 at 19:02