diff --git a/CHANGELOG.md b/CHANGELOG.md index 82f2fabf9..6cb743fcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file. - [#1584] SVG Import - paths with horizontal/vertical lines and rotation - [#1572] SVG Export - clipping must not use groups - [#270] AS decompilation - switch in loop +- [#270] AS decompilation - loop followed by try ## [14.2.0] - 2021-03-12 ### Added diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java index ca30c2bf6..606c3b5f5 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java @@ -2189,6 +2189,7 @@ public class AVM2Graph extends Graph { ts.targetPart = searchPart(code.adr2pos(body.exceptions[e].target), allParts); int startIp = code.adr2pos(body.exceptions[e].start, true); int endIp = code.adr2pos(body.exceptions[e].end, true); + ts.startPart = searchPart(startIp, allParts); for (GraphPart p : allParts) { if (p.start >= startIp && p.start < endIp) { ts.throwingParts.add(p); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java index 48552c574..ccb048cd0 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java @@ -1411,12 +1411,6 @@ public class Graph { } checkGetLoopsPart(part); - for (ThrowState ts : throwStates) { - if (ts.throwingParts.contains(part)) { - ts.state = 1; - } - } - if (debugGetLoops) { System.err.println("getloops: " + part); } @@ -1443,26 +1437,34 @@ public class Graph { } } } - if (lastP1 != null && canBeCandidate && canBeBreakCandidate(localData, part, throwStates)) { - if (lastP1.breakCandidates.contains(part)) { - lastP1.breakCandidates.add(part); - lastP1.breakCandidatesLevels.add(level); - return; - } else { - List loops2 = new ArrayList<>(loops); - loops2.remove(lastP1); - if (!part.leadsTo(localData, this, code, lastP1.loopContinue, loops2, throwStates, true)) { - if (lastP1.breakCandidatesLocked == 0) { - if (debugGetLoops) { - System.err.println("added breakCandidate " + part + " to " + lastP1); - } + try { + if (lastP1 != null && canBeCandidate && canBeBreakCandidate(localData, part, throwStates)) { + if (lastP1.breakCandidates.contains(part)) { + lastP1.breakCandidates.add(part); + lastP1.breakCandidatesLevels.add(level); + return; + } else { + List loops2 = new ArrayList<>(loops); + loops2.remove(lastP1); + if (!part.leadsTo(localData, this, code, lastP1.loopContinue, loops2, throwStates, true)) { + if (lastP1.breakCandidatesLocked == 0) { + if (debugGetLoops) { + System.err.println("added breakCandidate " + part + " to " + lastP1); + } - lastP1.breakCandidates.add(part); - lastP1.breakCandidatesLevels.add(level); - return; + lastP1.breakCandidates.add(part); + lastP1.breakCandidatesLevels.add(level); + return; + } } } } + } finally { + for (ThrowState ts : throwStates) { + if (ts.throwingParts.contains(part)) { + ts.state = 1; + } + } } for (Loop el : loops) { @@ -1586,7 +1588,7 @@ public class Graph { GraphPart cand = currentLoop.breakCandidates.get(c); List candThrowStates = new ArrayList<>(); for (ThrowState ts : throwStates) { - if (ts.throwingParts.contains(cand)) { + if (ts.throwingParts.contains(cand) && ts.startPart != cand) { if (contThrowStates.equals(candThrowStates)) { //adding new ts //this means breakcandidate is in nested try diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/ThrowState.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/ThrowState.java index 908e21ee0..a5886d68c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/ThrowState.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/ThrowState.java @@ -13,6 +13,7 @@ public class ThrowState { public Set throwingParts = new HashSet<>(); public GraphPart targetPart; + public GraphPart startPart; public Set catchParts = new HashSet<>(); @Override diff --git a/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf b/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf index d4460a11b..94800a379 100644 Binary files a/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf and b/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf differ