Package ghidra.app.util.demangler
Class DemangledObject
java.lang.Object
ghidra.app.util.demangler.DemangledObject
- All Implemented Interfaces:
Demangled
- Direct Known Subclasses:
DemangledAddressTable
,DemangledFunction
,DemangledLabel
,DemangledString
,DemangledThunk
,DemangledUnknown
,DemangledVariable
A class to represent a demangled object.
-
Field Summary
Modifier and TypeFieldDescriptionprotected String
protected static final String
protected boolean
protected boolean
protected boolean
protected boolean
protected boolean
protected final String
protected String
protected Demangled
protected static final String
protected String
protected static final String
protected static final Pattern
protected String
protected String
protected String
-
Method Summary
Modifier and TypeMethodDescriptionprotected Symbol
applyDemangledName
(Address addr, boolean setPrimary, boolean functionNamespacePermitted, Program prog) protected Symbol
applyDemangledName
(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) Apply this demangled object detail to the specified program.static Namespace
createNamespace
(Program program, Demangled typeNamespace, Namespace parentNamespace, boolean functionPermitted) Get or create the specified typeNamespace.boolean
Returns the success state of converting a mangled String into a demangled Stringprotected static String
ensureNameLength
(String name) Ensure name does not pass the limit defined by Ghidraprotected String
Creates descriptive text that is intended to be used as documentation.Returns the unmodified demangled name of this object.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 byapplyTo(Program, Address, DemanglerOptions,TaskMonitor)
.Returns the original mangled stringgetName()
Returns the demangled name of this object.Returns the namespace containing this demangled objectReturns this object's namespace name without the fully-qualified parent path.Returns a representation of this object as fully-qualified namespace.Returns the original demangled string returned by the demangling servicefinal String
Generates a complete representation of this object to include all know attributes of this objectabstract String
getSignature
(boolean format) Returns a complete signature for the demangled symbol.protected boolean
isAlreadyDemangled
(Program program, Address address) Determine if the symbol at address has already been demangled.boolean
isConst()
boolean
boolean
boolean
isStatic()
boolean
isThunk()
boolean
boolean
boolean
void
setBackupPlateComment
(String plateComment) Sets the plate comment to be used if thegetOriginalDemangled()
string is not availablevoid
setBasedName
(String basedName) void
setConst
(boolean isConst) protected void
setErrorMessage
(String message) Set the message thatapplyTo(Program, Address, DemanglerOptions,TaskMonitor)
caller can readvoid
setMemberScope
(String memberScope) void
Sets the name of the demangled objectvoid
setNamespace
(Demangled namespace) Sets the namespace of this demangled objectvoid
setOriginalDemangled
(String originalDemangled) Sets the original demangled string.void
setPointer64
(boolean isPointer64) void
void
setSpecialPrefix
(String special) void
setStatic
(boolean isStatic) void
setStorageClass
(String storageClass) void
setThunk
(boolean isThunk) void
void
setVirtual
(boolean isVirtual) void
setVisibilty
(String visibility) void
setVolatile
(boolean isVolatile) toString()
-
Field Details
-
SPACE
- See Also:
-
SPACE_PATTERN
-
NAMESPACE_SEPARATOR
- See Also:
-
EMPTY_STRING
- See Also:
-
mangled
-
originalDemangled
-
specialPrefix
-
namespace
-
visibility
-
storageClass
-
isStatic
protected boolean isStatic -
isVirtual
protected boolean isVirtual -
isThunk
protected boolean isThunk -
isUnaligned
protected boolean isUnaligned -
isRestrict
protected boolean isRestrict -
basedName
-
memberScope
-
-
Method Details
-
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
Description copied from interface:Demangled
Returns the demangled name of this object. NOTE: unsupported symbol characters, like whitespace, will be converted to an underscore. -
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
-
setBasedName
-
getMemberScope
-
setMemberScope
-
setName
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
Description copied from interface:Demangled
Returns the original mangled string- Specified by:
getMangledString
in interfaceDemangled
- Returns:
- the 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
-
setOriginalDemangled
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
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
Description copied from interface:Demangled
Sets the namespace of this demangled object- Specified by:
setNamespace
in interfaceDemangled
- Parameters:
namespace
- the namespace
-
getVisibility
-
setVisibilty
-
getStorageClass
-
setStorageClass
-
getSpecialPrefix
-
setSpecialPrefix
-
getSignature
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
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
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
-
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
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
-
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 byapplyTo(Program, Address, DemanglerOptions,TaskMonitor)
.- Returns:
- a message pertaining to issues encountered in the apply methods. Can be null
-
setErrorMessage
Set the message thatapplyTo(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 objectoptions
- options which control how demangled data is appliedmonitor
- task monitor- Returns:
- true if successfully applied, else false
- Throws:
Exception
- if an error occurs during the apply operation
-
applyPlateCommentOnly
- Parameters:
program
- The program for which to apply the commentaddress
- 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
Sets the plate comment to be used if thegetOriginalDemangled()
string is not available- Parameters:
plateComment
- the plate comment text
-
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(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
Ensure name does not pass the limit defined by Ghidra- Parameters:
name
- the name whose length to restrict- Returns:
- the name, updated as needed
-