diff --git a/CHANGELOG.md b/CHANGELOG.md index bc0574925..0ea1715c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ All notable changes to this project will be documented in this file. - AS1/2 Hide icons panel when editing - AS1/2 both pcode and AS editable at the same time - AS3 direct editation - Allow some special words (like `override`) as identifiers +- [#2486] AS1/2 if jump to function end as return ### Changed - Icon of "Deobfuscation options" menu from pile of pills to medkit 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 8c94e20ce..9698b7a4d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java @@ -486,6 +486,9 @@ public class Graph { if (next == null) { continue; } + if (next.start >= code.size()) { + continue; + } for (Loop l : loops) { if ((l.phase == 1) || (l.reachableMark == 1)) { @@ -3320,7 +3323,7 @@ public class Graph { break; } } - + if (isRealStopPart) { if (currentLoop != null) { currentLoop.phase = 0; @@ -3734,18 +3737,23 @@ public class Graph { if (isEmpty) { next = nps.get(0); } - boolean hasOntrue = nps.get(1) != next; + boolean hasOnTrue = nps.get(1) != next; boolean hasOnFalse = nps.get(0) != next; - - List stopPart2 = new ArrayList<>(stopPart); - List stopPartKind2 = new ArrayList<>(stopPartKind); - - if (!isEmpty && next != null) { - //handle end of as1/2 script or function - if (next.start >= code.size()) { - next = null; - } + + if (nps.get(1).start >= code.size()) { + next = null; + hasOnTrue = true; + hasOnFalse = true; + } else if (nps.get(0).start >= code.size()) { + next = null; + hasOnTrue = true; + hasOnFalse = true; } + + + + List stopPart2 = new ArrayList<>(stopPart); + List stopPartKind2 = new ArrayList<>(stopPartKind); if ((!isEmpty) && (next != null)) { stopPart2.add(next); @@ -3753,7 +3761,7 @@ public class Graph { } List onTrue = new ArrayList<>(); - if (!isEmpty && hasOntrue) { + if (!isEmpty && hasOnTrue) { onTrue = printGraph(foundGotos, partCodes, partCodePos, visited, prepareBranchLocalData(localData), trueStack, allParts, part, nps.get(1), stopPart2, stopPartKind2, loops, throwStates, null, staticOperation, path, recursionLevel + 1); } List onFalse = new ArrayList<>(); diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2AssemblerTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2AssemblerTest.java index 533afeced..91d222738 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2AssemblerTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2AssemblerTest.java @@ -452,4 +452,48 @@ public class ActionScript2AssemblerTest extends ActionScript2TestBase { + "}\n" + "trace(\"end\");"); } + + @Test + public void testReturnAsJumpAfterFunction() { + String res = decompilePcode("DefineFunction \"test\", 0 {\n" + + "Push register1\n" + + "Push \"A\"\n" + + "Equals2\n" + + "Not\n" + + "If loc002d\n" + + "Push \"in A\"\n" + + "Trace\n" + + "Jump loc0053\n" + + "loc002d:Push register1\n" + + "Push \"B\"\n" + + "Equals2\n" + + "Not\n" + + "If loc004e\n" + + "Push \"in B\"\n" + + "Trace\n" + + "Jump loc0053\n" + + "loc004e:Jump loc005f\n" + + "loc0053:Jump loc0058\n" + + "loc0058:Push \"C\"\n" + + "Trace\n" + + "}\n" + + "loc005f:\n"); + res = cleanPCode(res); + assertEquals(res, "function test()\n" + + "{\n" + + "if(_loc1_ == \"A\")\n" + + "{\n" + + "trace(\"in A\");\n" + + "}\n" + + "else if(_loc1_ == \"B\")\n" + + "{\n" + + "trace(\"in B\");\n" + + "}\n" + + "else\n" + + "{\n" + + "return;\n" + + "}\n" + + "trace(\"C\");\n" + + "}"); + } }