diff --git a/trunk/src/com/jpexs/asdec/abc/ABC.java b/trunk/src/com/jpexs/asdec/abc/ABC.java index b693918e1..3b46f4cf8 100644 --- a/trunk/src/com/jpexs/asdec/abc/ABC.java +++ b/trunk/src/com/jpexs/asdec/abc/ABC.java @@ -36,6 +36,7 @@ import java.io.*; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import java.util.Stack; import java.util.regex.Pattern; public class ABC { @@ -232,6 +233,11 @@ public class ABC { method_info[mb.method_info].setBody(mb); bodyIdxFromMethodIdx[mb.method_info] = i; } + + /*for(ScriptInfo si:script_info){ + System.out.println("--------------------------------------------"); + System.out.println(findBody(si.init_index).toString(true, false, -1, this, constants, method_info,new Stack())); + }*/ } public void saveToStream(OutputStream os) throws IOException { @@ -608,7 +614,7 @@ public class ABC { String bodyStr = ""; int bodyIndex = findBodyIndex(class_info[i].cinit_index); if (bodyIndex != -1) { - bodyStr = addTabs(bodies[bodyIndex].toString(pcode, true, i, this, constants, method_info, highlight), 3); + bodyStr = addTabs(bodies[bodyIndex].toString(pcode, true, i, this, constants, method_info, new Stack(),highlight), 3); } // if (!bodyStr.equals("")) { toPrint = IDENT_STRING + IDENT_STRING + "{\r\n" + bodyStr + "\r\n" + IDENT_STRING + IDENT_STRING + "}"; @@ -637,7 +643,7 @@ public class ABC { bodyStr = ""; bodyIndex = findBodyIndex(instance_info[i].iinit_index); if (bodyIndex != -1) { - bodyStr = addTabs(bodies[bodyIndex].toString(pcode, false, i, this, constants, method_info, highlight), 3); + bodyStr = addTabs(bodies[bodyIndex].toString(pcode, false, i, this, constants, method_info, new Stack(),highlight), 3); constructorParams = method_info[instance_info[i].iinit_index].getParamStr(constants, bodies[bodyIndex], this); } else { constructorParams = method_info[instance_info[i].iinit_index].getParamStr(constants, null, this); @@ -658,7 +664,7 @@ public class ABC { bodyStr = ""; bodyIndex = findBodyIndex(tm.method_info); if (bodyIndex != -1) { - bodyStr = addTabs(bodies[bodyIndex].toString(pcode, true, i, this, constants, method_info, highlight), 3); + bodyStr = addTabs(bodies[bodyIndex].toString(pcode, true, i, this, constants, method_info, new Stack(), highlight), 3); } toPrint = IDENT_STRING + IDENT_STRING + tm.convert(constants, method_info, this, true) + " {\r\n" + bodyStr + "\r\n" + IDENT_STRING + IDENT_STRING + "}"; } @@ -687,7 +693,7 @@ public class ABC { bodyStr = ""; bodyIndex = findBodyIndex(tm.method_info); if (bodyIndex != -1) { - bodyStr = addTabs(bodies[bodyIndex].toString(pcode, false, i, this, constants, method_info, highlight), 3); + bodyStr = addTabs(bodies[bodyIndex].toString(pcode, false, i, this, constants, method_info, new Stack(), highlight), 3); } toPrint = IDENT_STRING + IDENT_STRING + tm.convert(constants, method_info, this, false) + " {\r\n" + bodyStr + "\r\n" + IDENT_STRING + IDENT_STRING + "}"; } diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java b/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java index 2c1387f43..462daf052 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/AVM2Code.java @@ -59,7 +59,7 @@ import java.util.regex.Pattern; public class AVM2Code { - private static final boolean DEBUG_MODE=false; + private static final boolean DEBUG_MODE=true; public static int toSourceLimit = -1; public ArrayList code = new ArrayList(); public static boolean DEBUG_REWRITE = false; @@ -1617,8 +1617,8 @@ public class AVM2Code { return ret; } - public String toSource(boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], MethodBody body, HashMap localRegNames) { - return toSource(isStatic, classIndex, abc, constants, method_info, body, false, localRegNames); + public String toSource(boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], MethodBody body, HashMap localRegNames,Stack scopeStack) { + return toSource(isStatic, classIndex, abc, constants, method_info, body, false, localRegNames,scopeStack); } public List toTree(boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], MethodBody body, HashMap localRegNames) { @@ -1695,7 +1695,7 @@ public class AVM2Code { } } - public String toSource(boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], MethodBody body, boolean hilighted, HashMap localRegNames) { + public String toSource(boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], MethodBody body, boolean hilighted, HashMap localRegNames,Stack scopeStack) { toSourceCount = 0; loopList = new ArrayList(); unknownJumps = new ArrayList(); @@ -1717,7 +1717,7 @@ public class AVM2Code { } try { - list = toSource(isStatic, classIndex, localRegs, new Stack(), new Stack(), abc, constants, method_info, body, 0, code.size() - 1, localRegNames).output; + list = toSource(isStatic, classIndex, localRegs, new Stack(), scopeStack, abc, constants, method_info, body, 0, code.size() - 1, localRegNames).output; //Declarations boolean declaredRegisters[]=new boolean[regCount]; @@ -1754,6 +1754,9 @@ public class AVM2Code { s = listToString(list, constants, localRegNames); } catch (Exception ex) { + if(DEBUG_MODE){ + ex.printStackTrace(); + } s = "/*\r\n * Decompilation error\r\n * Code may be obfuscated\r\n * Error Message: " + ex.getMessage() + "\r\n */"; return s; } diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/construction/NewFunctionIns.java b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/construction/NewFunctionIns.java index 8f760f915..aed5e8c53 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/construction/NewFunctionIns.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/construction/NewFunctionIns.java @@ -43,7 +43,7 @@ public class NewFunctionIns extends InstructionDefinition { String bodyStr = ""; String paramStr = ""; if (mybody != null) { - bodyStr = Highlighting.hilighMethodEnd() + mybody.toString(false, isStatic, classIndex, abc, constants, method_info, true) + Highlighting.hilighMethodBegin(body.method_info); + bodyStr = Highlighting.hilighMethodEnd() + mybody.toString(false, isStatic, classIndex, abc, constants, method_info,scopeStack, true) + Highlighting.hilighMethodBegin(body.method_info); paramStr = method_info[methodIndex].getParamStr(constants, mybody, abc); } stack.push(new NewFunctionTreeItem(ins, paramStr, method_info[methodIndex].getReturnTypeStr(constants), bodyStr)); diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/localregs/GetLocal0Ins.java b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/localregs/GetLocal0Ins.java index 5396b532c..3181fadb0 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/localregs/GetLocal0Ins.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/localregs/GetLocal0Ins.java @@ -43,9 +43,9 @@ public class GetLocal0Ins extends InstructionDefinition implements GetLocalTypeI @Override public void translate(boolean isStatic, int classIndex, java.util.HashMap localRegs, Stack stack, java.util.Stack scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List output, com.jpexs.asdec.abc.types.MethodBody body, com.jpexs.asdec.abc.ABC abc, HashMap localRegNames) { if (isStatic) { - stack.push(new ClassTreeItem(abc.instance_info[classIndex].getName(constants).getName(constants))); + stack.push(new ClassTreeItem(abc.instance_info[classIndex].getName(constants))); } else { - stack.push(new ThisTreeItem()); + stack.push(new ThisTreeItem(abc.instance_info[classIndex].getName(constants))); } } diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetGlobalScopeIns.java b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetGlobalScopeIns.java index c15c6efed..2ad19f029 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetGlobalScopeIns.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetGlobalScopeIns.java @@ -21,6 +21,7 @@ import com.jpexs.asdec.abc.avm2.ConstantPool; import com.jpexs.asdec.abc.avm2.LocalDataArea; import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction; import com.jpexs.asdec.abc.avm2.instructions.InstructionDefinition; +import com.jpexs.asdec.abc.avm2.treemodel.ClassTreeItem; import com.jpexs.asdec.abc.avm2.treemodel.TreeItem; import com.jpexs.asdec.abc.types.MethodInfo; import java.util.HashMap; diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetSlotIns.java b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetSlotIns.java index 3381a6336..585a219f6 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetSlotIns.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/instructions/other/GetSlotIns.java @@ -21,7 +21,9 @@ import com.jpexs.asdec.abc.avm2.AVM2Code; import com.jpexs.asdec.abc.avm2.ConstantPool; import com.jpexs.asdec.abc.avm2.instructions.AVM2Instruction; import com.jpexs.asdec.abc.avm2.instructions.InstructionDefinition; +import com.jpexs.asdec.abc.avm2.treemodel.ClassTreeItem; import com.jpexs.asdec.abc.avm2.treemodel.GetSlotTreeItem; +import com.jpexs.asdec.abc.avm2.treemodel.ThisTreeItem; import com.jpexs.asdec.abc.avm2.treemodel.TreeItem; import com.jpexs.asdec.abc.avm2.treemodel.clauses.ExceptionTreeItem; import com.jpexs.asdec.abc.types.MethodInfo; @@ -44,8 +46,11 @@ public class GetSlotIns extends InstructionDefinition { Multiname slotname = null; if (obj instanceof ExceptionTreeItem) { slotname = constants.constant_multiname[((ExceptionTreeItem) obj).exception.name_index]; - } else { - + } else if(obj instanceof ClassTreeItem){ + slotname=((ClassTreeItem)obj).className; + } else if(obj instanceof ThisTreeItem){ + slotname=((ThisTreeItem)obj).className; + }else{ for (int t = 0; t < body.traits.traits.length; t++) { if (body.traits.traits[t] instanceof TraitSlotConst) { if (((TraitSlotConst) body.traits.traits[t]).slot_id == slotIndex) { diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/ClassTreeItem.java b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/ClassTreeItem.java index 547dbbe9a..35943554f 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/ClassTreeItem.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/ClassTreeItem.java @@ -17,19 +17,20 @@ package com.jpexs.asdec.abc.avm2.treemodel; import com.jpexs.asdec.abc.avm2.ConstantPool; +import com.jpexs.asdec.abc.types.Multiname; import java.util.HashMap; public class ClassTreeItem extends TreeItem { - public String className; + public Multiname className; - public ClassTreeItem(String className) { + public ClassTreeItem(Multiname className) { super(null, PRECEDENCE_PRIMARY); this.className = className; } @Override public String toString(ConstantPool constants, HashMap localRegNames) { - return className; + return className.getName(constants); } } diff --git a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/ThisTreeItem.java b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/ThisTreeItem.java index b1a222aef..29ac40fd8 100644 --- a/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/ThisTreeItem.java +++ b/trunk/src/com/jpexs/asdec/abc/avm2/treemodel/ThisTreeItem.java @@ -17,12 +17,15 @@ package com.jpexs.asdec.abc.avm2.treemodel; import com.jpexs.asdec.abc.avm2.ConstantPool; +import com.jpexs.asdec.abc.types.Multiname; import java.util.HashMap; public class ThisTreeItem extends TreeItem { - public ThisTreeItem() { + public Multiname className; + public ThisTreeItem(Multiname className) { super(null, PRECEDENCE_PRIMARY); + this.className=className; } @Override diff --git a/trunk/src/com/jpexs/asdec/abc/types/MethodBody.java b/trunk/src/com/jpexs/asdec/abc/types/MethodBody.java index 51265750f..ac87c1117 100644 --- a/trunk/src/com/jpexs/asdec/abc/types/MethodBody.java +++ b/trunk/src/com/jpexs/asdec/abc/types/MethodBody.java @@ -21,9 +21,11 @@ import com.jpexs.asdec.abc.ABC; import com.jpexs.asdec.abc.avm2.AVM2Code; import com.jpexs.asdec.abc.avm2.CodeStats; import com.jpexs.asdec.abc.avm2.ConstantPool; +import com.jpexs.asdec.abc.avm2.treemodel.TreeItem; import com.jpexs.asdec.abc.types.traits.Traits; import com.jpexs.asdec.helpers.Highlighting; import java.util.HashMap; +import java.util.Stack; public class MethodBody implements Cloneable { @@ -71,11 +73,11 @@ public class MethodBody implements Cloneable { return ret; } - public String toString(boolean pcode, boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[]) { - return toString(pcode, isStatic, classIndex, abc, constants, method_info, false); + public String toString(boolean pcode, boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], Stack scopeStack) { + return toString(pcode, isStatic, classIndex, abc, constants, method_info, scopeStack,false); } - public String toString(boolean pcode, boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], boolean hilight) { + public String toString(boolean pcode, boolean isStatic, int classIndex, ABC abc, ConstantPool constants, MethodInfo method_info[], Stack scopeStack, boolean hilight) { String s = ""; //s+="method_info="+method_info+" max_stack="+max_stack+" max_regs="+max_regs+" scope_depth="+scope_depth+" max_scope="+max_scope; @@ -84,7 +86,7 @@ public class MethodBody implements Cloneable { s += code.toASMSource(constants, this); } else { try { - s += code.toSource(isStatic, classIndex, abc, constants, method_info, this, hilight, getLocalRegNames(abc)); + s += code.toSource(isStatic, classIndex, abc, constants, method_info, this, hilight, getLocalRegNames(abc),scopeStack); s = s.trim(); if (hilight) { s = Highlighting.hilighMethod(s, this.method_info);