1

I have a Problem with the ConfuserEx CLI tool. I want to start the CLI from a C# Programm like that:

System.Diagnostics.Process p = new System.Diagnostics.Process();

//p.StartInfo.RedirectStandardOutput = true;
//p.StartInfo.UseShellExecute = false;
//p.StartInfo.CreateNoWindow = true;

p.StartInfo.FileName = strConfuserExFilePath;
p.StartInfo.Arguments = strConfuserExProjectFilePath;

p.Start();

strConfuserExFilePath = D:\Examples .Net\Diagramm\TEST\Haupt-Projekt\packages\ConfuserEx.Final.1.0.0\tools\Confuser.CLI.exe

strConfuserExProjectFilePath = D:\Examples .Net\Diagramm\TEST\Haupt-Projekt\TEST\bin\x86\Debug\ConfuserEx.crproj

My .crproj File looks like this:

<project outputDir="D:\Examples .Net\Diagramm\TEST\Haupt-Projekt\TEST\bin\x86\Debug\Confused" baseDir="D:\Examples .Net\Diagramm\TEST\Haupt-Projekt\TEST\bin\x86\Debug" debug="false" xmlns="http://confuser.codeplex.com">
  <rule pattern="true" preset="normal" inherit="false">
    <protection id="anti ildasm" action="add" />
    <protection id="anti tamper" action="add" />
    <protection id="constants" action="add" />
    <protection id="ctrl flow" action="add" />
    <protection id="anti dump" action="add" />
    <protection id="anti debug" action="add" />
    <protection id="invalid metadata" action="remove" />
    <protection id="ref proxy" action="remove" />
    <protection id="resources" action="remove" />
    <protection id="rename" />
  </rule>
  <module path="h01_SonstVerwaltung.dll" />
</project>

When I ran that Code the CommandBox disappered so quickly that I couldn't read the Error. So I tought I would start the CLI via CommandLine to see what happens. When I do the following:

D:\Examples .Net\Diagramm\TEST\Haupt.Projekt\packages\ConfuserEx.Final.1.0.0\tools>Confuser.CLI.exe D:\Examples .Net\Diagramm\TEST\Haupt-Projekt\TEST\bin\x86\Debug\ConfuserEx.crproj

I get the Error

Confuser.Ex.CLI: No output directory specified

The strange thing is If I run the same Code but in PowerShell it works:

function ObfuscateProjectAssembly
{
    [CmdletBinding()]
    param()    

    Utility_AssertValid_FilePath $ConfuserExFilePath
    Utility_AssertValid_FilePath $ConfuserExProjectFilePath

    if( Test-Path -Path $ObfuscatedAssemblyFilePath ) {
        Remove-Item -Path $ObfuscatedAssemblyFilePath
    }


    & $ConfuserExFilePath -nopause $ConfuserExProjectFilePath

    Utility_AssertValid_FilePath $ObfuscatedAssemblyFilePath    
}

Why does it work with PowerShell but not with C#. And I have already tried adding the -n|-noPause Parameter in my C# Code.

EDIT I have tried executing PowerShell from my C#-Code but still with the same error Message.

using (PowerShell PowerShellInstance = PowerShell.Create())
{
    PowerShellInstance.AddScript("& (\"" + strConfuserExFilePath + "\") -nopause " + strConfuserExFilePath);
    Collection<PSObject> PSOutput = PowerShellInstance.Invoke();

    if (PowerShellInstance.Streams.Error.Count > 0)
    {
        foreach(ErrorRecord er in PowerShellInstance.Streams.Error)
        {

        }
    }

    foreach (PSObject outputItem in PSOutput)
    {
        if (outputItem != null)
        {
            //System.Diagnostics.Debug.WriteLine(outputItem.BaseObject.GetType().FullName);
            System.Diagnostics.Debug.Write(outputItem.BaseObject.ToString() + "\n");
        }
    }
}
BluePalmTree
  • 299
  • 3
  • 23

1 Answers1

1

So I have found my Problem, it was quite simple. I forgot the " around the .crproj file.

Here the correct ways: Number 1 via Proces:

p.StartInfo.Arguments = "-nopause \"" + strConfuserExProjectFilePath + "\"";

Number 2 via PowerShell:

PowerShellInstance.AddScript("& \"" + strConfuserExFilePath + "\" -nopause \"" + strConfuserExProjectFilePath + "\"");

BluePalmTree
  • 299
  • 3
  • 23