fix: handle methods with all NOPs (#744)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package jadx.core.dex.attributes;
|
||||
|
||||
public enum AFlag {
|
||||
MTH_ENTER_BLOCK,
|
||||
TRY_ENTER,
|
||||
TRY_LEAVE,
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public class BlockProcessor extends AbstractVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(MethodNode mth) {
|
||||
if (mth.isNoCode()) {
|
||||
if (mth.isNoCode() || mth.getBasicBlocks().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
processBlocksTree(mth);
|
||||
|
||||
@@ -77,6 +77,7 @@ public class BlockSplitter extends AbstractVisitor {
|
||||
InsnNode prevInsn = null;
|
||||
Map<Integer, BlockNode> blocksMap = new HashMap<>();
|
||||
BlockNode curBlock = startNewBlock(mth, 0);
|
||||
curBlock.add(AFlag.MTH_ENTER_BLOCK);
|
||||
mth.setEnterBlock(curBlock);
|
||||
|
||||
// split into blocks
|
||||
@@ -331,7 +332,8 @@ public class BlockSplitter extends AbstractVisitor {
|
||||
static boolean removeEmptyDetachedBlocks(MethodNode mth) {
|
||||
return mth.getBasicBlocks().removeIf(block -> block.getInstructions().isEmpty()
|
||||
&& block.getPredecessors().isEmpty()
|
||||
&& block.getSuccessors().isEmpty());
|
||||
&& block.getSuccessors().isEmpty()
|
||||
&& !block.contains(AFlag.MTH_ENTER_BLOCK));
|
||||
}
|
||||
|
||||
private static boolean removeUnreachableBlocks(MethodNode mth) {
|
||||
@@ -385,7 +387,8 @@ public class BlockSplitter extends AbstractVisitor {
|
||||
return block.getInstructions().isEmpty()
|
||||
&& block.isAttrStorageEmpty()
|
||||
&& block.getSuccessors().size() <= 1
|
||||
&& !block.getPredecessors().isEmpty();
|
||||
&& !block.getPredecessors().isEmpty()
|
||||
&& !block.contains(AFlag.MTH_ENTER_BLOCK);
|
||||
}
|
||||
|
||||
private static void collectSuccessors(BlockNode startBlock, Set<BlockNode> toRemove) {
|
||||
|
||||
@@ -39,7 +39,7 @@ public class RegionMakerVisitor extends AbstractVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(MethodNode mth) throws JadxException {
|
||||
if (mth.isNoCode()) {
|
||||
if (mth.isNoCode() || mth.getBasicBlocks().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
RegionMaker rm = new RegionMaker(mth);
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package jadx.tests.integration.others;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
import jadx.tests.api.SmaliTest;
|
||||
|
||||
import static jadx.tests.api.utils.JadxMatchers.containsLines;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
public class TestAllNops extends SmaliTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
disableCompilation();
|
||||
ClassNode cls = getClassNodeFromSmali();
|
||||
String code = cls.getCode().toString();
|
||||
|
||||
assertThat(code, containsLines(1, "private boolean test() {", "}"));
|
||||
assertThat(code, containsLines(1, "private boolean testWithTryCatch() {", "}"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
.class public Lothers/TestAllNops;
|
||||
.super Ljava/lang/Object;
|
||||
|
||||
.method public constructor <init>()V
|
||||
.registers 1
|
||||
|
||||
.line 55
|
||||
nop
|
||||
|
||||
nop
|
||||
|
||||
nop
|
||||
|
||||
nop
|
||||
.end method
|
||||
|
||||
.method private test()Z
|
||||
.registers 11
|
||||
|
||||
.line 1480
|
||||
nop
|
||||
|
||||
nop
|
||||
|
||||
.line 1481
|
||||
nop
|
||||
|
||||
nop
|
||||
|
||||
nop
|
||||
|
||||
nop
|
||||
|
||||
nop
|
||||
|
||||
nop
|
||||
|
||||
.line 1485
|
||||
nop
|
||||
|
||||
nop
|
||||
|
||||
.line 1486
|
||||
nop
|
||||
|
||||
nop
|
||||
|
||||
.line 1487
|
||||
nop
|
||||
|
||||
.end method
|
||||
|
||||
.method private testWithTryCatch()Z
|
||||
.registers 11
|
||||
|
||||
.line 1480
|
||||
:try_start_0
|
||||
nop
|
||||
nop
|
||||
|
||||
.line 1481
|
||||
nop
|
||||
|
||||
nop
|
||||
|
||||
nop
|
||||
|
||||
nop
|
||||
|
||||
nop
|
||||
|
||||
nop
|
||||
|
||||
.line 1485
|
||||
nop
|
||||
|
||||
nop
|
||||
|
||||
:try_end_35
|
||||
.catch Ljava/security/NoSuchAlgorithmException; {:try_start_0 .. :try_end_35} :catch_36
|
||||
|
||||
nop
|
||||
|
||||
.line 1547
|
||||
:catch_36
|
||||
|
||||
nop
|
||||
|
||||
.line 1487
|
||||
nop
|
||||
|
||||
.end method
|
||||
Reference in New Issue
Block a user