Package ghidra.util

Class NamingUtilities

java.lang.Object
ghidra.util.NamingUtilities

public final class NamingUtilities extends Object
NamingUtilities is a static utility class with methods for validating project file names or constrained file path elements.
  • Field Details

    • VALID_NAME_CHARSET NEW

      public static final Set<Character> VALID_NAME_CHARSET
  • Method Details

    • isValidProjectName

      public static boolean isValidProjectName(String name)
      Tests whether the given string is a valid project name.

      Rules:

      • Name may not be blank (i.e., no characters or all space characters)
      • Name may not start with period
      • All characters must be a letter, digit (0..9), or within the allowed character set: '.', '-', '=', '@', ' ', '_', '(', ')', '[', ']', '~'
      • isValidName REMOVED

        static boolean isValidName(String name)
      Parameters:
      name - name to validate
      Returns:
      true if specified name is valid, else false
    • checkProjectName NEW

      public static void checkProjectName(String name) throws IllegalArgumentException
      Check the specified project name for character restrictions.
      Parameters:
      name - project name
      Throws:
      IllegalArgumentException - if name restrictions are violated
    • checkName NEW

      public static void checkName(String pathElement, String elementType) throws IllegalArgumentException
      Check the specified project or file path element name for character restrictions. The specified path element must exclude any path separators and must nut include any Windows drive specification (e.g., C:). If this naming restriction needs to be imposed on an entire path, it must be invoked on each path element separately.

      Restrictions include:

      • Path element may not be blank (i.e., no characters or all space characters).
      • Path element may not start with a '.' which may result in path traversal or hidden file/folder use.
      • Path element may only contain the letters, numbers, or the following characters: '.', '-', '=', '@', ' ', '_', '(', ')', '[', ']', '~'
      Parameters:
      pathElement - project or file path element (use of leading and trailing spaces should be avoided but is not prohibited).
      elementType - descriptive name for type of path element or null for default: "Path element"
      Throws:
      IllegalArgumentException - if name restrictions are violated
    • findInvalidChar MODIFIED

      public static String findInvalidChar(String name)
      return type: char → String
      -static char findInvalidChar(java.lang.String name)
      +static java.lang.String findInvalidChar(java.lang.String name)
      Identify an invalid/unsupported character which may be present in the specific name. This method applies to project and individual path name elements only.
      Parameters:
      name - string to be scanned
      Returns:
      an invalid/unsupported character found or null. A string is used to allow for rendering of non-ASCII characters.
    • mangle

      public static String mangle(String name)
      Returns a string such that all uppercase characters in the given string are replaced by the MANGLE_CHAR followed by the lowercase version of the character. MANGLE_CHARs are replaced by 2 MANGLE_CHARs.

      This method is to get around case-insensitive filesystems since Ghidra is case-sensitive. To fix this we mangle names first such that "Foo.exe" becomes "_foo.exe".

      Parameters:
      name - name string to be mangled
      Returns:
      mangled name
    • demangle

      public static String demangle(String mangledName)
      Performs the inverse of the mangle method. A string is returned such that all characters following a MANGLE_CHAR are converted to uppercase. Two MANGLE chars in a row are replace by a single MANGLE_CHAR.
      Parameters:
      mangledName - mangled name string
      Returns:
      demangle name
    • isValidMangledName

      public static boolean isValidMangledName(String name)
      Performs a validity check on a mangled name
      Parameters:
      name - mangled name
      Returns:
      true if name can be demangled else false