mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-05-25 13:57:09 +00:00
Fixed #1195 this keyword in functions outside class
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.NewActivationAVM2Item;
|
||||
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);
|
||||
return localData.getConstants().getMultiname(((ExceptionAVM2Item) obj).exception.name_index);
|
||||
} else if ((obj instanceof ThisAVM2Item) || (obj instanceof ClassAVM2Item)) {
|
||||
List<Trait> traits = localData.getScriptInfo().get(localData.scriptIndex).traits.traits;
|
||||
for (int t = 0; t < traits.size(); t++) {
|
||||
Trait trait = traits.get(t);
|
||||
|
||||
@@ -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<Trait> 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;
|
||||
}
|
||||
|
||||
@@ -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.instructions.InstructionDefinition;
|
||||
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<GraphTargetItem> output, String path) {
|
||||
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> 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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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, DottedChain className, boolean basicObject) {
|
||||
super(instruction, lineStartIns, PRECEDENCE_PRIMARY);
|
||||
this.className = className;
|
||||
this.className = className;
|
||||
this.basicObject = basicObject;
|
||||
getSrcData().localName = "this";
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
+ "}");
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -16,7 +16,7 @@
|
||||
</define>
|
||||
<define append="true">
|
||||
<name>CONFIG::timeStamp</name>
|
||||
<value>'07.02.2021'</value>
|
||||
<value>'08.02.2021'</value>
|
||||
</define>
|
||||
<define append="true">
|
||||
<name>CONFIG::air</name>
|
||||
|
||||
@@ -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;
|
||||
|
||||
18
libsrc/ffdec_lib/testdata/as3_new/src/tests_classes/TestThisOutsideClass.as
vendored
Normal file
18
libsrc/ffdec_lib/testdata/as3_new/src/tests_classes/TestThisOutsideClass.as
vendored
Normal file
@@ -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++;
|
||||
}
|
||||
Reference in New Issue
Block a user