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
FieldsModifier and TypeFieldDescriptionprotected Stringprotected static final Stringprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected final Stringprotected MangledContextprotected Stringprotected Demangledprotected static final Stringprotected Stringprotected Stringprotected static final Stringprotected static final Patternprotected Stringprotected Stringprotected String -
Method Summary
Modifier and TypeMethodDescriptionprotected SymbolapplyDemangledName(Address addr, boolean setPrimary, boolean functionNamespacePermitted, Program prog) protected SymbolapplyDemangledName(String symbolName, Address addr, boolean setPrimary, boolean functionNamespacePermitted, Program prog) booleanapplyPlateCommentOnly(Program program, Address address) booleanapplyTo(Program program, Address address, DemanglerOptions options, TaskMonitor monitor) Apply this demangled object detail to the specified program.booleanapplyUsingContext(TaskMonitor monitor) Apply this demangled object detail to the specified program.static NamespacecreateNamespace(Program program, Demangled typeNamespace, Namespace parentNamespace, boolean functionPermitted) Get or create the specified typeNamespace.booleanReturns the success state of converting a mangled String into a demangled Stringprotected static StringensureNameLength(String name) Ensure name does not pass the limit defined by Ghidraprotected StringCreates 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 mangled contextReturns 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 serviceReturns the raw demangled string.final StringGenerates a complete representation of this object to include all know attributes of this objectabstract StringgetSignature(boolean format) Returns a complete signature for the demangled symbol.protected booleanisAlreadyDemangled(Program program, Address address) Determine if the symbol at address has already been demangled.booleanisConst()booleanbooleanbooleanisStatic()booleanisThunk()booleanbooleanbooleanvoidsetBackupPlateComment(String plateComment) Sets the plate comment to be used if thegetOriginalDemangled()string is not availablevoidsetBasedName(String basedName) voidsetConst(boolean isConst) protected voidsetErrorMessage(String message) Set the message thatapplyTo(Program, Address, DemanglerOptions,TaskMonitor)caller can readvoidsetMangledContext(MangledContext mangledContextArg) Sets the mangled contextvoidsetMemberScope(String memberScope) voidSets the name of the demangled objectvoidsetNamespace(Demangled namespace) Sets the namespace of this demangled objectvoidsetOriginalDemangled(String originalDemangled) Sets the original demangled string.voidsetPointer64(boolean isPointer64) voidSets the raw demangled string.voidvoidsetSpecialPrefix(String special) voidsetStatic(boolean isStatic) voidsetStorageClass(String storageClass) voidsetThunk(boolean isThunk) voidvoidsetVirtual(boolean isVirtual) voidsetVisibilty(String visibility) voidsetVolatile(boolean isVolatile) toString()
-
Field Details
-
SPACE
- See Also:
-
SPACE_PATTERN
-
NAMESPACE_SEPARATOR
- See Also:
-
EMPTY_STRING
- See Also:
-
mangledContext
-
mangled
-
rawDemangled
-
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:DemangledReturns 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:
getDemangledNamein interfaceDemangled- Returns:
- name of this DemangledObject
-
getName
Description copied from interface:DemangledReturns 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
-
setMangledContext
Description copied from interface:DemangledSets the mangled contextThis method currently has a
defaultimplementation so not to break existing class implementations. However, at some point thedefaulttag and implementation, which is empty, will be removed. Thus, all implementers need to implement this method before the removal of thedefault- Specified by:
setMangledContextin interfaceDemangled- Parameters:
mangledContextArg- the mangled context
-
getMangledContext
Description copied from interface:DemangledReturns the mangled contextThis method currently has a
defaultimplementation so not to break existing class implementations. However, at some point thedefaulttag and implementation, which returns null, will be removed. Thus, all implementers need to implement this method before the removal of thedefault- Specified by:
getMangledContextin interfaceDemangled- Returns:
- the context or null if no context
-
getMangledString
Description copied from interface:DemangledReturns the original mangled string- Specified by:
getMangledStringin interfaceDemangled- Returns:
- the string
-
getOriginalDemangled
Description copied from interface:DemangledReturns the original demangled string returned by the demangling service- Specified by:
getOriginalDemangledin 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
-
getRawDemangled
Returns the raw demangled string. This is the value returned from the demangler before any simplifications or transformations have been made.- Returns:
- the string
-
setRawDemangledString
Sets the raw demangled string. This is the value returned from the demangler before any simplifications or transformations have been made.- Parameters:
s- the string
-
getNamespace
Description copied from interface:DemangledReturns the namespace containing this demangled object- Specified by:
getNamespacein interfaceDemangled- Returns:
- the namespace containing this demangled object
-
setNamespace
Description copied from interface:DemangledSets the namespace of this demangled object- Specified by:
setNamespacein 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:DemangledGenerates a complete representation of this object to include all know attributes of this object- Specified by:
getSignaturein interfaceDemangled- Returns:
- the signature
-
getNamespaceName
Description copied from interface:DemangledReturns 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:
getNamespaceNamein interfaceDemangled- Returns:
- the name
-
toString
-
getNamespaceString
Description copied from interface:DemangledReturns 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:
getNamespaceStringin 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
-
applyUsingContext
Apply this demangled object detail to the specified program. This method only works if theMangledContextwas set with the appropriate constructor or with thesetMangledContext(MangledContext)method
NOTE: An open Program transaction must be established prior to invoking this method.- Parameters:
monitor- task monitor- Returns:
- true if successfully applied, else false
- Throws:
Exception- if an error occurs during the apply operation or if the context is null
-
applyPlateCommentOnly
- Parameters:
program- The program for which to apply the commentaddress- The address for the comment- Returns:
trueif 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
-