Class CFG<InsnType extends ILocatedInstruction>
- Type Parameters:
InsnType- the located instruction type, Dalvik instruction or IR instruction
- All Implemented Interfaces:
IControlFlowGraph<InsnType,,BasicBlock<InsnType>> Iterable<BasicBlock<InsnType>>
instructions. It is used by the Android
plugins specifically, including dexdec. (The native code analysis pipeline, including
gendec, use another class of CFG components.)
This class provides Data Flow Analysis support. A client can request simple and full def-use- and use-def chains. Full chains contain more precise cross-block information. Reach-chains are also available.
There are two ways to build a CFG:
- By using the
CFG(Collection)constructor with a list ofbuildGraph(List, List)with a list ofpre-basic blocks. - By calling the
CFG(List, List)constructor and passing a flat list of instructions.
NOTE: This class is to be used exclusively by the Android components.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final AtomicIntegerPerformance counter reserved for internal use. -
Constructor Summary
ConstructorsConstructorDescriptionShallow duplication of the current CFG.CFG(Collection<BasicBlockBuilder<InsnType>> builders) Create a CFG using a pre-computed list of partial basic block.CFG(List<InsnType> insns, List<IrregularFlowData> irrdata) Create a CFG by recursively parsing a list of instructions. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBlock(int index, BasicBlock<InsnType> b) Insert a block, does nothing else.voidAdd a block, does nothing else.booleanaddEdge(BasicBlock<InsnType> x, BasicBlock<InsnType> y) Append an out-edge.intaddEdge(BasicBlock<InsnType> x, BasicBlock<InsnType> y, int index) Add an out-edge.booleanConnect (irregularly) a source block to destination block.intaddIrregularEdge(BasicBlock<InsnType> x, BasicBlock<InsnType> y, int index) Connect (irregularly) a source block to destination block.Get an instruction-with-address iterator.booleancontainsInstruction(InsnType targetInsn) Determine whether the CFG contains the provided instruction.Create an unmanaged data flow analysis object initialized with this CFG's DFA settings.booleandeleteEdge(BasicBlock<InsnType> x, BasicBlock<InsnType> y) Delete an edge x->y.intdeleteEdge(BasicBlock<InsnType> x, BasicBlock<InsnType> y, int xToYPos) Delete an edge x->y.intdeleteEdges(BasicBlock<InsnType> x, BasicBlock<InsnType> y) Delete all regular edges from one block to another.booleanDelete an irregular edge x->y.intdeleteIrregularEdge(BasicBlock<InsnType> x, BasicBlock<InsnType> y, int xToYPos) Delete an irregular edge x->y.intDelete all irregular edges from one block to another.voidDelete all irregular output edges for the provided block.voidDelete all regular output edges for the provided block.Create or retrieve a DFA object with current settings.doDataFlowAnalysis(boolean redo) Create or retrieve a DFA object with current settings.doDataFlowAnalysis(boolean redo, int varCollectionFlags, boolean integrateCalculatedInputRegisters) Create or retrieve a DFA object.format()Format the CFG into a printable string.Format the CFG into a printable string.Format the edges of this CFG to a string.(Re-)generate the irregular control flow information present in this CFG.get(int index) Retrieve a basic block.Get a complete map of the basic blocks and their addresses in the CFG.getBlock(int index) Get a basic block.getBlockAt(long address) Get the basic block that starts at the provided address or offset.getBlockByLastAddress(long lastAddress) Get the basic block whose last address is the provided address.getBlockContaining(long address) Get the basic block that contains the provided address.getBlockEndingAt(long address) Get the basic block that ends on the provided address.getBlockFor(InsnType insn) Search an instruction by reference.intgetBlockIndex(long address) Get the index of the basic block starting at the provided address.Get a copy of the block list of the CFG.Get a read-only view of the list of blocks for this CFG.Retrieve a list of all managed data flow analysis objects.Retrieve a valid DFA object done with standard parameters (conservative, with inputs, no copies).getDataFlowAnalysis(int varCollectionFlags, boolean integrateCalculatedInputRegisters) Retrieve a valid DFA object matching the provided parameters.intNote that the initial value is set toIDFA.STANDARD_COLLECTION_FLAGS.intCalculate the 'effective' size of this CFG, that is, the sum of the size of each basic block.longRoutine highest address (exclusive).longRoutine entry-point address.Get the entry block.Get the ordered list of exit blocks.longRoutine lowest address (inclusive).voidgetGraphRepresentation(List<int[]> edges, List<int[]> irregularEdges) Get the a graph representation of the CFG.getInstruction(long address) Get the instruction located at the exact address.getInstructionAt(long address) Get the instruction located at the provided address.intGet the total number of instructions in the CFG.getInstructionLocation(long address) Locate an instruction.getInstructionLocation(long address, boolean precise) Locate an instruction.Get the instruction list of this CFG by aggregating each instruction of every block.Retrieve an ordered dictionary of instructions.getLast()Get the last block.longRoutine highest address (inclusive).Get the variable information provider used by data-flow analyses.handlers()Iterate over exception handler blocks.booleanhasExit()Determine if this CFG has exit blocks, that is, blocks without out-edges.booleanDetermine if this CFG does not have any exit block.intGet the index of a basic block.Get an instruction iterator.instructions(long fromAddress) Iterate over a range of instructions of this CFG.voidInvalidate all previously performed data flow analyses.voidinvalidateDataFlowAnalysis(long addressOfInstructionChange) Partially invalidate data flow analyses.booleanNote that the initial value is set toIDFA.STANDARD_INTEGRATE_INPUTS.iterator()intreconnectEdge(BasicBlock<InsnType> x, BasicBlock<InsnType> y, BasicBlock<InsnType> z) This method reconnects a block x from y to z, i.e.intreconnectEdge(BasicBlock<InsnType> x, BasicBlock<InsnType> y, BasicBlock<InsnType> z, Integer xToYPos) This method reconnects a block x from y to z, i.e.intreconnectEdges(BasicBlock<InsnType> x, BasicBlock<InsnType> y, BasicBlock<InsnType> z) Reconnect all regular edges from one destination to another.intThis method irregularly reconnects a block x from y to z, i.e.intreconnectIrregularEdge(BasicBlock<InsnType> x, BasicBlock<InsnType> y, BasicBlock<InsnType> z, Integer xToYPos) This method irregularly reconnects a block x from y to z, i.e.intReconnect all irregular edges from one destination to another.voidRemove a block (preferably empty) and update the fixtures.booleanRemove a block (preferably empty) and update the fixtures.intRemove duplicate edges (regular) from a source block to a destination block.intRemove duplicate irregular edges from a source block to a destination block.intReorganize the input block list so that the fallthrough input block, if any, is placed first.replaceInstruction(long address, InsnType insn) Replace an instruction.booleanreplaceInstructionsInBlock(long address, int cnt, Collection<InsnType> insns) Replace a sequence of instructions contained in a single basic block.intsetDFADefaultCollectionFlags(int collectionFlags) Note that the initial value is set toIDFA.STANDARD_COLLECTION_FLAGS.booleansetDFADefaultIntegrateInputs(boolean integrateInputs) Note that the initial value is set toIDFA.STANDARD_INTEGRATE_INPUTS.Set the variable information provider used by data-flow analyses.intsimplify()Merge the blocks that can be merged, without changing the flow of the graph.intMerge blocks that can be merged, taking into accounts irregular flows.
A follow through may be merged with a block inside a try (with irregular outedges) if no instruction within the block can raise.intsize()Get the number of blocks.splitBlock(BasicBlock<InsnType> b, int index) Split a block into two blocks.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
cfgfwccnt
Performance counter reserved for internal use.
-
-
Constructor Details
-
CFG
Create a CFG using a pre-computed list of partial basic block.- Parameters:
builders- pre-computed basic block builders
-
CFG
Create a CFG by recursively parsing a list of instructions.- Parameters:
insns- list of instructions to be processedirrdata- (optional) irregular flow information, used for exception support
-
CFG
Shallow duplication of the current CFG. The graph is reconstructed; the instructions are not duplicated.- Parameters:
cfg- source graph
-
-
Method Details
-
get
Description copied from interface:IControlFlowGraphRetrieve a basic block.- Specified by:
getin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Parameters:
index- block index- Returns:
- basic block
-
indexOf
Description copied from interface:IControlFlowGraphGet the index of a basic block.- Specified by:
indexOfin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Parameters:
b- basic block- Returns:
- block index, or -1
-
getLast
Description copied from interface:IControlFlowGraphGet the last block.- Specified by:
getLastin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Returns:
- last block
-
size
public int size()Description copied from interface:IControlFlowGraphGet the number of blocks.- Specified by:
sizein interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Returns:
- block count
-
getEntryAddress
public long getEntryAddress()Description copied from interface:IControlFlowGraphRoutine entry-point address. Note that this address may not be the lowest one in the CFG.- Specified by:
getEntryAddressin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Returns:
- the address of the entry block
-
getFirstAddress
public long getFirstAddress()Description copied from interface:IControlFlowGraphRoutine lowest address (inclusive). Note that this address may not be the entry-point address for this routine.- Specified by:
getFirstAddressin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Returns:
- first address
-
getLastAddress
public long getLastAddress()Description copied from interface:IControlFlowGraphRoutine highest address (inclusive).- Specified by:
getLastAddressin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Returns:
- last address
-
getEndAddress
public long getEndAddress()Description copied from interface:IControlFlowGraphRoutine highest address (exclusive).- Specified by:
getEndAddressin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Returns:
- end address
-
getEffectiveSize
public int getEffectiveSize()Description copied from interface:IControlFlowGraphCalculate the 'effective' size of this CFG, that is, the sum of the size of each basic block.- Specified by:
getEffectiveSizein interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Returns:
- the CFG size
-
getBlock
Description copied from interface:IControlFlowGraphGet a basic block.- Specified by:
getBlockin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Parameters:
index- block index- Returns:
- basic block
-
getBlocks
Description copied from interface:IControlFlowGraphGet a copy of the block list of the CFG. The list is ordered by ascending block address. Modifying the list does not impact the CFG.- Specified by:
getBlocksin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Returns:
- a copy of the list of blocks
-
getBlocksView
Description copied from interface:IControlFlowGraphGet a read-only view of the list of blocks for this CFG. The list is ordered by ascending block address.- Specified by:
getBlocksViewin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Returns:
- the list of blocks
-
getBlockAt
Description copied from interface:IControlFlowGraphGet the basic block that starts at the provided address or offset.- Specified by:
getBlockAtin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Parameters:
address- the block address/offset- Returns:
- basic block, or null if none starts at that address
-
getBlockIndex
public int getBlockIndex(long address) Get the index of the basic block starting at the provided address.- Parameters:
address- block start address- Returns:
- the block index, or -1 if none starts at the address
-
getBlockEndingAt
Description copied from interface:IControlFlowGraphGet the basic block that ends on the provided address.- Specified by:
getBlockEndingAtin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Parameters:
address- wanted block end address (exclusive)- Returns:
- basic block, or null if none ends at that address
-
getBlockContaining
Description copied from interface:IControlFlowGraphGet the basic block that contains the provided address.Note that the address just needs to be in the block address range; it does not need to point to the beginning of an instruction within the block
- Specified by:
getBlockContainingin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Parameters:
address- an address within the block- Returns:
- containing block, or null
-
getEntryBlock
Description copied from interface:IControlFlowGraphGet the entry block. The entry block is unique.- Specified by:
getEntryBlockin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Returns:
- never null; the method throws on error
-
getExitBlocks
Description copied from interface:IControlFlowGraphGet the ordered list of exit blocks. A CFG may have zero or more exit blocks; CFG representing standard routines will have at least one (generally one) exit block.- Specified by:
getExitBlocksin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Returns:
- a collection of blocks, possibly empty
-
getBlockByLastAddress
Description copied from interface:IControlFlowGraphGet the basic block whose last address is the provided address.- Specified by:
getBlockByLastAddressin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Parameters:
lastAddress- last instruction address- Returns:
- basic block, or null
-
hasExit
public boolean hasExit()Determine if this CFG has exit blocks, that is, blocks without out-edges.- Returns:
- true if at least one exit block exists
-
hasNoExit
public boolean hasNoExit()Determine if this CFG does not have any exit block.- Returns:
- true if no exit block exists
-
getAddressBlockMap
Get a complete map of the basic blocks and their addresses in the CFG. This method is recommended for use when multiple, repeated invocations ofgetBlockAt(int)are to be made.- Returns:
- a map of address->block
-
getBlockFor
Search an instruction by reference. This method's performance is sub-optimal.This method is not the same as
getBlockAt(insn.getOffset()).- Parameters:
insn- instruction reference- Returns:
- containing block, or null if the instruction is not part of this CFG
-
getInstructionCount
public int getInstructionCount()Description copied from interface:IControlFlowGraphGet the total number of instructions in the CFG. This method sums the number of instructions of each block of the CFG.- Specified by:
getInstructionCountin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Returns:
- instruction count
-
getInstructionAt
Get the instruction located at the provided address.- Parameters:
address- instruction address- Returns:
- the instruction, or null if none is located at the address
-
getInstruction
Description copied from interface:IControlFlowGraphGet the instruction located at the exact address.- Specified by:
getInstructionin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Parameters:
address- instruction address- Returns:
- an instruction, null if none
-
getInstructionLocation
Description copied from interface:IControlFlowGraphLocate an instruction.- Specified by:
getInstructionLocationin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Parameters:
address- instruction address- Returns:
- a couple (basic block, instruction index within that block); null on error
-
getInstructionLocation
Locate an instruction.- Parameters:
address- instruction addressprecise- if true, the instruction is expected to start at the provided address; else, the provided address may address any byte of the instruction- Returns:
- a couple (basic block, instruction index within that block); null on error
-
containsInstruction
Determine whether the CFG contains the provided instruction.- Parameters:
targetInsn- instruction- Returns:
- true if the instruction is part of the graph
-
getInstructions
Description copied from interface:IControlFlowGraphGet the instruction list of this CFG by aggregating each instruction of every block. The list is ordered by ascending address/offset.- Specified by:
getInstructionsin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Returns:
- instruction list
-
getInstructionSet
Retrieve an ordered dictionary of instructions.- Returns:
- key= offset, value= instruction at offset
-
iterator
- Specified by:
iteratorin interfaceIterable<InsnType extends ILocatedInstruction>
-
instructions
Description copied from interface:IControlFlowGraphGet an instruction iterator. Also seeIControlFlowGraph.addressableInstructions().- Specified by:
instructionsin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Returns:
- an iterator (not supporting
remove)
-
instructions
Iterate over a range of instructions of this CFG.- Parameters:
fromAddress- exact address of the first instruction to be iterated over- Returns:
- iterable over instructions starting at the requested address
-
addressableInstructions
Description copied from interface:IControlFlowGraphGet an instruction-with-address iterator. Also seeIControlFlowGraph.instructions().- Specified by:
addressableInstructionsin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Returns:
- an iterator (not supporting
remove)
-
handlers
Iterate over exception handler blocks.- Returns:
- iterable over handler blocks
-
getGraphRepresentation
Description copied from interface:IControlFlowGraphGet the a graph representation of the CFG. The list of edges use a 1-based node numbering scheme.- Specified by:
getGraphRepresentationin interfaceIControlFlowGraph<InsnType extends ILocatedInstruction,BasicBlock<InsnType extends ILocatedInstruction>> - Parameters:
edges- (output) array of regular edges, eg: {{1,2},{1,3},{2,3}}irregularEdges- (output) array of irregular edges
-
generateIrregularFlowDataObjects
(Re-)generate the irregular control flow information present in this CFG.- Returns:
- generated irregular flow data objects
-
simplify
public int simplify()Merge the blocks that can be merged, without changing the flow of the graph.Necessary conditions include: adjacent blocks, first block falls-through the second one, no block shall have irregular outputs, only the first block may have irregular inputs.
- Returns:
- number of mergers
-
simplifyIrregularFlows
public int simplifyIrregularFlows()Merge blocks that can be merged, taking into accounts irregular flows.
A follow through may be merged with a block inside a try (with irregular outedges) if no instruction within the block can raise.- Returns:
- the number of simplifications performed
-
reorganizeInputs
public int reorganizeInputs()Reorganize the input block list so that the fallthrough input block, if any, is placed first.- Returns:
- the number of reorganizations
-
removeBlockSafe
Remove a block (preferably empty) and update the fixtures. This method is content-agnostic (it does not examine the instructions of the blocks). This method returns false on failure.See
removeBlock(BasicBlock)for full javadoc.- Parameters:
b- block to be removed- Returns:
- success indicator
-
removeBlock
Remove a block (preferably empty) and update the fixtures. This method is content-agnostic (it does not examine the instructions of the blocks). This method throwsIllegalStateExceptionon error.Context: a CFG should never contain empty blocks. However, when the CFG is optimized, instructions are removed, and some nodes might end up empty. This transient, stale state is fine as long as the client knows what it is doing and removes the empty block as soon as they're done, before passing it down the processing chain. This method removes empty blocks and updates the edges of connected and connecting blocks. Caveats:
- 1) The block must be disconnected from the graph or it must have an out-degree or in-degree of one, to enable its reconnection. (Otherwise, stitching up the edges would not be possible.) The block must not contain irregular inputs. The block should not contain irregular outputs, as they will be discarded upon removal.
- 2) Duplicate edges can be introduced. The client should remove them if it doesn't like that.
- 3) The fixtures update is instruction-agnostic. This means that the client is solely responsible regarding the decision to remove an empty block. For instance, the last instruction of the predecessor block should be checked and the client should make sure that removing the block and updating the fixtures is an operation compatible with the semantics of that last instruction.
- Parameters:
b- block to be removed
-
splitBlock
Split a block into two blocks. Note that the newly-created block will be set up to have the same irregular outputs as the original block.- Parameters:
b- block to splitindex- index of the "split instruction" in the block; that instruction will be the first instruction of the newly-created block- Returns:
- the newly-created block
-
addBlock
Insert a block, does nothing else. The block is not connected, it is up to client code to connect it.- Parameters:
index- insertion index; negative values are relative to the end of the block listb- block to insert
-
addBlock
Add a block, does nothing else. The block is not connected, it is up to client code to connect it.- Parameters:
b- block to add
-
addEdge
Append an out-edge. Duplicates are not allowed.- Parameters:
x- source blocky- destination block- Returns:
- true if an edge was added, false if one already existed
-
addEdge
Add an out-edge. Duplicates are allowed.- Parameters:
x- source blocky- destination blockindex- position (negative index is allowed, e.g. -1 means append last)- Returns:
- the updated number of edges x->y
-
addIrregularEdge
Connect (irregularly) a source block to destination block. This method does NOT allow the addition of duplicate connections.This method should not be used. Use
addIrregularEdge(BasicBlock, BasicBlock, int)instead.- Parameters:
x- source blocky- destination block- Returns:
- true if an edge was added, false if one already existed
-
addIrregularEdge
Connect (irregularly) a source block to destination block. This method allows the addition of duplicate connections.- Parameters:
x- source blocky- destinationindex- out-irr.edge index (negative indices can be used; e.g. -1 means append)- Returns:
- the updated number of irregular edges x-to-y
-
reconnectEdges
Reconnect all regular edges from one destination to another.- Parameters:
x- source blocky- current destination blockz- new destination block, or null to delete the edges- Returns:
- the number of reconnected edges
-
reconnectEdge
This method reconnects a block x from y to z, i.e. x->y becomes x->z. Duplicates edges are forbidden.See
reconnectEdge(BasicBlock, BasicBlock, BasicBlock, Integer).- Parameters:
x- source blocky- current destination blockz- new destination block, or null to delete the edge- Returns:
- the number of reconnected edges
-
reconnectEdge
public int reconnectEdge(BasicBlock<InsnType> x, BasicBlock<InsnType> y, BasicBlock<InsnType> z, Integer xToYPos) This method reconnects a block x from y to z, i.e. x->y becomes x->z. If z is null, this method deletes the edge x>y.- Parameters:
x- source blocky- original destination blockz- new destination block; null to indicate that the edge x>y should be deletedxToYPos- optional index specifying which x>y edge (if there are more than one) should be picked (this index is not an index into the full out-list of x); if null, this method will fail on duplicate edges (see return codes)- Returns:
- +1: success
0: failure, x->y does not exist
-1: failure, a edge x->z already exists, and duplicate edges are never allowed
-2: failure, multiple edges x->y were found
-
removeDuplicateEdges
Remove duplicate edges (regular) from a source block to a destination block.- Parameters:
x- src blocky- dst block- Returns:
- the number of duplicate edges removed; -1 if no such edge exists
-
removeDuplicateIrregularEdges
Remove duplicate irregular edges from a source block to a destination block.- Parameters:
x- src blocky- dst block- Returns:
- the number of duplicate edges removed; -1 if no such edge exists
-
reconnectIrregularEdges
public int reconnectIrregularEdges(BasicBlock<InsnType> x, BasicBlock<InsnType> y, BasicBlock<InsnType> z) Reconnect all irregular edges from one destination to another.- Parameters:
x- source blocky- current destination blockz- new destination block, or null to delete the edges- Returns:
- the number of reconnected irregular edges
-
reconnectIrregularEdge
public int reconnectIrregularEdge(BasicBlock<InsnType> x, BasicBlock<InsnType> y, BasicBlock<InsnType> z) This method irregularly reconnects a block x from y to z, i.e. x->y becomes x->z. Duplicates edges are forbidden.See
reconnectIrregularEdge(BasicBlock, BasicBlock, BasicBlock, Integer).- Parameters:
x- source blocky- current destination blockz- new destination block, or null to delete the edge- Returns:
- the number of reconnected irregular edges
-
reconnectIrregularEdge
public int reconnectIrregularEdge(BasicBlock<InsnType> x, BasicBlock<InsnType> y, BasicBlock<InsnType> z, Integer xToYPos) This method irregularly reconnects a block x from y to z, i.e. x->y becomes x->z. If z is null, this method deletes the irregular edge x>y.- Parameters:
x- source blocky- original destination blockz- new destination block; null to indicate that the irregular edge x>y should be deletedxToYPos- optional index specifying which x>y irregular edge (if there are more than one) should be picked (this index is not an index into the full irrout-list of x); if null, this method will fail on duplicate irregular edges (see return codes); a negative index can be used to specify a block starting from the list's end (e.g. -2 will mean the second-to-last destination y)- Returns:
- +1: success
0: failure, x->y does not exist
-1: failure, a edge x->z already exists, and duplicate irregular edges are never allowed
-2: failure, multiple irregular edges x->y were found
-
deleteEdges
Delete all regular edges from one block to another.- Parameters:
x- source blocky- destination block- Returns:
- the number of deleted edges
-
deleteEdge
Delete an edge x->y. If duplicates exist, the first one in the list of out-edges is deleted.- Parameters:
x- source blocky- destination block- Returns:
- true if x->y existed and was deleted
-
deleteEdge
Delete an edge x->y.- Parameters:
x- source blocky- destination blockxToYPos- position of the edge to delete among duplicate edges- Returns:
- the number of deleted edges
-
deleteIrregularEdges
Delete all irregular edges from one block to another.- Parameters:
x- source blocky- destination block- Returns:
- the number of deleted irregular edges
-
deleteIrregularEdge
Delete an irregular edge x->y. If duplicates exist, the first one in the list of irrout-edges is deleted.- Parameters:
x- source blocky- destination block- Returns:
- true if x->y existed and was deleted
-
deleteIrregularEdge
Delete an irregular edge x->y.- Parameters:
x- source blocky- destination blockxToYPos- position of the edge to delete among duplicate irregular edges- Returns:
- the number of deleted irregular edges
-
deleteOutEdges
Delete all regular output edges for the provided block.- Parameters:
b- block
-
deleteIrregularOutEdges
Delete all irregular output edges for the provided block.- Parameters:
b- block
-
replaceInstruction
Replace an instruction. An existing instruction must exist at the provided address. No adjustment is done (eg, the replaced instruction size is not modified). It is up to the caller to adjust the instruction in order to keep a valid CFG object.- Parameters:
address- the target addressinsn- the instruction that will replace the instruction at the provided address- Returns:
- null on error, else the instruction that was replaced
-
replaceInstructionsInBlock
Replace a sequence of instructions contained in a single basic block.- Parameters:
address- start address for replacementcnt- number of instructions to be replacedinsns- new instructions; the total size must be equal to the size of the instructions being replaced- Returns:
- success indicator
-
setVariableInformationProvider
public IVariableInformationProvider setVariableInformationProvider(IVariableInformationProvider prv) Set the variable information provider used by data-flow analyses.- Parameters:
prv- provider to set, or null to clear it- Returns:
- the previously set provider, or null if none was set
-
getVariableInformationProvider
Get the variable information provider used by data-flow analyses.- Returns:
- the current provider, or null if none is set
-
setDFADefaultCollectionFlags
public int setDFADefaultCollectionFlags(int collectionFlags) Note that the initial value is set toIDFA.STANDARD_COLLECTION_FLAGS.- Parameters:
collectionFlags- new default collection flags- Returns:
- the previously set value
-
getDFADefaultCollectionFlags
public int getDFADefaultCollectionFlags()Note that the initial value is set toIDFA.STANDARD_COLLECTION_FLAGS.- Returns:
- current default collection flags
-
setDFADefaultIntegrateInputs
public boolean setDFADefaultIntegrateInputs(boolean integrateInputs) Note that the initial value is set toIDFA.STANDARD_INTEGRATE_INPUTS.- Parameters:
integrateInputs- true to integrate calculated input registers by default- Returns:
- the previously set value
-
isDFADefaultIntegrateInputs
public boolean isDFADefaultIntegrateInputs()Note that the initial value is set toIDFA.STANDARD_INTEGRATE_INPUTS.- Returns:
- current default input integration setting
-
getCurrentDFAs
Retrieve a list of all managed data flow analysis objects.- Returns:
- list of current managed data flow analysis objects
-
doDataFlowAnalysis
Create or retrieve a DFA object with current settings.- Returns:
- a DFA object
-
doDataFlowAnalysis
Create or retrieve a DFA object with current settings.- Parameters:
redo- if true, force a new analysis even if one is not required- Returns:
- a DFA object
-
doDataFlowAnalysis
public IDFA<InsnType> doDataFlowAnalysis(boolean redo, int varCollectionFlags, boolean integrateCalculatedInputRegisters) Create or retrieve a DFA object.- Parameters:
redo- if true, force a new analysis even if one is not requiredvarCollectionFlags- variable collection flagsintegrateCalculatedInputRegisters- if true, the live registers determined after analysis will be integrated in the use-def chains- Returns:
- a DFA object
-
getDataFlowAnalysis
Retrieve a valid DFA object done with standard parameters (conservative, with inputs, no copies).- Returns:
- a DFA object, null if no valid matching DFA object is retrieved
-
getDataFlowAnalysis
public IDFA<InsnType> getDataFlowAnalysis(int varCollectionFlags, boolean integrateCalculatedInputRegisters) Retrieve a valid DFA object matching the provided parameters.- Parameters:
varCollectionFlags- variable collection flagsintegrateCalculatedInputRegisters- if true, the live registers determined after analysis will be integrated in the use-def chains- Returns:
- a DFA object, null if no valid matching DFA object is retrieved
-
createDataFlowAnalysisHelperObject
Create an unmanaged data flow analysis object initialized with this CFG's DFA settings. These objects are not managed by this CFG object. For managed DFA objects, clients should usedoDataFlowAnalysis()or#getDataFlowAnalysis().- Returns:
- new unmanaged data flow analysis helper object
-
invalidateDataFlowAnalysis
public void invalidateDataFlowAnalysis()Invalidate all previously performed data flow analyses. This method can be used after a CFG modification that would render DFA objects obsoletes. -
invalidateDataFlowAnalysis
public void invalidateDataFlowAnalysis(long addressOfInstructionChange) Partially invalidate data flow analyses. This method can be used after modifying an instruction of the CFG.- Parameters:
addressOfInstructionChange- address
-
format
Format the CFG into a printable string. Instruction addresses are included, edges are appended to the CFG.- Returns:
- formatted CFG string
-
format
Format the CFG into a printable string.- Parameters:
format_addresses- true to prepend instructions by their addressesformat_edgelists- true to append the explicit list of edges to the CFGcontext- optional formatting context- Returns:
- formatted CFG string
-
formatEdges
Format the edges of this CFG to a string.- Returns:
- a two-line string with the list of regular edges and irregular edges
-
toString
-