Fixed: #2651 Loop breaks detection

This commit is contained in:
Jindra Petřík
2026-03-04 08:29:46 +01:00
parent 29ead369bf
commit d487ef7064
12 changed files with 108 additions and 56 deletions

View File

@@ -20,6 +20,7 @@ All notable changes to this project will be documented in this file.
- AS3 goto definition missing some namespaces
- [#2514] AS3 direct editation - problems with namespaces
- [#2649] SVG export - blur scaling (on supported browsers)
- [#2651] Loop breaks detection
### Changed
- Icon of Debug listen action from ear to phone receiver
@@ -4190,6 +4191,7 @@ Major version of SWF to XML export changed to 2.
[#2645]: https://www.free-decompiler.com/flash/issues/2645
[#2514]: https://www.free-decompiler.com/flash/issues/2514
[#2649]: https://www.free-decompiler.com/flash/issues/2649
[#2651]: https://www.free-decompiler.com/flash/issues/2651
[#2639]: https://www.free-decompiler.com/flash/issues/2639
[#2642]: https://www.free-decompiler.com/flash/issues/2642
[#2636]: https://www.free-decompiler.com/flash/issues/2636

View File

@@ -1878,14 +1878,14 @@ public class AVM2Graph extends Graph {
if (caseBodyParts.size() == 2) {
boolean isIf = false;
for (GraphPart r : part.refs) {
if (r != origPart && !origPart.leadsTo(localData, this, code, r, loops, throwStates)) {
if (r != origPart && !origPart.leadsTo(localData, this, code, r, loops, throwStates, false)) {
isIf = true;
break;
}
}
if (!isIf) {
for (GraphPart r : caseBodyParts.get(1).refs) {
if (r != origPart && !origPart.leadsTo(localData, this, code, r, loops, throwStates)) {
if (r != origPart && !origPart.leadsTo(localData, this, code, r, loops, throwStates, false)) {
isIf = true;
break;
}

View File

@@ -581,7 +581,7 @@ public class Graph {
if (q == p) {
continue;
}
if (!q.leadsTo(localData, this, code, p, loops, throwStates)) {
if (!q.leadsTo(localData, this, code, p, loops, throwStates, false)) {
common = false;
break;
}
@@ -666,10 +666,10 @@ public class Graph {
int levelCompare = o2.level - o1.level;
if (levelCompare == 0) {
try {
if (o1.part.leadsTo(localData, Graph.this, code, o2.part, loops, throwStates)) {
if (o1.part.leadsTo(localData, Graph.this, code, o2.part, loops, throwStates, false)) {
return -1;
}
if (o2.part.leadsTo(localData, Graph.this, code, o1.part, loops, throwStates)) {
if (o2.part.leadsTo(localData, Graph.this, code, o1.part, loops, throwStates, false)) {
return 1;
}
return 0;
@@ -732,7 +732,7 @@ public class Graph {
if (visited.contains(n)) {
continue;
}
if (!n.leadsTo(localData, this, code, r, loops, throwStates)) {
if (!n.leadsTo(localData, this, code, r, loops, throwStates, false)) {
common = false;
break loopprocess;
}
@@ -1738,7 +1738,7 @@ public class Graph {
}
}
}
if (el.loopContinue.leadsTo(localData, this, code, r, loops, throwStates)) {
if (el.loopContinue.leadsTo(localData, this, code, r, loops, throwStates, false)) {
el.backEdges.add(r);
}
}
@@ -2713,7 +2713,7 @@ public class Graph {
}
try {
if (!part.leadsTo(localData, this, code, lastP1.loopContinue, loops2, throwStates)) {
if (!part.leadsTo(localData, this, code, lastP1.loopContinue, loops2, throwStates, false)) {
if (lastP1.breakCandidatesLocked == 0) {
if (debugGetLoops) {
System.err.println("added breakCandidate " + part + " to " + lastP1);
@@ -2746,7 +2746,7 @@ public class Graph {
}
part.level = level;
isLoop = part.leadsTo(localData, this, code, part, loops, throwStates);
isLoop = part.leadsTo(localData, this, code, part, loops, throwStates, false);
currentLoop = null;
if (isLoop) {
currentLoop = new Loop(loops.size(), part, null);
@@ -2906,7 +2906,7 @@ public class Graph {
for (int c = 0; c < currentLoop.breakCandidates.size(); c++) {
GraphPart cand = currentLoop.breakCandidates.get(c);
GraphPart sp = currentLoop.stopParts.get(currentLoop.stopParts.size() - 1);
if (cand == sp || cand.leadsTo(localData, this, code, sp, new ArrayList<>() /*ignore existing loop states*/, throwStates)) {
if (cand == sp || cand.leadsTo(localData, this, code, sp, new ArrayList<>() /*ignore existing loop states*/, throwStates, false)) {
breakCandidatesLeft.add(c);
}
}
@@ -2932,7 +2932,7 @@ public class Graph {
if (cand == cand2) {
continue;
}
if (cand.leadsTo(localData, this, code, cand2, loops, throwStates)) {
if (cand.leadsTo(localData, this, code, cand2, loops, throwStates, false)) {
int curLevl = currentLoop.breakCandidatesLevels.get(c1);
int curLev2 = currentLoop.breakCandidatesLevels.get(c2);
@@ -3882,7 +3882,7 @@ public class Graph {
continue;
}
// also #2636
if (!part.leadsTo(localData, this, code, r, loops, throwStates)) {
if (!part.leadsTo(localData, this, code, r, loops, throwStates, true /*IMPORTANT*/)) {
continue;
}
@@ -3901,7 +3901,7 @@ public class Graph {
if (v.contains(n)) {
continue;
}
if (!n.leadsTo(localData, this, code, next, loops, throwStates)) {
if (!n.leadsTo(localData, this, code, next, loops, throwStates, true /*IMPORTANT*/)) {
GraphPart n2 = getCommonPart(localData, r, Arrays.asList(next, n), loops, throwStates);
if (n2 != null) {
//System.err.println("Found block: start = " + part + ", break = " + n2 + ", exit = " + r);
@@ -4834,7 +4834,7 @@ public class Graph {
*/
//must go backwards to hit case 2, not case 1
for (int i = caseBodyParts.size() - 1; i >= 0; i--) {
if (caseBodyParts.get(i).leadsTo(localData, this, code, defaultPart, loops, throwStates)) {
if (caseBodyParts.get(i).leadsTo(localData, this, code, defaultPart, loops, throwStates, false)) {
DefaultItem di = new DefaultItem(dialect);
caseValuesMap.add(i + 1, di);
caseBodyParts.add(i + 1, defaultPart);
@@ -4855,7 +4855,7 @@ public class Graph {
trace("2");
*/
for (int i = 0; i < caseBodyParts.size(); i++) {
if (defaultPart.leadsTo(localData, this, code, caseBodyParts.get(i), loops, throwStates)) {
if (defaultPart.leadsTo(localData, this, code, caseBodyParts.get(i), loops, throwStates, false)) {
DefaultItem di = new DefaultItem(dialect);
caseValuesMap.add(i, di);
caseBodyParts.add(i, defaultPart);
@@ -4905,8 +4905,8 @@ public class Graph {
GraphPart b = caseBodies.get(i);
for (int j = i + 1; j < caseBodies.size(); j++) {
GraphPart b2 = caseBodies.get(j);
if (b2.leadsTo(localData, this, code, b, loops, throwStates)) {
if (b.leadsTo(localData, this, code, b2, loops, throwStates)) { //unstructured code
if (b2.leadsTo(localData, this, code, b, loops, throwStates, false)) {
if (b.leadsTo(localData, this, code, b2, loops, throwStates, false)) { //unstructured code
continue;
}
caseBodies.remove(j);
@@ -4914,7 +4914,7 @@ public class Graph {
i--;
continue loopi;
} else if (j > i + 1) {
if (b.leadsTo(localData, this, code, b2, loops, throwStates)) {
if (b.leadsTo(localData, this, code, b2, loops, throwStates, false)) {
caseBodies.remove(j);
caseBodies.add(i + 1, b2);
continue loopi;
@@ -4932,7 +4932,7 @@ public class Graph {
List<GraphTargetItem> currentCaseCommands = new ArrayList<>();
boolean willHaveBreak = false;
if (i < caseBodies.size() - 1) {
if (!caseBodies.get(i).leadsTo(localData, this, code, caseBodies.get(i + 1), loops, throwStates)) {
if (!caseBodies.get(i).leadsTo(localData, this, code, caseBodies.get(i + 1), loops, throwStates, false)) {
willHaveBreak = true;
}
}

View File

@@ -140,17 +140,18 @@ public class GraphPart implements Serializable {
* @param visited Visited parts
* @param loops Loops
* @param throwStates Throw states
* @param firstCanBeLoopContinue Can entry point be loop continue?
* @return True if this part leads to the other part
* @throws InterruptedException On interrupt
*/
private boolean leadsTo(BaseLocalData localData, Graph gr, GraphSource code, GraphPart prev, GraphPart part, HashSet<GraphPart> visited, List<Loop> loops, List<ThrowState> throwStates) throws InterruptedException {
private boolean leadsTo(BaseLocalData localData, Graph gr, GraphSource code, GraphPart prev, GraphPart part, HashSet<GraphPart> visited, List<Loop> loops, List<ThrowState> throwStates, boolean firstCanBeLoopContinue) throws InterruptedException {
if (CancellableWorker.isInterrupted()) {
throw new InterruptedException();
}
Stack<GraphPart> todo = new Stack<>();
todo.push(this);
boolean first = true;
boolean first = firstCanBeLoopContinue; //This is big HACK of how to get always-break working
looptodo:
while (!todo.isEmpty()) {
@@ -224,14 +225,15 @@ public class GraphPart implements Serializable {
* @param part Part to check
* @param loops Loops
* @param throwStates Throw states
* @param firstCanBeLoopContinue Can entry point be loop continue?
* @return True if this part leads to the other part
* @throws InterruptedException On interrupt
*/
public boolean leadsTo(BaseLocalData localData, Graph gr, GraphSource code, GraphPart part, List<Loop> loops, List<ThrowState> throwStates) throws InterruptedException {
public boolean leadsTo(BaseLocalData localData, Graph gr, GraphSource code, GraphPart part, List<Loop> loops, List<ThrowState> throwStates, boolean firstCanBeLoopContinue) throws InterruptedException {
for (Loop l : loops) {
l.leadsToMark = 0;
}
return leadsTo(localData, gr, code, null /*???*/, part, new HashSet<>(), loops, throwStates);
return leadsTo(localData, gr, code, null /*???*/, part, new HashSet<>(), loops, throwStates, firstCanBeLoopContinue);
}
/**

View File

@@ -556,26 +556,19 @@ public class ActionScript2AssemblerTest extends ActionScript2TestBase {
assertEquals(res, "function f()\n"
+ "{\n"
+ "var a = [1,2,3];\n"
+ "loop0:\n"
+ "for(v in a)\n"
+ "{\n"
+ "trace(v);\n"
+ "var b = 0;\n"
+ "while(true)\n"
+ "{\n"
+ "if(b < 10)\n"
+ "while(b < 10)\n"
+ "{\n"
+ "if(b == 4)\n"
+ "{\n"
+ "break;\n"
+ "trace(\"ret\");\n"
+ "return;\n"
+ "}\n"
+ "b++;\n"
+ "continue;\n"
+ "}\n"
+ "continue loop0;\n"
+ "}\n"
+ "trace(\"ret\");\n"
+ "break;\n"
+ "}\n"
+ "}");
}

View File

@@ -2647,5 +2647,27 @@ public class ActionScript2Test extends ActionScript2TestBase {
+ "trace(\"finish\");\r\n"
);
}
@Test
public void frame97_twoInTest() {
compareSrc(97, "trace(\"twoInTest\");\r\n"
+ "var o = {a:{}};\r\n"
+ "for(var n in o)\r\n"
+ "{\r\n"
+ "var c = 5;\r\n"
+ "for(var i in o.a)\r\n"
+ "{\r\n"
+ "if(i == c)\r\n"
+ "{\r\n"
+ "if(i == 0)\r\n"
+ "{\r\n"
+ "trace(\"xx\");\r\n"
+ "break;\r\n"
+ "}\r\n"
+ "}\r\n"
+ "}\r\n"
+ "}\r\n"
);
}
//--FRAMES-END--
}

Binary file not shown.

View File

@@ -31,7 +31,7 @@
<Include href="Tween 5.xml" itemIcon="1" loadImmediate="false" itemID="60429674-00000289" lastModified="1753122968"/>
</symbols>
<timelines>
<DOMTimeline name="Scene 1" currentFrame="95">
<DOMTimeline name="Scene 1" currentFrame="96">
<layers>
<DOMLayer name="Layer 17" color="#4FFF4F">
<frames>
@@ -771,9 +771,9 @@
</fills>
<edges>
<Edge fillStyle0="1" fillStyle1="2" edges="
!3159 7239[3270 7033 3327 6947!3327 6947[3353 6908 3412 6794!3412 6794[3470 6682 3500 6639!3500 6639[3602 6491 3649 6692!3649 6692|3713 6670!3713 6670[3760 6655 3782 6655!3782 6655[3942 6655 3985 6781!3985 6781[4007 6844 3996 6914!3996
6914[3996 6948 3999 6995!3999 6995[4000 7031 3993 7054!3993 7054[3976 7106 3860 7224!3860 7224[3847 7237 3741 7292!3741 7292[3638 7346 3616 7372!3616 7372[3594 7396 3511 7442!3511 7442[3435 7483 3427 7483!3427 7483[3409 7483 3407 7468
!3407 7468[3405 7453 3386 7453!3386 7453[3361 7468 3330 7483!3330 7483[3270 7512 3235 7512!3235 7512[3220 7512 3156 7501!3156 7501[3091 7490 3054 7490!3054 7490[3050 7494 3050 7457!3050 7457[3050 7441 3159 7239"/>
!3156 7501[3091 7490 3054 7490!3054 7490[3050 7494 3050 7457!3050 7457[3050 7441 3159 7239!3159 7239[3270 7033 3327 6947!3327 6947[3353 6908 3412 6794!3412 6794[3470 6682 3500 6639!3500 6639[3602 6491 3649 6692!3649 6692|3713 6670!3713
6670[3760 6655 3782 6655!3782 6655[3942 6655 3985 6781!3985 6781[4007 6844 3996 6914!3996 6914[3996 6948 3999 6995!3999 6995[4000 7031 3993 7054!3993 7054[3976 7106 3860 7224!3860 7224[3847 7237 3741 7292!3741 7292[3638 7346 3616 7372
!3616 7372[3594 7396 3511 7442!3511 7442[3435 7483 3427 7483!3427 7483[3409 7483 3407 7468!3407 7468[3405 7453 3386 7453!3386 7453[3361 7468 3330 7483!3330 7483[3270 7512 3235 7512!3235 7512[3220 7512 3156 7501"/>
<Edge fillStyle1="1" edges="
!2675 7305[2675 6953 2924 6704!2924 6704[3174 6454 3525 6454!3525 6454[3622 6454 3711 6474!3711 6474[3733 6454 3765 6434!3765 6434[3806 6409 3930 6340!3930 6340[4062 6261 4196 6152!4196 6152[4256 6104 4311 6071!4311 6071[4428 5999 4520
6000!4520 6000[4595 5999 4654 6049!4654 6049[4666 6059 4677 6071!4677 6071[4717 6116 4741 6186!4741 6186[4765 6256 4765 6315!4765 6315[4765 6361 4719 6443!4719 6443[4667 6534 4584 6614!4584 6614[4420 6774 4222 6815!4222 6815[4376 7028
@@ -3556,6 +3556,30 @@ trace("finish");]]></script>
</Actionscript>
<elements/>
</DOMFrame>
<DOMFrame index="96" name="twoInTest" labelType="name" keyMode="9728">
<Actionscript>
<script><![CDATA[trace("twoInTest");
var o = {a:{}};
for(var n in o)
{
var c = 5;
for(var i in o.a)
{
if(i == c)
{
if(i == 0)
{
trace("xx");
break;
}
}
}
}]]></script>
</Actionscript>
<elements/>
</DOMFrame>
</frames>
</DOMLayer>
</layers>
@@ -3563,6 +3587,7 @@ trace("finish");]]></script>
</timelines>
<PrinterSettings/>
<publishHistory>
<PublishItem publishSize="110002" publishTime="1772608573"/>
<PublishItem publishSize="109906" publishTime="1769340743"/>
<PublishItem publishSize="109817" publishTime="1768962510"/>
<PublishItem publishSize="109815" publishTime="1768962439"/>
@@ -3582,6 +3607,5 @@ trace("finish");]]></script>
<PublishItem publishSize="108954" publishTime="1729979068"/>
<PublishItem publishSize="108927" publishTime="1729978944"/>
<PublishItem publishSize="108786" publishTime="1722543124"/>
<PublishItem publishSize="108700" publishTime="1722540660"/>
</publishHistory>
</DOMDocument>

View File

@@ -37,27 +37,30 @@
</StrokeStyle>
</strokes>
<edges>
<Edge fillStyle0="1" fillStyle1="2" strokeStyle="1" edges="!7000 0|7000 1000!7000 1000|8000 1000"/>
<Edge fillStyle0="1" strokeStyle="1" edges="!8000 1000|8000 0"/>
<Edge fillStyle0="1" edges="!8000 0|7000 0"/>
<Edge fillStyle0="3" fillStyle1="2" strokeStyle="1" edges="!8000 3000|7000 3000!7000 3000|7000 4000"/>
<Edge fillStyle1="2" strokeStyle="1" edges="!7000 4000|1000 4000"/>
<Edge fillStyle0="5" fillStyle1="2" strokeStyle="1" edges="!1000 4000|1000 3000!1000 3000|0 3000"/>
<Edge fillStyle0="5" strokeStyle="1" edges="!0 3000|0 4000!0 4000|1000 4000"/>
<Edge fillStyle0="1" fillStyle1="2" strokeStyle="1" edges="!7000 0|7000 1000!7000 1000|8000 1000"/>
<Edge fillStyle1="2" strokeStyle="1" edges="!8000 1000|8000 3000"/>
<Edge fillStyle1="3" strokeStyle="1" edges="!8000 3000|8000 4000!8000 4000|7000 4000"/>
<Edge fillStyle0="3" fillStyle1="2" strokeStyle="1" edges="!8000 3000|7000 3000!7000 3000|7000 4000"/>
<Edge fillStyle0="3" strokeStyle="1" edges="!7000 4000|8000 4000!8000 4000|8000 3000"/>
<Edge fillStyle0="1" strokeStyle="1" edges="!8000 1000|8000 0"/>
<Edge fillStyle0="2" fillStyle1="6" strokeStyle="1" edges="!4000 3000[2757 3000 1878 2707!1878 2707[1000 2414 1000 2000!1000 2000[1000 1586 1878 1293!1878 1293[2757 1000 4000 1000!4000 1000[5243 1000 6121 1293!6121 1293[7000 1586 7000 2000!7000 2000[7000 2414 6121 2707!6121 2707[5243 3000 4000
3000"/>
<Edge fillStyle0="4" edges="
!1000 0|0 0"/>
<Edge fillStyle0="4" strokeStyle="1" edges="
!0 0|0 1000"/>
<Edge fillStyle0="2" strokeStyle="1" edges="
!0 1000|0 3000"/>
<Edge fillStyle0="5" strokeStyle="1" edges="
!0 3000|0 4000!0 4000|1000 4000"/>
<Edge fillStyle0="5" fillStyle1="2" strokeStyle="1" edges="
!1000 4000|1000 3000!1000 3000|0 3000"/>
<Edge fillStyle0="2" fillStyle1="4" strokeStyle="1" edges="
!1000 0|1000 1000!1000 1000|0 1000"/>
<Edge fillStyle0="2" strokeStyle="1" edges="
!0 1000|0 3000"/>
<Edge fillStyle0="4" strokeStyle="1" edges="
!0 0|0 1000"/>
<Edge fillStyle0="4" edges="
!1000 0|0 0"/>
<Edge fillStyle0="2" strokeStyle="1" edges="
!7000 0|1000 0"/>
<Edge fillStyle1="2" strokeStyle="1" edges="
!7000 4000|1000 4000"/>
</edges>
</DOMShape>
</elements>

View File

@@ -36,8 +36,8 @@ trace("init_blue");
</StrokeStyle>
</strokes>
<edges>
<Edge fillStyle1="1" strokeStyle="1" edges="!1321 562[1336 582 1523 825!1523 825[1642 976 1647 1087!1647 1087[1654 1238 1475 1397!1475 1397[1351 1509 1091 1776!1091 1776[861 2014 767 2089!767 2089[619 2208 569 2155!569 2155[511 2092 568 1787!568 1787|724 930!724 930[464 939 243
859!243 859[50 787 -57 669!-57 669[-160 555 -134 455!-134 455[-106 348 59 314!59 314[178 288 456 198!456 198[750 102 875 73!875 73[1331 -36 1262 253!1262 253[1226 402 1321 562"/>
<Edge fillStyle1="1" strokeStyle="1" edges="!1523 825[1642 976 1647 1087!1647 1087[1654 1238 1475 1397!1475 1397[1351 1509 1091 1776!1091 1776[861 2014 767 2089!767 2089[619 2208 569 2155!569 2155[511 2092 568 1787!568 1787|724 930!724 930[464 939 243 859!243 859[50 787 -57 669
!-57 669[-160 555 -134 455!-134 455[-106 348 59 314!59 314[178 288 456 198!456 198[750 102 875 73!875 73[1331 -36 1262 253!1262 253[1226 402 1321 562!1321 562[1336 582 1523 825"/>
<Edge cubics="!724 930(;-16,957 -399,411 59,314q724 930Q464 939q243 859Q50 787q-57 669Q-160 555q-134 455Q-106 348q59 314);"/>
<Edge cubics="!59 314(;518,215 1372,-211 1262,253q59 314Q178 288q456 198Q750 102q875 73Q1331 -36q1262 253);"/>
<Edge cubics="!1262 253(;1152,717 1996,929 1475,1397q1262 253Q1226 402q1321 562Q1336 582q1523 825Q1642 976q1647 1087Q1654 1238q1475 1397);"/>

View File

@@ -5,8 +5,8 @@
xmlns:xmp="http://ns.adobe.com/xap/1.0/">
<xmp:CreatorTool>Adobe Flash CS4 Professional</xmp:CreatorTool>
<xmp:CreateDate>2010-08-03T10:48:58+02:00</xmp:CreateDate>
<xmp:MetadataDate>2026-01-25T03:31:05-08:00</xmp:MetadataDate>
<xmp:ModifyDate>2026-01-25T03:31:05-08:00</xmp:ModifyDate>
<xmp:MetadataDate>2026-03-03T23:15:56-08:00</xmp:MetadataDate>
<xmp:ModifyDate>2026-03-03T23:15:56-08:00</xmp:ModifyDate>
</rdf:Description>
<rdf:Description rdf:about=""
xmlns:dc="http://purl.org/dc/elements/1.1/">
@@ -22,7 +22,7 @@
<stRef:originalDocumentID>xmp.did:8DD71700DC9EDF1194ADAC9B23608190</stRef:originalDocumentID>
</xmpMM:DerivedFrom>
<xmpMM:DocumentID>xmp.did:F0EB4FF7CAC3ED11AC9DC078F41E1AA7</xmpMM:DocumentID>
<xmpMM:InstanceID>xmp.iid:54232456E1F9F01185C4F57BEF746DBF</xmpMM:InstanceID>
<xmpMM:InstanceID>xmp.iid:B144D2FC9917F111A74DE617D61B86A4</xmpMM:InstanceID>
<xmpMM:OriginalDocumentID>xmp.did:8DD71700DC9EDF1194ADAC9B23608190</xmpMM:OriginalDocumentID>
<xmpMM:History>
<rdf:Seq>
@@ -518,6 +518,12 @@
<stEvt:when>2010-08-03T10:48:58+02:00</stEvt:when>
<stEvt:softwareAgent>Adobe Flash Professional CS6 - build 481</stEvt:softwareAgent>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<stEvt:action>created</stEvt:action>
<stEvt:instanceID>xmp.iid:B144D2FC9917F111A74DE617D61B86A4</stEvt:instanceID>
<stEvt:when>2010-08-03T10:48:58+02:00</stEvt:when>
<stEvt:softwareAgent>Adobe Flash Professional CS6 - build 481</stEvt:softwareAgent>
</rdf:li>
</rdf:Seq>
</xmpMM:History>
</rdf:Description>