Class VariableAnnotatedStringHandler

java.lang.Object
ghidra.app.util.viewer.field.VariableAnnotatedStringHandler
All Implemented Interfaces:
AnnotatedStringHandler, ExtensionPoint

public class VariableAnnotatedStringHandler extends Object implements AnnotatedStringHandler
Provides support for local function variable annotations.

This allows users to reference function variables in comments without having to change the comment text when the variable is renamed. Users can enter the annotation using the variable's name:

	{@variable local_8}
	 		
 or
	 		
{@variable coolVariable SomeFunction}
The user annotation will be converted to use address information:
	{@variable Stack[0xa] FUN_1234eaea}
  • Constructor Details

    • VariableAnnotatedStringHandler

      public VariableAnnotatedStringHandler()
  • Method Details

    • getSupportedAnnotations

      public String[] getSupportedAnnotations()
      Description copied from interface: AnnotatedStringHandler
      Returns the annotation string names that this AnnotatedStringHandler supports (e.g., "symbol", "address", etc...).
      Specified by:
      getSupportedAnnotations in interface AnnotatedStringHandler
      Returns:
      the annotation string names that this AnnotatedStringHandler supports.
    • getDisplayString

      public String getDisplayString()
      Description copied from interface: AnnotatedStringHandler
      Returns the String that represents the GUI presence of this option
      Specified by:
      getDisplayString in interface AnnotatedStringHandler
      Returns:
      the String to display in GUI components.
    • getPrototypeString

      public String getPrototypeString()
      Description copied from interface: AnnotatedStringHandler
      Returns an example string of how the annotation is used
      Specified by:
      getPrototypeString in interface AnnotatedStringHandler
      Returns:
      the example of how this is used.
    • getPrototypeString

      public String getPrototypeString(String displayText)
      Description copied from interface: AnnotatedStringHandler
      Returns an example string of how the annotation is used
      Specified by:
      getPrototypeString in interface AnnotatedStringHandler
      Parameters:
      displayText - the text that may be wrapped, will not be null
      Returns:
      the example of how this is used.
    • createAnnotatedString

      public AttributedString createAnnotatedString(AttributedString prototypeString, String[] text, Program program) throws AnnotationException
      Description copied from interface: AnnotatedStringHandler
      Creates an FieldElement based upon the give array of Strings. The first String in the list is expected to be the annotation tag used to create the annotation. At the very least the array is expected to be comprised of two elements, the annotation and some data. Extra data may be provided as needed by implementing classes.
      Specified by:
      createAnnotatedString in interface AnnotatedStringHandler
      Parameters:
      prototypeString - The prototype FieldElement that dictates the attributes for the newly created string. Implementations may change attributes as needed.
      text - An array of Strings used to create the FieldElement being returned.
      program - The program with which the returned string is associated.
      Returns:
      An AnnotatedTextFieldElement that will be used to render the given text.
      Throws:
      AnnotationException - if the given text data does not fit the expected format for the given handler implementation.
    • modify

      public String[] modify(String[] text, Program program, Address addr)
      Update the annotation to convert names to addresses.
      Specified by:
      modify in interface AnnotatedStringHandler
      Parameters:
      text - the array of annotation parts to modify
      program - the program
      addr - address of the annotation in the program
      Returns:
      the modified array; null otherwise
    • handleMouseClick

      public boolean handleMouseClick(String[] text, Navigatable sourceNavigatable, ServiceProvider serviceProvider)
      Description copied from interface: AnnotatedStringHandler
      A method that is notified when an annotation is clicked. Returns true if this annotation handles the click; return false if this annotation does not do anything with the click.
      Specified by:
      handleMouseClick in interface AnnotatedStringHandler
      Parameters:
      text - the constituent parts of the annotation
      sourceNavigatable - the location in the program that was clicked.
      serviceProvider - the service provider for needed services.
      Returns:
      true if this annotation handles the click; return false if this annotation does not do anything with the click.