Package ghidra.util

Class SystemUtilities


  • public class SystemUtilities
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String FONT_SIZE_OVERRIDE_PROPERTY_NAME
      System property that signals to override the font settings for Java and Ghidra components.
      static java.lang.String HEADLESS_PROPERTY
      The system property that can be checked during runtime to determine if we are running with a GUI or headless.
      static java.lang.String SINGLE_JAR_MODE_PROPERTY
      The system property that can be checked during runtime to determine if we are running in single-jar mode.
      static java.lang.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.
      static java.lang.String TESTING_PROPERTY
      The system property that can be checked during testing to determine if the system is running in test mode.
    • Constructor Summary

      Constructors 
      Constructor Description
      SystemUtilities()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.awt.Font adjustForFontSizeOverride​(java.awt.Font font)
      Checks to see if the font size override setting is enabled and adjusts the given font as necessary to match the override setting.
      static void assertThisIsTheSwingThread​(java.lang.String errorMessage)
      A development/testing time method to make sure the current thread is the swing thread.
      static void assertTrue​(boolean booleanValue, java.lang.String string)  
      static <T extends java.lang.Comparable<T>>
      int
      compareTo​(T c1, T c2)  
      static java.lang.String currentTimeStamp()  
      static boolean getBooleanProperty​(java.lang.String name, boolean defaultValue)
      Gets the boolean value of the system property by the given name.
      static java.lang.String getDateTime()
      returns the current date/time using default DATE/TIME format
      static java.lang.String getDateTime​(java.lang.String dateTimeFormat)
      returns the current date/time using specified DATE/TIME format
      static int getDefaultThreadPoolSize()
      Returns the default size (in number of threads) for a CPU processing bound thread pool.
      static java.lang.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.
      static java.io.File getSourceLocationForClass​(java.lang.Class<?> classObject)
      Returns a file that contains the given class.
      static java.lang.String getUserName()
      Get the user that is running the ghidra application
      static boolean isArrayEqual​(java.lang.Object[] array1, java.lang.Object[] array2)  
      static boolean isEqual​(java.lang.Object o1, java.lang.Object o2)
      Returns whether or not the two indicated objects are equal.
      static boolean isEventDispatchThread()
      Returns true if this is the event dispatch thread.
      static boolean isInDevelopmentMode()
      Returns true if we are running in development mode.
      static boolean isInHeadlessMode()
      Returns true if the system is running without a GUI.
      static boolean isInReleaseMode()
      Returns true if the application is a release and not in development or testing
      static boolean isInTestingBatchMode()
      Returns true if the system is running during a batch, automated test.
      static boolean isInTestingMode()
      Returns true if the system is running during a test.
      static boolean printString​(java.lang.String string, java.io.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.
      static void runIfSwingOrPostSwingLater​(java.lang.Runnable r)  
      static void runSwingLater​(java.lang.Runnable r)
      Calls the given runnable on the Swing thread in the future by putting the request on the back of the event queue.
      static void runSwingNow​(java.lang.Runnable r)
      Calls the given runnable on the Swing thread.
      static <T> T runSwingNow​(java.util.function.Supplier<T> s)
      Calls the given suppler on the Swing thread, blocking with a SwingUtilities.invokeAndWait(Runnable).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • FONT_SIZE_OVERRIDE_PROPERTY_NAME

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

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

        public static final java.lang.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:
        Constant Field Values
      • HEADLESS_PROPERTY

        public static final java.lang.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:
        Constant Field Values
      • SINGLE_JAR_MODE_PROPERTY

        public static final java.lang.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:
        Constant Field Values
    • Constructor Detail

      • SystemUtilities

        public SystemUtilities()
    • Method Detail

      • getUserName

        public static java.lang.String getUserName()
        Get the user that is running the ghidra application
        Returns:
        the user name
      • getBooleanProperty

        public static boolean getBooleanProperty​(java.lang.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 java.lang.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:
        FONT_SIZE_OVERRIDE_PROPERTY_NAME
      • adjustForFontSizeOverride

        public static java.awt.Font adjustForFontSizeOverride​(java.awt.Font font)
        Checks to see if the font size override setting is enabled and adjusts the given font as necessary to match the override setting. If the setting is not enabled, then font is returned.
        Parameters:
        font - The current font to adjust, if necessary.
        Returns:
        a font object with the proper size.
      • getDateTime

        public static java.lang.String getDateTime()
        returns the current date/time using default DATE/TIME format
        Returns:
        the current date/time using default DATE/TIME format
      • currentTimeStamp

        public static java.lang.String currentTimeStamp()
      • getDateTime

        public static java.lang.String getDateTime​(java.lang.String dateTimeFormat)
        returns the current date/time using specified DATE/TIME format
        Parameters:
        dateTimeFormat - the format for the time
        Returns:
        the formatted date
      • 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​(java.util.function.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(Runnable)
      • runSwingLater

        public static void runSwingLater​(java.lang.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​(java.lang.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​(java.lang.Object o1,
                                      java.lang.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 java.lang.Comparable<T>> int compareTo​(T c1,
                                                                        T c2)
      • isArrayEqual

        public static boolean isArrayEqual​(java.lang.Object[] array1,
                                           java.lang.Object[] array2)
      • assertTrue

        public static void assertTrue​(boolean booleanValue,
                                      java.lang.String string)
      • assertThisIsTheSwingThread

        public static void assertThisIsTheSwingThread​(java.lang.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 java.io.File getSourceLocationForClass​(java.lang.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​(java.lang.String string,
                                          java.io.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.