Package ghidra.app.decompiler.component
Class DecompilerUtils
- java.lang.Object
-
- ghidra.app.decompiler.component.DecompilerUtils
-
public class DecompilerUtils extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description DecompilerUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Address
findAddressBefore(Field[] lines, ClangToken token)
static AddressSet
findClosestAddressSet(Program program, AddressSpace functionSpace, java.util.List<ClangToken> tokenList)
static int
findIndexOfFirstField(java.util.List<ClangToken> queryTokens, Field[] fields)
Find index of first field containing a ClangNode in tokenListstatic java.util.Set<Varnode>
getBackwardSlice(Varnode seed)
static java.util.Set<PcodeOp>
getBackwardSliceToPCodeOps(Varnode seed)
static Address
getClosestAddress(Program program, ClangToken token)
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 typestatic FieldSelection
getFieldSelection(java.util.List<ClangToken> tokens)
static java.util.Set<Varnode>
getForwardSlice(Varnode seed)
Construct the set of varnodes making up a simple forward slice of seedstatic java.util.Set<PcodeOp>
getForwardSliceToPCodeOps(Varnode seed)
static 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)
static java.util.List<ClangToken>
getTokens(ClangNode root, Address address)
static java.util.List<ClangToken>
getTokens(ClangNode root, AddressSetView addressSet)
Find all ClangNodes that have a minimum address in the AddressSetViewstatic java.util.List<ClangToken>
getTokensFromView(Field[] fields, Address address)
Similar togetTokens(ClangNode, AddressSetView)
, but uses the tokens from the given view fields.static java.util.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(ClangSyntaxToken token)
static boolean
isGoToStatement(ClangToken token)
static boolean
isMatchingBrace(ClangSyntaxToken braceToken, ClangSyntaxToken otherBraceToken)
static java.util.ArrayList<ClangLine>
toLines(ClangTokenGroup group)
A token hierarchy is flattened and then split into individual lines at the ClangBreak tokens.
-
-
-
Method Detail
-
getVarnodeRef
public static Varnode getVarnodeRef(ClangToken token)
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
public static java.util.Set<Varnode> getForwardSlice(Varnode seed)
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
-
getForwardSliceToPCodeOps
public static java.util.Set<PcodeOp> getForwardSliceToPCodeOps(Varnode seed)
-
getBackwardSliceToPCodeOps
public static java.util.Set<PcodeOp> getBackwardSliceToPCodeOps(Varnode seed)
-
getFunction
public static Function getFunction(Program program, ClangFuncNameToken token)
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
public static int findIndexOfFirstField(java.util.List<ClangToken> queryTokens, Field[] fields)
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
public static java.util.List<ClangToken> getTokensFromView(Field[] fields, Address address)
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
public static java.util.List<ClangToken> getTokens(ClangNode root, AddressSetView addressSet)
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
public static java.util.List<ClangToken> getTokens(ClangNode root, Address address)
-
getClosestAddress
public static Address getClosestAddress(Program program, ClangToken token)
-
findClosestAddressSet
public static AddressSet findClosestAddressSet(Program program, AddressSpace functionSpace, java.util.List<ClangToken> tokenList)
-
getFieldSelection
public static FieldSelection getFieldSelection(java.util.List<ClangToken> tokens)
-
getTokensInSelection
public static java.util.List<ClangToken> getTokensInSelection(FieldSelection selection, Field[] lines)
-
findAddressBefore
public static Address findAddressBefore(Field[] lines, ClangToken token)
-
getGoToTargetToken
public static ClangLabelToken getGoToTargetToken(ClangTokenGroup root, ClangLabelToken label)
-
getMatchingBrace
public static ClangSyntaxToken getMatchingBrace(ClangSyntaxToken startToken)
-
isMatchingBrace
public static boolean isMatchingBrace(ClangSyntaxToken braceToken, ClangSyntaxToken otherBraceToken)
-
isBrace
public static boolean isBrace(ClangSyntaxToken token)
-
isGoToStatement
public static boolean isGoToStatement(ClangToken token)
-
toLines
public static java.util.ArrayList<ClangLine> toLines(ClangTokenGroup group)
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
-
-