From d00045733098d54c1994b495448eba8da7ea11ed Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Sun, 29 May 2016 07:23:16 +0200 Subject: [PATCH] Issue #1244 Remove unknown actions when deobfuscation is enabled --- .../flash/action/ActionListReader.java | 12 ------------ .../deobfuscation/ActionDeobfuscator.java | 5 +++-- .../action/fastactionlist/FastActionList.java | 18 ++++++++++++++++++ src/com/jpexs/decompiler/flash/gui/Main.java | 2 +- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java index 20f9d8d39..f48eca48d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java @@ -22,7 +22,6 @@ import com.jpexs.decompiler.flash.action.deobfuscation.ActionDeobfuscator; import com.jpexs.decompiler.flash.action.model.ConstantPool; import com.jpexs.decompiler.flash.action.special.ActionDeobfuscateJump; import com.jpexs.decompiler.flash.action.special.ActionEnd; -import com.jpexs.decompiler.flash.action.special.ActionNop; import com.jpexs.decompiler.flash.action.special.ActionStore; import com.jpexs.decompiler.flash.action.special.ActionUnknown; import com.jpexs.decompiler.flash.action.swf4.ActionIf; @@ -821,17 +820,6 @@ public class ActionListReader { int actionLengthWithHeader = a.getTotalActionLength(); - // unknown action, replace with jump - if (a instanceof ActionNop) { - ActionJump aJump = new ActionDeobfuscateJump(0); - int jumpLength = aJump.getTotalActionLength(); - aJump.setAddress(a.getAddress()); - //FIXME! This offset can be larger than SI16 value! - aJump.setJumpOffset(actionLengthWithHeader - jumpLength); - a = aJump; - actionLengthWithHeader = a.getTotalActionLength(); - } - Action existingAction = actionMap.get(ip); if (existingAction != null) { break; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscator.java index 0af47a08b..7b03f5d6b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscator.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscator.java @@ -101,6 +101,7 @@ public class ActionDeobfuscator extends SWFDecompilerAdapter { @Override public void actionListParsed(ActionList actions, SWF swf) throws InterruptedException { FastActionList fastActions = new FastActionList(actions); + fastActions.removeUnknownActions(); fastActions.expandPushes(); Map fakeFunctions = getFakeFunctionResults(fastActions); boolean changed = true; @@ -466,9 +467,9 @@ public class ActionDeobfuscator extends SWFDecompilerAdapter { Action action = item.action; /*System.out.print(action.getASMSource(actions, new ArrayList(), ScriptExportMode.PCODE)); - for (int j = 0; j < stack.size(); j++) { + for (int j = 0; j < stack.size(); j++) { System.out.print(" '" + stack.get(j).getResult() + "'"); - } + } System.out.println();*/ if (action instanceof ActionConstantPool) { lastConstantPool = (ActionConstantPool) action; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java index 7c88139a8..655c0b8f1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.action.fastactionlist; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.ActionList; import com.jpexs.decompiler.flash.action.special.ActionStore; +import com.jpexs.decompiler.flash.action.special.ActionUnknown; import com.jpexs.decompiler.flash.action.swf4.ActionIf; import com.jpexs.decompiler.flash.action.swf4.ActionJump; import com.jpexs.decompiler.flash.action.swf4.ActionPush; @@ -402,6 +403,23 @@ public class FastActionList implements Collection { } while (item != firstItem); } + public void removeUnknownActions() { + ActionItem item = firstItem; + if (item == null) { + return; + } + + do { + Action action = item.action; + if (action instanceof ActionUnknown) { + item = removeItem(item); + continue; + } + + item = item.next; + } while (item != firstItem); + } + public void removeZeroJumps() { ActionItem item = firstItem; if (item == null) { diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index 799cd5120..94bd445cb 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -1090,7 +1090,7 @@ public class Main { final SWFList swfs1 = swfs; final boolean first1 = first; first = false; - if (firstSWF == null) { + if (firstSWF == null && swfs1.size() > 0) { firstSWF = swfs1.get(0); }