mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-05 02:05:49 +00:00
Fixed: #2486 AS1/2 if jump to function end as return
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<GraphPart> stopPart2 = new ArrayList<>(stopPart);
|
||||
List<StopPartKind> 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<GraphPart> stopPart2 = new ArrayList<>(stopPart);
|
||||
List<StopPartKind> stopPartKind2 = new ArrayList<>(stopPartKind);
|
||||
|
||||
if ((!isEmpty) && (next != null)) {
|
||||
stopPart2.add(next);
|
||||
@@ -3753,7 +3761,7 @@ public class Graph {
|
||||
}
|
||||
|
||||
List<GraphTargetItem> 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<GraphTargetItem> onFalse = new ArrayList<>();
|
||||
|
||||
@@ -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"
|
||||
+ "}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user