Package ghidra.app.util.demangler
Class DemangledObject
- java.lang.Object
-
- ghidra.app.util.demangler.DemangledObject
-
- All Implemented Interfaces:
Demangled
- Direct Known Subclasses:
DemangledAddressTable
,DemangledFunction
,DemangledString
,DemangledThunk
,DemangledUnknown
,DemangledVariable
public abstract class DemangledObject extends java.lang.Object implements Demangled
A class to represent a demangled object.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
basedName
protected static java.lang.String
EMPTY_STRING
protected boolean
isRestrict
protected boolean
isStatic
protected boolean
isThunk
protected boolean
isUnaligned
protected boolean
isVirtual
protected java.lang.String
mangled
protected java.lang.String
memberScope
protected Demangled
namespace
protected static java.lang.String
NAMESPACE_SEPARATOR
protected java.lang.String
originalDemangled
protected static java.lang.String
SPACE
protected static java.util.regex.Pattern
SPACE_PATTERN
protected java.lang.String
specialPrefix
protected java.lang.String
storageClass
protected java.lang.String
visibility
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected Symbol
applyDemangledName(Address addr, boolean setPrimary, boolean functionNamespacePermitted, Program prog)
protected Symbol
applyDemangledName(java.lang.String symbolName, Address addr, boolean setPrimary, boolean functionNamespacePermitted, Program prog)
boolean
applyPlateCommentOnly(Program program, Address address)
boolean
applyTo(Program program, Address address, DemanglerOptions options, TaskMonitor monitor)
static Namespace
createNamespace(Program program, Demangled typeNamespace, Namespace parentNamespace, boolean functionPermitted)
Get or create the specified typeNamespace.boolean
demangledNameSuccessfully()
Returns the success state of converting a mangled String into a demangled Stringprotected static java.lang.String
ensureNameLength(java.lang.String name)
Ensure name does not pass the limit defined by Ghidraprotected java.lang.String
generatePlateComment()
Creates descriptive text that is intended to be used as documentation.java.lang.String
getBasedName()
java.lang.String
getDemangledName()
Returns the unmodified demangled name of this object.java.lang.String
getMangledString()
Returns the original mangled stringjava.lang.String
getMemberScope()
java.lang.String
getName()
Returns the demangled name of this object.Demangled
getNamespace()
Returns the namespace containing this demangled objectjava.lang.String
getNamespaceName()
Returns this object's namespace name without the fully-qualified parent path.java.lang.String
getNamespaceString()
Returns a representation of this object as fully-qualified namespace.java.lang.String
getOriginalDemangled()
Returns the original demangled string returned by the demangling servicejava.lang.String
getSignature()
Generates a complete representation of this object to include all know attributes of this objectabstract java.lang.String
getSignature(boolean format)
Returns a complete signature for the demangled symbol.java.lang.String
getSpecialPrefix()
java.lang.String
getStorageClass()
java.lang.String
getVisibility()
protected boolean
isAlreadyDemangled(Program program, Address address)
Determine if the symbol at address has already been demangled.boolean
isConst()
boolean
isPointer64()
boolean
isRestrict()
boolean
isStatic()
boolean
isThunk()
boolean
isUnaligned()
boolean
isVirtual()
boolean
isVolatile()
void
setBackupPlateComment(java.lang.String plateComment)
Sets the plate comment to be used if thegetOriginalDemangled()
string is not availablevoid
setBasedName(java.lang.String basedName)
void
setConst(boolean isConst)
void
setMemberScope(java.lang.String memberScope)
void
setName(java.lang.String name)
Sets the name of the demangled objectvoid
setNamespace(Demangled namespace)
Sets the namespace of this demangled objectvoid
setPointer64(boolean isPointer64)
void
setRestrict()
void
setSpecialPrefix(java.lang.String special)
void
setStatic(boolean isStatic)
void
setStorageClass(java.lang.String storageClass)
void
setThunk(boolean isThunk)
void
setUnaligned()
void
setVirtual(boolean isVirtual)
void
setVisibilty(java.lang.String visibility)
void
setVolatile(boolean isVolatile)
java.lang.String
toString()
-
-
-
Field Detail
-
SPACE
protected static final java.lang.String SPACE
- See Also:
- Constant Field Values
-
SPACE_PATTERN
protected static final java.util.regex.Pattern SPACE_PATTERN
-
NAMESPACE_SEPARATOR
protected static final java.lang.String NAMESPACE_SEPARATOR
- See Also:
- Constant Field Values
-
EMPTY_STRING
protected static final java.lang.String EMPTY_STRING
- See Also:
- Constant Field Values
-
mangled
protected final java.lang.String mangled
-
originalDemangled
protected final java.lang.String originalDemangled
-
specialPrefix
protected java.lang.String specialPrefix
-
namespace
protected Demangled namespace
-
visibility
protected java.lang.String visibility
-
storageClass
protected java.lang.String storageClass
-
isStatic
protected boolean isStatic
-
isVirtual
protected boolean isVirtual
-
isThunk
protected boolean isThunk
-
isUnaligned
protected boolean isUnaligned
-
isRestrict
protected boolean isRestrict
-
basedName
protected java.lang.String basedName
-
memberScope
protected java.lang.String memberScope
-
-
Method Detail
-
getDemangledName
public java.lang.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. SeeDemangled.getName()
for the same name modified for use within Ghidra.- Specified by:
getDemangledName
in interfaceDemangled
- Returns:
- name of this DemangledObject
-
getName
public java.lang.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 interfaceDemangled
- Returns:
- name of this DemangledObject with unsupported characters converted to underscore
- See Also:
Demangled.getDemangledName()
-
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 java.lang.String getBasedName()
-
setBasedName
public void setBasedName(java.lang.String basedName)
-
getMemberScope
public java.lang.String getMemberScope()
-
setMemberScope
public void setMemberScope(java.lang.String memberScope)
-
setName
public void setName(java.lang.String name)
Sets the name of the demangled object
-
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 java.lang.String getMangledString()
Description copied from interface:Demangled
Returns the original mangled string- Specified by:
getMangledString
in interfaceDemangled
- Returns:
- the string
-
getOriginalDemangled
public java.lang.String getOriginalDemangled()
Description copied from interface:Demangled
Returns the original demangled string returned by the demangling service- Specified by:
getOriginalDemangled
in interfaceDemangled
- Returns:
- the original demangled string
-
getNamespace
public Demangled getNamespace()
Description copied from interface:Demangled
Returns the namespace containing this demangled object- Specified by:
getNamespace
in interfaceDemangled
- 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 interfaceDemangled
- Parameters:
namespace
- the namespace
-
getVisibility
public java.lang.String getVisibility()
-
setVisibilty
public void setVisibilty(java.lang.String visibility)
-
getStorageClass
public java.lang.String getStorageClass()
-
setStorageClass
public void setStorageClass(java.lang.String storageClass)
-
getSpecialPrefix
public java.lang.String getSpecialPrefix()
-
setSpecialPrefix
public void setSpecialPrefix(java.lang.String special)
-
getSignature
public abstract java.lang.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 java.lang.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 interfaceDemangled
- Returns:
- the signature
-
getNamespaceName
public java.lang.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 interfaceDemangled
- Returns:
- the name
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getNamespaceString
public java.lang.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 interfaceDemangled
- 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 modifiedaddress
- address of demangled symbol- Returns:
- true if symbol at address has already been demangled
-
applyTo
public boolean applyTo(Program program, Address address, DemanglerOptions options, TaskMonitor monitor) throws java.lang.Exception
- Throws:
java.lang.Exception
-
applyPlateCommentOnly
public boolean applyPlateCommentOnly(Program program, Address address) throws java.lang.Exception
- Parameters:
program
- The program for which to apply the commentaddress
- The address for the comment- Returns:
true
if a comment was applied- Throws:
java.lang.Exception
- if the symbol could not be demangled or if the address is invalid
-
setBackupPlateComment
public void setBackupPlateComment(java.lang.String plateComment)
Sets the plate comment to be used if thegetOriginalDemangled()
string is not available- Parameters:
plateComment
- the plate comment text
-
generatePlateComment
protected java.lang.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 bysetBackupPlateComment(String)
will be used. The last choice for this text is the signature generated bygetSignature(boolean)
.- Returns:
- the text
-
applyDemangledName
protected Symbol applyDemangledName(Address addr, boolean setPrimary, boolean functionNamespacePermitted, Program prog) throws InvalidInputException
- Throws:
InvalidInputException
-
applyDemangledName
protected Symbol applyDemangledName(java.lang.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 programtypeNamespace
- demangled namespaceparentNamespace
- 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 java.lang.String ensureNameLength(java.lang.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
-
-