Package ghidra.app.decompiler.component
Class DecompilerUtils
java.lang.Object
ghidra.app.decompiler.component.DecompilerUtils
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Address
findAddressBefore
(Field[] lines, ClangToken token) static AddressSet
findClosestAddressSet
(Program program, AddressSpace functionSpace, List<ClangToken> tokenList) static int
findIndexOfFirstField
(List<ClangToken> queryTokens, Field[] fields) Find index of first field containing a ClangNode in tokenListgetBackwardSlice
(Varnode seed) static Address
getClosestAddress
(Program program, ClangToken token) static DataType
getDataType
(ClangToken token) Returns the data type for the given tokenstatic DataType
getDataType
(ghidra.app.plugin.core.decompile.DecompilerActionContext context) Returns the data type for the given context if the context pertains to a data typestatic DataType
Get the data-type associated with a Varnode.static DataType
Get the data-type associated with a Varnode.static DecompileOptions
getDecompileOptions
(ServiceProvider serviceProvider, Program program) Gather decompiler options from tool and program.static FieldSelection
getFieldSelection
(List<ClangToken> tokens) getForwardSlice
(Varnode seed) Construct the set of varnodes making up a simple forward slice of seedstatic Function
getFunction
(Program program, ClangFuncNameToken token) Returns the function represented by the given token.static ClangLabelToken
getGoToTargetToken
(ClangTokenGroup root, ClangLabelToken label) static ClangSyntaxToken
getMatchingBrace
(ClangSyntaxToken startToken) Find the matching brace, '{' or '}', for the given brace token, taking into account brace nesting.static ClangSyntaxToken
getNextBrace
(ClangToken startToken, boolean forward) Starts at the given token and finds the next enclosing brace, depending on the given direction.static List
<ClangToken> static List
<ClangToken> getTokens
(ClangNode root, AddressSetView addressSet) Find all ClangNodes that have a minimum address in the AddressSetViewstatic List
<ClangToken> getTokensFromView
(Field[] fields, Address address) Similar togetTokens(ClangNode, AddressSetView)
, but uses the tokens from the given view fields.static List
<ClangToken> getTokensInSelection
(FieldSelection selection, Field[] lines) static Varnode
getVarnodeRef
(ClangToken token) If the token refers to an individual Varnode, return it.static boolean
isBrace
(ClangToken token) static boolean
isGoToStatement
(ClangToken token) static boolean
isThisParameter
(HighVariable var, Function function) Test specified variable to see if it corresponds to the autothis
parameter of the specifiedFunction
toLines
(ClangTokenGroup group) A token hierarchy is flattened and then split into individual lines at the ClangBreak tokens.
-
Constructor Details
-
DecompilerUtils
public DecompilerUtils()
-
-
Method Details
-
getDecompileOptions
public static DecompileOptions getDecompileOptions(ServiceProvider serviceProvider, Program program) Gather decompiler options from tool and program. If tool is null or does not provide aOptionsService
provider only options stored within the program will be consumed.- Parameters:
serviceProvider
- plugin tool or service provider providing access toOptionsService
program
- program- Returns:
- decompiler options
-
getDataTypeTraceForward
Get the data-type associated with a Varnode. If the Varnode is input to a CAST p-code op, take the most specific data-type between what it was cast from and cast to.- Parameters:
vn
- is the Varnode to get the data-type for- Returns:
- the data-type
-
getDataTypeTraceBackward
Get the data-type associated with a Varnode. If the Varnode is produce by a CAST p-code op, take the most specific data-type between what it was cast from and cast to.- Parameters:
vn
- is the Varnode to get the data-type for- Returns:
- the data-type
-
getVarnodeRef
If the token refers to an individual Varnode, return it. Otherwise return null- Parameters:
token
- the token to check- Returns:
- the Varnode or null otherwise
-
getForwardSlice
Construct the set of varnodes making up a simple forward slice of seed- Parameters:
seed
- Varnode where the slice starts- Returns:
- set of Varnodes in the slice
-
getBackwardSlice
-
getForwardSliceToPCodeOps
-
getBackwardSliceToPCodeOps
-
isThisParameter
Test specified variable to see if it corresponds to the autothis
parameter of the specifiedFunction
- Parameters:
var
- decompilervariable
function
- decompiled function- Returns:
- true if
var
corresponds to existing autothis
parameter, else false
-
getFunction
Returns the function represented by the given token. This will be either the decompiled function or a function referenced within the decompiled function.- Parameters:
program
- the programtoken
- the token- Returns:
- the function
-
findIndexOfFirstField
Find index of first field containing a ClangNode in tokenList- Parameters:
queryTokens
- the list of tokens of interestfields
- the universe of fields to check- Returns:
- index of field, or -1
-
getTokensFromView
Similar togetTokens(ClangNode, AddressSetView)
, but uses the tokens from the given view fields. Sometimes the tokens in the model (represented by theClangNode
) are different than the fields in the view (such as when a list of comment tokens are condensed into a single comment token).- Parameters:
fields
- the fields to checkaddress
- the address each returned token must match- Returns:
- the matching tokens
-
getTokens
Find all ClangNodes that have a minimum address in the AddressSetView- Parameters:
root
- the root of the token treeaddressSet
- the addresses to restrict- Returns:
- the list of tokens
-
getTokens
-
getClosestAddress
-
findClosestAddressSet
public static AddressSet findClosestAddressSet(Program program, AddressSpace functionSpace, List<ClangToken> tokenList) -
getFieldSelection
-
getTokensInSelection
-
findAddressBefore
-
getGoToTargetToken
-
getNextBrace
Starts at the given token and finds the next enclosing brace, depending on the given direction. If going forward, the next unpaired closing brace will be returned; if going backward, the next enclosing open brace will be found. If no enclosing braces exist, then null is returned.- Parameters:
startToken
- the starting tokenforward
- true for forward; false for backward- Returns:
- the next enclosing brace or null
-
getMatchingBrace
Find the matching brace, '{' or '}', for the given brace token, taking into account brace nesting. For an open brace, search forward to find the corresponding close brace. For a close brace, search backward to find the corresponding open brace.- Parameters:
startToken
- is the given brace token- Returns:
- the match brace token or null if there is no match
-
isBrace
-
isGoToStatement
-
toLines
A token hierarchy is flattened and then split into individual lines at the ClangBreak tokens. An array of the lines, each as a ClangLine object that owns its respective tokens, is returned. Sequences of comment tokens are collapsed into a single ClangCommentToken.- Parameters:
group
- is the token hierarchy- Returns:
- the array of ClangLine objects
-
getDataType
public static DataType getDataType(ghidra.app.plugin.core.decompile.DecompilerActionContext context) Returns the data type for the given context if the context pertains to a data type- Parameters:
context
- the context- Returns:
- the data type or null
-
getDataType
Returns the data type for the given token- Parameters:
token
- the token- Returns:
- the data type or null
-