diff --git a/CHANGELOG.md b/CHANGELOG.md index 6508d3b91..ea0167927 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ All notable changes to this project will be documented in this file. - AS3 deobfuscator on &&, || operators - Merged continues in try..catch - AS3 method display in GUI when method name is null +- #1195 this keyword in functions outside class ### Changed - AS3 test methods separated to classes diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/InstructionDefinition.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/InstructionDefinition.java index 54d008138..6f3752d68 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/InstructionDefinition.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/InstructionDefinition.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.abc.avm2.instructions; import com.jpexs.decompiler.flash.abc.ABC; @@ -32,7 +33,6 @@ import com.jpexs.decompiler.flash.abc.avm2.model.ClassAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.FindPropertyAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.FullMultinameAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.NewActivationAVM2Item; -import com.jpexs.decompiler.flash.abc.avm2.model.ScriptAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.ThisAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.clauses.ExceptionAVM2Item; import com.jpexs.helpers.Reference; @@ -332,7 +332,7 @@ public abstract class InstructionDefinition implements Serializable { private Multiname searchSlotName(int slotIndex, AVM2LocalData localData, GraphTargetItem obj, int multiNameIndex) { if ((obj instanceof ExceptionAVM2Item) && (multiNameIndex == -1 || ((ExceptionAVM2Item) obj).exception.name_index == multiNameIndex)) { return localData.getConstants().getMultiname(((ExceptionAVM2Item) obj).exception.name_index); - } else if ((obj instanceof ThisAVM2Item) || (obj instanceof ClassAVM2Item) || (obj instanceof ScriptAVM2Item)) { + } else if ((obj instanceof ThisAVM2Item) || (obj instanceof ClassAVM2Item)) { List traits = localData.getScriptInfo().get(localData.scriptIndex).traits.traits; for (int t = 0; t < traits.size(); t++) { Trait trait = traits.get(t); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocalTypeIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocalTypeIns.java index 2110eabf3..179c811e5 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocalTypeIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocalTypeIns.java @@ -32,7 +32,6 @@ import com.jpexs.decompiler.flash.abc.avm2.model.IncrementAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.PostDecrementAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.PostIncrementAVM2Item; -import com.jpexs.decompiler.flash.abc.avm2.model.ScriptAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.SetLocalAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.SetPropertyAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.model.SetTypeAVM2Item; @@ -71,17 +70,16 @@ public abstract class GetLocalTypeIns extends InstructionDefinition { if (regId == 0) { if ((localData.classIndex >= localData.getInstanceInfo().size()) || localData.classIndex < 0) { - stack.push(new ScriptAVM2Item(localData.scriptIndex)); + stack.push(new ThisAVM2Item(ins, localData.lineStartInstruction, null, false)); return; } if (localData.isStatic) { stack.push(new ClassAVM2Item(localData.getInstanceInfo().get(localData.classIndex).getName(localData.getConstants()))); } else { - List ts = localData.getInstanceInfo().get(localData.classIndex).instance_traits.traits; boolean isBasicObject = localData.thisHasDefaultToPrimitive; Multiname m = localData.getInstanceInfo().get(localData.classIndex).getName(localData.getConstants()); - stack.push(new ThisAVM2Item(ins, localData.lineStartInstruction, m, m.getNameWithNamespace(localData.getConstants(), true), isBasicObject)); + stack.push(new ThisAVM2Item(ins, localData.lineStartInstruction, m.getNameWithNamespace(localData.getConstants(), true), isBasicObject)); } return; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetGlobalScopeIns.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetGlobalScopeIns.java index 7f854d8c7..c7c55249c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetGlobalScopeIns.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/other/GetGlobalScopeIns.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.abc.avm2.instructions.other; import com.jpexs.decompiler.flash.abc.ABC; @@ -21,7 +22,6 @@ import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.model.ScriptAVM2Item; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.TranslateStack; import java.util.List; @@ -43,16 +43,6 @@ public class GetGlobalScopeIns extends InstructionDefinition { @Override public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List output, String path) { - if (localData.scopeStack.isEmpty()) { - /*if (localData.classIndex == -1) { - - } else { - stack.push(new ClassAVM2Item(localData.getInstanceInfo().get(localData.classIndex).getName(localData.getConstants()))); - }*/ - //FIXME?? - stack.push(new ScriptAVM2Item(localData.scriptIndex)); - return; - } stack.push(localData.scopeStack.get(0)); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/ScriptAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/ScriptAVM2Item.java deleted file mode 100644 index 3c9cbc3ba..000000000 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/ScriptAVM2Item.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2010-2021 JPEXS, All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3.0 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ -package com.jpexs.decompiler.flash.abc.avm2.model; - -import com.jpexs.decompiler.flash.helpers.GraphTextWriter; -import com.jpexs.decompiler.graph.GraphTargetItem; -import com.jpexs.decompiler.graph.TypeItem; -import com.jpexs.decompiler.graph.model.LocalData; - -/** - * - * @author JPEXS - */ -public class ScriptAVM2Item extends AVM2Item { - - public int scriptIndex; - - public ScriptAVM2Item(int scriptIndex) { - super(null, null, NOPRECEDENCE); - this.scriptIndex = scriptIndex; - } - - @Override - public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) { - return writer.append("script").append(scriptIndex); - } - - @Override - public GraphTargetItem returnType() { - return TypeItem.UNBOUNDED; - } - - @Override - public boolean hasReturnValue() { - return false; - } -} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/ThisAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/ThisAVM2Item.java index d014313e6..a1341e07c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/ThisAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/model/ThisAVM2Item.java @@ -12,7 +12,8 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library. */ + * License along with this library. + */ package com.jpexs.decompiler.flash.abc.avm2.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; @@ -42,12 +43,9 @@ public class ThisAVM2Item extends AVM2Item { public boolean basicObject; - public Multiname classMultiname; - - public ThisAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, Multiname classMultiname, DottedChain className, boolean basicObject) { + public ThisAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, DottedChain className, boolean basicObject) { super(instruction, lineStartIns, PRECEDENCE_PRIMARY); this.className = className; - this.classMultiname = classMultiname; this.basicObject = basicObject; getSrcData().localName = "this"; } diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassTest.java index 6dc891b21..7fa0d264a 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/as3decompile/ActionScript3ClassTest.java @@ -214,4 +214,33 @@ public class ActionScript3ClassTest extends ActionScript3DecompileTestBase { + " }\n" + "}"); } + + @Test + public void testThisOutsideClass() { + decompileScriptPack("tests_classes.TestThisOutsideClass", "package tests_classes\n" + + "{\n" + + " public class TestThisOutsideClass\n" + + " {\n" + + " \n" + + " \n" + + " public var attrib:int = 0;\n" + + " \n" + + " public function TestThisOutsideClass()\n" + + " {\n" + + " super();\n" + + " }\n" + + " \n" + + " public function run() : void\n" + + " {\n" + + " helperFunc.call(this,\"hello\");\n" + + " }\n" + + " }\n" + + "}\n" + + "\n" + + "function helperFunc(a:String):void\n" + + "{\n" + + " trace(a);\n" + + " this.attrib++;\n" + + "}"); + } } diff --git a/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.air.swf b/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.air.swf index 5ce622dad..927ae8b59 100644 Binary files a/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.air.swf and b/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.air.swf differ diff --git a/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf b/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf index a435a92ad..068bde491 100644 Binary files a/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf and b/libsrc/ffdec_lib/testdata/as3_new/bin/as3_new.flex.swf differ diff --git a/libsrc/ffdec_lib/testdata/as3_new/obj/as3_newConfig.old b/libsrc/ffdec_lib/testdata/as3_new/obj/as3_newConfig.old index 58612c672..ae615d5d5 100644 --- a/libsrc/ffdec_lib/testdata/as3_new/obj/as3_newConfig.old +++ b/libsrc/ffdec_lib/testdata/as3_new/obj/as3_newConfig.old @@ -16,7 +16,7 @@ CONFIG::timeStamp - '07.02.2021' + '08.02.2021' CONFIG::air diff --git a/libsrc/ffdec_lib/testdata/as3_new/src/Main.as b/libsrc/ffdec_lib/testdata/as3_new/src/Main.as index 237141a4f..baa414564 100644 --- a/libsrc/ffdec_lib/testdata/as3_new/src/Main.as +++ b/libsrc/ffdec_lib/testdata/as3_new/src/Main.as @@ -6,6 +6,7 @@ package import tests_classes.mypackage1.SetupMyPackage1; import tests_classes.mypackage2.SetupMyPackage2; import tests_classes.mypackage3.SetupMyPackage3; + import tests_classes.TestThisOutsideClass; /** * ... @@ -79,6 +80,7 @@ package TestSwitchComma; TestSwitchDefault; TestTernarOperator; + TestThisOutsideClass; TestTry; TestTryIf; TestTryReturn; diff --git a/libsrc/ffdec_lib/testdata/as3_new/src/tests_classes/TestThisOutsideClass.as b/libsrc/ffdec_lib/testdata/as3_new/src/tests_classes/TestThisOutsideClass.as new file mode 100644 index 000000000..3704494d1 --- /dev/null +++ b/libsrc/ffdec_lib/testdata/as3_new/src/tests_classes/TestThisOutsideClass.as @@ -0,0 +1,18 @@ +package tests_classes +{ + + public class TestThisOutsideClass + { + public var attrib : int = 0; + public function run():void + { + helperFunc.call(this,"hello"); + } + } +} + +function helperFunc(a:String): void +{ + trace(a); + this.attrib++; +}