fix: fix as3 direct edit - protected access (#2686, #2688)

Fixes #2686, #2688
This commit is contained in:
Jindra Petřík
2026-04-04 20:41:16 +02:00
parent 480b23b004
commit c6c847edb8
7 changed files with 46 additions and 32 deletions

View File

@@ -760,7 +760,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
*/
List<GraphTargetItem> getterBody = new ArrayList<>();
UnresolvedAVM2Item sp = new UnresolvedAVM2Item(new ArrayList<>(), importedClasses, false, TypeItem.UNBOUNDED, 0, new DottedChain(new String[]{"_skinParts"}),
null, openedNamespaces, abcIndex);
null, openedNamespaces, abcIndex, new TypeItem(""));
getterBody.add(new ReturnValueAVM2Item(null, null, sp));
List<AssignableAVM2Item> subvars = new ArrayList<>();
subvars.add(sp);
@@ -3121,7 +3121,7 @@ public class AVM2SourceGenerator implements SourceGenerator {
ret.add(ins(AVM2Instructions.NewObject, 0));
ret.add(ins(AVM2Instructions.PushWith));
scope = localData.scopeStack.size();
localData.scopeStack.add(new PropertyAVM2Item(null, false, item.functionName, "" /*??*/, abcIndex, new ArrayList<>(), localData.callStack, false, null, -1));
localData.scopeStack.add(new PropertyAVM2Item(null, false, item.functionName, "" /*??*/, abcIndex, new ArrayList<>(), localData.callStack, false, null, -1, new TypeItem("")));
}
AVM2ConstantPool constants = abcIndex.getSelectedAbc().constants;
ret.add(ins(AVM2Instructions.NewFunction, method(null, false, constants.getStringId(item.functionName, true), true, false, false, localData.callStack, localData.pkg, item.needsActivation, item.subvariables, 0 /*Set later*/, item.hasRest, item.line, localData.currentClassBaseName, null, false, localData, item.paramTypes, item.paramNames, item.paramValues, item.body, item.retType)));

View File

