Package ghidra.util
Class NamingUtilities
java.lang.Object
ghidra.util.NamingUtilities
NamingUtilities is a static utility class with methods for validating project file
names or constrained file path elements.-
Field Summary
Fields -
Method Summary
ChangeModifier and TypeMethodDescriptionstatic voidCheck the specified project or file path element name for character restrictions.static voidcheckProjectName(String name) Check the specified project name for character restrictions.static StringPerforms the inverse of the mangle method.static StringfindInvalidChar(String name) Identify an invalid/unsupported character which may be present in the specific name.static booleanisValidMangledName(String name) Performs a validity check on a mangled namestatic booleanisValidProjectName(String name) Tests whether the given string is a valid project name.static StringReturns 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.
-
Field Details
-
VALID_NAME_CHARSET
-
-
Method Details
-
isValidProjectName
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: '.', '-', '=', '@', ' ', '_', '(', ')', '[', ']', '~'
- Parameters:
name- name to validate- Returns:
- true if specified name is valid, else false
-
checkProjectName
Check the specified project name for character restrictions.- Parameters:
name- project name- Throws:
IllegalArgumentException- if name restrictions are violated
-
checkName
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
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
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
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
Performs a validity check on a mangled name- Parameters:
name- mangled name- Returns:
- true if name can be demangled else false
-