diff --git a/CHANGELOG.md b/CHANGELOG.md index b40e202a9..bcdb1fe5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file. - AS1/2 DefineFunction cleaner - AS1/2 direct editation - postincrement/decrement - Reload menu disabled when do SWF selected +- AS2 - Do not detect classes inside functions ## [14.5.2] - 2021-11-20 ### 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 1517016e9..974bc97e2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -2370,7 +2370,7 @@ public final class SWF implements SWFContainerItem, Timelined { int staticOperation = Graph.SOP_USE_STATIC; //(Boolean) Configuration.getConfig("autoDeobfuscate", true) ? Graph.SOP_SKIP_STATIC : Graph.SOP_USE_STATIC; List dec; try { - dec = Action.actionsToTree(true /*Yes, inside doInitAction*/, dia.getActions(), version, staticOperation, ""/*FIXME*/); + dec = Action.actionsToTree(true /*Yes, inside doInitAction*/, false, dia.getActions(), version, staticOperation, ""/*FIXME*/); } catch (EmptyStackException ex) { continue; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java index a59207772..59e7b803a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java @@ -830,8 +830,8 @@ public abstract class Action implements GraphSourceItem { return -1; } - public static List actionsToTree(boolean insideDoInitAction, List actions, int version, int staticOperation, String path) throws InterruptedException { - return actionsToTree(insideDoInitAction, new HashMap<>(), new HashMap<>(), new HashMap<>(), actions, version, staticOperation, path); + public static List actionsToTree(boolean insideDoInitAction, boolean insideFunction, List actions, int version, int staticOperation, String path) throws InterruptedException { + return actionsToTree(insideDoInitAction, insideFunction, new HashMap<>(), new HashMap<>(), new HashMap<>(), actions, version, staticOperation, path); } /** @@ -857,7 +857,7 @@ public abstract class Action implements GraphSourceItem { public List call() throws Exception { int staticOperation = Graph.SOP_USE_STATIC; //(Boolean) Configuration.getConfig("autoDeobfuscate", true) ? Graph.SOP_SKIP_STATIC : Graph.SOP_USE_STATIC; boolean insideDoInitAction = (asm instanceof DoInitActionTag); - List tree = actionsToTree(insideDoInitAction, new HashMap<>(), new HashMap<>(), new HashMap<>(), actions, version, staticOperation, path); + List tree = actionsToTree(insideDoInitAction, false, new HashMap<>(), new HashMap<>(), new HashMap<>(), actions, version, staticOperation, path); SWFDecompilerPlugin.fireActionTreeCreated(tree, swf); if (Configuration.autoDeobfuscate.get()) { new ActionDeobfuscator().actionTreeCreated(tree, swf); @@ -916,8 +916,9 @@ public abstract class Action implements GraphSourceItem { * @return List of treeItems * @throws java.lang.InterruptedException */ - public static List actionsToTree(boolean insideDoInitAction, HashMap regNames, HashMap variables, HashMap functions, List actions, int version, int staticOperation, String path) throws InterruptedException { - return ActionGraph.translateViaGraph(insideDoInitAction, regNames, variables, functions, actions, version, staticOperation, path); + public static List actionsToTree(boolean insideDoInitAction, boolean insideFunction, HashMap regNames, HashMap variables, HashMap functions, List actions, int version, int staticOperation, String path) throws InterruptedException { + return ActionGraph.translateViaGraph(insideDoInitAction, insideFunction, regNames, variables, functions, actions, version, staticOperation, path + ); } @Override @@ -1039,7 +1040,7 @@ public abstract class Action implements GraphSourceItem { } } } - out = ActionGraph.translateViaGraph(insideDoInitAction, regNames, variables2, functions, actions.subList(adr2ip(actions, endAddr), adr2ip(actions, endAddr + size)), version, staticOperation, path + (cntName == null ? "" : "/" + cntName)); + out = ActionGraph.translateViaGraph(insideDoInitAction, true, regNames, variables2, functions, actions.subList(adr2ip(actions, endAddr), adr2ip(actions, endAddr + size)), version, staticOperation, path + (cntName == null ? "" : "/" + cntName)); } catch (OutOfMemoryError | TranslateException | StackOverflowError ex) { logger.log(Level.SEVERE, "Decompilation error in: " + path, ex); if (ex instanceof OutOfMemoryError) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraph.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraph.java index b6ed337b2..6c461cfb2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraph.java @@ -83,9 +83,12 @@ public class ActionGraph extends Graph { private boolean insideDoInitAction; - public ActionGraph(String path, boolean insideDoInitAction, List code, HashMap registerNames, HashMap variables, HashMap functions, int version) { + private boolean insideFunction; + + public ActionGraph(String path, boolean insideDoInitAction, boolean insideFunction, List code, HashMap registerNames, HashMap variables, HashMap functions, int version) { super(new ActionGraphSource(path, insideDoInitAction, code, version, registerNames, variables, functions), new ArrayList<>()); this.insideDoInitAction = insideDoInitAction; + this.insideFunction = insideFunction; } @Override @@ -110,7 +113,7 @@ public class ActionGraph extends Graph { for (ActionList al : outs) { subgraphs.put("loc" + Helper.formatAddress(code.pos2adr(ip)) + ": function " + functionName, - new ActionGraph("", false, al, new HashMap<>(), new HashMap<>(), new HashMap<>(), SWF.DEFAULT_VERSION) + new ActionGraph("", false, false, al, new HashMap<>(), new HashMap<>(), new HashMap<>(), SWF.DEFAULT_VERSION) ); } } @@ -128,8 +131,8 @@ public class ActionGraph extends Graph { } - public static List translateViaGraph(boolean insideDoInitAction, HashMap registerNames, HashMap variables, HashMap functions, List code, int version, int staticOperation, String path) throws InterruptedException { - ActionGraph g = new ActionGraph(path, insideDoInitAction, code, registerNames, variables, functions, version); + public static List translateViaGraph(boolean insideDoInitAction, boolean insideFunction, HashMap registerNames, HashMap variables, HashMap functions, List code, int version, int staticOperation, String path) throws InterruptedException { + ActionGraph g = new ActionGraph(path, insideDoInitAction, insideFunction, code, registerNames, variables, functions, version); ActionLocalData localData = new ActionLocalData(insideDoInitAction, registerNames); g.init(localData); return g.translate(localData, staticOperation, path); @@ -186,11 +189,6 @@ public class ActionGraph extends Graph { list.addAll(0, removed); } - if (insideDoInitAction) { - ActionScript2ClassDetector detector = new ActionScript2ClassDetector(); - detector.checkClass(list, path); - } - int targetStart; int targetEnd; @@ -316,9 +314,14 @@ public class ActionGraph extends Graph { } @Override - protected void finalProcessAfter(List list, int level, FinalProcessLocalData localData, String path) { - super.finalProcessAfter(list, level, localData, path); - makeDefineRegistersUp(list); + public List translate(BaseLocalData localData, int staticOperation, String path) throws InterruptedException { + List ret = super.translate(localData, staticOperation, path); + if (insideDoInitAction && !insideFunction) { + ActionScript2ClassDetector detector = new ActionScript2ClassDetector(); + detector.checkClass(ret, path); + } + makeDefineRegistersUp(ret); + return ret; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf3/ActionWaitForFrame.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf3/ActionWaitForFrame.java index 95e71ccb9..874324b1e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf3/ActionWaitForFrame.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf3/ActionWaitForFrame.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.action.swf3; import com.jpexs.decompiler.flash.SWF; @@ -101,7 +102,7 @@ public class ActionWaitForFrame extends Action implements ActionStore { @Override public void translate(boolean insideDoInitAction, GraphSourceItem lineStartAction, TranslateStack stack, List output, HashMap regNames, HashMap variables, HashMap functions, int staticOperation, String path) throws InterruptedException { GraphTargetItem frameTi = new DirectValueActionItem(null, null, 0, (Long)((long)frame), new ArrayList<>()); - List body = ActionGraph.translateViaGraph(insideDoInitAction, regNames, variables, functions, skipped, SWF.DEFAULT_VERSION, staticOperation, path); + List body = ActionGraph.translateViaGraph(insideDoInitAction, true, regNames, variables, functions, skipped, SWF.DEFAULT_VERSION, staticOperation, path); output.add(new IfFrameLoadedActionItem(frameTi, body, this, lineStartAction)); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionWaitForFrame2.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionWaitForFrame2.java index 80430c754..be01d3564 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionWaitForFrame2.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionWaitForFrame2.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.action.swf4; import com.jpexs.decompiler.flash.BaseLocalData; @@ -147,7 +148,7 @@ public class ActionWaitForFrame2 extends Action implements ActionStore { @Override public void translate(boolean insideDoInitAction, GraphSourceItem lineStartAction, TranslateStack stack, List output, HashMap regNames, HashMap variables, HashMap functions, int staticOperation, String path) throws InterruptedException { GraphTargetItem frame = stack.pop(); - List body = ActionGraph.translateViaGraph(insideDoInitAction, regNames, variables, functions, skipped, SWF.DEFAULT_VERSION, staticOperation, path); + List body = ActionGraph.translateViaGraph(insideDoInitAction, true, regNames, variables, functions, skipped, SWF.DEFAULT_VERSION, staticOperation, path); output.add(new IfFrameLoadedActionItem(frame, body, this, lineStartAction)); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/PcodeGraphVizExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/PcodeGraphVizExporter.java index 74e6535a9..da3e4b4f1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/PcodeGraphVizExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/PcodeGraphVizExporter.java @@ -80,7 +80,7 @@ public class PcodeGraphVizExporter { public void exportAs12(ASMSource src, GraphTextWriter writer) throws InterruptedException { ActionList alist = src.getActions(); - ActionGraph gr = new ActionGraph("", false, alist, new HashMap<>(), new HashMap<>(), new HashMap<>(), SWF.DEFAULT_VERSION); + ActionGraph gr = new ActionGraph("", false, false, alist, new HashMap<>(), new HashMap<>(), new HashMap<>(), SWF.DEFAULT_VERSION); export(gr, writer); } diff --git a/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java b/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java index c4f49626e..d25dd6eb8 100644 --- a/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java @@ -980,7 +980,7 @@ public class ActionPanel extends JPanel implements SearchListener(), new HashMap<>(), new HashMap<>(), SWF.DEFAULT_VERSION), ""); + GraphDialog gf = new GraphDialog(mainPanel.getMainFrame().getWindow(), new ActionGraph(this.src.getScriptName(), insideDoInitAction, false, lastCode, new HashMap<>(), new HashMap<>(), new HashMap<>(), SWF.DEFAULT_VERSION), ""); gf.setVisible(true); } catch (InterruptedException ex) { logger.log(Level.SEVERE, null, ex);