Interface IDExpression
- All Superinterfaces:
IDElement
,IInstructionOperand
- All Known Subinterfaces:
IDAllocObjectInfo
,IDArrayElt
,IDCallInfo
,IDField
,IDImm
,IDInstanceField
,IDInstruction
,IDInvokeInfo
,IDNewArrayInfo
,IDNewInfo
,IDOperation
,IDReferenceType
,IDStaticField
,IDVar
dexdec
IR expressions, such as IR instructions, fields/attributes,
immediates, variables/identifiers, operations, etc.-
Field Summary
Fields inherited from interface com.pnfsoftware.jeb.core.units.code.android.ir.IDElement
DEFAULT_COMPARE_WITH_FULL_EQUALITY
-
Method Summary
Modifier and TypeMethodDescriptiondefault IDArrayElt
default IDCallInfo
default IDImm
asImm()
default IDInstanceField
default IDInstruction
default IDNewArrayInfo
default IDNewInfo
default IDOperation
default IDReferenceType
default IDStaticField
default IDVar
asVar()
boolean
canThrow
(IDMethodContext ctx) Determine whether a hypothetical execution of this IR expression could throw.boolean
void
collectAllPhysicalMethodIndices
(Collection<Integer> physicalMethodIndices) void
collectAllPhysicalOffsets
(Collection<Integer> physicalOffsets) Gather all physical offsets for this element and all its constituents.void
Collect all sub-expressions of this expression, in evaluation order.void
collectVarIds
(Set<Integer> sink) Recursively collect all the variable ids used and defined by this expression.copy
(DCopyOptions opt) Copy this element.int
countVariable
(IDVar var) Count how many times a given identifier is present in an expression.Duplicate this element.evaluate
(IDGlobalContext g, Map<Integer, IDImm> varmap) Convenience method: evaluate anon-instruction
IR expression using the provided set a variable values.evaluate
(IDMethodContext ctx) Convenience method: Evaluate this expression within the context of the provided method.Evaluate this expression.find
(IDExpression elt, int start, int comparisonMethod, IDExpression thisParent) Find the parent of the the provided child element.<T extends IDExpression>
TfindByType
(Class<T> clazz) Find the first child element by type.<T extends IDExpression>
TfindByType
(Class<T> clazz, int start) Find a child element by type.findParent
(IDExpression elt) Find the parent of the first instance of the provided child element.findParent
(IDExpression elt, int start) Find the parent of the the provided child element.generateAST
(IDMethodContext ctx, IJavaMethod m) Generate the Java AST element for this IR expression.Retrieve the custom override set forcanThrow(IDMethodContext)
.Retrieve a value from this IR element's data map.Retrieve the origin info string of this IR element, if there is one.int
Retrieve the low-level dex method index mapping to this IR element.int
Retrieve the physical offset (dalvik) associated with this IR.default List<IDExpression>
Convenience method used to retrieve all the sub-expressions of this IR, in evaluation order.getType()
Get the IR expression type.Recursively collect all the variable ids used and defined by this expression.boolean
hasSideEffects
(IDMethodContext ctx, boolean includeCanThrow) Determine whether a hypothetical execution of this IR expression would change the program internal state.default boolean
default boolean
default boolean
isCallInfo
(String wantedMsig) default boolean
default boolean
isCastOperation
(IJavaType expectedCastType) default boolean
default boolean
isConstantImm
(long expectedRawValue) default boolean
isImm()
default boolean
default boolean
default boolean
default boolean
default boolean
default boolean
isOperation
(JavaOperatorType expectedOperatorType) default boolean
isOperation
(JavaOperatorType expectedOperatorType1, JavaOperatorType expectedOperatorType2) default boolean
isOperation
(JavaOperatorType expectedOperatorType1, JavaOperatorType expectedOperatorType2, JavaOperatorType expectedOperatorType3) default boolean
isOperation
(JavaOperatorType expectedOperatorType1, JavaOperatorType expectedOperatorType2, JavaOperatorType expectedOperatorType3, JavaOperatorType expectedOperatorType4) default boolean
isOperation
(JavaOperatorType expectedOperatorType1, JavaOperatorType expectedOperatorType2, JavaOperatorType expectedOperatorType3, JavaOperatorType expectedOperatorType4, JavaOperatorType expectedOperatorType5) default boolean
isOperation
(JavaOperatorType expectedOperatorType1, JavaOperatorType expectedOperatorType2, JavaOperatorType expectedOperatorType3, JavaOperatorType expectedOperatorType4, JavaOperatorType expectedOperatorType5, JavaOperatorType expectedOperatorType6) default boolean
default boolean
default boolean
default boolean
isVar()
default boolean
isVar
(int wantedVarId) void
removeData
(String key) Remove an entry from this IR element's data map.boolean
replaceSubExpression
(IDExpression target, IDExpression repl) Replace an expression of this IR.int
replaceVariable
(IDVar var, IDExpression repl) Deep replace all matching variables by the provided expression.void
setCustomCanThrow
(Boolean elemenCanThrow) Set a custom override forcanThrow(IDMethodContext)
.void
Store a key-value pair in this IR element's data map.void
Set an optional origin info string for this IR element.void
setPhysicalMethodIndex
(int physicalMethodIndex) Set a low-level dex method index mapping to this IR element.void
setPhysicalOffset
(int physicalOffset) Set the main physical offset associated with this IR.boolean
Update the type of an expression.boolean
Update the type of an expression.boolean
Update the type of an expression.spawn
(long rawvalue) Create a new immediate IR with the provided 64-bit raw value, and the type of this IR expression.void
transferMetadataFrom
(IDExpression srcExp) Transfer (shallow copy) metadata from a source IR to this IR.void
updateAllPhysicalMethodIndices
(int physicalMethodIndex) void
updateAllPhysicalOffsets
(int physicalOffset) Update the physical offset of this element and all its constituents.void
updateTypes
(DTypeInfo ti) Deep update the types of the constituents of this IR expression and update to determine the IR type as well.boolean
visitDepthPost
(IDVisitor visitor) Visit this expression and its constituents, depth-first post-order.boolean
visitDepthPost
(IDVisitor visitor, IDExpression parent) Visit this expression and its constituents, depth-first post-order.boolean
visitDepthPost
(IDVisitor visitor, IDExpression parent, DVisitResults results) Visit this expression and its constituents, depth-first post-order.boolean
visitDepthPre
(IDVisitor visitor) Visit this expression and its constituents, depth-first pre-order.boolean
visitDepthPre
(IDVisitor visitor, IDExpression parent) Visit this expression and its constituents, depth-first pre-order.boolean
visitDepthPre
(IDVisitor visitor, IDExpression parent, DVisitResults results) Visit this expression and its constituents, depth-first pre-order.Methods inherited from interface com.pnfsoftware.jeb.core.units.code.android.ir.IDElement
equalsEx, format, toString, toString
Methods inherited from interface com.pnfsoftware.jeb.core.units.code.IInstructionOperand
format
-
Method Details
-
copy
Description copied from interface:IDElement
Copy this element. This operation can be seen as a custom duplication; the resulting element may not be of the same type as this element.- Specified by:
copy
in interfaceIDElement
- Parameters:
opt
- optional; if one is provided,DCopyOptions.onDup(IDExpression)
will be tried first to create a copy- Returns:
- the copied element
-
duplicate
IDExpression duplicate()Description copied from interface:IDElement
Duplicate this element. -
transferMetadataFrom
Transfer (shallow copy) metadata from a source IR to this IR. Currently, this includes the physical offset and the data map.- Parameters:
srcExp
- source IR expression
-
setPhysicalMethodIndex
void setPhysicalMethodIndex(int physicalMethodIndex) Set a low-level dex method index mapping to this IR element. This is useful to override the default (ownerIDMethodContext
's dex method), such as when a method contains inlined code from another method.- Parameters:
physicalMethodIndex
- a lower-level dex method index, or -1 to signify none or the default
-
getPhysicalMethodIndex
int getPhysicalMethodIndex()Retrieve the low-level dex method index mapping to this IR element.- Returns:
- a lower-level method index, or -1 to signify the default (which is the
IDMethodContext
's dex method index)
-
collectAllPhysicalMethodIndices
- Parameters:
physicalMethodIndices
-
-
updateAllPhysicalMethodIndices
void updateAllPhysicalMethodIndices(int physicalMethodIndex) - Parameters:
physicalMethodIndex
-
-
setPhysicalOffset
void setPhysicalOffset(int physicalOffset) Set the main physical offset associated with this IR.- Parameters:
physicalOffset
- an offset, -1 for none
-
getPhysicalOffset
int getPhysicalOffset()Retrieve the physical offset (dalvik) associated with this IR.- Returns:
- a dalvik method offset (in bytes); -1 if there is no offset associated with the IR
-
collectAllPhysicalOffsets
Gather all physical offsets for this element and all its constituents.- Parameters:
physicalOffsets
- sink; it is recommended to provide a Set to avoid the collection of duplicates
-
updateAllPhysicalOffsets
void updateAllPhysicalOffsets(int physicalOffset) Update the physical offset of this element and all its constituents.- Parameters:
physicalOffset
- new physical offset, -1 to reset (to none)
-
setData
Store a key-value pair in this IR element's data map.- Parameters:
key
- mandatory keyvalue
- mandatory value
-
getData
Retrieve a value from this IR element's data map.- Parameters:
key
- mandatory key- Returns:
- value associated with the key, null if none
-
removeData
Remove an entry from this IR element's data map.- Parameters:
key
-
-
setOrigin
Set an optional origin info string for this IR element. Note that the origin is stored as an entry in the data map. -
getOrigin
String getOrigin()Retrieve the origin info string of this IR element, if there is one.- Returns:
-
updateTypes
Deep update the types of the constituents of this IR expression and update to determine the IR type as well.- Parameters:
ti
- optional type information object, used to record type updates and conflicts
-
getType
IJavaType getType()Get the IR expression type.- Returns:
- the expression type
-
checkType
- Parameters:
wantedType
- expected type- Returns:
- true if the type of the expression is as expected
-
setType
Update the type of an expression.- Parameters:
newType
- mandatory new type- Returns:
- true if the type was updated, false otherwise
-
setType
Update the type of an expression.- Parameters:
newType
- mandatory new typeti
- optional type information object, used to record type update results- Returns:
- true if the type was updated, false otherwise
-
setType
Update the type of an expression.- Parameters:
newType
- mandatory new typeti
- optional type information object, used to record type update resultsforceUpdate
- if true, the new type will always be set (compatibility checks are bypassed)- Returns:
- true if the type was updated, false otherwise
-
replaceVariable
Deep replace all matching variables by the provided expression. Important notes:
- Matching is done by reference equality (IDVar
are factory-created, no two variables created by the same context can have the same id)
- When a replacement is to be performed, aduplication
ofrepl
is done and used as the replacement expression to avoid reuse.
- The exploration is recursive: the constituents are explored for replacement.
- If this expression is itself an identifier, it will not be replaced; only the constituents are matched for replacement.- Parameters:
var
- target variable to be replacedrepl
- expression that will replace the identifier- Returns:
- the number of replacements
-
collectSubExpressions
Collect all sub-expressions of this expression, in evaluation order. If the full expression were to be evaluated at runtime, a sub-expression at indexi
in the list would be evaluated before a sub-expression at indexi+1
.- Parameters:
sink
- a list to which all sub-expressions will be added
-
getSubExpressions
Convenience method used to retrieve all the sub-expressions of this IR, in evaluation order. UsescollectSubExpressions(List)
.- Returns:
- a list of sub-expressions
-
replaceSubExpression
Replace an expression of this IR. This method does not perform deep replacement. The target expression is compared by equality.- Parameters:
target
- IR expression to be replacedrepl
- replacement expression- Returns:
- true if the target was successfully replaced
-
collectVarIds
Recursively collect all the variable ids used and defined by this expression.- Parameters:
sink
- collection receiving the variable ids
-
getVarIds
Recursively collect all the variable ids used and defined by this expression.- Returns:
- a set of unique variable ids
-
countVariable
Count how many times a given identifier is present in an expression. Matching is done usingsame
.- Parameters:
var
- a variable- Returns:
- the number of occurrences of this variable in this IR expression
-
setCustomCanThrow
Set a custom override forcanThrow(IDMethodContext)
. If one is set,canThrow(IDMethodContext)
will return the override value instead of performing regular verifications to determine whether the IR element may raise.Note: Currently, the custom value is only supported by
IDArrayElt
.- Parameters:
elemenCanThrow
- custom value, null to reset
-
getCustomCanThrow
Boolean getCustomCanThrow()Retrieve the custom override set forcanThrow(IDMethodContext)
. SeesetCustomCanThrow(Boolean)
for details.Note: Currently, the custom value is only supported by
IDArrayElt
.- Returns:
- the custom value, or null if none was set
-
canThrow
Determine whether a hypothetical execution of this IR expression could throw.This method is not fail-safe, it works on a best-effort basis.
- Parameters:
ctx
- mandatory method context- Returns:
-
hasSideEffects
Determine whether a hypothetical execution of this IR expression would change the program internal state.This method is not fail-safe, it works on a best-effort basis.
- Parameters:
ctx
- method contextincludeCanThrow
- if true, the possibility of this IR to raise exceptions is checked and considered to be a side-effect- Returns:
-
evaluate
Evaluate this expression.Note about evaluating instructions: When evaluating an
IDInstruction
, a context and frame must be present in the state. The value of PC is not directly updated after the execution of this instruction. Instead, the next expected PC is stored in the current frame, and can be retrieved viaIDEmuFrame.getNextPC()
. Only the evaluation ofASSIGN
,RETURN
,INVOKE
IR instructions may return a value; else, the method will return null.To perform emulation of a stub of IR with full controls, use methods in
IDState
directly.- Parameters:
state
- a machine state- Returns:
- the evaluated expression (be careful, it may be a
reference-immediate
!) - Throws:
DexDecEvaluationException
- on evaluation error
-
evaluate
Convenience method: Evaluate this expression within the context of the provided method.See important note in
evaluate(IDState)
.- Parameters:
ctx
- method context- Returns:
- the evaluated expression (be careful, it may be a
reference-immediate
!) - Throws:
DexDecEvaluationException
- on evaluation error
-
evaluate
Convenience method: evaluate anon-instruction
IR expression using the provided set a variable values.- Parameters:
g
- global IR contextvarmap
- a map of variable values to be used when evaluating the expression- Returns:
- the evaluation result (be careful, it may be a
reference-immediate
!) - Throws:
DexDecEvaluationException
-
generateAST
Generate the Java AST element for this IR expression.- Parameters:
ctx
- IR method context (of which this IR element belongs)m
- AST Method context (of which the resulting AST element will belong)- Returns:
- the generated AST element
-
spawn
Create a new immediate IR with the provided 64-bit raw value, and the type of this IR expression.- Parameters:
rawvalue
- raw bits- Returns:
- the new immediate
-
visitDepthPre
Visit this expression and its constituents, depth-first pre-order.If the visitor replaces an element, the new element must be specified by calling
setReplacedNode()
.- Parameters:
visitor
- visitor object- Returns:
- success indicator; true unless a different value was specified in
DVisitResults
when visiting an element
-
visitDepthPre
Visit this expression and its constituents, depth-first pre-order.If the visitor replaces an element, the new element must be specified by calling
setReplacedNode()
.- Parameters:
visitor
- visitor objectparent
- the optional parent of this expression- Returns:
- success indicator; true unless a different value was specified in
DVisitResults
when visiting an element
-
visitDepthPre
Visit this expression and its constituents, depth-first pre-order.If the visitor replaces an element, the new element must be specified by calling
setReplacedNode()
.- Parameters:
visitor
- visitor objectparent
- the optional parent of this expressionresults
- an optional result object provided to the visitor, containing flags used to customize the visiting process- Returns:
- success indicator; true unless a different value was specified in
DVisitResults
when visiting an element
-
visitDepthPost
Visit this expression and its constituents, depth-first post-order.- Parameters:
visitor
- visitor object- Returns:
- success indicator; true unless a different value was specified in
DVisitResults
when visiting an element
-
visitDepthPost
Visit this expression and its constituents, depth-first post-order.- Parameters:
visitor
- visitor objectparent
- the optional parent of this expression- Returns:
- success indicator; true unless a different value was specified in
DVisitResults
when visiting an element
-
visitDepthPost
Visit this expression and its constituents, depth-first post-order.- Parameters:
visitor
- visitor objectparent
- the optional parent of this expressionresults
- an optional result object provided to the visitor, containing flags used to customize the visiting process- Returns:
- success indicator; true unless a different value was specified in
DVisitResults
when visiting an element
-
findParent
Find the parent of the first instance of the provided child element. The comparison is done by identity.- Parameters:
elt
- an IR element; if the element isthis
, the method will return null- Returns:
- the parent or null
-
findParent
Find the parent of the the provided child element. The comparison is done by identity.- Parameters:
elt
- an IR element; if the element isthis
, the method will return nullstart
- count of instances ofelt
that should be skipped before returning the parent element; this is useful is the element provided may not be unique within the tree (e.g. var)- Returns:
- the parent or null
-
find
Couple<IDExpression,IDExpression> find(IDExpression elt, int start, int comparisonMethod, IDExpression thisParent) Find the parent of the the provided child element.- Parameters:
elt
- an IR element; if the element isthis
, the method will return nullstart
- count of instances ofelt
that should be skipped before returning the parent element; this is useful is the element provided may not be unique within the tree (e.g. var)comparisonMethod
- 0= identity, 1= equality, 2= type-less equalitythisParent
- optional parent of this IR element- Returns:
- if found, the pair (parent, element) parent; else, null
-
findByType
Find the first child element by type.- Type Parameters:
T
-- Parameters:
clazz
- type of the element to be found; careful, if the type is the one ofthis
, then this object will be returned- Returns:
- the element or null
-
findByType
Find a child element by type.- Type Parameters:
T
-- Parameters:
clazz
- type of the element to be found; careful, if the type is the one ofthis
, then this object will be returnedstart
- count of matched elements that should be skipped before returning the element- Returns:
- the element or null
-
isInstruction
default boolean isInstruction()- Returns:
- true if this IR is an
IDInstruction
-
asInstruction
- Returns:
- this IR as an
IDInstruction
-
isArrayElt
default boolean isArrayElt()- Returns:
- true if this IR is an
IDArrayElt
-
asArrayElt
- Returns:
- this IR as an
IDArrayElt
-
isReferenceType
default boolean isReferenceType()- Returns:
- true if this IR is an
IDReferenceType
-
asReferenceType
- Returns:
- this IR as an
IDReferenceType
-
isInstanceField
default boolean isInstanceField()- Returns:
- true if this IR is an
IDInstanceField
-
asInstanceField
- Returns:
- this IR as an
IDInstanceField
-
isStaticField
default boolean isStaticField()- Returns:
- true if this IR is an
IDStaticField
-
asStaticField
- Returns:
- this IR as an
IDStaticField
-
isOperation
default boolean isOperation()- Returns:
- true if this IR is an
IDOperation
or its sub-typeIDPredicate
-
isOperation
- Parameters:
expectedOperatorType
- an operator type- Returns:
- true if this IR is an
operation
of the provided type
-
isOperation
default boolean isOperation(JavaOperatorType expectedOperatorType1, JavaOperatorType expectedOperatorType2) - Parameters:
expectedOperatorType1
- an operator typeexpectedOperatorType2
- an operator type- Returns:
- true if this IR is an
operation
of any of the provided types
-
isOperation
default boolean isOperation(JavaOperatorType expectedOperatorType1, JavaOperatorType expectedOperatorType2, JavaOperatorType expectedOperatorType3) - Parameters:
expectedOperatorType1
- an operator typeexpectedOperatorType2
- an operator typeexpectedOperatorType3
- an operator type- Returns:
- true if this IR is an
operation
of any of the provided types
-
isOperation
default boolean isOperation(JavaOperatorType expectedOperatorType1, JavaOperatorType expectedOperatorType2, JavaOperatorType expectedOperatorType3, JavaOperatorType expectedOperatorType4) - Parameters:
expectedOperatorType1
- an operator typeexpectedOperatorType2
- an operator typeexpectedOperatorType3
- an operator typeexpectedOperatorType4
- an operator type- Returns:
- true if this IR is an
operation
of any of the provided types
-
isOperation
default boolean isOperation(JavaOperatorType expectedOperatorType1, JavaOperatorType expectedOperatorType2, JavaOperatorType expectedOperatorType3, JavaOperatorType expectedOperatorType4, JavaOperatorType expectedOperatorType5) - Parameters:
expectedOperatorType1
- an operator typeexpectedOperatorType2
- an operator typeexpectedOperatorType3
- an operator typeexpectedOperatorType4
- an operator typeexpectedOperatorType5
- an operator type- Returns:
- true if this IR is an
operation
of any of the provided types
-
isOperation
default boolean isOperation(JavaOperatorType expectedOperatorType1, JavaOperatorType expectedOperatorType2, JavaOperatorType expectedOperatorType3, JavaOperatorType expectedOperatorType4, JavaOperatorType expectedOperatorType5, JavaOperatorType expectedOperatorType6) - Parameters:
expectedOperatorType1
- an operator typeexpectedOperatorType2
- an operator typeexpectedOperatorType3
- an operator typeexpectedOperatorType4
- an operator typeexpectedOperatorType5
- an operator typeexpectedOperatorType6
- an operator type- Returns:
- true if this IR is an
operation
of any of the provided types
-
isCastOperation
default boolean isCastOperation()- Returns:
- true if this IR is a cast
operation
-
isCastOperation
- Parameters:
expectedCastType
- wanted cast type- Returns:
- true if this IR is an
operation
casting to the wanted type
-
asOperation
- Returns:
- this IR as an
IDOperation
-
isCallInfo
default boolean isCallInfo()- Returns:
- true if this IR is an
IDCallInfo
or its sub-typeIDNewInfo
-
isCallInfo
- Parameters:
wantedMsig
-- Returns:
- true if this IR is an
IDCallInfo
or its sub-typeIDNewInfo
invoking the provided method signature
-
asCallInfo
- Returns:
- this IR as an
IDCallInfo
-
isNewInfo
default boolean isNewInfo()- Returns:
- true if this IR is an
IDNewInfo
-
asNewInfo
- Returns:
- this IR as an
IDNewInfo
-
isNewArrayInfo
default boolean isNewArrayInfo()- Returns:
- true if this IR is an
IDNewArrayInfo
-
asNewArrayInfo
- Returns:
- this IR as an
IDNewArrayInfo
-
isImm
default boolean isImm()- Returns:
- true if this IR is an
IDImm
-
isConstantImm
default boolean isConstantImm()- Returns:
- true if this IR is an
IDImm
holding a non-reference immediate, that is, a primitive value or a pooled string. (For references, including the null references, this method will return false.)
-
isConstantImm
default boolean isConstantImm(long expectedRawValue) - Parameters:
expectedRawValue
- wanted value- Returns:
- true if this IR is an
IDImm
holding a non-reference immediate with the provided raw value
-
isStringImm
default boolean isStringImm()- Returns:
- true if this IR is an
IDImm
holding a pooled String constant. (String references are not constants.)
-
asImm
- Returns:
- this IR as an
IDImm
-
isVar
default boolean isVar()- Returns:
- true if this IR is an
IDVar
-
isVar
default boolean isVar(int wantedVarId) - Parameters:
wantedVarId
- a variable id- Returns:
- true if this IR is a
variable
having the provided id
-
asVar
- Returns:
- this IR as an
IDVar
-