Commit b861151f authored by Skylot's avatar Skylot

core: rollback finally block extraction if some blocks not removed (#327)

parent feeafc40
......@@ -14,6 +14,7 @@ import jadx.core.dex.attributes.nodes.LoopInfo;
import jadx.core.utils.BlockUtils;
import jadx.core.utils.EmptyBitSet;
import jadx.core.utils.InsnUtils;
import jadx.core.utils.exceptions.JadxRuntimeException;
import static jadx.core.utils.Utils.lockList;
......@@ -70,6 +71,9 @@ public class BlockNode extends AttrNode implements IBlock {
successors = lockList(successors);
predecessors = lockList(predecessors);
dominatesOn = lockList(dominatesOn);
if (domFrontier == null) {
throw new JadxRuntimeException("Dominance frontier not set for block: " + this);
}
}
/**
......
......@@ -8,6 +8,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
......@@ -194,11 +195,21 @@ public class BlockFinallyExtract extends AbstractVisitor {
laBefore.runAnalysis();
}
int removeApplied = 0;
for (BlocksRemoveInfo removeInfo : removes) {
if (!applyRemove(mth, removeInfo)) {
return false;
if (applyRemove(mth, removeInfo)) {
removeApplied++;
removeInfo.setApplied(true);
}
}
if (removeApplied == 0) {
return false;
}
if (removeApplied != removes.size()) {
throw new JadxRuntimeException("Some finally instructions failed to remove: "
+ removes.stream().filter(n -> !n.isApplied()).map(BlocksRemoveInfo::toString).collect(Collectors.joining(","))
);
}
LiveVarAnalysis laAfter = null;
......
......@@ -23,6 +23,8 @@ public final class BlocksRemoveInfo {
private BlockNode startPredecessor;
private boolean applied;
public BlocksRemoveInfo(BlocksPair start) {
this.start = start;
}
......@@ -99,13 +101,22 @@ public final class BlocksRemoveInfo {
return null;
}
public boolean isApplied() {
return applied;
}
public void setApplied(boolean applied) {
this.applied = applied;
}
@Override
public String toString() {
return "BRI start: " + start
return "BRI{start: " + start
+ ", end: " + end
+ ", list: " + processed
+ ", processed: " + processed
+ ", outs: " + outs
+ ", regMap: " + regMap
+ ", split: " + startSplitIndex;
+ ", split: " + startSplitIndex + "-" + endSplitIndex
+ "}";
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment