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 454adb864..64df99a0d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -23,6 +23,8 @@ import com.jpexs.decompiler.flash.abc.CachedDecompilation; import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.RenameType; import com.jpexs.decompiler.flash.abc.ScriptPack; +import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; +import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.ScriptInfo; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.ActionGraphSource; @@ -1868,6 +1870,17 @@ public final class SWF implements SWFContainerItem, Timelined { getVariables(variables, actionsMap, functions, strings, usageTypes, asm, path); } + public void fixAS3Code() { + for (ABCContainerTag abcTag : getAbcList()) { + ABC abc = abcTag.getABC(); + for (MethodBody body : abc.bodies) { + AVM2Code code = body.getCode(); + } + + ((Tag) abcTag).setModified(true); + } + } + public int deobfuscateAS3Identifiers(RenameType renameType) { for (Tag tag : tags) { if (tag instanceof ABCContainerTag) { diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java index df8ec530f..177dd114d 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/RecompileTest.java @@ -16,8 +16,12 @@ */ package com.jpexs.decompiler.flash; +import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.NotSameException; +import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; +import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.TagStub; import java.io.BufferedInputStream; @@ -43,6 +47,26 @@ public class RecompileTest extends FileTestBase { public static final String TESTDATADIR = "testdata/recompile"; @Test(dataProvider = "provideFiles") + public void testAS3InstructionParsing(String fileName) { + try { + Configuration.debugCopy.set(false); + try (FileInputStream fis = new FileInputStream(TESTDATADIR + File.separator + fileName)) { + SWF swf = new SWF(new BufferedInputStream(fis), false); + for (ABCContainerTag abcTag : swf.getAbcList()) { + ABC abc = abcTag.getABC(); + for (MethodBody body : abc.bodies) { + AVM2Code code = body.getCode(); + } + + ((Tag) abcTag).setModified(true); + } + } + } catch (Throwable ex) { + fail("Exception during decompilation: " + fileName + " " + ex.getMessage()); + } + } + + //@Test(dataProvider = "provideFiles") public void testRecompile(String fileName) { try { try (FileInputStream fis = new FileInputStream(TESTDATADIR + File.separator + fileName)) { diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java index 2554e85ab..3e18b12e9 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java @@ -737,12 +737,21 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener } }); + JCommandButton fixAs3CodeCommandButton = new JCommandButton(fixCommandTitle("Fix AS3 code"), icon); + fixAs3CodeCommandButton.addActionListener(e -> { + SWF swf = mainFrame.getPanel().getCurrentSwf(); + if (swf != null) { + swf.fixAS3Code(); + } + }); + debugBand.addCommandButton(removeNonScriptsCommandButton, RibbonElementPriority.MEDIUM); debugBand.addCommandButton(refreshDecompiledCommandButton, RibbonElementPriority.MEDIUM); debugBand.addCommandButton(checkResourcesCommandButton, RibbonElementPriority.MEDIUM); debugBand.addCommandButton(callGcCommandButton, RibbonElementPriority.MEDIUM); debugBand.addCommandButton(emptyCacheCommandButton, RibbonElementPriority.MEDIUM); debugBand.addCommandButton(memoryInformationCommandButton, RibbonElementPriority.MEDIUM); + debugBand.addCommandButton(fixAs3CodeCommandButton, RibbonElementPriority.MEDIUM); return new RibbonTask("Debug", debugBand); } diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java index cf24866af..da54545fb 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java @@ -484,9 +484,14 @@ public class TagTreeModel implements TreeModel { } else if (parentNode instanceof DefineSpriteTag) { return ((DefineSpriteTag) parentNode).getTimeline().getFrames(); } else if (parentNode instanceof DefineBinaryDataTag) { - List result = new ArrayList<>(1); - result.add(((DefineBinaryDataTag) parentNode).innerSwf); - return result; + DefineBinaryDataTag binaryDataTag = (DefineBinaryDataTag) parentNode; + if (binaryDataTag.innerSwf != null) { + List result = new ArrayList<>(1); + result.add(((DefineBinaryDataTag) parentNode).innerSwf); + return result; + } else { + return new ArrayList<>(0); + } } else if (parentNode instanceof AS2Package) { return ((AS2Package) parentNode).getAllChildren(); } else if (parentNode instanceof FrameScript) {