diff --git a/trunk/src/com/jpexs/decompiler/flash/ReReadableInputStream.java b/trunk/src/com/jpexs/decompiler/flash/ReReadableInputStream.java index 610ad72e1..ba3596b5a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/ReReadableInputStream.java +++ b/trunk/src/com/jpexs/decompiler/flash/ReReadableInputStream.java @@ -32,6 +32,10 @@ public class ReReadableInputStream extends InputStream { int pos = 0; int count = 0; + public int getCount() { + return count; + } + public byte[] getAllRead() { return baos.toByteArray(); } @@ -46,6 +50,7 @@ public class ReReadableInputStream extends InputStream { public void setPos(int pos) throws IOException { if (pos > count) { + this.pos = count; skip(pos - count); } this.pos = pos; diff --git a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java index 35f2ea825..2040c4eaf 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java @@ -16,7 +16,7 @@ */ package com.jpexs.decompiler.flash; -import com.jpexs.decompiler.flash.action.UnknownActionException; +import com.jpexs.decompiler.flash.abc.CopyOutputStream; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.parser.ASMParser; import com.jpexs.decompiler.flash.action.parser.ParseException; @@ -506,7 +506,6 @@ public class SWFInputStream extends InputStream { List localData = Helper.toList(new HashMap(), new HashMap(), new HashMap()); - //ReReadableInputStream rri = new ReReadableInputStream(this); SWFInputStream sis = new SWFInputStream(rri, version); boolean goesPrev = false; try { @@ -517,6 +516,10 @@ public class SWFInputStream extends InputStream { if (goesPrev) { retdups.add(0, new ActionJump(ip)); + } else { + for (int i = 0; i < ip; i++) { + retdups.remove(0); + } } List ret = new ArrayList(); Action last = null; @@ -527,9 +530,13 @@ public class SWFInputStream extends InputStream { last = a; } String s = null; + ByteArrayInputStream bais = new ByteArrayInputStream(Action.actionsToBytes(ret, false, version)); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + CopyOutputStream cos = new CopyOutputStream(baos, bais); + try { s = Highlighting.stripHilights(Action.actionsToString(ret, null, version)); - ret = ASMParser.parse(new ByteArrayInputStream(s.getBytes()), SWF.DEFAULT_VERSION); + ret = ASMParser.parse(false, new ByteArrayInputStream(s.getBytes()), SWF.DEFAULT_VERSION); } catch (ParseException ex) { Logger.getLogger(SWFInputStream.class.getName()).log(Level.SEVERE, "parsing error", ex); } @@ -546,19 +553,24 @@ public class SWFInputStream extends InputStream { List output = new ArrayList(); long filePos = rri.getPos(); Scanner sc = new Scanner(System.in); + int prevIp = ip; while ((a = sis.readAction()) != null) { - /*int info=a.actionLength+1+((a.actionCode>0x80)?2:0); - int actual=a.getBytes(sis.version).length; - if(info!=actual){ - if(!(a instanceof ActionDefineFunction)) if(!(a instanceof ActionDefineFunction2)) - throw new RuntimeException("Lengths do not match "+a+" "+info+"<>"+actual); - }*/ + a.setAddress(prevIp, SWF.DEFAULT_VERSION); + int info = a.actionLength + 1 + ((a.actionCode > 0x80) ? 2 : 0); + int actual = a.getBytes(sis.version).length; + if (info != actual) { + if (!(a instanceof ActionDefineFunction)) { + if (!(a instanceof ActionDefineFunction2)) { + //throw new RuntimeException("Lengths do not match "+a+" "+info+"<>"+actual); + } + } + } if (ip < startIp) { retv = true; } if (debugMode) { //if(a instanceof ActionIf){ - System.out.println(" ip: " + ip + " action(len " + a.actionLength + "): " + a + " stack:" + Highlighting.stripHilights(stack.toString()) + " " + Helper.byteArrToString(a.getBytes(SWF.DEFAULT_VERSION))); + System.out.println(" rripos: " + rri.getPos() + " rricount:" + rri.getCount() + " ip: " + (ip - startIp) + " action(len " + a.actionLength + "): " + a + " stack:" + Highlighting.stripHilights(stack.toString()) + " " + Helper.byteArrToString(a.getBytes(SWF.DEFAULT_VERSION))); //} } /*if(a instanceof ActionConstantPool){ @@ -628,6 +640,7 @@ public class SWFInputStream extends InputStream { //rri.setPos(newip); if (!enableVariables) { a = new ActionJump(aif.offset); + a.setAddress(aif.getAddress(), SWF.DEFAULT_VERSION); } if (debugMode) { System.out.println("jump"); @@ -638,6 +651,7 @@ public class SWFInputStream extends InputStream { } if (!enableVariables) { a = new ActionNop(); + a.setAddress(aif.getAddress(), SWF.DEFAULT_VERSION); } } if (!enableVariables) { @@ -669,10 +683,18 @@ public class SWFInputStream extends InputStream { } else { a.translate(localData, stack, output); } + int nopos = -1; for (int i = 0; i < actionLen; i++) { ensureCapacity(ret, ip + i); if (a instanceof ActionNop) { + int prevPos = (int) a.getAddress(); a = new ActionNop(); + a.setAddress(prevPos, SWF.DEFAULT_VERSION); + nopos++; + if (nopos > 0) { + a.setAddress(a.getAddress() + 1, SWF.DEFAULT_VERSION); + } + if (i == 0) { a.beforeInsert = beforeInsert; } @@ -696,6 +718,7 @@ public class SWFInputStream extends InputStream { } rri.setPos(oldPos); } + prevIp = ip; } return retv; } @@ -1262,8 +1285,8 @@ public class SWFInputStream extends InputStream { if (actionLength > 0) { skip(actionLength); } - throw new UnknownActionException(actionCode); - //return new Action(actionCode, actionLength); + //throw new UnknownActionException(actionCode); + return new Action(actionCode, actionLength); } } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/CopyOutputStream.java b/trunk/src/com/jpexs/decompiler/flash/abc/CopyOutputStream.java index f49f4b617..458853a52 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/CopyOutputStream.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/CopyOutputStream.java @@ -49,6 +49,7 @@ public class CopyOutputStream extends OutputStream { boolean output = true; if (output) { + System.out.println("Position: " + pos); System.out.print("Last written:"); for (int i = 0; i < TEMPSIZE; i++) { System.out.print("" + Integer.toHexString(temp[(tempPos + i) % TEMPSIZE]) + " "); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/IfTypeIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/IfTypeIns.java index f74cf2c8b..77bf8944f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/IfTypeIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/IfTypeIns.java @@ -16,10 +16,10 @@ */ package com.jpexs.decompiler.flash.abc.avm2.instructions; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.TreeItem; +import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.util.Stack; public interface IfTypeIns { - public abstract void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins); + public abstract void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins); } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/arithmetic/NotIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/arithmetic/NotIns.java index 997415f2c..2092f1e12 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/arithmetic/NotIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/arithmetic/NotIns.java @@ -20,9 +20,9 @@ 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.operations.NotTreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.flash.graph.GraphTargetItem; +import com.jpexs.decompiler.flash.graph.NotItem; import java.util.HashMap; import java.util.List; import java.util.Stack; @@ -36,7 +36,7 @@ public class NotIns extends InstructionDefinition { @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.decompiler.flash.abc.types.MethodBody body, com.jpexs.decompiler.flash.abc.ABC abc, HashMap localRegNames, List fullyQualifiedNames) { GraphTargetItem v = (GraphTargetItem) stack.pop(); - stack.push(new NotTreeItem(ins, v)); + stack.push(new NotItem(ins, v)); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfEqIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfEqIns.java index 324014e46..72a6b597e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfEqIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfEqIns.java @@ -22,7 +22,6 @@ 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.IfTypeIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.TreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.EqTreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.NeqTreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; @@ -44,7 +43,7 @@ public class IfEqIns extends InstructionDefinition implements IfTypeIns { stack.push(new EqTreeItem(ins, v1, v2)); } - public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { + public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { GraphTargetItem v2 = (GraphTargetItem) stack.pop(); GraphTargetItem v1 = (GraphTargetItem) stack.pop(); stack.push(new NeqTreeItem(ins, v1, v2)); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfFalseIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfFalseIns.java index d96d4d173..fb7e2f219 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfFalseIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfFalseIns.java @@ -22,10 +22,9 @@ 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.IfTypeIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.TreeItem; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.NotTreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.flash.graph.GraphTargetItem; +import com.jpexs.decompiler.flash.graph.NotItem; import java.util.HashMap; import java.util.List; import java.util.Stack; @@ -39,10 +38,11 @@ public class IfFalseIns extends InstructionDefinition implements IfTypeIns { @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.decompiler.flash.abc.types.MethodBody body, com.jpexs.decompiler.flash.abc.ABC abc, HashMap localRegNames, List fullyQualifiedNames) { GraphTargetItem v1 = (GraphTargetItem) stack.pop(); - stack.push(new NotTreeItem(ins, v1)); + stack.push(new NotItem(ins, v1)); } - public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { + @Override + public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { //String v1 = stack.pop().toString(); //stack.push("(" + v1 + ")"); } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfGeIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfGeIns.java index eefc4894a..85fa386f4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfGeIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfGeIns.java @@ -22,7 +22,6 @@ 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.IfTypeIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.TreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.GeTreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.LtTreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; @@ -44,7 +43,7 @@ public class IfGeIns extends InstructionDefinition implements IfTypeIns { stack.push(new GeTreeItem(ins, v1, v2)); } - public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { + public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { GraphTargetItem v2 = (GraphTargetItem) stack.pop(); GraphTargetItem v1 = (GraphTargetItem) stack.pop(); stack.push(new LtTreeItem(ins, v1, v2)); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfGtIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfGtIns.java index eeb87a9b1..afc17eda0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfGtIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfGtIns.java @@ -22,7 +22,6 @@ 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.IfTypeIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.TreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.GtTreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.LeTreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; @@ -44,7 +43,7 @@ public class IfGtIns extends InstructionDefinition implements IfTypeIns { stack.push(new GtTreeItem(ins, v1, v2)); } - public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { + public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { GraphTargetItem v2 = (GraphTargetItem) stack.pop(); GraphTargetItem v1 = (GraphTargetItem) stack.pop(); stack.push(new LeTreeItem(ins, v1, v2)); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfLeIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfLeIns.java index dc7d25688..1f0e1e0d9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfLeIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfLeIns.java @@ -22,7 +22,6 @@ 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.IfTypeIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.TreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.GtTreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.LeTreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; @@ -44,7 +43,7 @@ public class IfLeIns extends InstructionDefinition implements IfTypeIns { stack.push(new LeTreeItem(ins, v1, v2)); } - public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { + public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { GraphTargetItem v2 = (GraphTargetItem) stack.pop(); GraphTargetItem v1 = (GraphTargetItem) stack.pop(); stack.push(new GtTreeItem(ins, v1, v2)); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfLtIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfLtIns.java index d768707d3..04fbab3d9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfLtIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfLtIns.java @@ -22,7 +22,6 @@ 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.IfTypeIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.TreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.GeTreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.LtTreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; @@ -44,7 +43,7 @@ public class IfLtIns extends InstructionDefinition implements IfTypeIns { stack.push(new LtTreeItem(ins, v1, v2)); } - public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { + public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { GraphTargetItem v2 = (GraphTargetItem) stack.pop(); GraphTargetItem v1 = (GraphTargetItem) stack.pop(); stack.push(new GeTreeItem(ins, v1, v2)); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNGeIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNGeIns.java index d5cbaac7c..ad31fa431 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNGeIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNGeIns.java @@ -22,7 +22,6 @@ 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.IfTypeIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.TreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.GeTreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.LtTreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; @@ -44,7 +43,7 @@ public class IfNGeIns extends InstructionDefinition implements IfTypeIns { stack.push(new LtTreeItem(ins, v1, v2)); } - public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { + public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { GraphTargetItem v2 = (GraphTargetItem) stack.pop(); GraphTargetItem v1 = (GraphTargetItem) stack.pop(); stack.push(new GeTreeItem(ins, v1, v2)); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNGtIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNGtIns.java index 88324d997..0ba20e1ad 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNGtIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNGtIns.java @@ -22,7 +22,6 @@ 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.IfTypeIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.TreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.GtTreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.LeTreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; @@ -44,7 +43,7 @@ public class IfNGtIns extends InstructionDefinition implements IfTypeIns { stack.push(new LeTreeItem(ins, v1, v2)); } - public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { + public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { GraphTargetItem v2 = (GraphTargetItem) stack.pop(); GraphTargetItem v1 = (GraphTargetItem) stack.pop(); stack.push(new GtTreeItem(ins, v1, v2)); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNLeIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNLeIns.java index f4fdbf76a..6412f18d5 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNLeIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNLeIns.java @@ -22,7 +22,6 @@ 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.IfTypeIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.TreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.GtTreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.LeTreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; @@ -44,7 +43,7 @@ public class IfNLeIns extends InstructionDefinition implements IfTypeIns { stack.push(new GtTreeItem(ins, v1, v2)); } - public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { + public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { GraphTargetItem v2 = (GraphTargetItem) stack.pop(); GraphTargetItem v1 = (GraphTargetItem) stack.pop(); stack.push(new LeTreeItem(ins, v1, v2)); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNLtIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNLtIns.java index 2b87c4875..3949ef031 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNLtIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNLtIns.java @@ -22,7 +22,6 @@ 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.IfTypeIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.TreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.GeTreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.LtTreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; @@ -44,7 +43,7 @@ public class IfNLtIns extends InstructionDefinition implements IfTypeIns { stack.push(new GeTreeItem(ins, v1, v2)); } - public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { + public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { GraphTargetItem v2 = (GraphTargetItem) stack.pop(); GraphTargetItem v1 = (GraphTargetItem) stack.pop(); stack.push(new LtTreeItem(ins, v1, v2)); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNeIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNeIns.java index 6a5c00462..b1fcee1f7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNeIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfNeIns.java @@ -22,7 +22,6 @@ 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.IfTypeIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.TreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.EqTreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.NeqTreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; @@ -44,7 +43,8 @@ public class IfNeIns extends InstructionDefinition implements IfTypeIns { stack.push(new NeqTreeItem(ins, v1, v2)); } - public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { + @Override + public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { GraphTargetItem v2 = (GraphTargetItem) stack.pop(); GraphTargetItem v1 = (GraphTargetItem) stack.pop(); stack.push(new EqTreeItem(ins, v1, v2)); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfStrictEqIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfStrictEqIns.java index 7a98998c1..45885bdbb 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfStrictEqIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfStrictEqIns.java @@ -22,7 +22,6 @@ 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.IfTypeIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.TreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.StrictEqTreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.StrictNeqTreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; @@ -44,7 +43,8 @@ public class IfStrictEqIns extends InstructionDefinition implements IfTypeIns { stack.push(new StrictEqTreeItem(ins, v1, v2)); } - public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { + @Override + public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { GraphTargetItem v2 = (GraphTargetItem) stack.pop(); GraphTargetItem v1 = (GraphTargetItem) stack.pop(); stack.push(new StrictNeqTreeItem(ins, v1, v2)); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfStrictNeIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfStrictNeIns.java index 213c30c8d..91460557a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfStrictNeIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfStrictNeIns.java @@ -22,7 +22,6 @@ 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.IfTypeIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.TreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.StrictEqTreeItem; import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.StrictNeqTreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; @@ -44,7 +43,8 @@ public class IfStrictNeIns extends InstructionDefinition implements IfTypeIns { stack.push(new StrictNeqTreeItem(ins, v1, v2)); } - public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { + @Override + public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { GraphTargetItem v2 = (GraphTargetItem) stack.pop(); GraphTargetItem v1 = (GraphTargetItem) stack.pop(); stack.push(new StrictEqTreeItem(ins, v1, v2)); diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfTrueIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfTrueIns.java index 5f959d5fc..7599f6c8d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfTrueIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/IfTrueIns.java @@ -22,10 +22,9 @@ 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.IfTypeIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.TreeItem; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.operations.NotTreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.flash.graph.GraphTargetItem; +import com.jpexs.decompiler.flash.graph.NotItem; import java.util.HashMap; import java.util.List; import java.util.Stack; @@ -42,9 +41,9 @@ public class IfTrueIns extends InstructionDefinition implements IfTypeIns { //stack.push("(" + v1 + ")"); } - public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { + public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { GraphTargetItem v1 = (GraphTargetItem) stack.pop(); - stack.push(new NotTreeItem(ins, v1)); + stack.push(new NotItem(ins, v1)); } @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/JumpIns.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/JumpIns.java index 39c9503b9..1a4d7ac71 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/JumpIns.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/jumps/JumpIns.java @@ -22,7 +22,6 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; import com.jpexs.decompiler.flash.abc.avm2.instructions.IfTypeIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; import com.jpexs.decompiler.flash.abc.avm2.treemodel.BooleanTreeItem; -import com.jpexs.decompiler.flash.abc.avm2.treemodel.TreeItem; import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.flash.graph.GraphTargetItem; import java.util.HashMap; @@ -40,6 +39,6 @@ public class JumpIns extends InstructionDefinition implements IfTypeIns { stack.push(new BooleanTreeItem(ins, Boolean.TRUE));// + ins.operands[0]); } - public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { + public void translateInverted(java.util.HashMap localRegs, Stack stack, AVM2Instruction ins) { } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/NotTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/NotTreeItem.java deleted file mode 100644 index 303320027..000000000 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/NotTreeItem.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 . - */ -package com.jpexs.decompiler.flash.abc.avm2.treemodel.operations; - -import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; -import com.jpexs.decompiler.flash.graph.GraphTargetItem; -import com.jpexs.decompiler.flash.graph.LogicalOpItem; -import com.jpexs.decompiler.flash.graph.NotItem; - -public class NotTreeItem extends UnaryOpTreeItem implements LogicalOpItem, NotItem { - - public NotTreeItem(AVM2Instruction instruction, GraphTargetItem value) { - super(instruction, PRECEDENCE_UNARY, value, "!"); - } - - @Override - public GraphTargetItem invert() { - return value; - } - - @Override - public GraphTargetItem getOriginal() { - return value; - } -} diff --git a/trunk/src/com/jpexs/decompiler/flash/action/Action.java b/trunk/src/com/jpexs/decompiler/flash/action/Action.java index bc13f8dcd..ca7249337 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/Action.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/Action.java @@ -16,7 +16,10 @@ */ package com.jpexs.decompiler.flash.action; +import com.jpexs.decompiler.flash.SWF; +import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; +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; @@ -26,14 +29,15 @@ import com.jpexs.decompiler.flash.action.swf6.ActionEnumerate2; import com.jpexs.decompiler.flash.action.swf7.ActionTry; import com.jpexs.decompiler.flash.action.treemodel.*; import com.jpexs.decompiler.flash.action.treemodel.clauses.*; -import com.jpexs.decompiler.flash.action.treemodel.operations.NotTreeItem; import com.jpexs.decompiler.flash.graph.Graph; 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.graph.IfItem; +import com.jpexs.decompiler.flash.graph.NotItem; import com.jpexs.decompiler.flash.helpers.Helper; import com.jpexs.decompiler.flash.helpers.Highlighting; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.*; @@ -349,7 +353,7 @@ public class Action implements GraphSourceItem { String ret = ""; long offset; if (importantOffsets == null) { - setActionsAddresses(list, 0, version); + //setActionsAddresses(list, 0, version); importantOffsets = getActionsAllRefs(list, version); } @@ -370,7 +374,7 @@ public class Action implements GraphSourceItem { ret += a.beforeInsert.getASMSource(importantOffsets, constantPool, version) + "\r\n"; } //if (!(a instanceof ActionNop)) { - ret += Highlighting.hilighOffset("", offset) + a.getASMSource(importantOffsets, constantPool, version) + "\r\n"; + ret += Highlighting.hilighOffset("", offset) + a.getASMSource(importantOffsets, constantPool, version) + (a.ignored ? "; ignored" : "") + "\r\n"; //} } offset += a.getBytes(version).length; @@ -772,8 +776,8 @@ public class Action implements GraphSourceItem { for (GraphTargetItem t : output) { if (t instanceof IfItem) { IfItem it = (IfItem) t; - if (it.expression instanceof NotTreeItem) { - NotTreeItem nti = (NotTreeItem) it.expression; + if (it.expression instanceof NotItem) { + NotItem nti = (NotItem) it.expression; if (nti.value instanceof GetMemberTreeItem) { if (true) { //it.onFalse.isEmpty()){ //||(it.onFalse.get(0) instanceof UnsupportedTreeItem)) { if ((it.onTrue.size() == 1) && (it.onTrue.get(0) instanceof SetMemberTreeItem) && (((SetMemberTreeItem) it.onTrue.get(0)).value instanceof NewObjectTreeItem)) { @@ -966,4 +970,16 @@ public class Action implements GraphSourceItem { public boolean ignoredLoops() { return false; } + + public static List removeNops(List actions, int version) { + List ret = actions; + String s = null; + try { + s = Highlighting.stripHilights(Action.actionsToString(ret, null, version)); + ret = ASMParser.parse(true, new ByteArrayInputStream(s.getBytes()), SWF.DEFAULT_VERSION); + } catch (Exception ex) { + Logger.getLogger(SWFInputStream.class.getName()).log(Level.SEVERE, "parsing error", ex); + } + return ret; + } } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/UnknownActionException.java b/trunk/src/com/jpexs/decompiler/flash/action/UnknownActionException.java index 106fc8fb9..7ecdaa3e4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/UnknownActionException.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/UnknownActionException.java @@ -4,11 +4,12 @@ package com.jpexs.decompiler.flash.action; * * @author JPEXS */ -public class UnknownActionException extends RuntimeException{ +public class UnknownActionException extends RuntimeException { + public int opCode; public UnknownActionException(int opCode) { + super("Unknown opCode: 0x" + Integer.toHexString(opCode)); this.opCode = opCode; } - } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/gui/ActionPanel.java b/trunk/src/com/jpexs/decompiler/flash/action/gui/ActionPanel.java index 9562996a5..384acdb51 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/gui/ActionPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/gui/ActionPanel.java @@ -253,7 +253,7 @@ public class ActionPanel extends JPanel implements ActionListener { editor.setText(lastDisasm); } else if (e.getActionCommand().equals("SAVEACTION")) { try { - src.setActions(ASMParser.parse(new ByteArrayInputStream(editor.getText().getBytes()), SWF.DEFAULT_VERSION), SWF.DEFAULT_VERSION); + src.setActions(ASMParser.parse(true, new ByteArrayInputStream(editor.getText().getBytes()), SWF.DEFAULT_VERSION), SWF.DEFAULT_VERSION); JOptionPane.showMessageDialog(this, "Code successfully saved"); } catch (IOException ex) { } catch (ParseException ex) { 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 c7975dd9a..cd1c5f0e6 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/parser/ASMParser.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/parser/ASMParser.java @@ -32,7 +32,7 @@ import java.util.List; public class ASMParser { - public static List parse(List