From 76a5fe169b9ce3b5c2a32fa4443cfa3d20cc38ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Fri, 26 Feb 2021 19:30:45 +0100 Subject: [PATCH] Fixed: #1450 AS3 direct editation - handling types from same package Fixed: AS3 goto definition for types in another ABC tag --- CHANGELOG.md | 2 ++ .../flash/abc/avm2/AVM2ConstantPool.java | 10 ++++---- .../parser/script/AVM2SourceGenerator.java | 15 +++++++----- .../parser/script/ActionScript3Parser.java | 8 +++---- .../parser/script/UnresolvedAVM2Item.java | 23 ++++++++++++++++++- .../decompiler/flash/abc/types/Multiname.java | 2 +- .../decompiler/flash/gui/abc/ABCPanel.java | 8 +++---- 7 files changed, 48 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2d34a843..f0ee4429b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ All notable changes to this project will be documented in this file. - #1169 AS1/2 direct editation - getmember after new operator - #1338, #1480 AS3 direct editation - Vector in combination with activation - AS3 decompilation - do not show setslot on activation when has same name as method parameter +- #1450 AS3 direct editation - handling types from same package +- AS3 goto definition for types in another ABC tag ### Changed - #1616 Close SWF menuitem is last in the context menu diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2ConstantPool.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2ConstantPool.java index 2e8d03fe1..7f96a1756 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2ConstantPool.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2ConstantPool.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; import com.jpexs.decompiler.flash.abc.ABCVersionRequirements; @@ -556,14 +557,15 @@ public class AVM2ConstantPool implements Cloneable { * @param origConst * @return */ - public int getMultinameId(Multiname val, AVM2ConstantPool origConst) { + public List getMultinameIds(Multiname val, AVM2ConstantPool origConst) { + List ret = new ArrayList<>(); for (int i = 1; i < getMultinameCount(); i++) { if (getMultiname(i).qnameEquals(this, val, origConst)) { - return i; + ret.add(i); } } - return -1; + return ret; } public int getStringId(String val, boolean add) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java index a8f046a2a..405858627 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java @@ -1622,7 +1622,7 @@ public class AVM2SourceGenerator implements SourceGenerator { UnresolvedAVM2Item n = (UnresolvedAVM2Item) an; if (n.resolved == null) { String fullClass = localData.getFullClass(); - GraphTargetItem res = n.resolve(new TypeItem(fullClass), paramTypes, paramNames, abcIndex, callStack, subvariables); + GraphTargetItem res = n.resolve(localData.currentClass, new TypeItem(fullClass), paramTypes, paramNames, abcIndex, callStack, subvariables); if (res instanceof AssignableAVM2Item) { subvariables.set(i, (AssignableAVM2Item) res); } else { @@ -1639,7 +1639,7 @@ public class AVM2SourceGenerator implements SourceGenerator { UnresolvedAVM2Item n = (UnresolvedAVM2Item) an; if (n.resolved == null) { String fullClass = localData.getFullClass(); - GraphTargetItem res = n.resolve(new TypeItem(fullClass), paramTypes, paramNames, abcIndex, callStack, subvariables); + GraphTargetItem res = n.resolve(localData.currentClass, new TypeItem(fullClass), paramTypes, paramNames, abcIndex, callStack, subvariables); paramTypes.set(t, res); } } @@ -2132,7 +2132,7 @@ public class AVM2SourceGenerator implements SourceGenerator { continue; } if (item instanceof ClassAVM2Item) { - + localData.currentClass = ((ClassAVM2Item) item).pkg.name.addWithSuffix(((ClassAVM2Item) item).className).toRawString(); InstanceInfo instanceInfo = abcIndex.getSelectedAbc().instance_info.get(((TraitClass) traits[k]).class_info); instanceInfo.name_index = abcIndex.getSelectedAbc().constants.getMultinameId( Multiname.createQName( @@ -2149,8 +2149,10 @@ public class AVM2SourceGenerator implements SourceGenerator { for (int i = 0; i < ((ClassAVM2Item) item).implementsOp.size(); i++) { instanceInfo.interfaces[i] = superIntName(localData, ((ClassAVM2Item) item).implementsOp.get(i)); } + localData.currentClass = null; } if (item instanceof InterfaceAVM2Item) { + localData.currentClass = ((InterfaceAVM2Item) item).pkg.name.addWithSuffix(((InterfaceAVM2Item) item).name).toRawString(); ABC abc = abcIndex.getSelectedAbc(); AVM2ConstantPool constants = abc.constants; InstanceInfo instanceInfo = abc.instance_info.get(((TraitClass) traits[k]).class_info); @@ -2162,13 +2164,14 @@ public class AVM2SourceGenerator implements SourceGenerator { GraphTargetItem un = ((InterfaceAVM2Item) item).superInterfaces.get(i); instanceInfo.interfaces[i] = superIntName(localData, un); } + localData.currentClass = null; } } } public int superIntName(SourceGeneratorLocalData localData, GraphTargetItem un) throws CompilationException { if (un instanceof UnresolvedAVM2Item) { - ((UnresolvedAVM2Item) un).resolve(null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), new ArrayList<>()); + ((UnresolvedAVM2Item) un).resolve(localData.currentClass, null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), new ArrayList<>()); un = ((UnresolvedAVM2Item) un).resolved; } if (!(un instanceof TypeItem)) { //not applyType @@ -2703,7 +2706,7 @@ public class AVM2SourceGenerator implements SourceGenerator { if (item instanceof UnresolvedAVM2Item) { String fullClass = localData.getFullClass(); - item = ((UnresolvedAVM2Item) item).resolve(new TypeItem(fullClass), new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), new ArrayList<>()); + item = ((UnresolvedAVM2Item) item).resolve(localData.currentClass, new TypeItem(fullClass), new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), new ArrayList<>()); } if (item instanceof TypeItem) { typeItem = item; @@ -2716,7 +2719,7 @@ public class AVM2SourceGenerator implements SourceGenerator { } if (typeItem instanceof UnresolvedAVM2Item) { String fullClass = localData.getFullClass(); - typeItem = ((UnresolvedAVM2Item) typeItem).resolve(new TypeItem(fullClass), new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), new ArrayList<>()); + typeItem = ((UnresolvedAVM2Item) typeItem).resolve(localData.currentClass, new TypeItem(fullClass), new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), new ArrayList<>()); } if (!(typeItem instanceof TypeItem)) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java index 4c08a418d..95fbf4788 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java @@ -880,8 +880,8 @@ public class ActionScript3Parser { List sinitVariables = new ArrayList<>(); NamespaceItem publicNs; NamespaceItem packageInternalNs; + DottedChain pkgName = DottedChain.TOPLEVEL; if (s.type == SymbolType.PACKAGE) { - DottedChain pkgName = DottedChain.TOPLEVEL; s = lex(); if (s.type != SymbolType.CURLY_OPEN) { expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER); @@ -1008,7 +1008,7 @@ public class ActionScript3Parser { List names = new ArrayList<>(); List namespaces = new ArrayList<>(); //FIXME for Private classes in script (?) - AVM2SourceGenerator.parentNamesAddNames(abcIndex, AVM2SourceGenerator.resolveType(new SourceGeneratorLocalData(new HashMap<>(), 0, false, 0), ((TypeItem) ((UnresolvedAVM2Item) extendsTypeStr).resolve(null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), new ArrayList<>())), abcIndex), indices, names, namespaces); + AVM2SourceGenerator.parentNamesAddNames(abcIndex, AVM2SourceGenerator.resolveType(new SourceGeneratorLocalData(new HashMap<>(), 0, false, 0), ((TypeItem) ((UnresolvedAVM2Item) extendsTypeStr).resolve(pkgName.addWithSuffix(subNameStr).toRawString(), null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), new ArrayList<>())), abcIndex), indices, names, namespaces); for (int i = 0; i < names.size(); i++) { if (namespaces.get(i) == null || namespaces.get(i).isEmpty()) { continue; @@ -1744,7 +1744,7 @@ public class ActionScript3Parser { UnresolvedAVM2Item ui = (UnresolvedAVM2Item) a; if (ui.getVariableName().equals(DottedChain.parseWithSuffix(e.getVariableName()))) { try { - ui.resolve(null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), variables); + ui.resolve(null, null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), variables); } catch (CompilationException ex) { // ignore } @@ -1767,7 +1767,7 @@ public class ActionScript3Parser { for (NameAVM2Item e : catchExceptions) { if (ui.getVariableName().equals(DottedChain.parseWithSuffix(e.getVariableName()))) { try { - ui.resolve(null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), variables); + ui.resolve(null, null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), variables); } catch (CompilationException ex) { // ignore } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java index 774d562b2..031df9f73 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/UnresolvedAVM2Item.java @@ -287,7 +287,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { throw new RuntimeException("Cannot assign"); } - public GraphTargetItem resolve(GraphTargetItem thisType, List paramTypes, List paramNames, AbcIndexing abc, List callStack, List variables) throws CompilationException { + public GraphTargetItem resolve(String currentClass, GraphTargetItem thisType, List paramTypes, List paramNames, AbcIndexing abc, List callStack, List variables) throws CompilationException { if (scopeStack.isEmpty()) { //Everything is multiname property in with command //search for variable @@ -315,6 +315,27 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { } } } + + if (currentClass != null) { + DottedChain classChain = DottedChain.parseWithSuffix(currentClass); + DottedChain pkg = classChain.getWithoutLast(); + + TypeItem ti = new TypeItem(pkg.addWithSuffix(name.get(0))); + AbcIndexing.ClassIndex ci = abc.findClass(ti); + + if (ci != null) { + resolved = ti; + for (int i = 1; i < name.size(); i++) { + resolved = new PropertyAVM2Item(resolved, name.get(i), abc, openedNamespaces, new ArrayList<>()); + if (i == name.size() - 1) { + ((PropertyAVM2Item) resolved).assignedValue = assignedValue; + } + } + return resolvedRoot = ti; + } + + } + //Search for types in imported classes for (DottedChain imp : importedClasses) { String impName = imp.getLast(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/Multiname.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/Multiname.java index 20741ebda..c0329828f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/Multiname.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/Multiname.java @@ -414,7 +414,7 @@ public class Multiname { } } } - String name = getName(constants, null, false, false); + String name = getName(constants, null, true, false); if (ns != null) { return ns.getName(constants).add(name, withSuffix ? getNamespaceSuffix() : ""); } diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index aafde6f4d..7843cf9fc 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -1139,8 +1139,8 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener 0) { + List mids = a.constants.getMultinameIds(m, abc.constants); + for (int mid : mids) { usages.addAll(a.findMultinameDefinition(mid)); } } @@ -1181,8 +1181,8 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener 0) { + List mids = a.constants.getMultinameIds(m, abc.constants); + for (int mid : mids) { usages.addAll(a.findMultinameDefinition(mid)); } }