Class DemangledObject

java.lang.Object
ghidra.app.util.demangler.DemangledObject
All Implemented Interfaces:
Demangled
Direct Known Subclasses:
DemangledAddressTable, DemangledFunction, DemangledLabel, DemangledString, DemangledThunk, DemangledUnknown, DemangledVariable

public abstract class DemangledObject extends Object implements Demangled
A class to represent a demangled object.
  • Field Details

    • SPACE

      protected static final String SPACE
      See Also:
    • SPACE_PATTERN

      protected static final Pattern SPACE_PATTERN
    • NAMESPACE_SEPARATOR

      protected static final String NAMESPACE_SEPARATOR
      See Also:
    • EMPTY_STRING

      protected static final String EMPTY_STRING
      See Also:
    • mangled

      protected final String mangled
    • originalDemangled

      protected String originalDemangled
    • specialPrefix

      protected String specialPrefix
    • namespace

      protected Demangled namespace
    • visibility

      protected String visibility
    • storageClass

      protected String storageClass
    • isStatic

      protected boolean isStatic
    • isVirtual

      protected boolean isVirtual
    • isThunk

      protected boolean isThunk
    • isUnaligned

      protected boolean isUnaligned
    • isRestrict

      protected boolean isRestrict
    • basedName

      protected String basedName
    • memberScope

      protected String memberScope
  • Method Details

    • getDemangledName

      public String getDemangledName()
      Description copied from interface: Demangled
      Returns the unmodified demangled name of this object. This name may contain whitespace and other characters not supported for symbol or data type creation. See Demangled.getName() for the same name modified for use within Ghidra.
      Specified by:
      getDemangledName in interface Demangled
      Returns:
      name of this DemangledObject
    • getName

      public String getName()
      Description copied from interface: Demangled
      Returns the demangled name of this object. NOTE: unsupported symbol characters, like whitespace, will be converted to an underscore.
      Specified by:
      getName in interface Demangled
      Returns:
      name of this DemangledObject with unsupported characters converted to underscore
      See Also:
    • isConst

      public boolean isConst()
    • setConst

      public void setConst(boolean isConst)
    • isVolatile

      public boolean isVolatile()
    • setVolatile

      public void setVolatile(boolean isVolatile)
    • isPointer64

      public boolean isPointer64()
    • setPointer64

      public void setPointer64(boolean isPointer64)
    • isStatic

      public boolean isStatic()
    • setStatic

      public void setStatic(boolean isStatic)
    • isVirtual

      public boolean isVirtual()
    • setVirtual

      public void setVirtual(boolean isVirtual)
    • isThunk

      public boolean isThunk()
    • setThunk

      public void setThunk(boolean isThunk)
    • setUnaligned

      public void setUnaligned()
    • isUnaligned

      public boolean isUnaligned()
    • setRestrict

      public void setRestrict()
    • isRestrict

      public boolean isRestrict()
    • getBasedName

      public String getBasedName()
    • setBasedName

      public void setBasedName(String basedName)
    • getMemberScope

      public String getMemberScope()
    • setMemberScope

      public void setMemberScope(String memberScope)
    • setName

      public void setName(String name)
      Sets the name of the demangled object
      Specified by:
      setName in interface Demangled
      Parameters:
      name - the new name
    • demangledNameSuccessfully

      public boolean demangledNameSuccessfully()
      Returns the success state of converting a mangled String into a demangled String
      Returns:
      true succeeded creating demangled String
    • getMangledString

      public String getMangledString()
      Description copied from interface: Demangled
      Returns the original mangled string
      Specified by:
      getMangledString in interface Demangled
      Returns:
      the string
    • getOriginalDemangled

      public String getOriginalDemangled()
      Description copied from interface: Demangled
      Returns the original demangled string returned by the demangling service
      Specified by:
      getOriginalDemangled in interface Demangled
      Returns:
      the original demangled string
    • setOriginalDemangled

      public void setOriginalDemangled(String originalDemangled)
      Sets the original demangled string. This is useful for clients that reuse constructed demangled objects for special case constructs.

      Note: this method is not on the interface

      Parameters:
      originalDemangled - the new original demangled string
    • getNamespace

      public Demangled getNamespace()
      Description copied from interface: Demangled
      Returns the namespace containing this demangled object
      Specified by:
      getNamespace in interface Demangled
      Returns:
      the namespace containing this demangled object
    • setNamespace

      public void setNamespace(Demangled namespace)
      Description copied from interface: Demangled
      Sets the namespace of this demangled object
      Specified by:
      setNamespace in interface Demangled
      Parameters:
      namespace - the namespace
    • getVisibility

      public String getVisibility()
    • setVisibilty

      public void setVisibilty(String visibility)
    • getStorageClass

      public String getStorageClass()
    • setStorageClass

      public void setStorageClass(String storageClass)
    • getSpecialPrefix

      public String getSpecialPrefix()
    • setSpecialPrefix

      public void setSpecialPrefix(String special)
    • getSignature

      public abstract String getSignature(boolean format)
      Returns a complete signature for the demangled symbol.
      For example: "unsigned long foo" "unsigned char * ClassA::getFoo(float, short *)" "void * getBar(int **, MyStruct &)"
      Note: based on the underlying mangling scheme, the return type may or may not be specified in the signature.
      Parameters:
      format - true if signature should be pretty printed
      Returns:
      a complete signature for the demangled symbol
    • getSignature

      public final String getSignature()
      Description copied from interface: Demangled
      Generates a complete representation of this object to include all know attributes of this object
      Specified by:
      getSignature in interface Demangled
      Returns:
      the signature
    • getNamespaceName

      public String getNamespaceName()
      Description copied from interface: Demangled
      Returns this object's namespace name without the fully-qualified parent path. The value returned here may have had some special characters replaced, such as ' ' replaced with '_' and '::' replaced with '--'.
      Specified by:
      getNamespaceName in interface Demangled
      Returns:
      the name
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getNamespaceString

      public String getNamespaceString()
      Description copied from interface: Demangled
      Returns a representation of this object as fully-qualified namespace. The value returned here may have had some special characters replaced, such as ' ' replaced with '_' and '::' replaced with '--'.
      Specified by:
      getNamespaceString in interface Demangled
      Returns:
      the full namespace
    • isAlreadyDemangled

      protected boolean isAlreadyDemangled(Program program, Address address)
      Determine if the symbol at address has already been demangled. While memory symbols check for presence of demangledName, external symbols simply check if demangled/alternate name has already been assigned.
      Parameters:
      program - the program being modified
      address - address of demangled symbol
      Returns:
      true if symbol at address has already been demangled
    • getErrorMessage

      public String getErrorMessage()
      Returns the error message that can be set when an error is encountered, but which is made available to the calling method to get details of the error beyond boolean value that is returned by applyTo(Program, Address, DemanglerOptions,TaskMonitor).
      Returns:
      a message pertaining to issues encountered in the apply methods. Can be null
    • setErrorMessage

      protected void setErrorMessage(String message)
      Set the message that applyTo(Program, Address, DemanglerOptions,TaskMonitor) caller can read
      Parameters:
      message - the message
    • applyTo

      public boolean applyTo(Program program, Address address, DemanglerOptions options, TaskMonitor monitor) throws Exception
      Apply this demangled object detail to the specified program.
      NOTE: An open Program transaction must be established prior to invoking this method.
      Parameters:
      program - program to which demangled data should be applied.
      address - address which corresponds to this demangled object
      options - options which control how demangled data is applied
      monitor - task monitor
      Returns:
      true if successfully applied, else false
      Throws:
      Exception - if an error occurs during the apply operation
    • applyPlateCommentOnly

      public boolean applyPlateCommentOnly(Program program, Address address) throws Exception
      Parameters:
      program - The program for which to apply the comment
      address - The address for the comment
      Returns:
      true if a comment was applied
      Throws:
      Exception - if the symbol could not be demangled or if the address is invalid
    • setBackupPlateComment

      public void setBackupPlateComment(String plateComment)
      Sets the plate comment to be used if the getOriginalDemangled() string is not available
      Parameters:
      plateComment - the plate comment text
    • generatePlateComment

      protected String generatePlateComment()
      Creates descriptive text that is intended to be used as documentation. The text defaults to the original demangled text. If that is not available, then any text set by setBackupPlateComment(String) will be used. The last choice for this text is the signature generated by getSignature(boolean).
      Returns:
      the text
    • applyDemangledName

      protected Symbol applyDemangledName(Address addr, boolean setPrimary, boolean functionNamespacePermitted, Program prog) throws InvalidInputException
      Throws:
      InvalidInputException
    • applyDemangledName

      protected Symbol applyDemangledName(String symbolName, Address addr, boolean setPrimary, boolean functionNamespacePermitted, Program prog) throws InvalidInputException
      Throws:
      InvalidInputException
    • createNamespace

      public static Namespace createNamespace(Program program, Demangled typeNamespace, Namespace parentNamespace, boolean functionPermitted)
      Get or create the specified typeNamespace. The returned namespace may only be a partial namespace if errors occurred. The caller should check the returned namespace and adjust any symbol creation accordingly.
      Parameters:
      program - the program
      typeNamespace - demangled namespace
      parentNamespace - root namespace to be used (e.g., library, global, etc.)
      functionPermitted - if true an existing function may be used as a namespace
      Returns:
      namespace or partial namespace if error occurs
    • ensureNameLength

      protected static String ensureNameLength(String name)
      Ensure name does not pass the limit defined by Ghidra
      Parameters:
      name - the name whose length to restrict
      Returns:
      the name, updated as needed