Fixed #1888 Properly resolve static vs nonstatic properties

This commit is contained in:
Jindra Petřík
2022-11-30 22:58:35 +01:00
parent 87a8a03ca1
commit 9324f01183
17 changed files with 101 additions and 94 deletions
@@ -1977,7 +1977,7 @@ public class AVM2Code implements Cloneable {
Slot sl = new Slot(new NewActivationAVM2Item(null, null), abc.constants.getMultiname(traits.get(traitName).name_index));
TraitSlotConst tsc = (TraitSlotConst) traits.get(traitName);
GraphTargetItem type = PropertyAVM2Item.multinameToType(tsc.type_index, abc.constants);
DeclarationAVM2Item d = new DeclarationAVM2Item(new GetLexAVM2Item(null, null, sl.multiname, abc.constants, type), type);
DeclarationAVM2Item d = new DeclarationAVM2Item(new GetLexAVM2Item(null, null, sl.multiname, abc.constants, type, false), type);
declaredSlotsDec.add(d);
declaredSlots.add(sl);
@@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.abc.AVM2LocalData;
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.other.GetPropertyIns;
import com.jpexs.decompiler.flash.abc.avm2.model.CallPropertyAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.FindPropertyAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.FullMultinameAVM2Item;
@@ -28,6 +29,7 @@ import com.jpexs.decompiler.flash.ecma.NotCompileTime;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.helpers.Reference;
import java.util.ArrayList;
import java.util.List;
@@ -81,29 +83,8 @@ public class CallPropLexIns extends CallPropertyIns {
FullMultinameAVM2Item multiname = resolveMultiname(localData, true, stack, localData.getConstants(), multinameIndex, ins);
GraphTargetItem receiver = stack.pop();
GraphTargetItem type = TypeItem.UNBOUNDED;
if (receiver instanceof FindPropertyAVM2Item) {
FindPropertyAVM2Item fprop = (FindPropertyAVM2Item) receiver;
if (fprop.propertyName.equals(multiname)) {
switch (multiname.resolvedMultinameName) {
case "Boolean":
case "int":
case "uint":
case "Number":
case "String":
type = new TypeItem(multiname.resolvedMultinameName);
break;
}
}
} else {
if (localData.abcIndex != null) {
GraphTargetItem receiverType = receiver.returnType();
if (!receiverType.equals(TypeItem.UNBOUNDED)) {
type = localData.abcIndex.findPropertyCallType(localData.abc, receiverType, multiname.resolvedMultinameName, localData.abc.constants.getMultiname(multinameIndex).namespace_index,true, true);
}
}
}
Reference<Boolean> isStatic = new Reference<>(false);
GraphTargetItem type = GetPropertyIns.resolvePropertyType(localData, receiver, multiname, isStatic, true);
stack.push(new CallPropertyAVM2Item(ins, localData.lineStartInstruction, false, receiver, multiname, args, type));
}
@@ -23,12 +23,14 @@ 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.other.GetPropertyIns;
import com.jpexs.decompiler.flash.abc.avm2.model.CallPropertyAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.FindPropertyAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.FullMultinameAVM2Item;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.helpers.Reference;
import java.util.ArrayList;
import java.util.List;
@@ -80,30 +82,9 @@ public class CallPropVoidIns extends InstructionDefinition {
}
FullMultinameAVM2Item multiname = resolveMultiname(localData, true, stack, localData.getConstants(), multinameIndex, ins);
GraphTargetItem receiver = stack.pop();
GraphTargetItem type = TypeItem.UNBOUNDED;
if (receiver instanceof FindPropertyAVM2Item) {
FindPropertyAVM2Item fprop = (FindPropertyAVM2Item) receiver;
if (fprop.propertyName.equals(multiname)) {
switch (multiname.resolvedMultinameName) {
case "Boolean":
case "int":
case "uint":
case "Number":
case "String":
type = new TypeItem(multiname.resolvedMultinameName);
break;
}
}
} else {
if (localData.abcIndex != null) {
GraphTargetItem receiverType = receiver.returnType();
if (!receiverType.equals(TypeItem.UNBOUNDED)) {
type = localData.abcIndex.findPropertyCallType(localData.abc, receiverType, multiname.resolvedMultinameName, localData.abc.constants.getMultiname(multinameIndex).namespace_index,true, true);
}
}
}
GraphTargetItem receiver = stack.pop();
Reference<Boolean> isStatic = new Reference<>(false);
GraphTargetItem type = GetPropertyIns.resolvePropertyType(localData, receiver, multiname, isStatic, true);
output.add(new CallPropertyAVM2Item(ins, localData.lineStartInstruction, true, receiver, multiname, args, type));
}
@@ -23,6 +23,7 @@ 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.other.GetPropertyIns;
import com.jpexs.decompiler.flash.abc.avm2.model.CallPropertyAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.FindPropertyAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.FullMultinameAVM2Item;
@@ -30,6 +31,7 @@ import com.jpexs.decompiler.flash.ecma.NotCompileTime;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.helpers.Reference;
import java.util.ArrayList;
import java.util.List;
@@ -81,29 +83,9 @@ public class CallPropertyIns extends InstructionDefinition {
FullMultinameAVM2Item multiname = resolveMultiname(localData, true, stack, localData.getConstants(), multinameIndex, ins);
GraphTargetItem receiver = stack.pop();
GraphTargetItem type = TypeItem.UNBOUNDED;
if (receiver instanceof FindPropertyAVM2Item) {
FindPropertyAVM2Item fprop = (FindPropertyAVM2Item) receiver;
if (fprop.propertyName.equals(multiname)) {
switch (multiname.resolvedMultinameName) {
case "Boolean":
case "int":
case "uint":
case "Number":
case "String":
type = new TypeItem(multiname.resolvedMultinameName);
break;
}
}
} else {
if (localData.abcIndex != null) {
GraphTargetItem receiverType = receiver.returnType();
if (!receiverType.equals(TypeItem.UNBOUNDED)) {
type = localData.abcIndex.findPropertyCallType(localData.abc, receiverType, multiname.resolvedMultinameName, localData.abc.constants.getMultiname(multinameIndex).namespace_index,true, true);
}
}
}
Reference<Boolean> isStatic = new Reference<>(false);
GraphTargetItem type = GetPropertyIns.resolvePropertyType(localData, receiver, multiname, isStatic, true);
stack.push(new CallPropertyAVM2Item(ins, localData.lineStartInstruction, false, receiver, multiname, args, type));
}
@@ -63,6 +63,7 @@ public class GetLexIns extends InstructionDefinition {
}
}
boolean isStatic = false;
if (slotType == null) {
if (localData.abcIndex != null) {
String currentClassName = localData.classIndex == -1 ? null : localData.abc.instance_info.get(localData.classIndex).getName(localData.abc.constants).getNameWithNamespace(localData.abc.constants, true).toRawString();
@@ -75,6 +76,7 @@ public class GetLexIns extends InstructionDefinition {
TypeItem ti = new TypeItem(multiname.getNameWithNamespace(localData.abc.constants, true));
if (localData.abcIndex.findClass(ti) != null) {
slotType = ti;
isStatic = true;
}
}
}
@@ -83,7 +85,7 @@ public class GetLexIns extends InstructionDefinition {
if (slotType == null) {
slotType = TypeItem.UNBOUNDED;
}
stack.push(new GetLexAVM2Item(ins, localData.lineStartInstruction, multiname, localData.getConstants(), slotType));
stack.push(new GetLexAVM2Item(ins, localData.lineStartInstruction, multiname, localData.getConstants(), slotType, isStatic));
}
@Override
@@ -42,6 +42,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.DuplicateItem;
import com.jpexs.helpers.Reference;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@@ -128,7 +129,17 @@ public class GetPropertyIns extends InstructionDefinition {
}
}
}
Reference<Boolean> isStatic = new Reference<>(false);
GraphTargetItem type = resolvePropertyType(localData, obj, multiname, isStatic, false);
stack.push(new GetPropertyAVM2Item(ins, localData.lineStartInstruction, obj, multiname, type, isStatic.getVal()));
}
public static GraphTargetItem resolvePropertyType(
AVM2LocalData localData,
GraphTargetItem obj,
FullMultinameAVM2Item multiname,
Reference<Boolean> isStatic, boolean call) {
GraphTargetItem type = null;
String multinameStr = localData.abc.constants.getMultiname(multiname.multinameIndex).getName(localData.abc.constants, new ArrayList<>(), true, true);
if (obj instanceof FindPropertyAVM2Item) {
@@ -146,19 +157,20 @@ public class GetPropertyIns extends InstructionDefinition {
}
}
}
if (type == null) {
if (localData.abcIndex != null) {
String currentClassName = localData.classIndex == -1 ? null : localData.abc.instance_info.get(localData.classIndex).getName(localData.abc.constants).getNameWithNamespace(localData.abc.constants, true).toRawString();
GraphTargetItem thisPropType = currentClassName == null ? TypeItem.UNBOUNDED : localData.abcIndex.findPropertyType(localData.abc, new TypeItem(currentClassName), multinameStr, localData.abc.constants.getMultiname(multinameIndex).namespace_index, true, true);
String currentClassName = localData.classIndex == -1 ? null : localData.abc.instance_info.get(localData.classIndex).getName(localData.abc.constants).getNameWithNamespace(localData.abc.constants, true).toRawString();
GraphTargetItem thisPropType = currentClassName == null ? TypeItem.UNBOUNDED : localData.abcIndex.findPropertyType(localData.abc, new TypeItem(currentClassName), multinameStr, localData.abc.constants.getMultiname(multiname.multinameIndex).namespace_index, true, true);
if (!thisPropType.equals(TypeItem.UNBOUNDED)) {
type = thisPropType;
}
if (type == null) {
TypeItem ti = new TypeItem(localData.abc.constants.getMultiname(multinameIndex).getNameWithNamespace(localData.abc.constants, true));
TypeItem ti = new TypeItem(localData.abc.constants.getMultiname(multiname.multinameIndex).getNameWithNamespace(localData.abc.constants, true));
if (localData.abcIndex.findClass(ti) != null) {
type = ti;
isStatic.setVal(true);
}
}
}
@@ -168,16 +180,32 @@ public class GetPropertyIns extends InstructionDefinition {
if (localData.abcIndex != null) {
GraphTargetItem receiverType = obj.returnType();
if (!receiverType.equals(TypeItem.UNBOUNDED)) {
type = localData.abcIndex.findPropertyType(localData.abc, receiverType, multiname.resolvedMultinameName, localData.abc.constants.getMultiname(multinameIndex).namespace_index,true, true);
}
boolean parentStatic = false;
if (obj instanceof GetLexAVM2Item) {
if (((GetLexAVM2Item) obj).isStatic) {
parentStatic = true;
}
}
if (obj instanceof GetPropertyAVM2Item) {
if (((GetPropertyAVM2Item) obj).isStatic) {
parentStatic = true;
}
}
if (call) {
type = localData.abcIndex.findPropertyCallType(localData.abc, receiverType, multiname.resolvedMultinameName, localData.abc.constants.getMultiname(multiname.multinameIndex).namespace_index, parentStatic, !parentStatic);
} else {
type = localData.abcIndex.findPropertyType(localData.abc, receiverType, multiname.resolvedMultinameName, localData.abc.constants.getMultiname(multiname.multinameIndex).namespace_index, parentStatic, !parentStatic);
}
}
}
}
if (type == null) {
type = TypeItem.UNBOUNDED;
}
stack.push(new GetPropertyAVM2Item(ins, localData.lineStartInstruction, obj, multiname, type));
return type;
}
@Override
@@ -29,6 +29,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.helpers.Reference;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@@ -51,7 +52,7 @@ public class InitPropertyIns extends InstructionDefinition {
FullMultinameAVM2Item multiname = resolveMultiname(localData, true, stack, localData.getConstants(), multinameIndex, ins);
GraphTargetItem obj = stack.pop();
GraphTargetItem propertyType = TypeItem.UNBOUNDED;
/*GraphTargetItem propertyType = TypeItem.UNBOUNDED;
String multinameStr = localData.abc.constants.getMultiname(multiname.multinameIndex).getName(localData.abc.constants, new ArrayList<>(), true, true);
for (Trait t : localData.methodBody.traits.traits) {
@@ -65,8 +66,12 @@ public class InitPropertyIns extends InstructionDefinition {
break;
}
}
}
InitPropertyAVM2Item result = new InitPropertyAVM2Item(ins, localData.lineStartInstruction, obj, multiname, val, propertyType);
}*/
Reference<Boolean> isStatic = new Reference<>(false);
GraphTargetItem type = GetPropertyIns.resolvePropertyType(localData, obj, multiname, isStatic, false);
InitPropertyAVM2Item result = new InitPropertyAVM2Item(ins, localData.lineStartInstruction, obj, multiname, val, type, isStatic.getVal());
SetPropertyIns.handleCompound(localData, obj, multiname, val, output, result);
output.add(result);
}
@@ -48,6 +48,7 @@ import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.CompoundableBinaryOp;
import com.jpexs.decompiler.graph.model.DuplicateItem;
import com.jpexs.helpers.Reference;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@@ -342,6 +343,7 @@ public class SetPropertyIns extends InstructionDefinition implements SetTypeIns
}
}
/*
GraphTargetItem propertyType = TypeItem.UNBOUNDED;
String multinameStr = localData.abc.constants.getMultiname(multiname.multinameIndex).getName(localData.abc.constants, new ArrayList<>(), true, true);
@@ -357,8 +359,11 @@ public class SetPropertyIns extends InstructionDefinition implements SetTypeIns
}
}
}
*/
Reference<Boolean> isStatic = new Reference<>(false);
GraphTargetItem type = GetPropertyIns.resolvePropertyType(localData, obj, multiname, isStatic, false);
SetPropertyAVM2Item result = new SetPropertyAVM2Item(ins, localData.lineStartInstruction, obj, multiname, value, propertyType);
SetPropertyAVM2Item result = new SetPropertyAVM2Item(ins, localData.lineStartInstruction, obj, multiname, value, type, isStatic.getVal());
handleCompound(localData, obj, multiname, value, output, result);
SetTypeIns.handleResult(value, stack, output, localData, result, -1);
@@ -36,14 +36,17 @@ public class GetLexAVM2Item extends AVM2Item implements SimpleValue {
public Multiname propertyName;
public GraphTargetItem type;
public boolean isStatic;
private final DottedChain fullPropertyName;
public GetLexAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, Multiname propertyName, AVM2ConstantPool constants, GraphTargetItem type) {
public GetLexAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, Multiname propertyName, AVM2ConstantPool constants, GraphTargetItem type, boolean isStatic) {
super(instruction, lineStartIns, PRECEDENCE_PRIMARY);
this.propertyName = propertyName;
this.type = type;
this.fullPropertyName = propertyName.getNameWithNamespace(constants, true);
this.isStatic = isStatic;
}
public String getRawPropertyName() {
@@ -48,6 +48,8 @@ public class GetPropertyAVM2Item extends AVM2Item {
public GraphTargetItem propertyName;
public GraphTargetItem type;
public boolean isStatic;
@Override
public void visit(GraphTargetVisitorInterface visitor) {
@@ -129,11 +131,12 @@ public class GetPropertyAVM2Item extends AVM2Item {
return null;
}
public GetPropertyAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem object, GraphTargetItem propertyName, GraphTargetItem type) {
public GetPropertyAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem object, GraphTargetItem propertyName, GraphTargetItem type, boolean isStatic) {
super(instruction, lineStartIns, PRECEDENCE_PRIMARY);
this.object = object;
this.propertyName = propertyName;
this.type = type;
this.isStatic = isStatic;
}
@Override
@@ -43,6 +43,8 @@ public class InitPropertyAVM2Item extends AVM2Item implements SetTypeAVM2Item, A
public String compoundOperator;
public GraphTargetItem type;
public boolean isStatic;
@Override
public void visit(GraphTargetVisitorInterface visitor) {
@@ -61,11 +63,12 @@ public class InitPropertyAVM2Item extends AVM2Item implements SetTypeAVM2Item, A
this.declaration = declaration;
}
public InitPropertyAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem object, FullMultinameAVM2Item propertyName, GraphTargetItem value, GraphTargetItem type) {
public InitPropertyAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem object, FullMultinameAVM2Item propertyName, GraphTargetItem value, GraphTargetItem type, boolean isStatic) {
super(instruction, lineStartIns, PRECEDENCE_ASSIGMENT, value);
this.object = object;
this.propertyName = propertyName;
this.type = type;
this.isStatic = isStatic;
}
@Override
@@ -84,7 +87,7 @@ public class InitPropertyAVM2Item extends AVM2Item implements SetTypeAVM2Item, A
@Override
public GraphTargetItem getObject() {
return new GetPropertyAVM2Item(getInstruction(), getLineStartIns(), object, propertyName, type);
return new GetPropertyAVM2Item(getInstruction(), getLineStartIns(), object, propertyName, type, isStatic);
}
@Override
@@ -50,6 +50,8 @@ public class SetPropertyAVM2Item extends AVM2Item implements SetTypeAVM2Item, As
public String compoundOperator;
public GraphTargetItem type;
public boolean isStatic;
@Override
public DeclarationAVM2Item getDeclaration() {
@@ -75,12 +77,13 @@ public class SetPropertyAVM2Item extends AVM2Item implements SetTypeAVM2Item, As
}
}
public SetPropertyAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem object, GraphTargetItem propertyName, GraphTargetItem value, GraphTargetItem type) {
public SetPropertyAVM2Item(GraphSourceItem instruction, GraphSourceItem lineStartIns, GraphTargetItem object, GraphTargetItem propertyName, GraphTargetItem value, GraphTargetItem type, boolean isStatic) {
super(instruction, lineStartIns, PRECEDENCE_ASSIGMENT);
this.object = object;
this.propertyName = propertyName;
this.value = value;
this.type = type;
this.isStatic = isStatic;
}
@Override
@@ -103,7 +106,7 @@ public class SetPropertyAVM2Item extends AVM2Item implements SetTypeAVM2Item, As
@Override
public GraphTargetItem getObject() {
return new GetPropertyAVM2Item(getInstruction(), getLineStartIns(), object, propertyName, type);
return new GetPropertyAVM2Item(getInstruction(), getLineStartIns(), object, propertyName, type, isStatic);
}
@Override