Skip to content

Commit

Permalink
feat: give ability to plugins to edit blocks before locking (PR #2336)
Browse files Browse the repository at this point in the history
Plugins can use `.before('BlockFinisher')` to edit blocks before they are locked.
  • Loading branch information
eybisi authored Nov 2, 2024
1 parent 57238de commit 4c74e8e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions jadx-core/src/main/java/jadx/core/Jadx.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import jadx.core.dex.visitors.ShadowFieldVisitor;
import jadx.core.dex.visitors.SignatureProcessor;
import jadx.core.dex.visitors.SimplifyVisitor;
import jadx.core.dex.visitors.blocks.BlockFinisher;
import jadx.core.dex.visitors.blocks.BlockProcessor;
import jadx.core.dex.visitors.blocks.BlockSplitter;
import jadx.core.dex.visitors.debuginfo.DebugInfoApplyVisitor;
Expand Down Expand Up @@ -131,6 +132,7 @@ public static List<IDexTreeVisitor> getRegionsModePasses(JadxArgs args) {
// blocks IR
passes.add(new BlockSplitter());
passes.add(new BlockProcessor());
passes.add(new BlockFinisher());
if (args.isRawCFGOutput()) {
passes.add(DotGraphVisitor.dumpRaw());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package jadx.core.dex.visitors.blocks;

import jadx.core.dex.attributes.AFlag;
import jadx.core.dex.nodes.MethodNode;
import jadx.core.dex.visitors.AbstractVisitor;

public class BlockFinisher extends AbstractVisitor {
@Override
public void visit(MethodNode mth) {
if (mth.isNoCode() || mth.getBasicBlocks().isEmpty()) {
return;
}
if (!mth.contains(AFlag.DISABLE_BLOCKS_LOCK)) {
mth.finishBasicBlocks();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ private static void processBlocksTree(MethodNode mth) {
PostDominatorTree.compute(mth);

updateCleanSuccessors(mth);
if (!mth.contains(AFlag.DISABLE_BLOCKS_LOCK)) {
mth.finishBasicBlocks();
}
}

static void updateCleanSuccessors(MethodNode mth) {
Expand Down

0 comments on commit 4c74e8e

Please sign in to comment.