diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index 7c3bb4db4..fd2de4b38 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -432,15 +432,15 @@ public class SWF { List list = createASTagList(list2, null); TagNode.setExport(list, true); - if(!outdir.endsWith(File.separator)){ - outdir+=File.separator; + if (!outdir.endsWith(File.separator)) { + outdir += File.separator; } outdir += "scripts" + File.separator; - return TagNode.exportNodeAS(list, outdir, isPcode,evl); + return TagNode.exportNodeAS(list, outdir, isPcode, evl); } return asV3Found; } - + public static List createASTagList(List list, Object parent) { List ret = new ArrayList(); int frame = 1; @@ -509,7 +509,6 @@ public class SWF { } return ret; } - protected HashSet listeners = new HashSet(); public void addEventListener(EventListener listener) { @@ -1000,42 +999,29 @@ public class SWF { try { ins.translate(localData, stack, output); } catch (Exception ex) { - Logger.getLogger(SWF.class.getName()).log(Level.SEVERE, "Error during getting variables", ex); + Logger.getLogger(SWF.class.getName()).log(Level.SEVERE, "Error during getting variables", ex); } if (ins.isExit()) { break; } if (ins.isBranch() || ins.isJump()) { - - if (false) { //ins instanceof ActionIf && !stack.isEmpty() && (stack.peek().isCompileTime())) { - boolean condition = stack.peek().toBoolean(); - if (debugMode) { - if (condition) { - System.out.println("JUMP"); - } else { - System.out.println("SKIP"); - } - } + if (ins instanceof ActionIf) { stack.pop(); - getVariables(constantPool, localData, stack, output, code, condition ? (code.adr2pos(((ActionIf) ins).getAddress() + ((ActionIf) ins).getBytes(code.version).length + ((ActionIf) ins).offset)) : ip + 1, ip, variables, functions, visited); - } else { - if (ins instanceof ActionIf) { - stack.pop(); - } - visited.add(ip); - List branches = ins.getBranches(code); - for (int b : branches) { - Stack brStack = (Stack) stack.clone(); - if (b >= 0) { - getVariables(constantPool, localData, brStack, output, code, b, ip, variables, functions, visited); - } else { - if (debugMode) { - System.out.println("Negative branch:" + b); - } + } + visited.add(ip); + List branches = ins.getBranches(code); + for (int b : branches) { + Stack brStack = (Stack) stack.clone(); + if (b >= 0) { + getVariables(constantPool, localData, brStack, output, code, b, ip, variables, functions, visited); + } else { + if (debugMode) { + System.out.println("Negative branch:" + b); } } } + break; } ip++; diff --git a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java index 3d0992d03..5c679f00d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java @@ -30,6 +30,7 @@ import com.jpexs.decompiler.flash.action.swf6.*; import com.jpexs.decompiler.flash.action.swf7.*; import com.jpexs.decompiler.flash.action.treemodel.ConstantPool; import com.jpexs.decompiler.flash.action.treemodel.DirectValueTreeItem; +import com.jpexs.decompiler.flash.action.treemodel.SetVariableTreeItem; import com.jpexs.decompiler.flash.graph.GraphSourceItem; import com.jpexs.decompiler.flash.graph.GraphSourceItemPos; import com.jpexs.decompiler.flash.graph.GraphTargetItem; @@ -652,7 +653,7 @@ public class SWFInputStream extends InputStream { method = 2; goesPrev = readActionListAtPos(true, localData, stack, cpool, sis, rri, ip, retdups, ip); }*/ - goesPrev = readActionListAtPos(false,true, localData, stack, cpool, sis, rri, ip, retdups, ip); + goesPrev = readActionListAtPos(false, true, localData, stack, cpool, sis, rri, ip, retdups, ip); if (goesPrev) { } else { @@ -708,7 +709,7 @@ public class SWFInputStream extends InputStream { return ret; } - private static boolean readActionListAtPos(boolean notCompileTime,boolean enableVariables, List localData, Stack stack, ConstantPool cpool, SWFInputStream sis, ReReadableInputStream rri, int ip, List ret, int startIp) throws IOException { + private static boolean readActionListAtPos(boolean notCompileTime, boolean enableVariables, List localData, Stack stack, ConstantPool cpool, SWFInputStream sis, ReReadableInputStream rri, int ip, List ret, int startIp) throws IOException { boolean debugMode = false; boolean decideBranch = false; boolean retv = false; @@ -743,7 +744,7 @@ public class SWFInputStream extends InputStream { } if (debugMode) { //if(a instanceof ActionIf){ - System.out.println("readActionListAtPos ip: " + (ip - startIp) + " action(len " + a.actionLength + "): " + a + " stack:" + Highlighting.stripHilights(stack.toString()) + " " + Helper.byteArrToString(a.getBytes(SWF.DEFAULT_VERSION))); + System.out.println("readActionListAtPos ip: " + (ip - startIp) + " action(len " + a.actionLength + "): " + a + (a.isIgnored()?" (ignored)":"") + " stack:" + Highlighting.stripHilights(stack.toString()) + " " + Helper.byteArrToString(a.getBytes(SWF.DEFAULT_VERSION))); //} } /*if(a instanceof ActionConstantPool){ @@ -785,110 +786,113 @@ public class SWFInputStream extends InputStream { Action beforeInsert = null; ActionIf aif = null; boolean goaif = false; - try { - if (a instanceof ActionIf) { - aif = (ActionIf) a; - GraphTargetItem top = null; - top = stack.pop(); + if (!a.isIgnored()) { + try { + if (a instanceof ActionIf) { + aif = (ActionIf) a; + GraphTargetItem top = null; + top = stack.pop(); - int nip = rri.getPos() + aif.offset; + int nip = rri.getPos() + aif.offset; - if (decideBranch) { - System.out.print("newip " + nip + ", "); - System.out.print("Action: jump(j),ignore(i),compute(c)?"); - String next = sc.next(); - if (next.equals("j")) { - newip = rri.getPos() + aif.offset; - rri.setPos(newip); + if (decideBranch) { + System.out.print("newip " + nip + ", "); + System.out.print("Action: jump(j),ignore(i),compute(c)?"); + String next = sc.next(); + if (next.equals("j")) { + newip = rri.getPos() + aif.offset; + rri.setPos(newip); - } else if (next.equals("i")) { - } else if (next.equals("c")) { + } else if (next.equals("i")) { + } else if (next.equals("c")) { + goaif = true; + } + } else if (top.isCompileTime() && ((!top.isVariableComputed()) || (top.isVariableComputed() && enableVariables && (!notCompileTime)))) { + //if(top.isCompileTime()) { + //if(false){ + if (enableVariables) { + ((ActionIf) a).compileTime = true; + } + if (debugMode) { + System.out.print("is compiletime -> "); + } + if (top.toBoolean()) { + newip = rri.getPos() + aif.offset; + //rri.setPos(newip); + if (((!enableVariables) || (!top.isVariableComputed())) && (!aif.ignoreUsed)) { + a = new ActionJump(aif.offset); + a.setAddress(aif.getAddress(), SWF.DEFAULT_VERSION); + } + aif.jumpUsed = true; + if (aif.ignoreUsed) { + aif.compileTime = false; + } + if (debugMode) { + System.out.println("jump"); + } + } else { + aif.ignoreUsed = true; + if (aif.jumpUsed) { + aif.compileTime = false; + } + if (debugMode) { + System.out.println("ignore"); + } + if (((!enableVariables) || (!top.isVariableComputed())) && (!aif.jumpUsed)) { + //a = new ActionNop(); + aif.setIgnored(true); + //a.setAddress(aif.getAddress(), SWF.DEFAULT_VERSION); + } + } + if (((!enableVariables) || (!top.isVariableComputed())) && (!(aif.jumpUsed && aif.ignoreUsed))) { + List needed = top.getNeededSources(); + for (GraphSourceItemPos ig : needed) { + if (ig.item == null) { + continue; + } + if (ig.item instanceof ActionPush) { + if (!((ActionPush) ig.item).ignoredParts.contains(ig.pos)) { + ((ActionPush) ig.item).ignoredParts.add(ig.pos); + + if (((ActionPush) ig.item).ignoredParts.size() == ((ActionPush) ig.item).values.size()) { + ((Action) ig.item).ignored = true; + } + } + } else { + ((Action) ig.item).ignored = true; + } + } + } + + } else { + if (debugMode) { + System.out.println("goaif"); + } + //throw new RuntimeException("goaif"); goaif = true; } - } else if (top.isCompileTime() && ((!top.isVariableComputed()) || (top.isVariableComputed() && enableVariables && (!notCompileTime)))) { - //if(top.isCompileTime()) { - //if(false){ - if (enableVariables) { - ((ActionIf) a).compileTime = true; - } - if (debugMode) { - System.out.print("is compiletime -> "); - } - if (top.toBoolean()) { - newip = rri.getPos() + aif.offset; - //rri.setPos(newip); - if (((!enableVariables) || (!top.isVariableComputed())) && (!aif.ignoreUsed)) { - a = new ActionJump(aif.offset); - a.setAddress(aif.getAddress(), SWF.DEFAULT_VERSION); - } - aif.jumpUsed = true; - if (aif.ignoreUsed) { - aif.compileTime = false; - } - if (debugMode) { - System.out.println("jump"); - } - } else { - aif.ignoreUsed = true; - if (aif.jumpUsed) { - aif.compileTime = false; - } - if (debugMode) { - System.out.println("ignore"); - } - if (((!enableVariables) || (!top.isVariableComputed())) && (!aif.jumpUsed)) { - a = new ActionNop(); - a.setAddress(aif.getAddress(), SWF.DEFAULT_VERSION); - } - } - if (((!enableVariables) || (!top.isVariableComputed())) && (!(aif.jumpUsed && aif.ignoreUsed))) { - List needed = top.getNeededSources(); - for (GraphSourceItemPos ig : needed) { - if (ig.item == null) { - continue; - } - if (ig.item instanceof ActionPush) { - if (!((ActionPush) ig.item).ignoredParts.contains(ig.pos)) { - ((ActionPush) ig.item).ignoredParts.add(ig.pos); - - if (((ActionPush) ig.item).ignoredParts.size() == ((ActionPush) ig.item).values.size()) { - ((Action) ig.item).ignored = true; - } - } - } else { - ((Action) ig.item).ignored = true; - } - } - } - + } else if (a instanceof ActionJump) { + newip = rri.getPos() + ((ActionJump) a).offset; + //if(newip>=0){ + //rri.setPos(newip); + //} } else { - if (debugMode) { - System.out.println("goaif"); + //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())); } - //throw new RuntimeException("goaif"); - goaif = true; + if ((a instanceof ActionStoreRegister) && stack.isEmpty()) { + stack.push(new DirectValueTreeItem(null, 0, new Null(), new ArrayList())); + } + a.translate(localData, stack, output); } - } else if (a instanceof ActionJump) { - newip = rri.getPos() + ((ActionJump) a).offset; - //if(newip>=0){ - //rri.setPos(newip); - //} - } else { - //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())); + } catch (RuntimeException ex) { + if (!enableVariables) { + throw ex; } - if ((a instanceof ActionStoreRegister) && stack.isEmpty()) { - stack.push(new DirectValueTreeItem(null, 0, new Null(), new ArrayList())); - } - a.translate(localData, stack, output); + log.log(Level.SEVERE, "Disassembly exception", ex); + break; } - } catch (RuntimeException ex) { - if (!enableVariables) { - throw ex; - } - log.log(Level.SEVERE, "Disassembly exception", ex); - break; } int nopos = -1; for (int i = 0; i < actionLen; i++) { @@ -922,14 +926,14 @@ public class SWFInputStream extends InputStream { rri.setPos(ip); filePos = rri.getPos(); if (goaif) { - if(aif.ignoreUsed && aif.jumpUsed){ + if (aif.ignoreUsed && aif.jumpUsed) { break; } aif.ignoreUsed = true; aif.jumpUsed = true; int oldPos = rri.getPos(); Stack substack = (Stack) stack.clone(); - if (readActionListAtPos(true,enableVariables, localData, substack, cpool, sis, rri, rri.getPos() + aif.offset, ret, startIp)) { + if (readActionListAtPos(true, enableVariables, localData, substack, cpool, sis, rri, rri.getPos() + aif.offset, ret, startIp)) { retv = true; } rri.setPos(oldPos); diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java index 932947670..aaa251170 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java @@ -225,6 +225,9 @@ public class ActionPush extends Action { public void translate(Stack stack, List output, java.util.HashMap regNames, HashMap variables, HashMap functions) { int pos = 0; for (Object o : values) { + if (ignoredParts.contains(pos)) { + continue; + } if (o instanceof ConstantIndex) { if ((constantPool == null) || (((ConstantIndex) o).index >= constantPool.size())) { o = "CONSTANT" + ((ConstantIndex) o).index;