@@ -220,7 +220,7 @@ public class ActionScript3Parser {
expectedType(SymbolType.PARENT_CLOSE);
break;
case PARENT_OPEN:
ret = new CallAVM2Item(openedNamespaces, lexer.yyline(), ret, call(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables, abc), abcIndex);
ret = new CallAVM2Item(openedNamespaces, lexer.yyline(), ret, call(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables, abc), abcIndex, thisType);
break;
case DESCENDANTS:
s = lex();
@@ -332,7 +332,7 @@ public class ActionScript3Parser {
GraphTargetItem ns = null;
if (s.type == SymbolType.NAMESPACE_OP) {
if (nsKeyword == null) {
ns = new UnresolvedAVM2Item(new ArrayList<>(), importedClasses, false, null, lexer.yyline(), new DottedChain(new String[]{propName}, new String[]{""} /*FIXME ???*/), null, openedNamespaces, abcIndex);
ns = new UnresolvedAVM2Item(new ArrayList<>(), importedClasses, false, null, lexer.yyline(), new DottedChain(new String[]{propName}, new String[]{""} /*FIXME ???*/), null, openedNamespaces, abcIndex, thisType);
variables.add((UnresolvedAVM2Item) ns);
}
s = lex();
@@ -359,7 +359,7 @@ public class ActionScript3Parser {
if (ns != null) {
ret = new NamespacedAVM2Item(ns, propName, propItem, ret, attr, openedNamespaces, null);
} else {
ret = new PropertyAVM2Item(ret, attr, propName, nsSuffix, abcIndex, openedNamespaces, new ArrayList<>(), nullDot, nsKeyword, lexer.yyline());
ret = new PropertyAVM2Item(ret, attr, propName, nsSuffix, abcIndex, openedNamespaces, new ArrayList<>(), nullDot, nsKeyword, lexer.yyline(), thisType);
}
s = lex();
}
@@ -466,16 +466,16 @@ public class ActionScript3Parser {
GraphTargetItem ret = null;
if (!name.isEmpty()) {
UnresolvedAVM2Item unr = new UnresolvedAVM2Item(new ArrayList<>(), importedClasses, typeOnly, null, lexer.yyline(), name, null, openedNamespaces, abcIndex);
UnresolvedAVM2Item unr = new UnresolvedAVM2Item(new ArrayList<>(), importedClasses, typeOnly, null, lexer.yyline(), name, null, openedNamespaces, abcIndex, thisType);
//unr.setIndex(index);
variables.add(unr);
ret = unr;
}
if (nsname != null) {
if (nsKeyword != null && nspropItem == null) {
ret = new PropertyAVM2Item(ret, nsAtribute, nsprop, nsSuffix, abcIndex, openedNamespaces, new ArrayList<MethodBody>(), false, nsKeyword, lexer.yyline());
ret = new PropertyAVM2Item(ret, nsAtribute, nsprop, nsSuffix, abcIndex, openedNamespaces, new ArrayList<MethodBody>(), false, nsKeyword, lexer.yyline(), thisType);
} else {
UnresolvedAVM2Item ns = new UnresolvedAVM2Item(new ArrayList<>(), importedClasses, typeOnly, null, lexer.yyline(), new DottedChain(new String[]{nsname}), null, openedNamespaces, abcIndex);
UnresolvedAVM2Item ns = new UnresolvedAVM2Item(new ArrayList<>(), importedClasses, typeOnly, null, lexer.yyline(), new DottedChain(new String[]{nsname}), null, openedNamespaces, abcIndex, thisType);
variables.add(ns);
ret = new NamespacedAVM2Item(ns, nsprop, nspropItem, ret, nsAtribute, openedNamespaces, null);
}
@@ -2775,14 +2775,14 @@ public class ActionScript3Parser {
newvar = applyType(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, newvar, registerVars, inFunction, inMethod, variables, abc);
expectedType(SymbolType.PARENT_CLOSE);
expectedType(SymbolType.PARENT_OPEN);
ret = new ConstructSomethingAVM2Item(lexer.yyline(), openedNamespaces, newvar, call(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables, abc), abcIndex);
ret = new ConstructSomethingAVM2Item(lexer.yyline(), openedNamespaces, newvar, call(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables, abc), abcIndex, thisType);
} else {
lexer.pushback(s);
GraphTargetItem newvar = name(allOpenedNamespaces, thisType, pkg, needsActivation, false /*?*/, openedNamespaces, registerVars, inFunction, inMethod, variables, importedClasses, abc);
newvar = applyType(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, newvar, registerVars, inFunction, inMethod, variables, abc);
expectedType(SymbolType.PARENT_OPEN);
ret = new ConstructSomethingAVM2Item(lexer.yyline(), openedNamespaces, newvar, call(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables, abc), abcIndex);
ret = new ConstructSomethingAVM2Item(lexer.yyline(), openedNamespaces, newvar, call(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, registerVars, inFunction, inMethod, variables, abc), abcIndex, thisType);
}
allowMemberOrCall = true;
break;

View File

@@ -70,6 +70,7 @@ public class CallAVM2Item extends AVM2Item {
* ABC indexing
*/
private AbcIndexing abcIndex;
private final TypeItem thisType;
/**
* Constructor.
@@ -78,14 +79,16 @@ public class CallAVM2Item extends AVM2Item {
* @param name Name
* @param arguments Arguments
* @param abcIndex ABC indexing
* @param thisType This type
*/
public CallAVM2Item(List<NamespaceItem> openedNamespaces, int line, GraphTargetItem name, List<GraphTargetItem> arguments, AbcIndexing abcIndex) {
public CallAVM2Item(List<NamespaceItem> openedNamespaces, int line, GraphTargetItem name, List<GraphTargetItem> arguments, AbcIndexing abcIndex, TypeItem thisType) {
super(null, null, NOPRECEDENCE);
this.openedNamespaces = openedNamespaces;
this.name = name;
this.arguments = arguments;
this.line = line;
this.abcIndex = abcIndex;
this.thisType = thisType;
}
@Override
@@ -136,7 +139,7 @@ public class CallAVM2Item extends AVM2Item {
nobj.setRegNumber(0);
obj = nobj;
}*/
PropertyAVM2Item p = new PropertyAVM2Item(obj, n.isAttribute(), n.getVariableName(), n.getNamespaceSuffix(), g.abcIndex, n.openedNamespaces, new ArrayList<>(), false, null, line);
PropertyAVM2Item p = new PropertyAVM2Item(obj, n.isAttribute(), n.getVariableName(), n.getNamespaceSuffix(), g.abcIndex, n.openedNamespaces, new ArrayList<>(), false, null, line, thisType);
p.setAssignedValue(n.getAssignedValue());
callable = p;
}

View File

@@ -37,7 +37,7 @@ public class ConstructSomethingAVM2Item extends CallAVM2Item {
* Opened namespaces
*/
public List<NamespaceItem> openedNamespaces;
/**
* Constructor.
* @param line Line
@@ -46,8 +46,8 @@ public class ConstructSomethingAVM2Item extends CallAVM2Item {
* @param arguments Arguments
* @param abcIndex ABC index
*/
public ConstructSomethingAVM2Item(int line, List<NamespaceItem> openedNamespaces, GraphTargetItem name, List<GraphTargetItem> arguments, AbcIndexing abcIndex) {
super(openedNamespaces, line, name, arguments, abcIndex);
public ConstructSomethingAVM2Item(int line, List<NamespaceItem> openedNamespaces, GraphTargetItem name, List<GraphTargetItem> arguments, AbcIndexing abcIndex, TypeItem thisType) {
super(openedNamespaces, line, name, arguments, abcIndex, thisType);
this.openedNamespaces = openedNamespaces;
}

View File

@@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.DottedChain;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.helpers.Reference;
import java.util.ArrayList;
import java.util.List;
@@ -145,7 +146,7 @@ public class NamespaceItem {
}
if (kind == KIND_NAMESPACE_CUSTOM) {
String custom = name.toRawString();
PropertyAVM2Item prop = new PropertyAVM2Item(null, false, custom, "", abcIndex, openedNamespaces, new ArrayList<>(), false, null, -1);
PropertyAVM2Item prop = new PropertyAVM2Item(null, false, custom, "", abcIndex, openedNamespaces, new ArrayList<>(), false, null, -1, new TypeItem(""));
Reference<ValueKind> value = new Reference<>(null);
Reference<ABC> outAbc = new Reference<>(null);
Reference<Boolean> isType = new Reference<>(false);

View File

@@ -102,10 +102,11 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
private final String nsKeyword;
private int line;
private final TypeItem thisType;
@Override
public AssignableAVM2Item copy() {
PropertyAVM2Item p = new PropertyAVM2Item(object, attribute, propertyName, namespaceSuffix, abcIndex, openedNamespaces, callStack, nullish, nsKeyword, line);
PropertyAVM2Item p = new PropertyAVM2Item(object, attribute, propertyName, namespaceSuffix, abcIndex, openedNamespaces, callStack, nullish, nsKeyword, line, thisType);
return p;
}
@@ -122,8 +123,9 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
* @param nullish Nullish
* @param nsKeyword Namespace keyword (public,protected,private,internal)
* @param line Source code line
* @param thisType This class
*/
public PropertyAVM2Item(GraphTargetItem object, boolean attribute, String propertyName, String namespaceSuffix, AbcIndexing abcIndex, List<NamespaceItem> openedNamespaces, List<MethodBody> callStack, boolean nullish, String nsKeyword, int line) {
public PropertyAVM2Item(GraphTargetItem object, boolean attribute, String propertyName, String namespaceSuffix, AbcIndexing abcIndex, List<NamespaceItem> openedNamespaces, List<MethodBody> callStack, boolean nullish, String nsKeyword, int line, TypeItem thisType) {
this.attribute = attribute;
this.propertyName = propertyName;
this.namespaceSuffix = namespaceSuffix;
@@ -134,6 +136,7 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
this.nullish = nullish;
this.nsKeyword = nsKeyword;
this.line = line;
this.thisType = thisType;
}
@Override
@@ -496,13 +499,17 @@ public class PropertyAVM2Item extends AssignableAVM2Item {
Reference<Boolean> isType = new Reference<>(false);
Reference<Trait> outPropTrait = new Reference<>(null);
try {
resolve(false, new SourceGeneratorLocalData(new HashMap<>(), 0, false, 0)/*???*/, isType, objType, propType, propIndex, outPropValue, outPropValueAbc, outPropTrait);
SourceGeneratorLocalData localData = new SourceGeneratorLocalData(new HashMap<>(), 0, false, 0);
localData.pkg = thisType.fullTypeName.getWithoutLast();
localData.currentClassBaseName = thisType.fullTypeName.getLast();
resolve(false, localData /*???*/, isType, objType, propType, propIndex, outPropValue, outPropValueAbc, outPropTrait);
return propType.getVal();
} catch (CompilationException ex) {
Logger.getLogger(PropertyAVM2Item.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
return TypeItem.UNBOUNDED;
}
/**

View File

@@ -106,10 +106,11 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
* ABC index
*/
private AbcIndexing abcIndex;
private final TypeItem thisType;
@Override
public AssignableAVM2Item copy() {
UnresolvedAVM2Item c = new UnresolvedAVM2Item(subtypes, importedClasses, mustBeType, type, line, name, assignedValue, openedNamespaces, abcIndex);
UnresolvedAVM2Item c = new UnresolvedAVM2Item(subtypes, importedClasses, mustBeType, type, line, name, assignedValue, openedNamespaces, abcIndex, this.thisType);
//c.setNs(ns);
c.nsKind = nsKind;
c.resolved = resolved;
@@ -245,8 +246,9 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
* @param storeValue Store value
* @param openedNamespaces Opened namespaces
* @param abcIndex ABC index
* @param thisType This type
*/
public UnresolvedAVM2Item(List<GraphTargetItem> subtypes, List<DottedChain> importedClasses, boolean mustBeType, GraphTargetItem type, int line, DottedChain name, GraphTargetItem storeValue, List<NamespaceItem> openedNamespaces, AbcIndexing abcIndex) {
public UnresolvedAVM2Item(List<GraphTargetItem> subtypes, List<DottedChain> importedClasses, boolean mustBeType, GraphTargetItem type, int line, DottedChain name, GraphTargetItem storeValue, List<NamespaceItem> openedNamespaces, AbcIndexing abcIndex, TypeItem thisType) {
super(storeValue);
this.name = name;
this.assignedValue = storeValue;
@@ -257,6 +259,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
this.importedClasses = importedClasses;
this.subtypes = subtypes;
this.abcIndex = abcIndex;
this.thisType = thisType;
}
/**
@@ -420,7 +423,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
ret.setRegNumber(n.getRegNumber());
resolved = ret;
for (int i = 1; i < name.size(); i++) {
resolved = new PropertyAVM2Item(resolved, name.isAttribute(i), name.get(i), name.getNamespaceSuffix(i), abc, openedNamespaces, new ArrayList<>(), false, null, line);
resolved = new PropertyAVM2Item(resolved, name.isAttribute(i), name.get(i), name.getNamespaceSuffix(i), abc, openedNamespaces, new ArrayList<>(), false, null, line, this.thisType);
if (i == name.size() - 1) {
((PropertyAVM2Item) resolved).assignedValue = assignedValue;
}
@@ -447,7 +450,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
GraphTargetItem ret = new NameAVM2Item(t, line, name.isAttribute(0), name.get(0), name.getNamespaceSuffix(0), null, false, openedNamespaces, abcIndex, false);
resolved = ret;
for (int i = 1; i < name.size(); i++) {
resolved = new PropertyAVM2Item(resolved, name.isAttribute(i), name.get(i), name.getNamespaceSuffix(i), abc, openedNamespaces, new ArrayList<>(), false, null, line);
resolved = new PropertyAVM2Item(resolved, name.isAttribute(i), name.get(i), name.getNamespaceSuffix(i), abc, openedNamespaces, new ArrayList<>(), false, null, line, this.thisType);
if (i == name.size() - 1) {
((PropertyAVM2Item) resolved).assignedValue = assignedValue;
}
@@ -460,7 +463,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
boolean isProperty = false;
if (localData != null) { //resolve can be called without localData
PropertyAVM2Item resolvedx = new PropertyAVM2Item(null, name.isAttribute(0), name.get(0), name.getNamespaceSuffix(0), abc, openedNamespaces, callStack, false, null, line);
PropertyAVM2Item resolvedx = new PropertyAVM2Item(null, name.isAttribute(0), name.get(0), name.getNamespaceSuffix(0), abc, openedNamespaces, callStack, false, null, line, this.thisType);
((PropertyAVM2Item) resolvedx).scopeStack = scopeStack;
((PropertyAVM2Item) resolvedx).setAssignedValue(assignedValue);
Reference<GraphTargetItem> objectType = new Reference<>(null);
@@ -490,7 +493,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
if (ci != null) {
resolved = ti;
for (int i = 1; i < name.size(); i++) {
resolved = new PropertyAVM2Item(resolved, name.isAttribute(i), name.get(i), name.getNamespaceSuffix(i), abc, openedNamespaces, new ArrayList<>(), false, null, line);
resolved = new PropertyAVM2Item(resolved, name.isAttribute(i), name.get(i), name.getNamespaceSuffix(i), abc, openedNamespaces, new ArrayList<>(), false, null, line, this.thisType);
if (i == name.size() - 1) {
((PropertyAVM2Item) resolved).assignedValue = assignedValue;
}
@@ -517,7 +520,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
}
resolved = ti;
for (int i = 1; i < name.size(); i++) {
resolved = new PropertyAVM2Item(resolved, name.isAttribute(i), name.get(i), name.getNamespaceSuffix(i), abc, openedNamespaces, new ArrayList<>(), false, null, line);
resolved = new PropertyAVM2Item(resolved, name.isAttribute(i), name.get(i), name.getNamespaceSuffix(i), abc, openedNamespaces, new ArrayList<>(), false, null, line, this.thisType);
if (i == name.size() - 1) {
((PropertyAVM2Item) resolved).assignedValue = assignedValue;
}
@@ -536,7 +539,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
resolved = ret;
for (int i = 1; i < name.size(); i++) {
resolved = new PropertyAVM2Item(resolved, name.isAttribute(i), name.get(i), name.getNamespaceSuffix(i), abc, openedNamespaces, new ArrayList<>(), false, null, line);
resolved = new PropertyAVM2Item(resolved, name.isAttribute(i), name.get(i), name.getNamespaceSuffix(i), abc, openedNamespaces, new ArrayList<>(), false, null, line, this.thisType);
if (i == name.size() - 1) {
((PropertyAVM2Item) resolved).assignedValue = assignedValue;
}
@@ -573,7 +576,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
TypeItem ret = new TypeItem(fname);
resolved = ret;
for (int j = i + 1; j < name.size(); j++) {
resolved = new PropertyAVM2Item(resolved, name.isAttribute(j), name.get(j), name.getNamespaceSuffix(j), abc, openedNamespaces, new ArrayList<>(), false, null, line);
resolved = new PropertyAVM2Item(resolved, name.isAttribute(j), name.get(j), name.getNamespaceSuffix(j), abc, openedNamespaces, new ArrayList<>(), false, null, line, this.thisType);
if (j == name.size() - 1) {
((PropertyAVM2Item) resolved).assignedValue = assignedValue;
}
@@ -602,7 +605,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
TypeItem ret = ti;
resolved = ret;
for (int i = 1; i < name.size(); i++) {
resolved = new PropertyAVM2Item(resolved, name.isAttribute(i), name.get(i), name.getNamespaceSuffix(i), abc, openedNamespaces, new ArrayList<>(), false, null, line);
resolved = new PropertyAVM2Item(resolved, name.isAttribute(i), name.get(i), name.getNamespaceSuffix(i), abc, openedNamespaces, new ArrayList<>(), false, null, line, this.thisType);
if (i == name.size() - 1) {
((PropertyAVM2Item) resolved).assignedValue = assignedValue;
}
@@ -639,7 +642,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
NameAVM2Item ret = new NameAVM2Item(ntype, line, name.isAttribute(0), name.get(0), name.getNamespaceSuffix(0), null, false, openedNamespaces, abcIndex, false);
resolved = ret;
for (int i = 1; i < name.size(); i++) {
resolved = new PropertyAVM2Item(resolved, name.isAttribute(i), name.get(i), name.getNamespaceSuffix(i), abc, openedNamespaces, new ArrayList<>(), false, null, line);
resolved = new PropertyAVM2Item(resolved, name.isAttribute(i), name.get(i), name.getNamespaceSuffix(i), abc, openedNamespaces, new ArrayList<>(), false, null, line, this.thisType);
if (i == name.size() - 1) {
((PropertyAVM2Item) resolved).assignedValue = assignedValue;
}
@@ -662,7 +665,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item {
resolved = null;
GraphTargetItem ret = null;
for (int i = 0; i < name.size(); i++) {
resolved = new PropertyAVM2Item(resolved, name.isAttribute(i), name.get(i), name.getNamespaceSuffix(i), abc, openedNamespaces, callStack, false, null, line);
resolved = new PropertyAVM2Item(resolved, name.isAttribute(i), name.get(i), name.getNamespaceSuffix(i), abc, openedNamespaces, callStack, false, null, line, this.thisType);
if (ret == null) {
((PropertyAVM2Item) resolved).scopeStack = scopeStack;
ret = resolved;