ConfuserEx icon indicating copy to clipboard operation
ConfuserEx copied to clipboard

ConfuserEx.CLI cannot use a path with spaces in -out parameter

Open LamerTex opened this issue 7 years ago • 3 comments

Hi I'm trying to use ConfuserEX.CLI in VisualStudio via a PostBuild Event to confuse the output files of the project. This is the script I'm using: If $(ConfigurationName) == Release+Obfuscated ( $(ProjectDir)..\..\ConfuserEx_bin\Confuser.CLI.exe -n -out=$(TargetDir) $(TargetPath) )

And it is working fine normally. The problems begin when the paths contains some spaces, to use them I need to add " " so the script become:

If $(ConfigurationName) == Release+Obfuscated ( "$(ProjectDir)..\..\ConfuserEx_bin\Confuser.CLI.exe" -n -out="$(TargetDir)" "$(TargetPath)" )

In this way the first and third parameters work again (both the Confuser.CLI.exe and the input module "$(TargetPath)" are found), but the second one, the one that specify the output folder, give the following error:

[ERROR] Unknown error occurred. Exception: System.ArgumentException: Characters not valid in the path. in System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional) in System.IO.Path.Combine(String path1, String path2) in Confuser.Core.ConfuserEngine.RunInternal(ConfuserParameters parameters, CancellationToken token) in C:\Users\MatteoTex\Downloads\ConfuserEx-Reborn-master\Confuser.Core\ConfuserEngine.cs:row 92

So I can't use ConfuserEx when the projects has some spaces in its path... I'm doing something wrong or it is a problem with the control for the -out parameter?

Thanks for the attention, Matteo Tessarotto.

LamerTex avatar Jan 18 '18 16:01 LamerTex

I had a similar problem with encasing the output directory with quotes, I was able to work around the issue by ensuring there is no trailing backslash in the output directory. It seems the NDesk.Options class that parses the command line escapes that quote if the backslash is there and then fails to correctly parse the rest of the line.

jhedlund avatar Jun 01 '18 15:06 jhedlund

I also had the same issue. When I look in to the details, I found that if path have spaces, it will be taken as two parameters inside any console application. So if you have spaces in your path, you cannot directly pass that into Confuser.CLI.exe. Instead you can use a .crproj file template with PowerShell script or a custom console app.

PowerShell Script.zip

Usage for ps script

if $(ConfigurationName) == Release (PowerShell.exe -ExecutionPolicy Bypass -File "D:\Developments\Software Tools\ConfuserEx\ConfuserEx.ps1" "'$(ProjectDir)'" "'$(TargetFileName)'" "'$(TargetExt)'")

Console App.zip Usage

if $(ConfigurationName) == Release (D:\Developments\SoftwareTools\ConfuserExAddon\ConfuserExPlugin.exe "'$(TargetDir)'" "'$(TargetFileName)'")

Hope this help you for obfuscating the application during build.

ghost avatar Jul 07 '18 08:07 ghost

For any potential future debuggers:

Another approach to resolve this is to simply add a space after the macro, which prevents the trailing backslash from escaping the quote as mentioned by @jhedlund.

It's not pretty, but it's certainly the easiest solution that doesn't involve restructuring your build process.

SteffanDonal avatar Sep 27 '18 08:09 SteffanDonal