From 7c85a9b8da147be478843df861f134deea821d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sat, 25 May 2013 17:50:38 +0200 Subject: [PATCH] Issue #100 Support for larger obfuscated code. --- .../decompiler/flash/abc/avm2/AVM2Code.java | 6 ++- .../flash/abc/types/traits/TraitClass.java | 9 +++- .../flash/abc/types/traits/TraitFunction.java | 4 ++ .../types/traits/TraitMethodGetterSetter.java | 4 ++ .../jpexs/decompiler/flash/gui/MainFrame.java | 46 ++++++++++--------- 5 files changed, 44 insertions(+), 25 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index 166c2d205..22cc27ff8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -2300,8 +2300,10 @@ public class AVM2Code implements Serializable { } } } - - ret += removeTraps(secondPass, useVisited, localData, stack, output, code, condition ? branches.get(0) : branches.get(1), ip, visited, visitedStates, decisions); + ip = condition ? branches.get(0) : branches.get(1); + lastIp = ip; + continue; + //ret += removeTraps(secondPass, useVisited, localData, stack, output, code, condition ? branches.get(0) : branches.get(1), ip, visited, visitedStates, decisions); } else { if (ins.isBranch() && (!ins.isJump())) { stack.pop(); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java index f69fb7dde..000baf1b8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitClass.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.abc.types.traits; +import com.jpexs.decompiler.flash.Main; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; @@ -405,7 +406,9 @@ public class TraitClass extends Trait implements TraitWithSlot { String bodyStr = ""; bodyIndex = abc.findBodyIndex(abc.class_info[class_info].cinit_index); if (bodyIndex != -1) { - bodyStr = abc.bodies[bodyIndex].toString(packageName + "." + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames) + ".staticinitializer", pcode, true, scriptIndex, class_info, abc, abc.constants, abc.method_info, new Stack(), true, highlight, fullyQualifiedNames, abc.class_info[class_info].static_traits); + if (Main.DO_DECOMPILE) { + bodyStr = abc.bodies[bodyIndex].toString(packageName + "." + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames) + ".staticinitializer", pcode, true, scriptIndex, class_info, abc, abc.constants, abc.method_info, new Stack(), true, highlight, fullyQualifiedNames, abc.class_info[class_info].static_traits); + } } if (Highlighting.stripHilights(bodyStr).equals("")) { toPrint = ABC.addTabs(bodyStr, 3); @@ -439,7 +442,9 @@ public class TraitClass extends Trait implements TraitWithSlot { bodyStr = ""; bodyIndex = abc.findBodyIndex(abc.instance_info[class_info].iinit_index); if (bodyIndex != -1) { - bodyStr = ABC.addTabs(abc.bodies[bodyIndex].toString(packageName + "." + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames) + ".initializer", pcode, false, scriptIndex, class_info, abc, abc.constants, abc.method_info, new Stack(), false, highlight, fullyQualifiedNames, abc.instance_info[class_info].instance_traits), 3); + if (Main.DO_DECOMPILE) { + bodyStr = ABC.addTabs(abc.bodies[bodyIndex].toString(packageName + "." + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames) + ".initializer", pcode, false, scriptIndex, class_info, abc, abc.constants, abc.method_info, new Stack(), false, highlight, fullyQualifiedNames, abc.instance_info[class_info].instance_traits), 3); + } constructorParams = abc.method_info[abc.instance_info[class_info].iinit_index].getParamStr(abc.constants, abc.bodies[bodyIndex], abc, fullyQualifiedNames); } else { constructorParams = abc.method_info[abc.instance_info[class_info].iinit_index].getParamStr(abc.constants, null, abc, fullyQualifiedNames); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java index 2faeebc24..80d9c8c29 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitFunction.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.abc.types.traits; +import com.jpexs.decompiler.flash.Main; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -51,6 +52,9 @@ public class TraitFunction extends Trait implements TraitWithSlot { @Override public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames) { + if (!Main.DO_DECOMPILE) { + return ""; + } String header = convertHeader(path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlight, fullyQualifiedNames); String bodyStr = ""; int bodyIndex = abc.findBodyIndex(method_info); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java index bfd08f571..dfada34e4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/TraitMethodGetterSetter.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.abc.types.traits; +import com.jpexs.decompiler.flash.Main; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -54,6 +55,9 @@ public class TraitMethodGetterSetter extends Trait { @Override public String convert(String path, List abcTags, ABC abc, boolean isStatic, boolean pcode, int scriptIndex, int classIndex, boolean highlight, List fullyQualifiedNames) { + if (!Main.DO_DECOMPILE) { + return ""; + } if (debugMode) { System.err.println("Decompiling " + path + "." + getName(abc).getName(abc.constants, fullyQualifiedNames)); } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java index bbd922a94..afc4323c9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java @@ -1678,30 +1678,34 @@ public class MainFrame extends JFrame implements ActionListener, TreeSelectionLi new SwingWorker() { @Override protected Object doInBackground() throws Exception { - if (deobfuscationDialog.processAllCheckbox.isSelected()) { - for (ABCContainerTag tag : abcPanel.list) { - if (deobfuscationDialog.codeProcessingLevel.getValue() == DeobfuscationDialog.LEVEL_REMOVE_DEAD_CODE) { - tag.getABC().removeDeadCode(); - } else if (deobfuscationDialog.codeProcessingLevel.getValue() == DeobfuscationDialog.LEVEL_REMOVE_TRAPS) { - tag.getABC().removeTraps(); - } else if (deobfuscationDialog.codeProcessingLevel.getValue() == DeobfuscationDialog.LEVEL_RESTORE_CONTROL_FLOW) { - tag.getABC().removeTraps(); - tag.getABC().restoreControlFlow(); + try { + if (deobfuscationDialog.processAllCheckbox.isSelected()) { + for (ABCContainerTag tag : abcPanel.list) { + if (deobfuscationDialog.codeProcessingLevel.getValue() == DeobfuscationDialog.LEVEL_REMOVE_DEAD_CODE) { + tag.getABC().removeDeadCode(); + } else if (deobfuscationDialog.codeProcessingLevel.getValue() == DeobfuscationDialog.LEVEL_REMOVE_TRAPS) { + tag.getABC().removeTraps(); + } else if (deobfuscationDialog.codeProcessingLevel.getValue() == DeobfuscationDialog.LEVEL_RESTORE_CONTROL_FLOW) { + tag.getABC().removeTraps(); + tag.getABC().restoreControlFlow(); + } } - } - } else { - int bi = abcPanel.detailPanel.methodTraitPanel.methodCodePanel.getBodyIndex(); - if (bi != -1) { - if (deobfuscationDialog.codeProcessingLevel.getValue() == DeobfuscationDialog.LEVEL_REMOVE_DEAD_CODE) { - abcPanel.abc.bodies[bi].removeDeadCode(abcPanel.abc.constants); - } else if (deobfuscationDialog.codeProcessingLevel.getValue() == DeobfuscationDialog.LEVEL_REMOVE_TRAPS) { - abcPanel.abc.bodies[bi].removeTraps(abcPanel.abc.constants, abcPanel.abc, abcPanel.decompiledTextArea.getScriptLeaf().scriptIndex, abcPanel.decompiledTextArea.getClassIndex(), abcPanel.decompiledTextArea.getIsStatic()); - } else if (deobfuscationDialog.codeProcessingLevel.getValue() == DeobfuscationDialog.LEVEL_RESTORE_CONTROL_FLOW) { - abcPanel.abc.bodies[bi].removeTraps(abcPanel.abc.constants, abcPanel.abc, abcPanel.decompiledTextArea.getScriptLeaf().scriptIndex, abcPanel.decompiledTextArea.getClassIndex(), abcPanel.decompiledTextArea.getIsStatic()); - abcPanel.abc.bodies[bi].restoreControlFlow(abcPanel.abc.constants); + } else { + int bi = abcPanel.detailPanel.methodTraitPanel.methodCodePanel.getBodyIndex(); + if (bi != -1) { + if (deobfuscationDialog.codeProcessingLevel.getValue() == DeobfuscationDialog.LEVEL_REMOVE_DEAD_CODE) { + abcPanel.abc.bodies[bi].removeDeadCode(abcPanel.abc.constants); + } else if (deobfuscationDialog.codeProcessingLevel.getValue() == DeobfuscationDialog.LEVEL_REMOVE_TRAPS) { + abcPanel.abc.bodies[bi].removeTraps(abcPanel.abc.constants, abcPanel.abc, abcPanel.decompiledTextArea.getScriptLeaf().scriptIndex, abcPanel.decompiledTextArea.getClassIndex(), abcPanel.decompiledTextArea.getIsStatic()); + } else if (deobfuscationDialog.codeProcessingLevel.getValue() == DeobfuscationDialog.LEVEL_RESTORE_CONTROL_FLOW) { + abcPanel.abc.bodies[bi].removeTraps(abcPanel.abc.constants, abcPanel.abc, abcPanel.decompiledTextArea.getScriptLeaf().scriptIndex, abcPanel.decompiledTextArea.getClassIndex(), abcPanel.decompiledTextArea.getIsStatic()); + abcPanel.abc.bodies[bi].restoreControlFlow(abcPanel.abc.constants); + } } + abcPanel.detailPanel.methodTraitPanel.methodCodePanel.setBodyIndex(bi, abcPanel.abc); } - abcPanel.detailPanel.methodTraitPanel.methodCodePanel.setBodyIndex(bi, abcPanel.abc); + } catch (Exception ex) { + Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, "Deobfuscation error", ex); } Main.stopWork(); JOptionPane.showMessageDialog(null, "Deobfuscation complete");