java.lang.Object | |
↳ | com.pnfsoftware.jeb.core.units.code.android.ir.DUtil |
dexdec
IR access and manipulation utility methods.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
DUtil() |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
static boolean | canHandlerCatchException(IDMethodContext ctx, IDExceptionHandler h, String exceptionSig) | ||||||||||
static boolean |
checkBlock(BasicBlock<IDInstruction> b, DOpcodeType... opcodes)
Check for instruction matching in the provided block.
| ||||||||||
static int |
checkSequence(CFG<IDInstruction> cfg, int blkindex, DOpcodeType... opcodes)
Check for instruction matching in a sequence of blocks.
| ||||||||||
static int |
countVariable(IDExpression e, IDVar var)
Count the number of occurrences of a given variable in the provided IR expression.
| ||||||||||
static long |
createVarId(int registerBase, boolean dualSlot)
Create an
IR variable id. | ||||||||||
static long |
createVarIdDualSlot(int registerBase)
Create an
IR variable id. | ||||||||||
static void |
dump(CFG<IDInstruction> cfg, String filename)
Dump an IR-CFG to a Graphviz
dot file in the user's temporary folder. | ||||||||||
static void |
dump(CFG<IDInstruction> cfg, String filename, String title)
Dump an IR-CFG to a Graphviz
dot file in the user's temporary folder. | ||||||||||
static String | generateNativeAddress(IDMethodContext ctx, IDExpression elt) | ||||||||||
static ICodeCoordinates | generateNativeCoordinates(IDMethodContext ctx, IDExpression elt) | ||||||||||
static ContextAccessType |
getCAT(IDInstruction insn, boolean inclAssigDst)
Determine the aggregated context type of an instruction.
| ||||||||||
static String | getExceptionSignature(IDMethodContext ctx, IDExceptionHandler h) | ||||||||||
static Collection<BasicBlock<IDInstruction>> |
getReachableBlocks(CFG<IDInstruction> cfg)
Get the list of reachable blocks of the provided IR-CFG.
| ||||||||||
static boolean |
hasInvokeInfo(IDExpression e)
Determine whether the IR expression makes invocations (general invocations, new, new-array).
| ||||||||||
static boolean |
hasVariables(IDExpression e)
Determine whether the provided expression contains
variables . | ||||||||||
static boolean | isUsingCaughtException(IDMethodContext ctx, BasicBlock<IDInstruction> b) | ||||||||||
static boolean |
mayBeFinal(IDField f, IDexUnit dex)
Determine whether the provided field is or appears to be
final . | ||||||||||
static boolean |
mayHaveRightSideSideEffects(IDInstruction insn, boolean includeCanThrow)
This heuristic determines whether the right-hand side of the instruction (the 'source', in
the case of an assignment) may have side-effects, i.e.
| ||||||||||
static boolean |
mayHaveSideEffects(IDExpression e, IDGlobalContext gctx, boolean includeCanThrow)
This heuristic determines whether the provided expression may have side-effects, i.e.
| ||||||||||
static boolean |
mayThrow(IDExpression e, IDGlobalContext gctx)
This heuristic determines whether the provided expression may possibly throw.
| ||||||||||
static int |
removeGaps(CFG<IDInstruction> cfg)
Remove all gaps from the provided IR-CFG.
| ||||||||||
static int |
removeUnreachableBlocks(CFG<IDInstruction> cfg, IDTryData ex)
Remove unreachable blocks from an IR-CFG.
| ||||||||||
static int |
removeUnreachableBlocks(IDMethodContext ctx)
Remove unreachable blocks from an IR-CFG.
| ||||||||||
static int |
removeUnreachableBlocks(List<BasicBlock<IDInstruction>> tbr, CFG<IDInstruction> cfg, IDTryData ex)
Remove blocks not reachable from the entry block (first block) of a CFG.
| ||||||||||
static int |
simplifyJCondsAndSwitches(IDMethodContext ctx)
Simply DOpcodeType#JCOND and
IR_SWITCH IR instructions:- JCOND: the target branch must not point to the fallthrough instruction; if it is, the JCOND must be replaced by a JUMP (while taking care of potential side-effects introduced by the evaluation of the JCOND predicate) - SWITCH: the case targets must not point to the fallthrough instruction; if any does, the case entry must be removed (and will be taken care by the switch's default entry)
Illegal JCOND/SWITCH are tolerated during an optimization phase; however, an optimizer, or any code modifying the IR, must provide a legal IR to subsequent components. | ||||||||||
static boolean |
unprotectBlock(CFG<IDInstruction> cfg, IDTryData exdata, int blkAddress)
Unprotect a basic block.
| ||||||||||
static boolean |
usesReferences(IDExpression e)
Determine whether the IR expression uses references, defined as any of: accessing fields,
accessing array elements, creating arrays.
| ||||||||||
static boolean |
verifyDefinitionLocation(Collection<IDInstruction> usingInstructions, Map<IDInstruction, Map<Integer, List<IDInstruction>>> dict_full_ud_chains, int reg, IDInstruction wanted_defloc)
DFA utility method: check whether a register, used in multiple places, was defined by a
single instruction.
| ||||||||||
static boolean |
verifyDefinitionLocation(Map<Integer, ? extends Collection<IDInstruction>> full_ud_chains, int reg, IDInstruction wanted_defloc)
DFA utility method.
| ||||||||||
static boolean |
verifyDefinitionLocation(Map<Integer, ? extends Collection<IDInstruction>> full_ud_chains, Set<Integer> registers, IDInstruction wanted_defloc)
DFA utility method.
| ||||||||||
static boolean |
verifyDefinitionWithSingleImm(Map<Integer, ? extends Collection<IDInstruction>> full_ud_chains, Collection<Integer> regs, IDImm[] aimm)
DFA utility method.
| ||||||||||
static void |
verifyGraph(IDMethodContext ctx, String info)
Verify an IR-CFG.
| ||||||||||
static void |
verifyGraph(CFG<IDInstruction> cfg, IDTryData exdata, String dumpFilename, String info)
Verify an IR-CFG.
| ||||||||||
static void |
verifyGraph(IDMethodContext ctx)
Verify an IR-CFG.
| ||||||||||
static void |
verifyGraph(IDMethodContext ctx, String dumpFilename, String info)
Verify an IR-CFG.
| ||||||||||
static boolean |
verifySingleDefinitionLocation(Map<Integer, ? extends Collection<IDInstruction>> full_ud_chains, int reg, IDInstruction[] aloc)
DFA utility method: check whether a register, used somewhere, was defined by a single
instruction.
| ||||||||||
static boolean |
verifySingleDefinitionLocation(Map<Integer, ? extends Collection<IDInstruction>> full_ud_chains, Collection<Integer> regs, IDInstruction[] aloc)
DFA utility method.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Check for instruction matching in the provided block. The block must be fully matched.
Check for instruction matching in a sequence of blocks. Blocks must be fully contiguous and
fully matched.
This is an extended version of #checkBlock(BasicBlock, DOpcodeType...), which
performs matching on a single block.
Count the number of occurrences of a given variable in the provided IR expression.
Dump an IR-CFG to a Graphviz dot
file in the user's temporary folder.
Dump an IR-CFG to a Graphviz dot
file in the user's temporary folder.
Determine the aggregated context type of an instruction.
insn | instruction |
---|---|
inclAssigDst | if true and the instruction is an assignment, the destination is included when calculated the CAT; else, the right-side only is considered |
Get the list of reachable blocks of the provided IR-CFG. They are the blocks that can be reached, regularly or irregularly, from the entry-point block (i.e. the first block, at offset 0).
Determine whether the IR expression makes invocations (general invocations, new, new-array).
Determine whether the provided expression contains variables
.
Determine whether the provided field is or appears to be final
.
This heuristic determines whether the right-hand side of the instruction (the 'source', in the case of an assignment) may have side-effects, i.e. whether it may modify the program state or alter its execution flow in unexpected ways.
This heuristic determines whether the provided expression may have side-effects, i.e. whether it may modify the program state or alter its execution flow in unexpected ways.
includeCanThrow | if false, this heuristic attempts to consider code that _may_ raise exceptions as side-effect-free |
---|
This heuristic determines whether the provided expression may possibly throw.
Remove all gaps from the provided IR-CFG.
Gaps are illegal in an IR-CFG. They are tolerated during an optimization phase; however, an optimizer, or any code modifying the IR, must provide a legal IR to subsequent components.
Remove unreachable blocks from an IR-CFG. They are blocks that cannot be reached, regularly or irregularly, from the entry-point block (i.e. the first block, at offset 0).
Unreachable blocks are illegal in an IR-CFG. They are tolerated during an optimization phase; however, an optimizer, or any code modifying the IR, must provide a legal IR to subsequent components.
Remove unreachable blocks from an IR-CFG. They are blocks that cannot be reached, regularly or irregularly, from the entry-point block (i.e. the first block, at offset 0).
Unreachable blocks are illegal in an IR-CFG. They are tolerated during an optimization phase; however, an optimizer, or any code modifying the IR, must provide a legal IR to subsequent components.
Remove blocks not reachable from the entry block (first block) of a CFG.
tbr | list of blocks to be removed: can be a bootstrap list of a full list, it doesn't matter (the impl. will take care of removing all related, unreachable blocks) |
---|---|
ex | optional exception data |
Simply DOpcodeType#JCOND and IR_SWITCH
IR instructions:
- JCOND: the target branch must not point to the fallthrough instruction; if it is, the JCOND
must be replaced by a JUMP (while taking care of potential side-effects introduced by the
evaluation of the JCOND predicate)
- SWITCH: the case targets must not point to the fallthrough instruction; if any does, the
case entry must be removed (and will be taken care by the switch's default
entry)
Illegal JCOND/SWITCH are tolerated during an optimization phase; however, an optimizer, or any code modifying the IR, must provide a legal IR to subsequent components.
Unprotect a basic block. The CFG is adjusted cleaned afterward.
blkAddress | block address |
---|
Determine whether the IR expression uses references, defined as any of: accessing fields, accessing array elements, creating arrays.
DFA utility method: check whether a register, used in multiple places, was defined by a single instruction.
usingInstructions | a list of instructions using `reg` |
---|---|
dict_full_ud_chains | dictionary of UD chains (provided by a DFA object) |
reg | a register id |
wanted_defloc | the requested definition instruction (null means defined as a method input variable) |
DFA utility method.
DFA utility method.
DFA utility method.
Verify an IR-CFG.
RuntimeException (or derived, such as IllegalArgumentException or IllegalStateException) if the IR and/or the CFG failed verification |
Verify an IR-CFG.
RuntimeException (or derived, such as IllegalArgumentException or IllegalStateException) if the IR and/or the CFG failed verification |
Verify an IR-CFG.
ctx | method context |
---|
RuntimeException (or derived, such as IllegalArgumentException or IllegalStateException) if the IR and/or the CFG failed verification |
Verify an IR-CFG.
RuntimeException (or derived, such as IllegalArgumentException or IllegalStateException) if the IR and/or the CFG failed verification |
DFA utility method: check whether a register, used somewhere, was defined by a single instruction.
full_ud_chains | UD chains at a given instruction |
---|---|
reg | a register id |
aloc | output sink (the result stored may be null, representing the a method input variable) |
DFA utility method.