feat: give ability to plugins to edit blocks before locking (PR #2336)

Plugins can use `.before('BlockFinisher')` to edit blocks before they are locked.
This commit is contained in:
Ahmet Bilal Can 2024-11-03 00:38:57 +03:00 committed by GitHub
parent 57238de6ff
commit 4c74e8e300
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 3 deletions

View File

@ -47,6 +47,7 @@ import jadx.core.dex.visitors.ReplaceNewArray;
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;
@ -131,6 +132,7 @@ public class Jadx {
// blocks IR
passes.add(new BlockSplitter());
passes.add(new BlockProcessor());
passes.add(new BlockFinisher());
if (args.isRawCFGOutput()) {
passes.add(DotGraphVisitor.dumpRaw());
}

View File

@ -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();
}
}
}

View File

@ -92,9 +92,6 @@ public class BlockProcessor extends AbstractVisitor {
PostDominatorTree.compute(mth);
updateCleanSuccessors(mth);
if (!mth.contains(AFlag.DISABLE_BLOCKS_LOCK)) {
mth.finishBasicBlocks();
}
}
static void updateCleanSuccessors(MethodNode mth) {