From 01fa395706ce2ae05eca76bb2f2c14f96bc98ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Fri, 18 Nov 2022 08:33:12 +0100 Subject: [PATCH] Fixed #1803 AS3 Direct editation - Colliding catch name with other variable names / arguments --- CHANGELOG.md | 1 + .../parser/script/ActionScript3Parser.java | 13 +++++---- .../abc/avm2/parser/script/NameAVM2Item.java | 27 ++++++++++++++++--- .../parser/script/UnresolvedAVM2Item.java | 2 +- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77c333425..d94795984 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file. - [#1692] Resolving use namespace - [#1692] Properly distinguish obfuscated names vs namespace suffixes and attributes - [#1757] Binary search - SWF files need to be sorted by file position +- [#1803] AS3 Direct editation - Colliding catch name with other variable names / arguments ### Changed - GFX - DefineExternalImage2 no longer handled as character 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 dedc574d6..c42084b39 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 @@ -1771,7 +1771,7 @@ public class ActionScript3Parser { expectedType(SymbolType.COLON); GraphTargetItem etype = type(allOpenedNamespaces, thisType, pkg, needsActivation, importedClasses, openedNamespaces, variables); NameAVM2Item e = new NameAVM2Item(etype, lexer.yyline(), false, enamestr, "", new ExceptionAVM2Item(null)/*?*/, true/*?*/, openedNamespaces, abcIndex); - variables.add(e); + //variables.add(e); catchExceptions.add(e); e.setSlotNumber(1); e.setSlotScope(Integer.MAX_VALUE); //will be changed later @@ -1787,24 +1787,27 @@ public class ActionScript3Parser { if (a instanceof UnresolvedAVM2Item) { UnresolvedAVM2Item ui = (UnresolvedAVM2Item) a; if (ui.getVariableName().equals(DottedChain.parseWithSuffix(e.getVariableName()))) { + List catchedVarAsList = new ArrayList<>(); + catchedVarAsList.add(e); try { - ui.resolve(null, null, null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), variables); + ui.resolve(null, null, null, new ArrayList<>(), new ArrayList<>(), abcIndex, new ArrayList<>(), catchedVarAsList); } catch (CompilationException ex) { // ignore } ui.setSlotNumber(e.getSlotNumber()); ui.setSlotScope(e.getSlotScope()); + variables.remove(a); } } - } + } catchCommands.add(cc); s = lex(); found = true; } //TODO: - for (int i = varCnt; i < variables.size(); i++) { + /*for (int i = varCnt; i < variables.size(); i++) { AssignableAVM2Item av = variables.get(i); if (av instanceof UnresolvedAVM2Item) { UnresolvedAVM2Item ui = (UnresolvedAVM2Item) av; @@ -1820,7 +1823,7 @@ public class ActionScript3Parser { } } } - } + }*/ List finallyCommands = null; if (s.type == SymbolType.FINALLY) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java index 1893c6bc1..71cfa402e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/NameAVM2Item.java @@ -374,8 +374,13 @@ public class NameAVM2Item extends AssignableAVM2Item { @Override public int hashCode() { - int hash = 7; - hash = 13 * hash + Objects.hashCode(this.variableName); + int hash = 3; + hash = 29 * hash + (this.attribute ? 1 : 0); + hash = 29 * hash + Objects.hashCode(this.variableName); + hash = 29 * hash + (this.definition ? 1 : 0); + hash = 29 * hash + this.regNumber; + hash = 29 * hash + this.slotNumber; + hash = 29 * hash + this.slotScope; return hash; } @@ -391,10 +396,24 @@ public class NameAVM2Item extends AssignableAVM2Item { return false; } final NameAVM2Item other = (NameAVM2Item) obj; - if (!Objects.equals(this.variableName, other.variableName)) { + if (this.attribute != other.attribute) { return false; } - return true; + if (this.definition != other.definition) { + return false; + } + if (this.regNumber != other.regNumber) { + return false; + } + if (this.slotNumber != other.slotNumber) { + return false; + } + if (this.slotScope != other.slotScope) { + return false; + } + return Objects.equals(this.variableName, other.variableName); } + + } 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 93d35520e..b5e0690b2 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 @@ -228,7 +228,7 @@ public class UnresolvedAVM2Item extends AssignableAVM2Item { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { if (resolved == null) { - throw new RuntimeException("Unresolved"); + throw new RuntimeException("Unresolved: " + toString()); } return resolved.toSource(localData, generator); }