From 4e893761740d7aa86cf6484b63aa02ca45e9f303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sat, 17 Aug 2024 11:03:11 +0200 Subject: [PATCH] Fixed direct editation - methods and script initializer imports. --- .../decompiler/flash/abc/ScriptPack.java | 24 ++++++++++++------- .../parser/script/ActionScript3Parser.java | 19 ++++++++++----- .../avm2/parser/script/MethodAVM2Item.java | 15 ++++++++++++ 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java index bbc0ebfc2..5eeb1c99f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java @@ -343,6 +343,18 @@ public class ScriptPack extends AS3ClassTreeItem { first = false; } + List fullyQualifiedNames = new ArrayList<>(); + if (!first) { + writer.newLine(); + } + DottedChain ignorePackage = null; + if (isSimple) { + ignorePackage = getPathPackage(); + } + Trait.writeImports(null, script_init, abcIndex, scriptIndex, -1, true, abc, writer, ignorePackage, fullyQualifiedNames); + first = true; + + //Slot const last for (int t : traitIndices) { @@ -378,16 +390,12 @@ public class ScriptPack extends AS3ClassTreeItem { writer.startTrait(GraphTextWriter.TRAIT_SCRIPT_INITIALIZER); writer.startMethod(script_init, null); if (exportMode != ScriptExportMode.AS_METHOD_STUBS) { - if (!scriptInitializerIsEmpty) { - DottedChain ignorePackage = null; - if (isSimple) { - ignorePackage = getPathPackage(); - } - List fullyQualifiedNames = new ArrayList<>(); - writer.newLine(); - Trait.writeImports(null, script_init, abcIndex, scriptIndex, -1, true, abc, writer, ignorePackage, fullyQualifiedNames); + if (!scriptInitializerIsEmpty) { List callStack = new ArrayList<>(); callStack.add(abc.bodies.get(bodyIndex)); + if (!first) { + writer.newLine(); + } abc.bodies.get(bodyIndex).toString(callStack, abcIndex, path + "/.scriptinitializer", exportMode, abc, null, writer, fullyQualifiedNames, new HashSet<>()); } else { writer.append(""); 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 fcbdfa8c3..246e5dff9 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 @@ -1263,14 +1263,17 @@ public class ActionScript3Parser { traits.add(new ConstAVM2Item(metadata, ns, null, true, nname, new TypeItem(DottedChain.NAMESPACE), new StringAVM2Item(null, null, nval), lexer.yyline(), generatedNs)); break; default: - lexer.pushback(s); - parseImportsUsages(importedClasses, openedNamespaces, numberUsageRef, numberPrecisionRef, numberRoundingRef, abc); + lexer.pushback(s); + if (parseImportsUsages(importedClasses, openedNamespaces, numberUsageRef, numberPrecisionRef, numberRoundingRef, abc)) { + break; + } GraphTargetItem cmd = command(allOpenedNamespaces, null, publicNs, sinitNeedsActivation, importedClasses, openedNamespaces, sinitLoops, sinitLoopLabels, sinitRegisterVars, true, false, 0, false, sinitVariables, abc); if (cmd != null) { traits.add(cmd); isEmpty = false; - } - break looptrait; + } else { + break looptrait; + } } } @@ -2672,14 +2675,16 @@ public class ActionScript3Parser { private List constantPool; - private void parseImportsUsages(List importedClasses, List openedNamespaces, Reference numberUsageRef, Reference numberPrecisionRef, Reference numberRoundingRef, ABC abc) throws IOException, AVM2ParseException, InterruptedException { + private boolean parseImportsUsages(List importedClasses, List openedNamespaces, Reference numberUsageRef, Reference numberPrecisionRef, Reference numberRoundingRef, ABC abc) throws IOException, AVM2ParseException, InterruptedException { + boolean isEmpty = true; ParsedSymbol s; s = lex(); while (s.isType(SymbolType.IMPORT, SymbolType.USE)) { if (s.isType(SymbolType.IMPORT)) { + isEmpty = false; s = lex(); expected(s, lexer.yyline(), SymbolGroup.IDENTIFIER); DottedChain fullName = new DottedChain(new String[]{}); @@ -2707,8 +2712,9 @@ public class ActionScript3Parser { } else { importedClasses.add(fullName); } - expected(s, lexer.yyline(), SymbolType.SEMICOLON); + expected(s, lexer.yyline(), SymbolType.SEMICOLON); } else if (s.isType(SymbolType.USE)) { + isEmpty = false; do { s = lex(); if (s.isType(SymbolType.NAMESPACE)) { @@ -2811,6 +2817,7 @@ public class ActionScript3Parser { s = lex(); } lexer.pushback(s); + return !isEmpty; } private List parseScript( diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/MethodAVM2Item.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/MethodAVM2Item.java index 6c7990ba3..f95be15f6 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/MethodAVM2Item.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/MethodAVM2Item.java @@ -16,9 +16,14 @@ */ package com.jpexs.decompiler.flash.abc.avm2.parser.script; +import com.jpexs.decompiler.flash.SourceGeneratorLocalData; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; +import com.jpexs.decompiler.graph.CompilationException; +import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -120,4 +125,14 @@ public class MethodAVM2Item extends FunctionAVM2Item { public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException { return writer; //todo? } + + @Override + public boolean hasReturnValue() { + return false; + } + + @Override + public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + return new ArrayList<>(); + } }