From cff3ca68995a5216a0c2b864d66a9b3d2b32d55a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sun, 7 Jul 2013 14:57:57 +0200 Subject: [PATCH] Improved error handling --- .../decompiler/flash/abc/avm2/AVM2Code.java | 12 ++- .../flash/abc/avm2/graph/AVM2Graph.java | 76 ++++++++++--------- .../instructions/localregs/GetLocal0Ins.java | 9 +-- .../instructions/localregs/GetLocal1Ins.java | 19 +---- .../instructions/localregs/GetLocal2Ins.java | 19 +---- .../instructions/localregs/GetLocal3Ins.java | 19 +---- .../instructions/localregs/GetLocalIns.java | 20 +---- .../localregs/GetLocalTypeIns.java | 32 +++++++- .../abc/avm2/treemodel/UndefinedTreeItem.java | 15 ++++ .../flash/abc/types/MethodBody.java | 26 +++---- .../flash/abc/types/traits/Trait.java | 1 - .../flash/abc/types/traits/TraitClass.java | 3 - .../types/traits/TraitMethodGetterSetter.java | 11 +-- .../jpexs/decompiler/flash/action/Action.java | 27 +++++-- .../jpexs/decompiler/flash/graph/Graph.java | 67 +++++++--------- 15 files changed, 157 insertions(+), 199 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 d974de0b8..726f599e5 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -1221,15 +1221,13 @@ public class AVM2Code implements Serializable { try { list = AVM2Graph.translateViaGraph(path, this, abc, body, isStatic, scriptIndex, classIndex, localRegs, scopeStack, localRegNames, fullyQualifiedNames); - } catch (Exception ex2) { + } catch (Exception | OutOfMemoryError | StackOverflowError ex2) { Logger.getLogger(AVM2Code.class.getName()).log(Level.SEVERE, "Decompilation error in " + path, ex2); - return "/*\r\n * Decompilation error\r\n * Code may be obfuscated\r\n * Error Message: " + ex2.getMessage() + "\r\n */"; + if (ex2 instanceof OutOfMemoryError) { + System.gc(); + } + return "/*\r\n * Decompilation error\r\n * Code may be obfuscated\r\n * Error type: " + ex2.getClass().getSimpleName() + "\r\n */\r\nthrow new IllegalOperationError(\"Not decompiled due to error\");\r\n"; } - /*try{ - list=toSourceOutput(true,isStatic, classIndex, localRegs, new Stack(), scopeStack, abc, constants, method_info, body, 0, code.size() - 1, localRegNames, fullyQualifiedNames, null).output; - }catch(Exception ex){ - - }*/ if (initTraits != null) { for (int i = 0; i < list.size(); i++) { GraphTargetItem ti = list.get(i); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java index 43dd1eb0a..9f3ba2930 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java @@ -1,16 +1,16 @@ /* * Copyright (C) 2010-2013 JPEXS - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -157,7 +157,7 @@ public class AVM2Graph extends Graph { } } - /*for(ABCException ex:body.exceptions){ + /*for(ABCException ex:body.exceptions){ for(GraphPart p:allBlocks){ boolean next_is_ex_start=false; for(GraphPart n:p.nextParts){ @@ -579,43 +579,45 @@ public class AVM2Graph extends Graph { WhileItem w = (WhileItem) loopItem; if ((!w.expression.isEmpty()) && (w.expression.get(w.expression.size() - 1) instanceof HasNextTreeItem)) { - if (((HasNextTreeItem) w.expression.get(w.expression.size() - 1)).collection.getNotCoerced().getThroughRegister() instanceof FilteredCheckTreeItem) { - //GraphTargetItem gti = ((HasNextTreeItem) ((HasNextTreeItem) w.expression.get(w.expression.size() - 1))).collection.getNotCoerced().getThroughRegister(); - if (w.commands.size() >= 3) { //((w.commands.size() == 3) || (w.commands.size() == 4)) { - int pos = 0; - while (w.commands.get(pos) instanceof SetLocalTreeItem) { - pos++; - } - GraphTargetItem ft = w.commands.get(pos); - if (ft instanceof WithTreeItem) { - ft = w.commands.get(pos + 1); - if (ft instanceof IfItem) { - IfItem ift = (IfItem) ft; - if (ift.onTrue.size() > 0) { - ft = ift.onTrue.get(0); - if (ft instanceof SetPropertyTreeItem) { - SetPropertyTreeItem spt = (SetPropertyTreeItem) ft; - if (spt.object instanceof LocalRegTreeItem) { - int regIndex = ((LocalRegTreeItem) spt.object).regIndex; - HasNextTreeItem iti = (HasNextTreeItem) w.expression.get(w.expression.size() - 1); - @SuppressWarnings("unchecked") - HashMap localRegs = (HashMap) localData.get(DATA_LOCALREGS); - localRegs.put(regIndex, new FilterTreeItem(null, iti.collection.getThroughRegister(), ift.expression)); - return null; + if (((HasNextTreeItem) w.expression.get(w.expression.size() - 1)).collection != null) { + if (((HasNextTreeItem) w.expression.get(w.expression.size() - 1)).collection.getNotCoerced().getThroughRegister() instanceof FilteredCheckTreeItem) { + //GraphTargetItem gti = ((HasNextTreeItem) ((HasNextTreeItem) w.expression.get(w.expression.size() - 1))).collection.getNotCoerced().getThroughRegister(); + if (w.commands.size() >= 3) { //((w.commands.size() == 3) || (w.commands.size() == 4)) { + int pos = 0; + while (w.commands.get(pos) instanceof SetLocalTreeItem) { + pos++; + } + GraphTargetItem ft = w.commands.get(pos); + if (ft instanceof WithTreeItem) { + ft = w.commands.get(pos + 1); + if (ft instanceof IfItem) { + IfItem ift = (IfItem) ft; + if (ift.onTrue.size() > 0) { + ft = ift.onTrue.get(0); + if (ft instanceof SetPropertyTreeItem) { + SetPropertyTreeItem spt = (SetPropertyTreeItem) ft; + if (spt.object instanceof LocalRegTreeItem) { + int regIndex = ((LocalRegTreeItem) spt.object).regIndex; + HasNextTreeItem iti = (HasNextTreeItem) w.expression.get(w.expression.size() - 1); + @SuppressWarnings("unchecked") + HashMap localRegs = (HashMap) localData.get(DATA_LOCALREGS); + localRegs.put(regIndex, new FilterTreeItem(null, iti.collection.getThroughRegister(), ift.expression)); + return null; + } } } } } } - } - } else if (!w.commands.isEmpty()) { - if (w.commands.get(0) instanceof SetTypeTreeItem) { - SetTypeTreeItem sti = (SetTypeTreeItem) w.commands.remove(0); - GraphTargetItem gti = sti.getValue().getNotCoerced(); - if (gti instanceof NextValueTreeItem) { - return new ForEachInTreeItem(w.src, w.loop, new InTreeItem(null, sti.getObject(), ((HasNextTreeItem) w.expression.get(w.expression.size() - 1)).collection), w.commands); - } else if (gti instanceof NextNameTreeItem) { - return new ForInTreeItem(w.src, w.loop, new InTreeItem(null, sti.getObject(), ((HasNextTreeItem) w.expression.get(w.expression.size() - 1)).collection), w.commands); + } else if (!w.commands.isEmpty()) { + if (w.commands.get(0) instanceof SetTypeTreeItem) { + SetTypeTreeItem sti = (SetTypeTreeItem) w.commands.remove(0); + GraphTargetItem gti = sti.getValue().getNotCoerced(); + if (gti instanceof NextValueTreeItem) { + return new ForEachInTreeItem(w.src, w.loop, new InTreeItem(null, sti.getObject(), ((HasNextTreeItem) w.expression.get(w.expression.size() - 1)).collection), w.commands); + } else if (gti instanceof NextNameTreeItem) { + return new ForInTreeItem(w.src, w.loop, new InTreeItem(null, sti.getObject(), ((HasNextTreeItem) w.expression.get(w.expression.size() - 1)).collection), w.commands); + } } } } @@ -638,7 +640,7 @@ public class AVM2Graph extends Graph { if (list.get(i) instanceof WhileItem) { WhileItem w = (WhileItem) list.get(i); - + } }*/ diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal0Ins.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal0Ins.java index d19b3d835..1b8186e68 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal0Ins.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal0Ins.java @@ -16,11 +16,9 @@ */ package com.jpexs.decompiler.flash.abc.avm2.instructions.localregs; -import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; -import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; import com.jpexs.decompiler.flash.abc.avm2.treemodel.ClassTreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.ScriptTreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.ThisTreeItem; @@ -30,7 +28,7 @@ import java.util.HashMap; import java.util.List; import java.util.Stack; -public class GetLocal0Ins extends InstructionDefinition implements GetLocalTypeIns { +public class GetLocal0Ins extends GetLocalTypeIns { public GetLocal0Ins() { super(0xd0, "getlocal_0", new int[]{}); @@ -58,9 +56,4 @@ public class GetLocal0Ins extends InstructionDefinition implements GetLocalTypeI public int getRegisterId(AVM2Instruction par0) { return 0; } - - @Override - public int getStackDelta(AVM2Instruction ins, ABC abc) { - return 1; - } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal1Ins.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal1Ins.java index 6c2077fd7..d5b505172 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal1Ins.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal1Ins.java @@ -16,19 +16,12 @@ */ package com.jpexs.decompiler.flash.abc.avm2.instructions.localregs; -import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; -import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.LocalRegTreeItem; -import com.jpexs.decompiler.flash.abc.types.MethodInfo; -import com.jpexs.decompiler.flash.graph.GraphTargetItem; -import java.util.HashMap; import java.util.List; -import java.util.Stack; -public class GetLocal1Ins extends InstructionDefinition implements GetLocalTypeIns { +public class GetLocal1Ins extends GetLocalTypeIns { public GetLocal1Ins() { super(0xd1, "getlocal_1", new int[]{}); @@ -39,18 +32,8 @@ public class GetLocal1Ins extends InstructionDefinition implements GetLocalTypeI lda.operandStack.push(lda.localRegisters.get(1)); } - @Override - public void translate(boolean isStatic, int scriptIndex, int classIndex, java.util.HashMap localRegs, Stack stack, java.util.Stack scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List output, com.jpexs.decompiler.flash.abc.types.MethodBody body, com.jpexs.decompiler.flash.abc.ABC abc, HashMap localRegNames, List fullyQualifiedNames) { - stack.push(new LocalRegTreeItem(ins, 1, localRegs.get(1))); - } - @Override public int getRegisterId(AVM2Instruction par0) { return 1; } - - @Override - public int getStackDelta(AVM2Instruction ins, ABC abc) { - return 1; - } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal2Ins.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal2Ins.java index 3ed3c0b3b..d9bdc12a7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal2Ins.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal2Ins.java @@ -16,19 +16,12 @@ */ package com.jpexs.decompiler.flash.abc.avm2.instructions.localregs; -import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; -import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.LocalRegTreeItem; -import com.jpexs.decompiler.flash.abc.types.MethodInfo; -import com.jpexs.decompiler.flash.graph.GraphTargetItem; -import java.util.HashMap; import java.util.List; -import java.util.Stack; -public class GetLocal2Ins extends InstructionDefinition implements GetLocalTypeIns { +public class GetLocal2Ins extends GetLocalTypeIns { public GetLocal2Ins() { super(0xd2, "getlocal_2", new int[]{}); @@ -39,18 +32,8 @@ public class GetLocal2Ins extends InstructionDefinition implements GetLocalTypeI lda.operandStack.push(lda.localRegisters.get(2)); } - @Override - public void translate(boolean isStatic, int scriptIndex, int classIndex, java.util.HashMap localRegs, Stack stack, java.util.Stack scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List output, com.jpexs.decompiler.flash.abc.types.MethodBody body, com.jpexs.decompiler.flash.abc.ABC abc, HashMap localRegNames, List fullyQualifiedNames) { - stack.push(new LocalRegTreeItem(ins, 2, localRegs.get(2))); - } - @Override public int getRegisterId(AVM2Instruction par0) { return 2; } - - @Override - public int getStackDelta(AVM2Instruction ins, ABC abc) { - return 1; - } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal3Ins.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal3Ins.java index a39b9e712..033e874d3 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal3Ins.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal3Ins.java @@ -16,19 +16,12 @@ */ package com.jpexs.decompiler.flash.abc.avm2.instructions.localregs; -import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; -import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.LocalRegTreeItem; -import com.jpexs.decompiler.flash.abc.types.MethodInfo; -import com.jpexs.decompiler.flash.graph.GraphTargetItem; -import java.util.HashMap; import java.util.List; -import java.util.Stack; -public class GetLocal3Ins extends InstructionDefinition implements GetLocalTypeIns { +public class GetLocal3Ins extends GetLocalTypeIns { public GetLocal3Ins() { super(0xd3, "getlocal_3", new int[]{}); @@ -39,18 +32,8 @@ public class GetLocal3Ins extends InstructionDefinition implements GetLocalTypeI lda.operandStack.push(lda.localRegisters.get(3)); } - @Override - public void translate(boolean isStatic, int scriptIndex, int classIndex, java.util.HashMap localRegs, Stack stack, java.util.Stack scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List output, com.jpexs.decompiler.flash.abc.types.MethodBody body, com.jpexs.decompiler.flash.abc.ABC abc, HashMap localRegNames, List fullyQualifiedNames) { - stack.push(new LocalRegTreeItem(ins, 3, localRegs.get(3))); - } - @Override public int getRegisterId(AVM2Instruction par0) { return 3; } - - @Override - public int getStackDelta(AVM2Instruction ins, ABC abc) { - return 1; - } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocalIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocalIns.java index 973c76d91..710e9af61 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocalIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocalIns.java @@ -16,20 +16,13 @@ */ package com.jpexs.decompiler.flash.abc.avm2.instructions.localregs; -import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.LocalDataArea; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; -import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.LocalRegTreeItem; -import com.jpexs.decompiler.flash.abc.types.MethodInfo; -import com.jpexs.decompiler.flash.graph.GraphTargetItem; -import java.util.HashMap; import java.util.List; -import java.util.Stack; -public class GetLocalIns extends InstructionDefinition implements GetLocalTypeIns { +public class GetLocalIns extends GetLocalTypeIns { public GetLocalIns() { super(0x62, "getlocal", new int[]{AVM2Code.DAT_LOCAL_REG_INDEX}); @@ -40,19 +33,8 @@ public class GetLocalIns extends InstructionDefinition implements GetLocalTypeIn lda.operandStack.push(lda.localRegisters.get((int) (long) (Long) arguments.get(0))); } - @Override - public void translate(boolean isStatic, int scriptIndex, int classIndex, java.util.HashMap localRegs, Stack stack, java.util.Stack scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List output, com.jpexs.decompiler.flash.abc.types.MethodBody body, com.jpexs.decompiler.flash.abc.ABC abc, HashMap localRegNames, List fullyQualifiedNames) { - int regIndex = ins.operands[0]; - stack.push(new LocalRegTreeItem(ins, regIndex, localRegs.get(regIndex))); - } - @Override public int getRegisterId(AVM2Instruction ins) { return ins.operands[0]; } - - @Override - public int getStackDelta(AVM2Instruction ins, ABC abc) { - return 1; - } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocalTypeIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocalTypeIns.java index d29ce21b4..aeb9a489b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocalTypeIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocalTypeIns.java @@ -16,9 +16,39 @@ */ package com.jpexs.decompiler.flash.abc.avm2.instructions.localregs; +import com.jpexs.decompiler.flash.abc.ABC; +import com.jpexs.decompiler.flash.abc.avm2.ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; +import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; +import com.jpexs.decompiler.flash.abc.avm2.treemodel.LocalRegTreeItem; +import com.jpexs.decompiler.flash.abc.avm2.treemodel.UndefinedTreeItem; +import com.jpexs.decompiler.flash.abc.types.MethodInfo; +import com.jpexs.decompiler.flash.graph.GraphTargetItem; +import java.util.HashMap; +import java.util.List; +import java.util.Stack; -public interface GetLocalTypeIns { +public abstract class GetLocalTypeIns extends InstructionDefinition { + + public GetLocalTypeIns(int instructionCode, String instructionName, int[] operands) { + super(instructionCode, instructionName, operands); + } + + @Override + public void translate(boolean isStatic, int scriptIndex, int classIndex, java.util.HashMap localRegs, Stack stack, java.util.Stack scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List output, com.jpexs.decompiler.flash.abc.types.MethodBody body, com.jpexs.decompiler.flash.abc.ABC abc, HashMap localRegNames, List fullyQualifiedNames) { + GraphTargetItem computedValue = localRegs.get(getRegisterId(ins)); + if (computedValue == null) { + if (!localRegNames.containsKey(getRegisterId(ins))) { + computedValue = new UndefinedTreeItem(null); + } + } + stack.push(new LocalRegTreeItem(ins, getRegisterId(ins), computedValue)); + } + + @Override + public int getStackDelta(AVM2Instruction ins, ABC abc) { + return 1; + } public abstract int getRegisterId(AVM2Instruction ins); } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/UndefinedTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/UndefinedTreeItem.java index fd4aea794..4e7c317b3 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/UndefinedTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/UndefinedTreeItem.java @@ -31,4 +31,19 @@ public class UndefinedTreeItem extends TreeItem { public String toString(ConstantPool constants, HashMap localRegNames, List fullyQualifiedNames) { return hilight("undefined"); } + + @Override + public boolean isCompileTime() { + return true; + } + + @Override + public double toNumber() { + return 0; + } + + @Override + public boolean toBoolean() { + return false; + } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java index be3d83223..1efa8e821 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java @@ -35,6 +35,7 @@ import java.util.logging.Logger; public class MethodBody implements Cloneable, Serializable { + boolean debugMode = false; public int method_info; public int max_stack; public int max_regs; @@ -102,6 +103,9 @@ public class MethodBody implements Cloneable, Serializable { } public String toString(String path, boolean pcode, boolean isStatic, int scriptIndex, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], Stack scopeStack, boolean isStaticInitializer, boolean hilight, List fullyQualifiedNames, Traits initTraits) { + if (debugMode) { + System.err.println("Decompiling " + path); + } String s = ""; if (!(Boolean) Configuration.getConfig("decompile", Boolean.TRUE)) { s = "//Decompilation skipped"; @@ -125,20 +129,16 @@ public class MethodBody implements Cloneable, Serializable { } } //deobfuscated.restoreControlFlow(constants, b); - try { - s += deobfuscated.toSource(path, isStatic, scriptIndex, classIndex, abc, constants, method_info, b, hilight, getLocalRegNames(abc), scopeStack, isStaticInitializer, fullyQualifiedNames, initTraits); - s = s.trim(); - if (hilight) { - s = Highlighting.hilighMethod(s, this.method_info); - } - } catch (Exception ex) { - Logger.getLogger(MethodBody.class.getName()).log(Level.SEVERE, "Exception during decompilation", ex); - s = "//error:" + ex.toString(); - } catch (OutOfMemoryError er) { - Logger.getLogger(MethodBody.class.getName()).log(Level.SEVERE, "Error during decompilation", er); - s = "//error:" + er.toString(); - System.gc(); + //try { + s += deobfuscated.toSource(path, isStatic, scriptIndex, classIndex, abc, constants, method_info, b, hilight, getLocalRegNames(abc), scopeStack, isStaticInitializer, fullyQualifiedNames, initTraits); + s = s.trim(); + if (hilight) { + s = Highlighting.hilighMethod(s, this.method_info); } + /*} catch (Exception|StackOverflowError|OutOfMemoryError er) { + Logger.getLogger(MethodBody.class.getName()).log(Level.SEVERE, "Error during decompilation", er); + s = "//error:" + er.toString(); + }*/ } return s; } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java index 23e999e2a..9c6012085 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java @@ -30,7 +30,6 @@ import java.util.List; public abstract class Trait implements Serializable { - public static boolean debugMode = false; public int name_index; public int kindType; public int kindFlags; 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 ef878cc60..8b963671d 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 @@ -349,9 +349,6 @@ public class TraitClass extends Trait implements TraitWithSlot { } String packageName = abc.instance_info[class_info].getName(abc.constants).getNamespace(abc.constants).getName(abc.constants); - if (debugMode) { - System.err.println("Decompiling " + packageName + "." + abc.instance_info[class_info].getName(abc.constants).getName(abc.constants, fullyQualifiedNames)); - } List namesInThisPackage = new ArrayList<>(); for (ABCContainerTag tag : abcTags) { for (ScriptInfo si : tag.getABC().script_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 5afd630da..9cf7990d1 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 @@ -54,21 +54,12 @@ 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, boolean paralel) { - - if (debugMode) { - System.err.println("Decompiling " + path + "." + getName(abc).getName(abc.constants, fullyQualifiedNames)); - } String header = convertHeader(path, abcTags, abc, isStatic, pcode, scriptIndex, classIndex, highlight, fullyQualifiedNames, paralel); String bodyStr = ""; int bodyIndex = abc.findBodyIndex(method_info); if (bodyIndex != -1) { - try { - bodyStr = ABC.addTabs(abc.bodies[bodyIndex].toString(path + "." + getName(abc).getName(abc.constants, fullyQualifiedNames), pcode, isStatic, scriptIndex, classIndex, abc, abc.constants, abc.method_info, new Stack(), false, highlight, fullyQualifiedNames, null), 3); - } catch (StackOverflowError er) { - er.printStackTrace(); - bodyStr = "//StackOverflowError"; - } + bodyStr = ABC.addTabs(abc.bodies[bodyIndex].toString(path + "." + getName(abc).getName(abc.constants, fullyQualifiedNames), pcode, isStatic, scriptIndex, classIndex, abc, abc.constants, abc.method_info, new Stack(), false, highlight, fullyQualifiedNames, null), 3); } return ABC.IDENT_STRING + ABC.IDENT_STRING + header + ((classIndex != -1 && abc.instance_info[classIndex].isInterface()) ? ";" : " {\r\n" + bodyStr + "\r\n" + ABC.IDENT_STRING + ABC.IDENT_STRING + "}"); } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/Action.java b/trunk/src/com/jpexs/decompiler/flash/action/Action.java index d5267840f..4cd5ec7c2 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/Action.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/Action.java @@ -360,10 +360,13 @@ public class Action implements GraphSourceItem { /** * Converts list of actions to ASM source * + * @param listeners + * @param address * @param list List of actions * @param importantOffsets List of important offsets to mark as labels * @param version SWF version * @param hex Add hexadecimal? + * @param swfPos * @return ASM source as String */ public static String actionsToString(List listeners, long address, List list, List importantOffsets, int version, boolean hex, long swfPos) { @@ -373,11 +376,14 @@ public class Action implements GraphSourceItem { /** * Converts list of actions to ASM source * + * @param listeners + * @param address * @param list List of actions * @param importantOffsets List of important offsets to mark as labels * @param constantPool Constant pool * @param version SWF version * @param hex Add hexadecimal? + * @param swfPos * @return ASM source as String */ public static String actionsToString(List listeners, long address, List list, List importantOffsets, List constantPool, int version, boolean hex, long swfPos) { @@ -541,6 +547,7 @@ public class Action implements GraphSourceItem { /** * Convert action to ASM source * + * @param container * @param knownAddreses List of important offsets to mark as labels * @param constantPool Constant pool * @param version SWF version @@ -647,9 +654,12 @@ public class Action implements GraphSourceItem { return Graph.graphToString(tree); - } catch (Exception ex) { - Logger.getLogger(Action.class.getName()).log(Level.SEVERE, null, ex); - return "//Decompilation error :" + ex.getLocalizedMessage(); + } catch (Exception | OutOfMemoryError | StackOverflowError ex2) { + Logger.getLogger(Action.class.getName()).log(Level.SEVERE, "Decompilation error", ex2); + if (ex2 instanceof OutOfMemoryError) { + System.gc(); + } + return "/*\r\n * Decompilation error\r\n * Code may be obfuscated\r\n * Error type: " + ex2.getClass().getSimpleName() + "\r\n */"; } } @@ -657,6 +667,8 @@ public class Action implements GraphSourceItem { * Converts list of actions to List of treeItems * * @param regNames Register names + * @param variables + * @param functions * @param actions List of actions * @param version SWF version * @return List of treeItems @@ -804,10 +816,13 @@ public class Action implements GraphSourceItem { List out; try { out = ActionGraph.translateViaGraph(cnt.getRegNames(), variables, functions, actions.subList(adr2ip(actions, endAddr, version), adr2ip(actions, endAddr + size, version)), version); - } catch (RuntimeException re) { + } catch (Exception | OutOfMemoryError | StackOverflowError ex2) { + Logger.getLogger(Action.class.getName()).log(Level.SEVERE, "Decompilation error", ex2); + if (ex2 instanceof OutOfMemoryError) { + System.gc(); + } out = new ArrayList<>(); - out.add(new CommentItem("Error " + re.getMessage())); - Logger.getLogger(Action.class.getName()).log(Level.SEVERE, "Error during container translation", re); + out.add(new CommentItem("\r\n * Decompilation error\r\n * Code may be obfuscated\r\n * Error type: " + ex2.getClass().getSimpleName() + "\r\n")); } outs.add(out); endAddr += size; diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java b/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java index 2df14ce09..0c9f900f8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java @@ -25,8 +25,6 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.Stack; -import java.util.logging.Level; -import java.util.logging.Logger; /** * @@ -536,37 +534,31 @@ public class Graph { } public List translate(List localData) { - try { - List allParts = new ArrayList<>(); - for (GraphPart head : heads) { - populateParts(head, allParts); - } - Stack stack = new Stack<>(); - List loops = new ArrayList<>(); - getLoops(heads.get(0), loops, null); - /*System.out.println(""); - for (Loop el : loops) { - System.out.println(el); - } - System.out.println("");*/ - getPrecontinues(null, heads.get(0), loops, null); - /*System.err.println(""); - for (Loop el : loops) { - System.err.println(el); - } - System.err.println("");//*/ - - List ret = printGraph(new ArrayList(), localData, stack, allParts, null, heads.get(0), null, loops); - processIfs(ret); - finalProcessStack(stack, ret); - finalProcessAll(ret, 0); - return ret; - } catch (StackOverflowError soe) { - List ret = new ArrayList<>(); - ret.add(new CommentItem("StackOverflowError")); - Logger.getLogger(Graph.class.getName()).log(Level.SEVERE, "error during printGraph", soe); - return ret; + List allParts = new ArrayList<>(); + for (GraphPart head : heads) { + populateParts(head, allParts); } + Stack stack = new Stack<>(); + List loops = new ArrayList<>(); + getLoops(heads.get(0), loops, null); + /*System.out.println(""); + for (Loop el : loops) { + System.out.println(el); + } + System.out.println("");*/ + getPrecontinues(null, heads.get(0), loops, null); + /*System.err.println(""); + for (Loop el : loops) { + System.err.println(el); + } + System.err.println("");//*/ + + List ret = printGraph(new ArrayList(), localData, stack, allParts, null, heads.get(0), null, loops); + processIfs(ret); + finalProcessStack(stack, ret); + finalProcessAll(ret, 0); + return ret; + } @@ -1543,14 +1535,9 @@ public class Graph { end = p.end; int start = p.start; - try { - output.addAll(code.translatePart(p, localData, stack, start, end)); - if ((end >= code.size() - 1) && p.nextParts.isEmpty()) { - output.add(new ScriptEndItem()); - } - } catch (Exception ex) { - Logger.getLogger(Graph.class.getName()).log(Level.SEVERE, "error during printgraph", ex); - return ret; + output.addAll(code.translatePart(p, localData, stack, start, end)); + if ((end >= code.size() - 1) && p.nextParts.isEmpty()) { + output.add(new ScriptEndItem()); } }