From 5a53822dd4e17fdafd95a681c12496a26dea56e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sun, 31 Mar 2013 22:06:35 +0200 Subject: [PATCH] Issue #51 AS1/2 displaying java class name instead of expression Better constantpool detection --- .../decompiler/flash/SWFInputStream.java | 35 ++++++++++--------- .../jpexs/decompiler/flash/action/Action.java | 11 +++--- .../treemodel/CallFunctionTreeItem.java | 2 +- .../action/treemodel/CallMethodTreeItem.java | 2 +- .../flash/action/treemodel/CallTreeItem.java | 2 +- .../action/treemodel/CastOpTreeItem.java | 2 +- .../action/treemodel/DefineLocalTreeItem.java | 4 +-- .../action/treemodel/DeleteTreeItem.java | 2 +- .../action/treemodel/ExtendsTreeItem.java | 2 +- .../action/treemodel/GetMemberTreeItem.java | 4 +-- .../action/treemodel/GetVariableTreeItem.java | 2 +- .../action/treemodel/NewObjectTreeItem.java | 2 +- .../action/treemodel/SetMemberTreeItem.java | 2 +- .../action/treemodel/SetVariableTreeItem.java | 2 +- .../flash/action/treemodel/TreeItem.java | 4 +-- .../treemodel/clauses/ForInTreeItem.java | 2 +- 16 files changed, 42 insertions(+), 38 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java index 0867b283a..15cbe0e73 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java @@ -753,23 +753,6 @@ public class SWFInputStream extends InputStream { if (ip < startIp) { retv = true; } - if (debugMode) { - //if(a instanceof ActionIf){ - String atos = a.getASMSource(new ArrayList(), cpool.constants, sis.version, false); - if (a instanceof ActionContainer) { - atos = a.toString(); - } - System.err.println("readActionListAtPos ip: " + (ip - startIp) + " (0x" + Helper.formatAddress(ip - startIp) + ") " + " action(len " + a.actionLength + "): " + atos + (a.isIgnored() ? " (ignored)" : "") + " stack:" + Helper.stackToString(stack, Helper.toList(cpool)) + " " + Helper.byteArrToString(a.getBytes(SWF.DEFAULT_VERSION))); - //} - String add = ""; - if (a instanceof ActionIf) { - add = " change: " + ((ActionIf) a).getJumpOffset(); - } - if (a instanceof ActionJump) { - add = " change: " + ((ActionJump) a).getJumpOffset(); - } - System.err.println(add); - } /*if(a instanceof ActionConstantPool){ @@ -793,6 +776,24 @@ public class SWFInputStream extends InputStream { cpool.count++; } } + + if (debugMode) { + //if(a instanceof ActionIf){ + String atos = a.getASMSource(new ArrayList(), cpool.constants, sis.version, false); + if (a instanceof ActionContainer) { + atos = a.toString(); + } + System.err.println("readActionListAtPos ip: " + (ip - startIp) + " (0x" + Helper.formatAddress(ip - startIp) + ") " + " action(len " + a.actionLength + "): " + atos + (a.isIgnored() ? " (ignored)" : "") + " stack:" + Helper.stackToString(stack, Helper.toList(cpool)) + " " + Helper.byteArrToString(a.getBytes(SWF.DEFAULT_VERSION))); + //} + String add = ""; + if (a instanceof ActionIf) { + add = " change: " + ((ActionIf) a).getJumpOffset(); + } + if (a instanceof ActionJump) { + add = " change: " + ((ActionJump) a).getJumpOffset(); + } + System.err.println(add); + } long newFilePos = rri.getPos(); long actionLen = newFilePos - filePos; diff --git a/trunk/src/com/jpexs/decompiler/flash/action/Action.java b/trunk/src/com/jpexs/decompiler/flash/action/Action.java index c96ed42d5..a7257ce38 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/Action.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/Action.java @@ -384,7 +384,10 @@ public class Action implements GraphSourceItem { //setActionsAddresses(list, 0, version); importantOffsets = getActionsAllRefs(list, version); } - + List cps = SWFInputStream.getConstantPool(new ActionGraphSource(list, version, new HashMap(), new HashMap(), new HashMap()), 0, version); + if (!cps.isEmpty()) { + setConstantPool(list, cps.get(cps.size() - 1)); + } offset = address; int pos = -1; for (Action a : list) { @@ -421,9 +424,9 @@ public class Action implements GraphSourceItem { if(a instanceof ActionJump){ add = " change: "+((ActionJump)a).getJumpOffset(); }*/ - ret += Highlighting.hilighOffset("", offset) + a.getASMSourceReplaced(importantOffsets, constantPool, version, hex) + (a.ignored ? "; ignored" : "")+/*"; ofs"+Helper.formatAddress(offset)+add +*/ "\r\n"; - - //} + ret += Highlighting.hilighOffset("", offset) + a.getASMSourceReplaced(importantOffsets, constantPool, version, hex) + (a.ignored ? "; ignored" : "") +/*"; ofs"+Helper.formatAddress(offset)+add +*/ "\r\n"; + + //} if (a.afterInsert != null) { ret += a.afterInsert.getASMSource(importantOffsets, constantPool, version, hex) + "\r\n"; } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallFunctionTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallFunctionTreeItem.java index 41700072c..6c7dd0c8b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallFunctionTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallFunctionTreeItem.java @@ -41,7 +41,7 @@ public class CallFunctionTreeItem extends TreeItem { } paramStr += arguments.get(t).toStringNL(constants); } - return stripQuotes(functionName) + hilight("(") + paramStr + hilight(")"); + return stripQuotes(functionName, constants) + hilight("(") + paramStr + hilight(")"); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallMethodTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallMethodTreeItem.java index 850d908a2..1c20070c3 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallMethodTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallMethodTreeItem.java @@ -57,7 +57,7 @@ public class CallMethodTreeItem extends TreeItem { if (blankMethod) { return scriptObject.toString(constants) + hilight("(") + paramStr + hilight(")"); } - return scriptObject.toString(constants) + hilight(".") + stripQuotes(methodName) + hilight("(") + paramStr + hilight(")"); + return scriptObject.toString(constants) + hilight(".") + stripQuotes(methodName, constants) + hilight("(") + paramStr + hilight(")"); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallTreeItem.java index 060c8d247..a71915659 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CallTreeItem.java @@ -31,7 +31,7 @@ public class CallTreeItem extends TreeItem { @Override public String toString(ConstantPool constants) { - return stripQuotes(value) + hilight("()"); + return stripQuotes(value, constants) + hilight("()"); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CastOpTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CastOpTreeItem.java index 831e0e366..024561921 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CastOpTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/CastOpTreeItem.java @@ -34,7 +34,7 @@ public class CastOpTreeItem extends TreeItem { @Override public String toString(ConstantPool constants) { - return hilight("(") + stripQuotes(constructor) + hilight(")") + object.toString(Helper.toList(constants)); + return hilight("(") + stripQuotes(constructor, constants) + hilight(")") + object.toString(Helper.toList(constants)); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DefineLocalTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DefineLocalTreeItem.java index 06d834833..3b6bb0959 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DefineLocalTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DefineLocalTreeItem.java @@ -34,9 +34,9 @@ public class DefineLocalTreeItem extends TreeItem implements SetTypeTreeItem { @Override public String toString(ConstantPool constants) { if (value == null) { - return hilight("var ") + stripQuotes(name); + return hilight("var ") + stripQuotes(name, constants); } - return hilight("var ") + stripQuotes(name) + hilight("=") + value.toString(constants); + return hilight("var ") + stripQuotes(name, constants) + hilight("=") + value.toString(constants); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DeleteTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DeleteTreeItem.java index bd7ec6413..d0015771d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DeleteTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/DeleteTreeItem.java @@ -36,7 +36,7 @@ public class DeleteTreeItem extends TreeItem { if (object == null) { return hilight("delete ") + propertyName.toString(constants); } - return hilight("delete ") + object.toString(constants) + "." + stripQuotes(propertyName); + return hilight("delete ") + object.toString(constants) + "." + stripQuotes(propertyName, constants); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/ExtendsTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/ExtendsTreeItem.java index 8824e157f..d63596676 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/ExtendsTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/ExtendsTreeItem.java @@ -37,7 +37,7 @@ public class ExtendsTreeItem extends TreeItem { public String toString(ConstantPool constants) { List localData = new ArrayList(); localData.add(constants); - return subclass.toString(localData) + hilight(" extends ") + stripQuotes(superclass); + return subclass.toString(localData) + hilight(" extends ") + stripQuotes(superclass, constants); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/GetMemberTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/GetMemberTreeItem.java index 4c3b228a7..ac9f7b273 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/GetMemberTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/GetMemberTreeItem.java @@ -35,9 +35,9 @@ public class GetMemberTreeItem extends TreeItem { public String toString(ConstantPool constants) { if (!((memberName instanceof DirectValueTreeItem) && (((DirectValueTreeItem) memberName).value instanceof String))) { //if(!(functionName instanceof GetVariableTreeItem)) - return object.toString(constants) + "[" + stripQuotes(memberName) + "]"; + return object.toString(constants) + "[" + stripQuotes(memberName, constants) + "]"; } - return object.toString(constants) + "." + stripQuotes(memberName); + return object.toString(constants) + "." + stripQuotes(memberName, constants); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/GetVariableTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/GetVariableTreeItem.java index 7390a24d4..8dd0f52f5 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/GetVariableTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/GetVariableTreeItem.java @@ -40,7 +40,7 @@ public class GetVariableTreeItem extends TreeItem { //return "null"; } //return ""+computedValue.toNumber(); - return stripQuotes(name); + return stripQuotes(name, constants); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/NewObjectTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/NewObjectTreeItem.java index 5984e69a7..249a21650 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/NewObjectTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/NewObjectTreeItem.java @@ -40,7 +40,7 @@ public class NewObjectTreeItem extends TreeItem { } paramStr += arguments.get(t).toString(constants); } - return hilight("new ") + stripQuotes(objectName) + hilight("(") + paramStr + hilight(")"); + return hilight("new ") + stripQuotes(objectName, constants) + hilight("(") + paramStr + hilight(")"); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/SetMemberTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/SetMemberTreeItem.java index bc5ba7d18..5c01e7402 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/SetMemberTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/SetMemberTreeItem.java @@ -35,7 +35,7 @@ public class SetMemberTreeItem extends TreeItem implements SetTypeTreeItem { @Override public String toString(ConstantPool constants) { - return object.toString(constants) + "." + stripQuotes(objectName) + "=" + value.toString(constants); + return object.toString(constants) + "." + stripQuotes(objectName, constants) + "=" + value.toString(constants); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/SetVariableTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/SetVariableTreeItem.java index c977d44e7..4918d0315 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/SetVariableTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/SetVariableTreeItem.java @@ -33,7 +33,7 @@ public class SetVariableTreeItem extends TreeItem implements SetTypeTreeItem { @Override public String toString(ConstantPool constants) { - return stripQuotes(name) + hilight("=") + value.toString(constants); + return stripQuotes(name, constants) + hilight("=") + value.toString(constants); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/TreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/TreeItem.java index e39e67820..6e9a9330f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/TreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/TreeItem.java @@ -46,7 +46,7 @@ public abstract class TreeItem extends GraphTargetItem { return false; } - protected String stripQuotes(GraphTargetItem target) { + protected String stripQuotes(GraphTargetItem target, ConstantPool constants) { if (target instanceof DirectValueTreeItem) { if (((DirectValueTreeItem) target).value instanceof String) { return (String) ((DirectValueTreeItem) target).hilight((String) ((DirectValueTreeItem) target).value); @@ -55,7 +55,7 @@ public abstract class TreeItem extends GraphTargetItem { if (target == null) { return ""; } else { - return target.toString(); + return target.toString(constants); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/clauses/ForInTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/clauses/ForInTreeItem.java index e9b4d71e6..604223885 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/treemodel/clauses/ForInTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/treemodel/clauses/ForInTreeItem.java @@ -51,7 +51,7 @@ public class ForInTreeItem extends LoopTreeItem implements Block { public String toString(ConstantPool constants) { String ret = ""; ret += "loop" + loop.id + ":\r\n"; - ret += hilight("for(") + ((variableName instanceof DirectValueTreeItem) && (((DirectValueTreeItem) variableName).value instanceof RegisterNumber) ? "var " : "") + stripQuotes(variableName) + " in " + enumVariable.toString(constants) + ")\r\n{\r\n"; + ret += hilight("for(") + ((variableName instanceof DirectValueTreeItem) && (((DirectValueTreeItem) variableName).value instanceof RegisterNumber) ? "var " : "") + stripQuotes(variableName, constants) + " in " + enumVariable.toString(constants) + ")\r\n{\r\n"; for (GraphTargetItem ti : commands) { ret += ti.toStringSemicoloned(constants) + "\r\n"; }