Package jadx.core.dex.visitors.finaly
Class MarkFinallyVisitor
java.lang.Object
jadx.core.dex.visitors.AbstractVisitor
jadx.core.dex.visitors.finaly.MarkFinallyVisitor
- All Implemented Interfaces:
IDexTreeVisitor
This visitor is responsible for extracting finally blocks from duplicated instructions located
within the ends of each branch leading to the terminating point of all code paths.
To do this, the terminating point of each handler / exit from try body is found relative to every
other handler / exit from try body. This, in effect, is used to identify the "scopes" of each
possible path within the try block and thus can be used to find a common series of included
blocks
within the "scope" of each handler and a block to start searching from in reverse to find common
instructions between that and the "nominated finally" handler. These groups are described by the
TryEdgeScopeGroupMap object.
After this, the TraverserController is responsible for traversing the block graphs from
each "scope terminus" along the blocks contained with each handlers "scope", comparing them
against
the "nominated finally" block. If the control flow and instructions of each block match, then
they
are added as duplicate instructions. At the end, the visitor will mark the identified duplicated
instructions and identified finally instructions with the respective AFlag to be handled
during regioning of the block graph.-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static booleanattemptRemoveImplicitHandlers(List<BlockNode> cutHandlerBlocks, MarkFinallyVisitor.TryExtractInfo tryInfo) Attempts to identify and remove an implicit try catch block.private static voidcopyCodeVars(InsnArg fromArg, InsnArg toArg) private static voidcopyCodeVars(InsnNode fromInsn, InsnNode toInsn) cutHandlerBlocks(MethodNode mth, MarkFinallyVisitor.TryExtractInfo tryInfo, ExceptionHandler handler) private static booleanextractFinally(MethodNode mth, MarkFinallyVisitor.TryExtractInfo tryInfo) Search and mark common code from 'try' block and 'handlers'.findCommonInsns(MethodNode mth, MarkFinallyVisitor.TryExtractInfo tryInfo) private static List<ExceptionHandler> getHandlersForTryCatch(TryCatchBlockAttr tryBlock) Gets a list of every exception handler attached to this try block, including handlers of inner try blocks.private static @Nullable BlockNodegetTerminusForHandler(ExceptionHandler handler, MarkFinallyVisitor.TryExtractInfo tryInfo) private static @Nullable MarkFinallyVisitor.TryExtractInfogetTryBlockData(MethodNode mth, TryCatchBlockAttr tryBlock) For a given try block, attempts to calculate try block data.private static booleanprocessTryBlock(MethodNode mth, MarkFinallyVisitor.TryExtractInfo tryInfo) Processes a try block, attempting to extract a finally by locating common instruction patterns between all try branches.private static voidremoveEmptyUpPath(List<BlockNode> handlerBlocks, BlockNode startBlock) private static voidresetTryBlocks(MethodNode mth, List<TryCatchBlockAttr> tryBlocks) private static voidReload method without applying this visitorvoidvisit(MethodNode mth) Visit methodMethods inherited from class jadx.core.dex.visitors.AbstractVisitor
getName, init, toString, visit
-
Field Details
-
LOG
private static final org.slf4j.Logger LOG
-
-
Constructor Details
-
MarkFinallyVisitor
public MarkFinallyVisitor()
-
-
Method Details
-
visit
Description copied from interface:IDexTreeVisitorVisit method- Specified by:
visitin interfaceIDexTreeVisitor- Overrides:
visitin classAbstractVisitor
-
resetTryBlocks
-
getTryBlockData
@Nullable private static @Nullable MarkFinallyVisitor.TryExtractInfo getTryBlockData(MethodNode mth, TryCatchBlockAttr tryBlock) For a given try block, attempts to calculate try block data. This includes the handler blocks for each try branch, data regarding the scope of each try branch relative to every other branch, and the blocks logically contained within each try branch. This information is stored via internal class members and is not returned by the function.- Parameters:
mth- The method containing the try block.tryBlock- The try block to determine the scope information of.- Returns:
- The handler identified as the "all" handler.
-
processTryBlock
Processes a try block, attempting to extract a finally by locating common instruction patterns between all try branches.- Parameters:
mth- The method containing the try block.tryInfo- The try block information.- Returns:
- Whether a finally block has been successfully extracted.
-
cutHandlerBlocks
@Nullable private static @Nullable List<BlockNode> cutHandlerBlocks(MethodNode mth, MarkFinallyVisitor.TryExtractInfo tryInfo, ExceptionHandler handler) -
attemptRemoveImplicitHandlers
private static boolean attemptRemoveImplicitHandlers(List<BlockNode> cutHandlerBlocks, MarkFinallyVisitor.TryExtractInfo tryInfo) Attempts to identify and remove an implicit try catch block.- Parameters:
cutHandlerBlocks- The cut handler blocks of the all handler.- Returns:
- Whether the try block is implicit and has been removed.
-
extractFinally
Search and mark common code from 'try' block and 'handlers'. -
getHandlersForTryCatch
Gets a list of every exception handler attached to this try block, including handlers of inner try blocks.- Parameters:
tryBlock- The source try block to get the list of exception handlers for- Returns:
- The list of exception handlers.
-
findCommonInsns
@Nullable private static @Nullable Map<InsnNode,List<InsnNode>> findCommonInsns(MethodNode mth, MarkFinallyVisitor.TryExtractInfo tryInfo) -
removeEmptyUpPath
-
copyCodeVars
-
copyCodeVars
-
undoFinallyVisitor
Reload method without applying this visitor -
getTerminusForHandler
@Nullable private static @Nullable BlockNode getTerminusForHandler(ExceptionHandler handler, MarkFinallyVisitor.TryExtractInfo tryInfo)
-