Package ghidra.pty

Enum Class ShellUtils.Shell

java.lang.Object
java.lang.Enum<ShellUtils.Shell>
ghidra.pty.ShellUtils.Shell
All Implemented Interfaces:
Serializable, Comparable<ShellUtils.Shell>, Constable
Enclosing class:
ShellUtils

public static enum ShellUtils.Shell NEW extends Enum<ShellUtils.Shell>
A target shell for command-line arguments

This determines how arguments are quoted and/or escaped. This should be set based on the shell that is going to receive the actual commands, which may or may not be the local shell. In many cases, it is the local shell, but please ensure for remote cases, the correct shell is specified.

  • Enum Constant Details

    • DISPLAY

      public static final ShellUtils.Shell DISPLAY
      For display purposes only. DO NOT pass to any actual shell.
    • UNIX_SH

      public static final ShellUtils.Shell UNIX_SH
      Unix shells that follow the same conventions as "sh". This is most Unix shells.
    • WINDOWS

      public static final ShellUtils.Shell WINDOWS
      Plain Windows command-line arguments for the C runtime
      See Also:
    • WINDOWS_CMD

      public static final ShellUtils.Shell WINDOWS_CMD
      The Windows cmd.exe shell.

      NOTE: It seems to me using this with ShellUtils.generateLine(List, Shell) is futile, if the intent is to use specific argument numbers in the batch file, e.g., %1. If you make clear certain constraints to the user, maybe it's suitable, but especially involving quotes, it's not possible to encode any arbitrary string. It seems the cmd shell is primarily concerned with just passing the arguments along to child processes, as encoded, and then the child figures out the parsing. That said, if the child process parses to argc/argv, then so long as the full command line is passed through the batch file, it should work as intended. However, if grabbing individual arguments, they cannot be reliably controlled.

      LATER: There may be a way to factor the escaping part separately from the argument catenation part, so that special logic can be applied here to better guarantee argument numbering, but then there's still the issue if the final target is expected to parse to argc/argv, if that can be encoded reliably.

  • Field Details

  • Method Details

    • values

      public static ShellUtils.Shell[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static ShellUtils.Shell valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • forOs

      public static ShellUtils.Shell forOs(OperatingSystem os)
      Get the probable shell for the given operating system
      Parameters:
      os - the operating system
      Returns:
      the shell, probably
    • generateArgument

      public abstract String generateArgument(String a)
      Escape and/or quote a single command-line argument
      Parameters:
      a - the argument
      Returns:
      the argument formed in such a way that the shell will interpret it as the given string in one argument