From b54b51d206f60f99e9868b1c14d4c1eaaabeafa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Tue, 16 Feb 2021 08:17:36 +0100 Subject: [PATCH] Removing AS3 scripts ("ScriptPacks") --- CHANGELOG.md | 1 + .../src/com/jpexs/decompiler/flash/SWF.java | 5 +++ .../decompiler/flash/abc/ScriptPack.java | 15 ++++++++ .../flash/gui/tagtree/TagTreeContextMenu.java | 35 ++++++++++++++++--- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b5b8c7ac..c5345106e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. - #1260, #1438 AS1/2 direct editing on(xxx), onClipEvent(xxx) handlers - #1366, #1409, #1429, #1573, #1598 AS1/2/3 Add script/class (context menu on scripts folder) - Removing BUTTONCONDACTION, CLIPACTIONRECORD +- Removing AS3 scripts - Japanese translation ### Fixed diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index 050ca0e7b..bad86334f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -93,6 +93,8 @@ import com.jpexs.decompiler.flash.tags.DebugIDTag; import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag; import com.jpexs.decompiler.flash.tags.DefineSoundTag; import com.jpexs.decompiler.flash.tags.DefineSpriteTag; +import com.jpexs.decompiler.flash.tags.DoABC2Tag; +import com.jpexs.decompiler.flash.tags.DoABCTag; import com.jpexs.decompiler.flash.tags.DoInitActionTag; import com.jpexs.decompiler.flash.tags.EnableDebugger2Tag; import com.jpexs.decompiler.flash.tags.EnableDebuggerTag; @@ -2993,6 +2995,9 @@ public final class SWF implements SWFContainerItem, Timelined { } private void removeTagInternal(Timelined timelined, Tag tag, boolean removeDependencies) { + if ((tag instanceof DoABC2Tag) || (tag instanceof DoABCTag)) { + clearAbcListCache(); + } if (tag instanceof ShowFrameTag || ShowFrameTag.isNestedTagType(tag.getId())) { timelined.removeTag(tag); timelined.setModified(true); 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 587e6732b..cb542480e 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 @@ -27,6 +27,7 @@ import com.jpexs.decompiler.flash.abc.types.ConvertData; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.Multiname; import com.jpexs.decompiler.flash.abc.types.Namespace; +import com.jpexs.decompiler.flash.abc.types.ScriptInfo; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.TraitClass; import com.jpexs.decompiler.flash.abc.types.traits.TraitFunction; @@ -331,6 +332,9 @@ public class ScriptPack extends AS3ClassTreeItem { @Override public boolean isModified() { + if (scriptIndex >= abc.script_info.size()) { + return false; + } return abc.script_info.get(scriptIndex).isModified(); } @@ -637,4 +641,15 @@ public class ScriptPack extends AS3ClassTreeItem { trait.getMethodInfos(abc, GraphTextWriter.TRAIT_UNKNOWN, -1, methodInfos); } } + + public void delete(ABC abc, boolean d) { + ScriptInfo si = abc.script_info.get(scriptIndex); + if (isSimple) { + si.delete(abc, d); + } else { + for (int t : traitIndices) { + si.traits.traits.get(t).delete(abc, d); + } + } + } } diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java index a09ef77fa..a84715a8f 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java @@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.IdentifiersDeobfuscation; import com.jpexs.decompiler.flash.ReadOnlyTagList; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.abc.avm2.parser.AVM2ParseException; import com.jpexs.decompiler.flash.abc.avm2.parser.script.ActionScript3Parser; import com.jpexs.decompiler.flash.action.Action; @@ -272,13 +273,13 @@ public class TagTreeContextMenu extends JPopupMenu { final List swfs = mainPanel.getSwfs(); boolean canRemove = true; - boolean onlyClipActionButtonCond = true; + boolean allDoNotHaveDependencies = true; for (TreeItem item : items) { if (!(item instanceof Tag) && !(item instanceof Frame)) { if (item instanceof TagScript) { Tag tag = ((TagScript) item).getTag(); if (tag instanceof DoActionTag || tag instanceof DoInitActionTag) { - onlyClipActionButtonCond = false; + allDoNotHaveDependencies = false; continue; } } @@ -290,10 +291,14 @@ public class TagTreeContextMenu extends JPopupMenu { continue; } + if (item instanceof ScriptPack) { + continue; + } + canRemove = false; break; } else { - onlyClipActionButtonCond = false; + allDoNotHaveDependencies = false; } } @@ -351,7 +356,7 @@ public class TagTreeContextMenu extends JPopupMenu { expandRecursiveMenuItem.setVisible(false); removeMenuItem.setVisible(canRemove); - removeWithDependenciesMenuItem.setVisible(canRemove && !onlyClipActionButtonCond); + removeWithDependenciesMenuItem.setVisible(canRemove && !allDoNotHaveDependencies); undoTagMenuItem.setVisible(allSelectedIsTag); exportSelectionMenuItem.setEnabled(tagTree.hasExportableNodes()); replaceMenuItem.setVisible(false); @@ -1288,6 +1293,10 @@ public class TagTreeContextMenu extends JPopupMenu { } itemsToRemoveParents.add(((TagScript) path.getParentPath().getLastPathComponent()).getTag()); itemsToRemoveSprites.add(sprite); + } else if (item instanceof ScriptPack) { + itemsToRemove.add(item); + itemsToRemoveParents.add(new Object()); + itemsToRemoveSprites.add(new Object()); } } @@ -1307,6 +1316,7 @@ public class TagTreeContextMenu extends JPopupMenu { if (View.showConfirmDialog(this, confirmationMessage, mainPanel.translate("message.confirm"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { Map> tagsToRemoveBySwf = new HashMap<>(); + Set swfsToClearCache = new HashSet<>(); for (int i = 0; i < itemsToRemove.size(); i++) { Object item = itemsToRemove.get(i); Object parent = itemsToRemoveParents.get(i); @@ -1336,7 +1346,20 @@ public class TagTreeContextMenu extends JPopupMenu { place.setModified(true); tim.resetTimeline(); } + if (item instanceof ScriptPack) { + ScriptPack sp = (ScriptPack) item; + sp.delete(sp.abc, true); + sp.abc.pack(); + swfsToClearCache.add(sp.getSwf()); + for (ABCContainerTag ct : sp.getSwf().getAbcList()) { + if (ct.getABC() == sp.abc) { + ((Tag) ct).setModified(true); + break; + } + } + } } + for (Tag tag : tagsToRemove) { SWF swf = tag.getSwf(); if (!tagsToRemoveBySwf.containsKey(swf)) { @@ -1350,6 +1373,10 @@ public class TagTreeContextMenu extends JPopupMenu { swf.removeTags(tagsToRemoveBySwf.get(swf), removeDependencies); } + for (SWF swf : swfsToClearCache) { + swf.clearAllCache(); + } + mainPanel.refreshTree(); } }