Package ghidra.util

Class SystemUtilities

java.lang.Object
ghidra.util.SystemUtilities

public class SystemUtilities extends Object
General purpose class to provide convenience methods for doing "System" type stuff, e.g., find resources, date/time, etc. All methods in this class are static.
  • Field Details

    • FONT_SIZE_OVERRIDE_PROPERTY_NAME

      public static final String FONT_SIZE_OVERRIDE_PROPERTY_NAME
      System property that signals to override the font settings for Java and Ghidra components.
      See Also:
    • TESTING_PROPERTY

      public static final String TESTING_PROPERTY
      The system property that can be checked during testing to determine if the system is running in test mode.
      See Also:
    • TESTING_BATCH_PROPERTY

      public static final String TESTING_BATCH_PROPERTY
      The system property that can be checked during testing to determine if the system is running in batch, automated test mode.
      See Also:
    • HEADLESS_PROPERTY

      public static final String HEADLESS_PROPERTY
      The system property that can be checked during runtime to determine if we are running with a GUI or headless.
      See Also:
    • SINGLE_JAR_MODE_PROPERTY

      public static final String SINGLE_JAR_MODE_PROPERTY
      The system property that can be checked during runtime to determine if we are running in single-jar mode.
      See Also:
  • Constructor Details

    • SystemUtilities

      public SystemUtilities()
  • Method Details

    • getCleanUserName

      public static String getCleanUserName(String name)
      Clean the specified user name to eliminate any spaces or leading domain name which may be present (e.g., "MyDomain\John Doe" becomes "JohnDoe").
      Parameters:
      name - user name string to be cleaned-up
      Returns:
      the clean user name
    • getUserName

      public static String getUserName()
      Get the user that is running the application. This name may be modified to eliminate any spaces or leading domain name which may be present in Java's user.name system property (see getCleanUserName(String)).
      Returns:
      the user name
    • getBooleanProperty

      public static boolean getBooleanProperty(String name, boolean defaultValue)
      Gets the boolean value of the system property by the given name. If the property is not set, the defaultValue is returned. If the value is set, then it will be passed into Boolean.parseBoolean(String).
      Parameters:
      name - the property name to check
      defaultValue - the default value
      Returns:
      true if the property is set and has a value of 'true', ignoring case
    • getFontSizeOverrideValue

      public static Integer getFontSizeOverrideValue()
      Returns a non-null value if the system property is set that triggers the font override setting, which makes all Java and Ghidra component fonts the same size.
      Returns:
      a non-null value if the system property is set that triggers the font override setting, which makes all Java and Ghidra component fonts the same size.
      See Also:
    • adjustForFontSizeOverride

      @Deprecated(since="11.1", forRemoval=true) public static Font adjustForFontSizeOverride(Font font)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use the theming system for fonts
      No longer supported. Use the theming system for fonts
      Parameters:
      font - the font
      Returns:
      the same font passed in
    • isInTestingMode

      public static boolean isInTestingMode()
      Returns true if the system is running during a test.
      Returns:
      true if the system is running during a test.
    • isInTestingBatchMode

      public static boolean isInTestingBatchMode()
      Returns true if the system is running during a batch, automated test.
      Returns:
      true if the system is running during a batch, automated test.
    • isInHeadlessMode

      public static boolean isInHeadlessMode()
      Returns true if the system is running without a GUI.
      Returns:
      true if the system is running without a GUI.
    • runSwingNow

      public static <T> T runSwingNow(Supplier<T> s)
      Calls the given suppler on the Swing thread, blocking with a SwingUtilities.invokeAndWait(Runnable). Use this method when you need to get a value while being on the Swing thread.
       		String value = runSwingNow(() -> label.getText());
       
      Parameters:
      s - the supplier that will be called on the Swing thread
      Returns:
      the result of the supplier
      See Also:
    • runSwingNow

      public static void runSwingNow(Runnable r)
      Calls the given runnable on the Swing thread.
      Parameters:
      r - the runnable
      See Also:
    • runSwingLater

      public static void runSwingLater(Runnable r)
      Calls the given runnable on the Swing thread in the future by putting the request on the back of the event queue.
      Parameters:
      r - the runnable
    • runIfSwingOrPostSwingLater

      public static void runIfSwingOrPostSwingLater(Runnable r)
    • isInDevelopmentMode

      public static boolean isInDevelopmentMode()
      Returns true if we are running in development mode. The assumption is that if this class is in a jar file, then we are in production mode.
      Returns:
      true if we are running in development mode
    • isInReleaseMode

      public static boolean isInReleaseMode()
      Returns true if the application is a release and not in development or testing
      Returns:
      true if the application is a release and not in development or testing
    • isEqual

      public static boolean isEqual(Object o1, Object o2)
      Returns whether or not the two indicated objects are equal. It allows either or both of the specified objects to be null.
      Parameters:
      o1 - the first object or null
      o2 - the second object or null
      Returns:
      true if the objects are equal.
    • compareTo

      public static <T extends Comparable<T>> int compareTo(T c1, T c2)
    • isArrayEqual

      public static boolean isArrayEqual(Object[] array1, Object[] array2)
    • assertTrue

      public static void assertTrue(boolean booleanValue, String string)
    • assertThisIsTheSwingThread

      public static void assertThisIsTheSwingThread(String errorMessage)
      A development/testing time method to make sure the current thread is the swing thread.
      Parameters:
      errorMessage - The message to display when the assert fails
    • getSourceLocationForClass

      public static File getSourceLocationForClass(Class<?> classObject)
      Returns a file that contains the given class. If the class is in a jar file, then the jar file will be returned. If the file is in a .class file, then the directory containing the package root will be returned (i.e. the "bin" directory).
      Parameters:
      classObject - the class for which to get the location
      Returns:
      the containing location
    • isEventDispatchThread

      public static boolean isEventDispatchThread()
      Returns true if this is the event dispatch thread. Note that this method returns true in headless mode because any thread in headless mode can dispatch its own events. In swing environments, the swing thread is usually used to dispatch events.
      Returns:
      true if this is the event dispatch thread -OR- is in headless mode.
    • printString

      public static boolean printString(String string, PrintStream printStream)
      A debugging utility that allows you to create a conditional breakpoint in Eclipse that will print items for you while it is performing its tests. This method always returns false. This means to use it you will have to OR (||) your conditional breakpoint expressions if you want them to pass. Otherwise, you can make this method be the only breakpoint expression and it will never stop on the breakpoint, but will still print your debug.

      This method is useful to print values of code that you cannot edit while debugging.

      Example, inside of your conditional breakpoint for a method on a Sun Java file you can put something like: printString("Value of first arg: " + arg0, System.err)

      Note: Don't remove this method simply because no code is referencing it, as it is used by conditional breakpoints.

      Parameters:
      string - The string to print
      printStream - The stream to print to (System.our or err)
      Returns:
      The string passed in so that you can use this method in an evaluation
    • getDefaultThreadPoolSize

      public static int getDefaultThreadPoolSize()
      Returns the default size (in number of threads) for a CPU processing bound thread pool.
      Returns:
      the default pool size.