Skip to content

Commit

Permalink
fix: support instructions removing in SimplifyVisitor
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Jul 13, 2019
1 parent fc58022 commit 2dbdd1f
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions jadx-core/src/main/java/jadx/core/dex/visitors/SimplifyVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,36 @@ public void visit(MethodNode mth) {
return;
}
for (BlockNode block : mth.getBasicBlocks()) {
List<InsnNode> list = block.getInstructions();
for (int i = 0; i < list.size(); i++) {
InsnNode modInsn = simplifyInsn(mth, list.get(i));
if (modInsn != null) {
if (i != 0 && modInsn.contains(AFlag.ARITH_ONEARG)) {

InsnNode mergedNode = simplifyOneArgConsecutive(
list.get(i - 1), list.get(i), (ArithNode) modInsn);

if (mergedNode != null) {
list.remove(i - 1);
modInsn = mergedNode;
i--;
}
simplifyBlock(mth, block);
}
}

private static void simplifyBlock(MethodNode mth, BlockNode block) {
List<InsnNode> list = block.getInstructions();
for (int i = 0; i < list.size(); i++) {
InsnNode insn = list.get(i);
int insnCount = list.size();
InsnNode modInsn = simplifyInsn(mth, insn);
if (modInsn != null) {
if (i != 0 && modInsn.contains(AFlag.ARITH_ONEARG)) {
InsnNode mergedNode = simplifyOneArgConsecutive(
list.get(i - 1), list.get(i), (ArithNode) modInsn);

if (mergedNode != null) {
list.remove(i - 1);
modInsn = mergedNode;
i--;
}
}
if (i < list.size() && list.get(i) == insn) {
list.set(i, modInsn);
}
}
if (list.size() < insnCount) {
// some insns removed => restart block processing
simplifyBlock(mth, block);
return;
}
}
}

Expand Down

0 comments on commit 2dbdd1f

Please sign in to comment.