From d1f010222cfdecbca59e1fa9a50513480a4ddc1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Thu, 24 Nov 2022 09:39:30 +0100 Subject: [PATCH] Fixed #1769 Missing some body trait variable declaration --- .../decompiler/flash/abc/avm2/AVM2Code.java | 39 +++++++++++- .../ActionScript3ClassicAirDecompileTest.java | 6 +- .../ActionScript3ClassicDecompileTest.java | 61 +++++++------------ ...ctionScript3CrossCompileDecompileTest.java | 15 ++--- 4 files changed, 65 insertions(+), 56 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index f24c527b9..707ae3cc4 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -1922,14 +1922,47 @@ public class AVM2Code implements Cloneable { } value = value.getNotCoerced(); - if (!((value instanceof NumberValueAVM2Item) + /*if (!((value instanceof NumberValueAVM2Item) || (value instanceof StringAVM2Item) || (value instanceof TrueItem) || (value instanceof FalseItem) || (value instanceof UndefinedAVM2Item) || (value instanceof NullAVM2Item) - || (value instanceof NewFunctionAVM2Item) - )) { + || (value instanceof NewFunctionAVM2Item))) { + break; + }*/ + Reference hasPrevReference = new Reference<>(false); + value.visitRecursivelyNoBlock(new AbstractGraphTargetVisitor() { + @Override + public void visit(GraphTargetItem subItem) { + Multiname propertyMultiName; + String propertyName; + if (subItem instanceof GetPropertyAVM2Item) { + GetPropertyAVM2Item propItem = (GetPropertyAVM2Item) subItem; + if (propItem.object instanceof FindPropertyAVM2Item) { + propertyMultiName = abc.constants.getMultiname(((FullMultinameAVM2Item) propItem.propertyName).multinameIndex); + } else { + return; + } + } else if (subItem instanceof GetLexAVM2Item) { + GetLexAVM2Item lex = (GetLexAVM2Item) subItem; + propertyMultiName = lex.propertyName; + } else { + return; + } + propertyName = propertyMultiName.getName(abc.constants, new ArrayList<>(), true, true); + + if (traits.containsKey(propertyName)) { + Slot sl = new Slot(new NewActivationAVM2Item(null, null), propertyMultiName); + if (!paramNames.contains(propertyName)) { + if (traits.containsKey(propertyName) && !beginDeclaredSlotsNames.contains(propertyName)) { + hasPrevReference.setVal(true); + } + } + } + } + }); + if (hasPrevReference.getVal()) { break; } diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicAirDecompileTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicAirDecompileTest.java index 261ee0960..eb5128c90 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicAirDecompileTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicAirDecompileTest.java @@ -1066,10 +1066,9 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile decompileMethod("classic_air", "testInlineFunctions", "var first:String = \"value1\";\r\n" + "var traceParameter:Function = function(aParam:String):String\r\n" + "{\r\n" - + "var traceParam2:Function;\r\n" + "var second:String = \"value2\";\r\n" + "second = second + \"cc\";\r\n" - + "traceParam2 = function(bParam:String):String\r\n" + + "var traceParam2:Function = function(bParam:String):String\r\n" + "{\r\n" + "trace(bParam + \",\" + aParam);\r\n" + "return first + second + aParam + bParam;\r\n" @@ -1217,8 +1216,7 @@ public class ActionScript3ClassicAirDecompileTest extends ActionScript3Decompile @Test public void testNamedAnonFunctions() { - decompileMethod("classic_air", "testNamedAnonFunctions", "var test:*;\r\n" - + "test = new (function():*\r\n" + decompileMethod("classic_air", "testNamedAnonFunctions", "var test:* = new (function():*\r\n" + "{\r\n" + "var testFunc:Function;\r\n" + "return testFunc = function(param1:*, param2:int, param3:Array):Boolean\r\n" diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicDecompileTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicDecompileTest.java index 24fbda760..e5df84a7f 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicDecompileTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassicDecompileTest.java @@ -120,11 +120,9 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testCompoundAssignments() { - decompileMethod("classic", "testCompoundAssignments", "var b:*;\r\n" - + "var a:int;\r\n" - + "var t:MyTest;\r\n" - + "b = [10,20,30];\r\n" - + "a = 0;\r\n" + decompileMethod("classic", "testCompoundAssignments", "var t:MyTest;\r\n" + + "var b:* = [10,20,30];\r\n" + + "var a:int = 0;\r\n" + "trace(\"a += 5\");\r\n" + "a += 5;\r\n" + "trace(\"arr[call()] = arr[call()] + 2;\");\r\n" @@ -393,8 +391,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testFinallyZeroJump() { - decompileMethod("classic", "testFinallyZeroJump", "var str:String;\r\n" - + "str = param1;\r\n" + decompileMethod("classic", "testFinallyZeroJump", "var str:String = param1;\r\n" + "try\r\n" + "{\r\n" + "}\r\n" @@ -652,23 +649,18 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testForXml() { - decompileMethod("classic", "testForXml", "var myXML:XML;\r\n" - + "var k:*;\r\n" - + "var len:int;\r\n" - + "var a:int;\r\n" - + "var b:int;\r\n" - + "var i:int;\r\n" + decompileMethod("classic", "testForXml", "var i:int;\r\n" + "var c:int = 0;\r\n" + "var name:String = \"ahoj\";\r\n" - + "myXML = \r\n" + + "var myXML:XML = \r\n" + "\r\n" + "{name}\r\n" + "\r\n" + ";\r\n" - + "k = null;\r\n" - + "len = 5;\r\n" - + "a = 5;\r\n" - + "b = 6;\r\n" + + "var k:* = null;\r\n" + + "var len:int = 5;\r\n" + + "var a:int = 5;\r\n" + + "var b:int = 6;\r\n" + "for(i = 0; i < len; k = myXML.book.(@isbn == \"12345\"))\r\n" + "{\r\n" + "c = 1;\r\n" @@ -903,8 +895,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testIfFinally() { - decompileMethod("classic", "testIfFinally", "var a:int;\r\n" - + "a = Math.random();\r\n" + decompileMethod("classic", "testIfFinally", "var a:int = Math.random();\r\n" + "if(a == 5)\r\n" + "{\r\n" + "try\r\n" @@ -1073,11 +1064,10 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes + "first = \"value1\";\r\n" + "var traceParameter:Function = function(aParam:String):String\r\n" + "{\r\n" - + "var traceParam2:Function;\r\n" + "var second:String = null;\r\n" + "second = \"value2\";\r\n" + "second += \"cc\";\r\n" - + "traceParam2 = function(bParam:String):String\r\n" + + "var traceParam2:Function = function(bParam:String):String\r\n" + "{\r\n" + "trace(bParam + \",\" + aParam);\r\n" + "return first + second + aParam + bParam;\r\n" @@ -1225,8 +1215,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testNamedAnonFunctions() { - decompileMethod("classic", "testNamedAnonFunctions", "var test:*;\r\n" - + "test = new function testFunc(param1:*, param2:int, param3:Array):Boolean\r\n" + decompileMethod("classic", "testNamedAnonFunctions", "var test:* = new function testFunc(param1:*, param2:int, param3:Array):Boolean\r\n" + "{\r\n" + "return (param1 as TestClass2).attrib1 == 5;\r\n" + "};\r\n", @@ -1467,8 +1456,7 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testTryIf() { - decompileMethod("classic", "testTryIf", "var a:int;\r\n" - + "a = Math.random();\r\n" + decompileMethod("classic", "testTryIf", "var a:int = Math.random();\r\n" + "try\r\n" + "{\r\n" + "if(a > 5 && a < 50)\r\n" @@ -1561,12 +1549,11 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testUndefined() { - decompileMethod("classic", "testUndefined", "var f:*;\r\n" - + "var i:int = 0;\r\n" + decompileMethod("classic", "testUndefined", "var i:int = 0;\r\n" + "var j:int = 0;\r\n" + "var c:int = 0;\r\n" + "c = 5 + i;\r\n" - + "f = function():*\r\n" + + "var f:* = function():*\r\n" + "{\r\n" + "trace(c);\r\n" + "trace(j);\r\n" @@ -1714,9 +1701,8 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testWhileTry2() { - decompileMethod("classic", "testWhileTry2", "var j:*;\r\n" - + "var i:*;\r\n" - + "j = undefined;\r\n" + decompileMethod("classic", "testWhileTry2", "var i:*;\r\n" + + "var j:* = undefined;\r\n" + "for(i = 0; i < 100; i++)\r\n" + "{\r\n" + "try\r\n" @@ -1742,20 +1728,17 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes @Test public void testXml() { - decompileMethod("classic", "testXml", "var myXML:XML;\r\n" - + "var k:*;\r\n" - + "var all:String;\r\n" - + "var g:XML = null;\r\n" + decompileMethod("classic", "testXml", "var g:XML = null;\r\n" + "var testCdata:XML = null;\r\n" + "var testComment:XML = null;\r\n" + "var name:String = \"ahoj\";\r\n" - + "myXML = \r\n" + + "var myXML:XML = \r\n" + "\r\n" + "{name}\r\n" + "\r\n" + ";\r\n" - + "k = myXML.@id;\r\n" - + "all = myXML.@*.toXMLString();\r\n" + + "var k:* = myXML.@id;\r\n" + + "var all:String = myXML.@*.toXMLString();\r\n" + "k = myXML.book;\r\n" + "k = myXML.book.(@isbn == \"12345\");\r\n" + "g =