diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index 8f4bf0c14..329f5e773 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -19,7 +19,7 @@ package com.jpexs.decompiler.flash; import SevenZip.Compression.LZMA.Encoder; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.ActionGraphSource; -import com.jpexs.decompiler.flash.action.special.ActionContainer; +import com.jpexs.decompiler.flash.graph.GraphSourceItemContainer; import com.jpexs.decompiler.flash.action.swf4.ActionEquals; import com.jpexs.decompiler.flash.action.swf4.ActionGetVariable; import com.jpexs.decompiler.flash.action.swf4.ActionIf; @@ -977,8 +977,8 @@ public class SWF { functions.add(ins); } - if (ins instanceof ActionContainer) { - getVariables(variables, functions, new ActionGraphSource(((ActionContainer) ins).getActions(), code.version, new HashMap(), new HashMap(), new HashMap()), 0); + if (ins instanceof GraphSourceItemContainer) { + //getVariables(variables, functions, new ActionGraphSource(((ActionContainer) ins).getActions(), code.version, new HashMap(), new HashMap(), new HashMap()), 0); } if ((ins instanceof ActionSetVariable) || (ins instanceof ActionSetMember) || (ins instanceof ActionDefineLocal)) { @@ -1042,7 +1042,9 @@ public class SWF { HashMap ret = new HashMap(); List actions = src.getActions(version); actionsMap.put(src, actions); - getVariables(variables, functions, new ActionGraphSource(actions, version, new HashMap(), new HashMap(), new HashMap()), 0); + List ss=new ArrayList(); + ss.addAll(actions); + getVariables(variables, functions, new ActionGraphSource(ss, version, new HashMap(), new HashMap(), new HashMap()), 0); return ret; } private HashMap> actionsMap = new HashMap>(); diff --git a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java index 15cbe0e73..3a62f5791 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java @@ -18,7 +18,7 @@ package com.jpexs.decompiler.flash; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.ActionGraphSource; -import com.jpexs.decompiler.flash.action.special.ActionContainer; +import com.jpexs.decompiler.flash.graph.GraphSourceItemContainer; import com.jpexs.decompiler.flash.action.special.ActionEnd; import com.jpexs.decompiler.flash.action.special.ActionNop; import com.jpexs.decompiler.flash.action.swf3.*; @@ -496,9 +496,9 @@ public class SWFInputStream extends InputStream { return readActionList(address, containerSWFOffset, rri, version, rri.getPos(), rri.getPos() + maxlen); } - private static void getConstantPool(ConstantPool cpool, List localData, Stack stack, List output, ActionGraphSource code, int ip, int lastIp, List constantPools, List visited, int version) { + private static void getConstantPool(ConstantPool cpool, List localData, Stack stack, List output, ActionGraphSource code, int ip, int lastIp, List constantPools, List visited, int version, int endIp) { boolean debugMode = false; - while ((ip > -1) && ip < code.size()) { + while (((endIp==-1)||(endIp>ip))&&(ip > -1) && ip < code.size()) { if (visited.contains(ip)) { break; } @@ -510,6 +510,17 @@ public class SWFInputStream extends InputStream { continue; } + if(ins instanceof GraphSourceItemContainer){ + GraphSourceItemContainer cnt=(GraphSourceItemContainer)ins; + long endAddr=((GraphSourceItemContainer)ins).getEndAddress(); + int nendIp = code.adr2pos(endAddr); + List localData2 = Helper.toList(new HashMap(), new HashMap(), new HashMap()); + List output2=new ArrayList(); + getConstantPool(cpool, localData2, new Stack(), output2, code, ip+1, lastIp, constantPools, visited, version,nendIp); + cnt.translateContainer(output2, stack, output,(HashMap) localData.get(0),(HashMap)localData.get(1),(HashMap)localData.get(2)); + ip = nendIp; + continue; + } if (ins instanceof ActionPush) { if (cpool != null) { ((ActionPush) ins).constantPool = cpool.constants; @@ -518,18 +529,21 @@ public class SWFInputStream extends InputStream { } if (ins instanceof ActionDefineFunction) { if (cpool != null) { - ((ActionDefineFunction) ins).setConstantPool(cpool.constants); + //((ActionDefineFunction) ins).setConstantPool(cpool.constants,code.getActions()); cpool.count++; } } if (ins instanceof ActionDefineFunction2) { if (cpool != null) { - ((ActionDefineFunction2) ins).setConstantPool(cpool.constants); + //((ActionDefineFunction2) ins).setConstantPool(cpool.constants,code.getActions()); cpool.count++; } } if (debugMode) { - System.out.println("getConstantPool ip " + ip + ": " + ins + " stack:" + Highlighting.stripHilights(stack.toString())); + System.err.println("getConstantPool ip " + ip + ": " + ins + " stack:" + Helper.stackToString(stack,Helper.toList(cpool))); + if(ip==68){ + System.err.println("kok"); + } } if (ins instanceof ActionConstantPool) { constantPools.add(new ConstantPool(((ActionConstantPool) ins).constantPool)); @@ -584,13 +598,13 @@ public class SWFInputStream extends InputStream { boolean condition = stack.peek().toBoolean(); if (debugMode) { if (condition) { - System.out.println("JUMP"); + System.err.println("JUMP"); } else { - System.out.println("SKIP"); + System.err.println("SKIP"); } } stack.pop(); - getConstantPool(cpool, localData, stack, output, code, condition ? (code.adr2pos(((ActionIf) ins).getAddress() + ((ActionIf) ins).getBytes(code.version).length + ((ActionIf) ins).getJumpOffset())) : ip + 1, ip, constantPools, visited, version); + getConstantPool(cpool, localData, stack, output, code, condition ? (code.adr2pos(((ActionIf) ins).getAddress() + ((ActionIf) ins).getBytes(code.version).length + ((ActionIf) ins).getJumpOffset())) : ip + 1, ip, constantPools, visited, version,endIp); } else { if (ins instanceof ActionIf) { stack.pop(); @@ -600,7 +614,7 @@ public class SWFInputStream extends InputStream { for (int b : branches) { Stack brStack = (Stack) stack.clone(); if (b >= 0) { - getConstantPool(cpool, localData, brStack, output, code, b, ip, constantPools, visited, version); + getConstantPool(cpool, localData, brStack, output, code, b, ip, constantPools, visited, version,endIp); } else { if (debugMode) { System.out.println("Negative branch:" + b); @@ -621,7 +635,7 @@ public class SWFInputStream extends InputStream { List ret = new ArrayList(); List localData = Helper.toList(new HashMap(), new HashMap(), new HashMap()); try { - getConstantPool(null, localData, new Stack(), new ArrayList(), code, code.adr2pos(addr), 0, ret, new ArrayList(), version); + getConstantPool(null, localData, new Stack(), new ArrayList(), code, code.adr2pos(addr), 0, ret, new ArrayList(), version,-1); } catch (Exception ex) { log.log(Level.SEVERE, "Error during getting constantpool", ex); } @@ -653,7 +667,7 @@ public class SWFInputStream extends InputStream { method = 2; goesPrev = readActionListAtPos(true, localData, stack, cpool, sis, rri, ip, retdups, ip); }*/ - goesPrev = readActionListAtPos(address, containerSWFOffset, false, true, localData, stack, cpool, sis, rri, ip, retdups, ip, endip); + goesPrev = readActionListAtPos(new ArrayList(),new HashMap>(),address, containerSWFOffset, false, true, localData, stack, cpool, sis, rri, ip, retdups, ip, endip); if (goesPrev) { } else { @@ -663,7 +677,7 @@ public class SWFInputStream extends InputStream { } } } - List ret = new ArrayList(); + List ret = new ArrayList(); Action last = null; for (Action a : retdups) { if (a != last) { @@ -692,8 +706,12 @@ public class SWFInputStream extends InputStream { if (goesPrev && (!DEOBFUSCATION_ALL_CODE_IN_PREVIOUS_TAG)) { ActionJump aj = new ActionJump(ip); int skip = aj.getBytes(version).length; - for (Action a : ret) { + for (GraphSourceItem s : ret) { + + if(s instanceof Action){ + Action a=(Action)s; a.setAddress(a.getAddress() + skip, version); + } } ret.add(0, aj); } @@ -708,41 +726,46 @@ public class SWFInputStream extends InputStream { } catch (ParseException ex) { Logger.getLogger(SWFInputStream.class.getName()).log(Level.SEVERE, "parsing error", ex); }*/ - return ret; + List reta=new ArrayList(); + for(Object o:ret){ + if(o instanceof Action){ + reta.add((Action)o); + } + } + return reta; } - private static boolean readActionListAtPos(long address, long containerSWFOffset, boolean notCompileTime, boolean enableVariables, List localData, Stack stack, ConstantPool cpool, SWFInputStream sis, ReReadableInputStream rri, int ip, List ret, int startIp, int endip) throws IOException { + private static boolean readActionListAtPos(List output,HashMap> containers,long address, long containerSWFOffset, boolean notCompileTime, boolean enableVariables, List localData, Stack stack, ConstantPool cpool, SWFInputStream sis, ReReadableInputStream rri, int ip, List ret, int startIp, int endip) throws IOException { boolean debugMode = false; boolean decideBranch = false; boolean retv = false; rri.setPos(ip); Action a; - List output = new ArrayList(); long filePos = rri.getPos(); Scanner sc = new Scanner(System.in); int prevIp = ip; while (((endip == -1) || (endip > ip)) && (a = sis.readAction(rri)) != null) { - if ((ip < ret.size()) && (!(ret.get(ip) instanceof ActionNop))) { + if ((ip < ret.size()) && (!(ret.get(ip) instanceof ActionNop))) { a = ret.get(ip); + if(a.getAddress()!=ip){ + new Exception("Jump to the middle of the instruction").printStackTrace(); + } } a.containerSWFOffset = containerSWFOffset; a.setAddress(prevIp, SWF.DEFAULT_VERSION, false); int info = a.actionLength + 1 + ((a.actionCode > 0x80) ? 2 : 0); byte b[] = a.getBytes(sis.version); - int infoCorrect = info; - if (a instanceof ActionContainer) { - infoCorrect += ((ActionContainer) a).getDataLength(); - } + int infoCorrect = info; if (b.length != infoCorrect) { //throw new RuntimeException("Wrong length "+a.toString()+" info:"+infoCorrect+" actual:"+b.length+" datalen:"+(infoCorrect-info)); } int actual = 0; - if (a instanceof ActionContainer) { - actual = ((ActionContainer) a).getHeaderBytes().length; + if (a instanceof GraphSourceItemContainer) { + actual = ((GraphSourceItemContainer) a).getHeaderBytes().length; } else { actual = a.getBytes(sis.version).length; } - if (!(a instanceof ActionContainer)) { + if (!(a instanceof GraphSourceItemContainer)) { int change = info - (rri.getPos() - ip); if (change > 0) { a.afterInsert = new ActionJump(change); @@ -766,25 +789,35 @@ public class SWFInputStream extends InputStream { } if (a instanceof ActionDefineFunction) { if (cpool != null) { - ((ActionDefineFunction) a).setConstantPool(cpool.constants); + //((ActionDefineFunction) a).setConstantPool(cpool.constants); cpool.count++; } } if (a instanceof ActionDefineFunction2) { if (cpool != null) { - ((ActionDefineFunction2) a).setConstantPool(cpool.constants); + //((ActionDefineFunction2) a).setConstantPool(cpool.constants); cpool.count++; } } if (debugMode) { //if(a instanceof ActionIf){ - String atos = a.getASMSource(new ArrayList(), cpool.constants, sis.version, false); - if (a instanceof ActionContainer) { + String atos = a.getASMSource(new ArrayList(),new ArrayList(), cpool.constants, sis.version, false); + if (a instanceof GraphSourceItemContainer) { 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))); + HashMap vars=(HashMap)localData.get(1); + System.err.print("variables: "); + for(String v:vars.keySet()){ + System.err.print("'"+v+"' = "+Highlighting.stripHilights(vars.get(v).toString(cpool))+", "); + } + System.err.println(); //} + if(ip - startIp==911){ + System.err.println("dd"); + //readActionListAtPos ip: 116 (0x0074) action(len 2): If loc0125 ;compileTime stack:[!(==734)] [9d 02 00 21 00] + } String add = ""; if (a instanceof ActionIf) { add = " change: " + ((ActionIf) a).getJumpOffset(); @@ -840,7 +873,7 @@ public class SWFInputStream extends InputStream { ((ActionIf) a).compileTime = true; } if (debugMode) { - System.out.print("is compiletime -> "); + System.err.print("is compiletime -> "); } if (top.toBoolean()) { newip = rri.getPos() + aif.getJumpOffset(); @@ -854,7 +887,7 @@ public class SWFInputStream extends InputStream { aif.compileTime = false; } if (debugMode) { - System.out.println("jump"); + System.err.println("jump"); } } else { aif.ignoreUsed = true; @@ -862,7 +895,7 @@ public class SWFInputStream extends InputStream { aif.compileTime = false; } if (debugMode) { - System.out.println("ignore"); + System.err.println("ignore"); } if (((!enableVariables) || (!top.isVariableComputed())) && (!aif.jumpUsed)) { //a = new ActionNop(); @@ -892,7 +925,7 @@ public class SWFInputStream extends InputStream { } else { if (debugMode) { - System.out.println("goaif"); + System.err.println("goaif"); } //throw new RuntimeException("goaif"); goaif = true; @@ -902,14 +935,14 @@ public class SWFInputStream extends InputStream { //if(newip>=0){ //rri.setPos(newip); //} - } else { + } else if(!(a instanceof GraphSourceItemContainer)){ //return in for..in, TODO:Handle this better way if (((a instanceof ActionEquals) || (a instanceof ActionEquals2)) && (stack.size() == 1) && (stack.peek() instanceof DirectValueTreeItem)) { stack.push(new DirectValueTreeItem(null, 0, new Null(), new ArrayList())); } if ((a instanceof ActionStoreRegister) && stack.isEmpty()) { stack.push(new DirectValueTreeItem(null, 0, new Null(), new ArrayList())); - } + } a.translate(localData, stack, output); } } catch (RuntimeException ex) { @@ -940,6 +973,26 @@ public class SWFInputStream extends InputStream { } ret.set(ip + i, a); } + + if (a instanceof GraphSourceItemContainer) { + GraphSourceItemContainer cnt=(GraphSourceItemContainer)a; + long endAddr=((GraphSourceItemContainer)a).getEndAddress(); + /*if(!containers.containsKey(endAddr)){ + containers.put(endAddr, new ArrayList()); + } + containers.get(endAddr).add((ActionContainer)a); + */ + List localData2 = Helper.toList(new HashMap(), new HashMap(), new HashMap()); + List output2=new ArrayList(); + readActionListAtPos(output2,containers, address, containerSWFOffset, notCompileTime, enableVariables, localData2, new Stack(), cpool, sis, rri, ip+info, ret, startIp, (int)endAddr); + cnt.translateContainer(output2, stack, output,(HashMap) localData.get(0),(HashMap)localData.get(1),(HashMap)localData.get(2)); + + ip = (int)endAddr; + prevIp = ip; + filePos = rri.getPos(); + continue; + //infoCorrect += ((ActionContainer) a).getDataLength(); + } if (a instanceof ActionEnd) { break; @@ -959,7 +1012,7 @@ public class SWFInputStream extends InputStream { aif.jumpUsed = true; int oldPos = rri.getPos(); Stack substack = (Stack) stack.clone(); - if (readActionListAtPos(address, containerSWFOffset, true, enableVariables, localData, substack, cpool, sis, rri, rri.getPos() + aif.getJumpOffset(), ret, startIp, endip)) { + if (readActionListAtPos(output,containers,address, containerSWFOffset, true, enableVariables, localData, substack, cpool, sis, rri, rri.getPos() + aif.getJumpOffset(), ret, startIp, endip)) { retv = true; } rri.setPos(oldPos); diff --git a/trunk/src/com/jpexs/decompiler/flash/action/Action.java b/trunk/src/com/jpexs/decompiler/flash/action/Action.java index d1f90ccf5..f0c4dca6c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/Action.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/Action.java @@ -23,7 +23,7 @@ import com.jpexs.decompiler.flash.action.parser.ASMParser; import com.jpexs.decompiler.flash.action.parser.FlasmLexer; import com.jpexs.decompiler.flash.action.parser.ParseException; import com.jpexs.decompiler.flash.action.parser.ParsedSymbol; -import com.jpexs.decompiler.flash.action.special.ActionContainer; +import com.jpexs.decompiler.flash.graph.GraphSourceItemContainer; import com.jpexs.decompiler.flash.action.swf4.*; import com.jpexs.decompiler.flash.action.swf5.*; import com.jpexs.decompiler.flash.action.swf6.ActionEnumerate2; @@ -377,35 +377,62 @@ public class Action implements GraphSourceItem { * @param hex Add hexadecimal? * @return ASM source as String */ - public static String actionsToString(long address, List list, List importantOffsets, List constantPool, int version, boolean hex, long swfPos) { + public static String actionsToString(long address, List list, List importantOffsets, List constantPool, int version, boolean hex, long swfPos) { String ret = ""; long offset; if (importantOffsets == null) { //setActionsAddresses(list, 0, version); importantOffsets = getActionsAllRefs(list, version); } - List cps = SWFInputStream.getConstantPool(new ActionGraphSource(list, version, new HashMap(), new HashMap(), new HashMap()), 0, version); + List srcList=new ArrayList(); + for(Object o:list){ + if(o instanceof Action){ + srcList.add((Action)o); + } + } + List cps = SWFInputStream.getConstantPool(new ActionGraphSource(srcList, version, new HashMap(), new HashMap(), new HashMap()), 0, version); if (!cps.isEmpty()) { setConstantPool(list, cps.get(cps.size() - 1)); } + HashMap> containers=new HashMap>(); offset = address; int pos = -1; - for (Action a : list) { + for (GraphSourceItem s : srcList) { + Action a=null; + if(s instanceof Action){ + a=(Action)s; + } pos++; if (hex) { - ret += "" +/*"0x"+Helper.formatAddress(a.getFileAddress())+": "+*/ Helper.bytesToHexString((a instanceof ActionContainer) ? ((ActionContainer) a).getHeaderBytes() : a.getBytes(version)) + "\r\n"; + ret += "" +/*"0x"+Helper.formatAddress(a.getFileAddress())+": "+*/ Helper.bytesToHexString((a instanceof GraphSourceItemContainer) ? ((GraphSourceItemContainer) a).getHeaderBytes() : a.getBytes(version)) + "\r\n"; } offset = a.getAddress(); + + if((!(a.ignored)) && (a instanceof GraphSourceItemContainer)){ + if(!containers.containsKey(((GraphSourceItemContainer)a).getEndAddress())){ + containers.put(((GraphSourceItemContainer)a).getEndAddress(), new ArrayList()); + } + containers.get(((GraphSourceItemContainer)a).getEndAddress()).add((GraphSourceItemContainer)a); + } + + if(containers.containsKey(offset)){ + for(int i=0;i knownAddreses, List constantPool, int version, boolean hex) { + public String getASMSource(List container, List knownAddreses, List constantPool, int version, boolean hex) { return toString(); } @@ -488,6 +517,12 @@ public class Action implements GraphSourceItem { * @return address */ public static long ip2adr(List actions, int ip, int version) { + /* List actions=new ArrayList(); + for(GraphSourceItem s:sources){ + if(s instanceof Action){ + actions.add((Action)s); + } + }*/ if (ip >= actions.size()) { if (actions.isEmpty()) { return 0; @@ -619,7 +654,13 @@ public class Action implements GraphSourceItem { logger.fine(s); } - public static List actionsPartToTree(HashMap registerNames, HashMap variables, HashMap functions, Stack stack, List actions, int start, int end, int version) { + public static List actionsPartToTree(HashMap registerNames, HashMap variables, HashMap functions, Stack stack, List src, int start, int end, int version) { + List actions=new ArrayList(); + for(GraphSourceItem s:src){ + if(s instanceof Action){ + actions.add((Action)s); + } + } if (start < actions.size() && (end > 0) && (start > 0)) { log("Entering " + start + "-" + end + (actions.size() > 0 ? (" (" + actions.get(start).toString() + " - " + actions.get(end == actions.size() ? end - 1 : end) + ")") : "")); } @@ -679,6 +720,17 @@ public class Action implements GraphSourceItem { ip++; continue; } + + if(action instanceof GraphSourceItemContainer){ + long endAddr=((GraphSourceItemContainer)action).getEndAddress(); + int endip=adr2ip(actions, endAddr, version); + //List out=actionsPartToTree(new HashMap(), new HashMap(),new HashMap(), new Stack(), src, ip+1,endip-1 , version); + List out=ActionGraph.translateViaGraph(registerNames, variables, functions, src.subList(ip+1, endip), version); + ((GraphSourceItemContainer)action).translateContainer(out, stack, output, registerNames, variables, functions); + ip=endip; + continue; + } + //System.out.println(" ip "+ip+" "+action); //return in for..in if ((action instanceof ActionPush) && (((ActionPush) action).values.size() == 1) && (((ActionPush) action).values.get(0) instanceof Null)) { @@ -721,11 +773,11 @@ public class Action implements GraphSourceItem { catchCommands.add(ActionGraph.translateViaGraph(registerNames, variables, functions, atry.catchBody, version)); List finallyCommands = ActionGraph.translateViaGraph(registerNames, variables, functions, atry.finallyBody, version); output.add(new TryTreeItem(tryCommands, catchExceptions, catchCommands, finallyCommands)); - } else if (action instanceof ActionWith) { + } else /*if (action instanceof ActionWith) { ActionWith awith = (ActionWith) action; - List withCommands = ActionGraph.translateViaGraph(registerNames, variables, functions, awith.actions, version); + List withCommands = ActionGraph.translateViaGraph(registerNames, variables, functions,new ArrayList() , version); //TODO:parse with actions output.add(new WithTreeItem(action, stack.pop(), withCommands)); - } else if (action instanceof ActionStoreRegister) { + } else */if (action instanceof ActionStoreRegister) { if ((ip + 1 <= end) && (actions.get(ip + 1) instanceof ActionPop)) { action.translate(localData, stack, output); stack.pop(); @@ -1062,6 +1114,9 @@ public class Action implements GraphSourceItem { public static List removeNops(long address, List actions, int version, long swfPos) { List ret = actions; + if(true){ + //return ret; + } String s = null; try { s = Highlighting.stripHilights(Action.actionsToString(address, ret, null, version, false, swfPos)); @@ -1072,8 +1127,8 @@ public class Action implements GraphSourceItem { return ret; } - public static void setConstantPool(List actions, ConstantPool cpool) { - for (Action a : actions) { + public static void setConstantPool(List actions, ConstantPool cpool) { + for (GraphSourceItem a : actions) { if (a instanceof ActionPush) { if (cpool != null) { ((ActionPush) a).constantPool = cpool.constants; @@ -1081,18 +1136,18 @@ public class Action implements GraphSourceItem { } if (a instanceof ActionDefineFunction) { if (cpool != null) { - ((ActionDefineFunction) a).setConstantPool(cpool.constants); + //((ActionDefineFunction) a).setConstantPool(cpool.constants,actions); } } if (a instanceof ActionDefineFunction2) { if (cpool != null) { - ((ActionDefineFunction2) a).setConstantPool(cpool.constants); + //((ActionDefineFunction2) a).setConstantPool(cpool.constants,actions); } } } } - public String getASMSourceReplaced(List knownAddreses, List constantPool, int version, boolean hex) { - return getASMSource(knownAddreses, constantPool, version, hex); + public String getASMSourceReplaced(List container, List knownAddreses, List constantPool, int version, boolean hex) { + return getASMSource(container,knownAddreses, constantPool, version, hex); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/ActionGraph.java b/trunk/src/com/jpexs/decompiler/flash/action/ActionGraph.java index b368feb52..0237c86bf 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/ActionGraph.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/ActionGraph.java @@ -53,7 +53,7 @@ import java.util.Stack; */ public class ActionGraph extends Graph { - public ActionGraph(List code, HashMap registerNames, HashMap variables, HashMap functions, int version) { + public ActionGraph(List code, HashMap registerNames, HashMap variables, HashMap functions, int version) { super(new ActionGraphSource(code, version, registerNames, variables, functions), new ArrayList()); //this.version = version; /*heads = makeGraph(code, new ArrayList()); @@ -63,7 +63,8 @@ public class ActionGraph extends Graph { }*/ } - public static List translateViaGraph(HashMap registerNames, HashMap variables, HashMap functions, List code, int version) { + public static List translateViaGraph(HashMap registerNames, HashMap variables, HashMap functions, List code, int version) { + ActionGraph g = new ActionGraph(code, registerNames, variables, functions, version); List localData = new ArrayList(); localData.add(registerNames); diff --git a/trunk/src/com/jpexs/decompiler/flash/action/ActionGraphSource.java b/trunk/src/com/jpexs/decompiler/flash/action/ActionGraphSource.java index f272020f3..117ab9b81 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/ActionGraphSource.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/ActionGraphSource.java @@ -1,8 +1,11 @@ package com.jpexs.decompiler.flash.action; +import com.jpexs.decompiler.flash.graph.GraphSourceItemContainer; import com.jpexs.decompiler.flash.graph.GraphSource; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphTargetItem; +import com.jpexs.decompiler.flash.helpers.Helper; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Stack; @@ -13,13 +16,19 @@ import java.util.Stack; */ public class ActionGraphSource extends GraphSource { - private List actions; + private List actions; public int version; private HashMap registerNames; private HashMap variables; private HashMap functions; - public ActionGraphSource(List actions, int version, HashMap registerNames, HashMap variables, HashMap functions) { + public List getActions() { + return actions; + } + + + + public ActionGraphSource(List actions, int version, HashMap registerNames, HashMap variables, HashMap functions) { this.actions = actions; this.version = version; this.registerNames = registerNames; @@ -50,13 +59,71 @@ public class ActionGraphSource extends GraphSource { public List translatePart(List localData, Stack stack, int start, int end) { return (Action.actionsPartToTree(registerNames, variables, functions, stack, actions, start, end, version)); } + + private List posCache=null; + private void rebuildCache(){ + posCache = new ArrayList(); + for(int i=0;iaddr){ + System.err.println("lastAddr="+lastAddr+" addr="+addr+" curAddr="+curAdr); + int contPos=adr2pos(lastAddr); + System.err.println("/insadr2po"); + GraphSourceItem src=get(contPos); + if(src instanceof ActionContainer){ + ActionContainer cnt=(ActionContainer)src; + return new ActionGraphSource(cnt.getActions(), version, registerNames, variables, functions).adr2pos(addr); + }else{ + return -1; + } + } + lastAddr=curAdr; + } + return -1; + }*/ @Override public int adr2pos(long adr) { - int pos = 0; + if(posCache==null){ + rebuildCache(); + } + if(adr==0){ + return 0; + } + int ret=posCache.indexOf((Long)adr); + if(ret==-1){ + if(!posCache.isEmpty() && (adr>posCache.get(posCache.size()-1))){ + return size(); + } + //ret = adr2posInside(adr); + if(ret==-1){ + System.err.println("Addr loc"+Helper.formatAddress(adr)+" not found"); + int pos=0; + for(long l:posCache){ + System.err.println("ip "+pos+" action "+get(pos).toString()+" loc"+Helper.formatAddress(l)); + pos++; + } + } + } + return ret; + /*int pos = 0; long lastAddr = 0; for (Action a : actions) { lastAddr = a.getAddress(); + System.err.println("ip "+pos+" addr "+Helper.formatAddress(lastAddr)); if (lastAddr == adr) { return pos; } @@ -70,11 +137,15 @@ public class ActionGraphSource extends GraphSource { return 0; } //throw new RuntimeException("Address "+Helper.formatAddress(adr)+" not found"); - return -1; + return -1;*/ } @Override public long pos2adr(int pos) { - return actions.get(pos).getAddress();//Action.ip2adr(actions, pos, version); + GraphSourceItem si=actions.get(pos); + if(si instanceof Action){ + return ((Action)si) .getAddress();//Action.ip2adr(actions, pos, version); + } + return 0; } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/parser/ASMParser.java b/trunk/src/com/jpexs/decompiler/flash/action/parser/ASMParser.java index cd98d7203..6f191e583 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/parser/ASMParser.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/parser/ASMParser.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.action.parser; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.flashlite.ActionFSCommand2; import com.jpexs.decompiler.flash.action.flashlite.ActionStrictMode; +import com.jpexs.decompiler.flash.graph.GraphSourceItemContainer; import com.jpexs.decompiler.flash.action.special.ActionNop; import com.jpexs.decompiler.flash.action.swf3.*; import com.jpexs.decompiler.flash.action.swf4.*; @@ -30,6 +31,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import java.util.Stack; import java.util.logging.Level; import java.util.logging.Logger; @@ -37,6 +39,7 @@ public class ASMParser { public static List parse(long containerSWFOffset, boolean ignoreNops, List