shunf4 / proxychains-windows

Windows and Cygwin port of proxychains, based on MinHook and DLL Injection
GNU General Public License v2.0
967 stars 117 forks source link

Error when parsing args: SearchPath() Failed. Command not found. #54

Closed Honghe closed 2 months ago

Honghe commented 2 months ago

I am confused, where does this mistake come from?

Environment:

> proxychains.exe -v conda env
[E] 2024/09/05 21:12:46 Error when parsing args: SearchPath() Failed. Command not found.
Proxychains.exe Win32 64-bit Release 0.6.8 - proxifier for Win32 and Cygwin.

Usage: C:\bin\proxychains_0.6.8_win32_x64\proxychains.exe [-q] [-Q] [-f <CUSTOM_CONFIG_FILE>] [-l <LOG_LEVEL>] <PROGRAM_NAME> <ARGUMENTS>...

 -q              Forces quiet (not printing any information except errors)
 -Q              Forces non-quiet (ignoring quiet option in configuration files)
 -f              Manually specify a configuration file.
                 By default, configuration file is searched in:
                  - %USERPROFILE%\.proxychains\proxychains.conf
                  - (Roaming directory of current user)\Proxychains\proxychains.conf
                  - (Global ProgramData directory)\Proxychains\proxychains.conf
 -l <LOG_LEVEL>  Manually set log level. <LOG_LEVEL> can be:
                  - V/VERBOSE
                  - D/DEBUG
                  - I/INFO
                  - W/WARNING
                  - E/ERROR
                  - C/CRITICAL
                 Note that some levels are always unavailable in a Release build.
Honghe commented 2 months ago

If using the absolute path of conda.exe, it works.

> proxychains.exe  C:\Users\x\miniforge3\Scripts\conda.exe env
usage: conda-script.py env [-h] command ...

positional arguments:
  command
    config    Configure a conda environment.
    create    Create an environment based on an environment definition file.
    export    Export a given environment
    list      An alias for `conda info --envs`. Lists all conda environments.
    remove    Remove an environment.
    update    Update the current environment based on environment file.

options:
  -h, --help  Show this help message and exit.

The conda is a alias of a function from Conda.psm1

> Get-Command conda

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           conda -> Invoke-Conda                              0.0        Conda

Conda.psm1:

function Invoke-Conda() {
    # Don't use any explicit args here, we'll use $args and tab completion
    # so that we can capture everything, INCLUDING short options (e.g. -n).
    if ($Args.Count -eq 0) {
        # No args, just call the underlying conda executable.
        & $Env:CONDA_EXE $Env:_CE_M $Env:_CE_CONDA;
    }
    else {
        $Command = $Args[0];
        if ($Args.Count -ge 2) {
            $OtherArgs = $Args[1..($Args.Count - 1)];
        } else {
            $OtherArgs = @();
        }
        switch ($Command) {
            "activate" {
                Enter-CondaEnvironment @OtherArgs;
            }
            "deactivate" {
                Exit-CondaEnvironment;
            }

            default {
                # There may be a command we don't know want to handle
                # differently in the shell wrapper, pass it through
                # verbatim.
                & $Env:CONDA_EXE $Env:_CE_M $Env:_CE_CONDA $Command @OtherArgs;
            }
        }
    }
}

New-Alias conda Invoke-Conda -Force
Honghe commented 2 months ago

It works fine in conda env, so it's the problem of Conda or Powershell.

(base) PS C:\Users\x> proxychains.exe conda
usage: conda-script.py [-h] [-v] [--no-plugins] [-V] COMMAND ...

conda is a tool for managing and deploying applications, environments and packages.

options:
  -h, --help          Show this help message and exit.
  -v, --verbose       Can be used multiple times. Once for detailed output, twice for INFO logging, thrice for DEBUG
                      logging, four times for TRACE logging.
  --no-plugins        Disable all plugins that are not built into conda.
  -V, --version       Show the conda version number and exit.
shunf4 commented 2 months ago

Please be aware that proxychains won't understand any shell (cmd, powershell, bash, *sh) syntax/aliases. It uses CreateProcessW to spawn child process. If a command line won't run when you type it in "Run Dialog", then it won't work with proxychains either.