diff --git a/CHANGELOG.md b/CHANGELOG.md index b343b6801..0002ee6d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file. - AS1/2 debugger - deletion of SWD file after debugging - Proper freeing memory after SWF close - AS1/2 improper selection of search result +- [#2459] AS1/2 StoreRegister improper declaration position ## [23.0.1] - 2025-05-16 ### Fixed @@ -3808,6 +3809,7 @@ Major version of SWF to XML export changed to 2. [#1418]: https://www.free-decompiler.com/flash/issues/1418 [#289]: https://www.free-decompiler.com/flash/issues/289 [#2456]: https://www.free-decompiler.com/flash/issues/2456 +[#2459]: https://www.free-decompiler.com/flash/issues/2459 [#2427]: https://www.free-decompiler.com/flash/issues/2427 [#1826]: https://www.free-decompiler.com/flash/issues/1826 [#2448]: https://www.free-decompiler.com/flash/issues/2448 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 d7da444b6..c00603c0f 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 @@ -49,6 +49,7 @@ import com.jpexs.decompiler.flash.action.swf5.ActionEquals2; import com.jpexs.decompiler.flash.action.swf6.ActionStrictEquals; import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2; import com.jpexs.decompiler.flash.ecma.Null; +import com.jpexs.decompiler.flash.ecma.Undefined; import com.jpexs.decompiler.graph.AbstractGraphTargetVisitor; import com.jpexs.decompiler.graph.Block; import com.jpexs.decompiler.graph.Graph; @@ -272,6 +273,8 @@ public class ActionGraph extends Graph { return !isSwitch; } + + @Override protected void finalProcess(GraphTargetItem parent, List list, int level, FinalProcessLocalData localData, String path) throws InterruptedException { @@ -288,7 +291,7 @@ public class ActionGraph extends Graph { } } list.addAll(0, removed); - } + } int targetStart; int targetEnd; @@ -672,7 +675,7 @@ public class ActionGraph extends Graph { sr.define = !definedRegisters.contains(sr.register.number); definedRegisters.add(sr.register.number); if (sr.define && sr != ti) { - list.add(ri.getVal(), new StoreRegisterActionItem(null, null, sr.register, new DirectValueActionItem(Null.INSTANCE), true)); + list.add(ri.getVal(), new StoreRegisterActionItem(null, null, sr.register, new DirectValueActionItem(Undefined.INSTANCE), true)); sr.define = false; ri.setVal(ri.getVal() + 1); } @@ -703,7 +706,27 @@ public class ActionGraph extends Graph { for (List items : b.getSubs()) { makeDefineRegistersUp(items, definedRegisters); } + + + for (List items : b.getSubs()) { + for (int j = 0; j < items.size(); j++) { + GraphTargetItem item = items.get(j); + if (item instanceof StoreRegisterActionItem) { + StoreRegisterActionItem sr = (StoreRegisterActionItem) item; + if (sr.define) { + list.add(ri.getVal(), new StoreRegisterActionItem(null, null, sr.register, new DirectValueActionItem(Undefined.INSTANCE), true)); + sr.define = false; + if ((sr.value instanceof DirectValueActionItem) && (((DirectValueActionItem) sr.value).value == Undefined.INSTANCE)) { + items.remove(j); + j--; + } + ri.setVal(ri.getVal() + 1); + } + } + } + } } + i = ri.getVal(); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/DefineLocalActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/DefineLocalActionItem.java index 2fd174eb1..a12a10576 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/DefineLocalActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/DefineLocalActionItem.java @@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.IdentifiersDeobfuscation; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; import com.jpexs.decompiler.flash.action.swf5.ActionDefineLocal; import com.jpexs.decompiler.flash.action.swf5.ActionDefineLocal2; +import com.jpexs.decompiler.flash.ecma.Undefined; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.flash.helpers.hilight.HighlightData; import com.jpexs.decompiler.graph.CompilationException; @@ -104,7 +105,7 @@ public class DefineLocalActionItem extends ActionItem implements SetTypeActionIt } else { stripQuotes(name, localData, writer); } - if (value == null) { + if (value == null || ((value instanceof DirectValueActionItem) && ((DirectValueActionItem) value).value == Undefined.INSTANCE)) { return writer; } writer.append(" = "); @@ -126,7 +127,7 @@ public class DefineLocalActionItem extends ActionItem implements SetTypeActionIt @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - if (value == null) { + if (value == null || (value instanceof DirectValueActionItem && ((DirectValueActionItem) value).value == Undefined.INSTANCE)) { return toSourceMerge(localData, generator, name, new ActionDefineLocal2()); } else { return toSourceMerge(localData, generator, name, value, new ActionDefineLocal()); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StoreRegisterActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StoreRegisterActionItem.java index fbb9dd803..88c04bc11 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StoreRegisterActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StoreRegisterActionItem.java @@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.SourceGeneratorLocalData; import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.RegisterNumber; import com.jpexs.decompiler.flash.action.swf5.ActionStoreRegister; +import com.jpexs.decompiler.flash.ecma.Undefined; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.flash.helpers.hilight.HighlightData; import com.jpexs.decompiler.graph.CompilationException; @@ -133,8 +134,10 @@ public class StoreRegisterActionItem extends ActionItem implements SetTypeAction writer.append("= "); return compoundValue.toString(writer, localData); } - writer.append(" = "); - value.toString(writer, localData); + if (value != null && !(value instanceof DirectValueActionItem && (((DirectValueActionItem) value).value == Undefined.INSTANCE))) { + writer.append(" = "); + value.toString(writer, localData); + } } return writer; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java index 35a27f783..d0bd198cd 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java @@ -1143,7 +1143,7 @@ public class ActionScript2Parser { ret = new VariableActionItem(varIdentifier, varval, true); variables.add((VariableActionItem) ret); } else { - ret = new VariableActionItem(varIdentifier, null, true); + ret = new VariableActionItem(varIdentifier, new DirectValueActionItem(Undefined.INSTANCE), true); variables.add((VariableActionItem) ret); lexer.pushback(s); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/VariableActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/VariableActionItem.java index 53d889ad1..60c4182b2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/VariableActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/VariableActionItem.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.parser.script; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; import com.jpexs.decompiler.flash.action.model.ActionItem; +import com.jpexs.decompiler.flash.action.model.DirectValueActionItem; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.graph.CompilationException; import com.jpexs.decompiler.graph.GraphSourceItem; @@ -99,7 +100,7 @@ public class VariableActionItem extends ActionItem { public List toSourceIgnoreReturnValue(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { if (it == null) { return new ArrayList<>(); - } + } return it.toSourceIgnoreReturnValue(localData, generator); } diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionDefineFunctionPushRegisterCleanerTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionDefineFunctionPushRegisterCleanerTest.java index 0fb280e6e..a8c313a00 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionDefineFunctionPushRegisterCleanerTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionDefineFunctionPushRegisterCleanerTest.java @@ -103,10 +103,11 @@ public class ActionDefineFunctionPushRegisterCleanerTest extends ActionScript2Te + "function testReturns()\r\n" + "{\r\n" + "var _loc2_ = 10;\r\n" + + "var _loc1_;\r\n" + "if(_loc2_ > 2)\r\n" + "{\r\n" + "_loc2_ = _loc2_ + 1;\r\n" - + "var _loc1_ = 0;\r\n" + + "_loc1_ = 0;\r\n" + "while(_loc1_ < 100)\r\n" + "{\r\n" + "if(_loc2_ + _loc1_ == 27)\r\n" 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 a6a61bbc5..9bf2fa28d 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2AssemblerTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2AssemblerTest.java @@ -167,7 +167,7 @@ public class ActionScript2AssemblerTest extends ActionScript2TestBase { res = cleanPCode(res); assertEquals(res, "function test(p)\n" + "{\n" - + "var _loc0_ = null;\n" + + "var _loc0_;\n" + "if((_loc0_ = p.type) === 1)\n" + "{\n" + "trace(\"Hello\");\n" @@ -323,7 +323,7 @@ public class ActionScript2AssemblerTest extends ActionScript2TestBase { + "Push \"after\"\n" + "Trace"); res = cleanPCode(res); - assertEquals(res, "var _loc1_ = null;\n" + assertEquals(res, "var _loc1_;\n" + "x = _loc1_ = new Object();\n" + "var _loc2_ = _global.x;\n" + "for(var _loc0_ in _loc2_)\n" diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2Test.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2Test.java index 3e143f286..958571bc3 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2Test.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2Test.java @@ -1989,9 +1989,10 @@ public class ActionScript2Test extends ActionScript2TestBase { + "{\r\n" + "var _loc3_ = {};\r\n" + "var _loc2_ = {};\r\n" + + "var _loc1_;\r\n" + "for(var _loc4_ in _loc3_)\r\n" + "{\r\n" - + "var _loc1_ = _loc2_[_loc4_];\r\n" + + "_loc1_ = _loc2_[_loc4_];\r\n" + "switch(_loc1_)\r\n" + "{\r\n" + "case \"A\":\r\n" @@ -2495,4 +2496,23 @@ public class ActionScript2Test extends ActionScript2TestBase { + "fscommand(\"test\" + r,\"xx\");\r\n" ); } + + @Test + public void frame92_Test() { + compareSrc(92, "function f(tst)\r\n" + + "{\r\n" + + "var _loc1_;\r\n" + + "if(tst)\r\n" + + "{\r\n" + + "_loc1_ = 1;\r\n" + + "}\r\n" + + "else\r\n" + + "{\r\n" + + "_loc1_ = 2;\r\n" + + "}\r\n" + + "}\r\n" + + "trace(\"testVarDefineInFunc\");\r\n" + + "f(tst);\r\n" + ); + } } diff --git a/libsrc/ffdec_lib/testdata/as2/as2.swf b/libsrc/ffdec_lib/testdata/as2/as2.swf index 73a27b6ba..9791b7a10 100644 Binary files a/libsrc/ffdec_lib/testdata/as2/as2.swf and b/libsrc/ffdec_lib/testdata/as2/as2.swf differ diff --git a/libsrc/ffdec_lib/testdata/as2/as2/DOMDocument.xml b/libsrc/ffdec_lib/testdata/as2/as2/DOMDocument.xml index 7e827fc36..bceacdb16 100644 --- a/libsrc/ffdec_lib/testdata/as2/as2/DOMDocument.xml +++ b/libsrc/ffdec_lib/testdata/as2/as2/DOMDocument.xml @@ -31,7 +31,7 @@ - + @@ -761,9 +761,9 @@ +!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"/> + + + + + + diff --git a/libsrc/ffdec_lib/testdata/as2/as2/LIBRARY/NineSlice.xml b/libsrc/ffdec_lib/testdata/as2/as2/LIBRARY/NineSlice.xml index 6d961fbcc..158791cc1 100644 --- a/libsrc/ffdec_lib/testdata/as2/as2/LIBRARY/NineSlice.xml +++ b/libsrc/ffdec_lib/testdata/as2/as2/LIBRARY/NineSlice.xml @@ -37,28 +37,23 @@ - - - - - + + + + + + + + + + + + - - - - - - +!0 1000|0 3000"/> diff --git a/libsrc/ffdec_lib/testdata/as2/as2/LIBRARY/blue.xml b/libsrc/ffdec_lib/testdata/as2/as2/LIBRARY/blue.xml index 7aa0f1c9f..56636e13c 100644 --- a/libsrc/ffdec_lib/testdata/as2/as2/LIBRARY/blue.xml +++ b/libsrc/ffdec_lib/testdata/as2/as2/LIBRARY/blue.xml @@ -36,8 +36,8 @@ trace("init_blue"); - + diff --git a/libsrc/ffdec_lib/testdata/as2/as2/META-INF/metadata.xml b/libsrc/ffdec_lib/testdata/as2/as2/META-INF/metadata.xml index 42e21776c..37b2464a4 100644 --- a/libsrc/ffdec_lib/testdata/as2/as2/META-INF/metadata.xml +++ b/libsrc/ffdec_lib/testdata/as2/as2/META-INF/metadata.xml @@ -5,8 +5,8 @@ xmlns:xmp="http://ns.adobe.com/xap/1.0/"> Adobe Flash CS4 Professional 2010-08-03T10:48:58+02:00 - 2024-10-26T14:36:05-07:00 - 2024-10-26T14:36:05-07:00 + 2025-05-25T02:00:38-07:00 + 2025-05-25T02:00:38-07:00 @@ -22,7 +22,7 @@ xmp.did:8DD71700DC9EDF1194ADAC9B23608190 xmp.did:F0EB4FF7CAC3ED11AC9DC078F41E1AA7 - xmp.iid:BC64DA72B493EF119A09BEAA35197FE1 + xmp.iid:947ACAA0D438F0118613AED963F21DE9 xmp.did:8DD71700DC9EDF1194ADAC9B23608190 @@ -470,6 +470,12 @@ 2010-08-03T10:48:58+02:00 Adobe Flash Professional CS6 - build 481 + + created + xmp.iid:947ACAA0D438F0118613AED963F21DE9 + 2010-08-03T10:48:58+02:00 + Adobe Flash Professional CS6 - build 481 + diff --git a/libsrc/ffdec_lib/testdata/as2/as2/bin/SymDepend.cache b/libsrc/ffdec_lib/testdata/as2/as2/bin/SymDepend.cache index de89e01ba..a80d76d3a 100644 Binary files a/libsrc/ffdec_lib/testdata/as2/as2/bin/SymDepend.cache and b/libsrc/ffdec_lib/testdata/as2/as2/bin/SymDepend.cache differ