diff --git a/CHANGELOG.md b/CHANGELOG.md index c111984a5..d1006d473 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Change Log All notable changes to this project will be documented in this file. +## [Unreleased] +### Fixed +- AS1/2 switch with getvariable decompilation + ## [14.6.0] - 2021-11-22 ### Added - Information message before importing scripts, text, XML, Symbol-Class diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraph.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraph.java index 1448773bc..3a56e8516 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraph.java @@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.action.model.DirectValueActionItem; import com.jpexs.decompiler.flash.action.model.EnumerateActionItem; import com.jpexs.decompiler.flash.action.model.FunctionActionItem; import com.jpexs.decompiler.flash.action.model.GetPropertyActionItem; +import com.jpexs.decompiler.flash.action.model.GetVariableActionItem; import com.jpexs.decompiler.flash.action.model.SetTarget2ActionItem; import com.jpexs.decompiler.flash.action.model.SetTargetActionItem; import com.jpexs.decompiler.flash.action.model.SetTypeActionItem; @@ -416,6 +417,9 @@ public class ActionGraph extends Graph { if (set.leftSide instanceof StoreRegisterActionItem) { switchedObject = ((StoreRegisterActionItem) set.leftSide).value; } + if (set.leftSide instanceof GetVariableActionItem) { + switchedObject = set.leftSide; + } List caseBodyParts = new ArrayList<>(); caseBodyParts.add(part.nextParts.get(0)); GraphTargetItem top = null; 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 d6cb83b02..f41e44e84 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2AssemblerTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2AssemblerTest.java @@ -192,4 +192,36 @@ public class ActionScript2AssemblerTest extends ActionScript2TestBase { + "return 0;\n" + "};"); } + + @Test + public void testSwitchVariable() { + String res = decompilePcode("ConstantPool \"t\"\n" + + "Push \"t\"\n" + + "GetVariable\n" + + "Push 0.0\n" + + "StrictEquals\n" + + "If loc0038\n" + + "Push \"t\"\n" + + "GetVariable\n" + + "Push 1\n" + + "StrictEquals\n" + + "If loc0041\n" + + "Jump loc004a\n" + + "loc0038:Push 0\n" + + "Return\n" + + "loc0041:Push 1\n" + + "Return\n" + + "loc004a:Push 3\n" + + "Return"); + res = cleanPCode(res); + assertEquals(res, "switch(t)\n" + + "{\n" + + "case 0:\n" + + "return 0;\n" + + "case 1:\n" + + "return 1;\n" + + "default:\n" + + "return 3;\n" + + "}"); + } }