AS1/2 better deobfuscation

This commit is contained in:
Jindra Pet��k
2013-03-10 13:57:31 +01:00
parent 4c1485808f
commit c9fe445372
58 changed files with 202 additions and 210 deletions
@@ -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;
@@ -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<Integer, String>(), new HashMap<String, GraphTargetItem>(), new HashMap<String, GraphTargetItem>());
//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<Action> ret = new ArrayList<Action>();
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<GraphTargetItem> output = new ArrayList<GraphTargetItem>();
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);
}
}
}
@@ -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]) + " ");
@@ -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<Integer, TreeItem> localRegs, Stack<TreeItem> stack, AVM2Instruction ins);
public abstract void translateInverted(java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, AVM2Instruction ins);
}
@@ -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<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, java.util.Stack<GraphTargetItem> scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List<GraphTargetItem> output, com.jpexs.decompiler.flash.abc.types.MethodBody body, com.jpexs.decompiler.flash.abc.ABC abc, HashMap<Integer, String> localRegNames, List<String> fullyQualifiedNames) {
GraphTargetItem v = (GraphTargetItem) stack.pop();
stack.push(new NotTreeItem(ins, v));
stack.push(new NotItem(ins, v));
}
@Override
@@ -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<Integer, TreeItem> localRegs, Stack<TreeItem> stack, AVM2Instruction ins) {
public void translateInverted(java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, AVM2Instruction ins) {
GraphTargetItem v2 = (GraphTargetItem) stack.pop();
GraphTargetItem v1 = (GraphTargetItem) stack.pop();
stack.push(new NeqTreeItem(ins, v1, v2));
@@ -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<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, java.util.Stack<GraphTargetItem> scopeStack, ConstantPool constants, AVM2Instruction ins, MethodInfo[] method_info, List<GraphTargetItem> output, com.jpexs.decompiler.flash.abc.types.MethodBody body, com.jpexs.decompiler.flash.abc.ABC abc, HashMap<Integer, String> localRegNames, List<String> fullyQualifiedNames) {
GraphTargetItem v1 = (GraphTargetItem) stack.pop();
stack.push(new NotTreeItem(ins, v1));
stack.push(new NotItem(ins, v1));
}
public void translateInverted(java.util.HashMap<Integer, TreeItem> localRegs, Stack<TreeItem> stack, AVM2Instruction ins) {
@Override
public void translateInverted(java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, AVM2Instruction ins) {
//String v1 = stack.pop().toString();
//stack.push("(" + v1 + ")");
}
@@ -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<Integer, TreeItem> localRegs, Stack<TreeItem> stack, AVM2Instruction ins) {
public void translateInverted(java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, AVM2Instruction ins) {
GraphTargetItem v2 = (GraphTargetItem) stack.pop();
GraphTargetItem v1 = (GraphTargetItem) stack.pop();
stack.push(new LtTreeItem(ins, v1, v2));
@@ -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<Integer, TreeItem> localRegs, Stack<TreeItem> stack, AVM2Instruction ins) {
public void translateInverted(java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, AVM2Instruction ins) {
GraphTargetItem v2 = (GraphTargetItem) stack.pop();
GraphTargetItem v1 = (GraphTargetItem) stack.pop();
stack.push(new LeTreeItem(ins, v1, v2));
@@ -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<Integer, TreeItem> localRegs, Stack<TreeItem> stack, AVM2Instruction ins) {
public void translateInverted(java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, AVM2Instruction ins) {
GraphTargetItem v2 = (GraphTargetItem) stack.pop();
GraphTargetItem v1 = (GraphTargetItem) stack.pop();
stack.push(new GtTreeItem(ins, v1, v2));
@@ -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<Integer, TreeItem> localRegs, Stack<TreeItem> stack, AVM2Instruction ins) {
public void translateInverted(java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, AVM2Instruction ins) {
GraphTargetItem v2 = (GraphTargetItem) stack.pop();
GraphTargetItem v1 = (GraphTargetItem) stack.pop();
stack.push(new GeTreeItem(ins, v1, v2));
@@ -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<Integer, TreeItem> localRegs, Stack<TreeItem> stack, AVM2Instruction ins) {
public void translateInverted(java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, AVM2Instruction ins) {
GraphTargetItem v2 = (GraphTargetItem) stack.pop();
GraphTargetItem v1 = (GraphTargetItem) stack.pop();
stack.push(new GeTreeItem(ins, v1, v2));
@@ -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<Integer, TreeItem> localRegs, Stack<TreeItem> stack, AVM2Instruction ins) {
public void translateInverted(java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, AVM2Instruction ins) {
GraphTargetItem v2 = (GraphTargetItem) stack.pop();
GraphTargetItem v1 = (GraphTargetItem) stack.pop();
stack.push(new GtTreeItem(ins, v1, v2));
@@ -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<Integer, TreeItem> localRegs, Stack<TreeItem> stack, AVM2Instruction ins) {
public void translateInverted(java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, AVM2Instruction ins) {
GraphTargetItem v2 = (GraphTargetItem) stack.pop();
GraphTargetItem v1 = (GraphTargetItem) stack.pop();
stack.push(new LeTreeItem(ins, v1, v2));
@@ -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<Integer, TreeItem> localRegs, Stack<TreeItem> stack, AVM2Instruction ins) {
public void translateInverted(java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, AVM2Instruction ins) {
GraphTargetItem v2 = (GraphTargetItem) stack.pop();
GraphTargetItem v1 = (GraphTargetItem) stack.pop();
stack.push(new LtTreeItem(ins, v1, v2));
@@ -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<Integer, TreeItem> localRegs, Stack<TreeItem> stack, AVM2Instruction ins) {
@Override
public void translateInverted(java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, AVM2Instruction ins) {
GraphTargetItem v2 = (GraphTargetItem) stack.pop();
GraphTargetItem v1 = (GraphTargetItem) stack.pop();
stack.push(new EqTreeItem(ins, v1, v2));
@@ -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<Integer, TreeItem> localRegs, Stack<TreeItem> stack, AVM2Instruction ins) {
@Override
public void translateInverted(java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, AVM2Instruction ins) {
GraphTargetItem v2 = (GraphTargetItem) stack.pop();
GraphTargetItem v1 = (GraphTargetItem) stack.pop();
stack.push(new StrictNeqTreeItem(ins, v1, v2));
@@ -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<Integer, TreeItem> localRegs, Stack<TreeItem> stack, AVM2Instruction ins) {
@Override
public void translateInverted(java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, AVM2Instruction ins) {
GraphTargetItem v2 = (GraphTargetItem) stack.pop();
GraphTargetItem v1 = (GraphTargetItem) stack.pop();
stack.push(new StrictEqTreeItem(ins, v1, v2));
@@ -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<Integer, TreeItem> localRegs, Stack<TreeItem> stack, AVM2Instruction ins) {
public void translateInverted(java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, AVM2Instruction ins) {
GraphTargetItem v1 = (GraphTargetItem) stack.pop();
stack.push(new NotTreeItem(ins, v1));
stack.push(new NotItem(ins, v1));
}
@Override
@@ -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<Integer, TreeItem> localRegs, Stack<TreeItem> stack, AVM2Instruction ins) {
public void translateInverted(java.util.HashMap<Integer, GraphTargetItem> localRegs, Stack<GraphTargetItem> stack, AVM2Instruction ins) {
}
}
@@ -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 <http://www.gnu.org/licenses/>.
*/
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;
}
}
@@ -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<Action> removeNops(List<Action> actions, int version) {
List<Action> 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;
}
}
@@ -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;
}
}
@@ -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) {
@@ -32,7 +32,7 @@ import java.util.List;
public class ASMParser {
public static List<Action> parse(List<Label> labels, long address, FlasmLexer lexer, List<String> constantPool, int version) throws IOException, ParseException {
public static List<Action> parse(boolean ignoreNops, List<Label> labels, long address, FlasmLexer lexer, List<String> constantPool, int version) throws IOException, ParseException {
List<Action> list = new ArrayList<Action>();
while (true) {
ParsedSymbol symb = lexer.yylex();
@@ -179,7 +179,7 @@ public class ASMParser {
} else if (instructionName.equals("Decrement".toLowerCase())) {
list.add(new ActionDecrement());
} else if (instructionName.equals("DefineFunction".toLowerCase())) {
list.add(new ActionDefineFunction(labels, address, lexer, constantPool, version));
list.add(new ActionDefineFunction(ignoreNops, labels, address, lexer, constantPool, version));
} else if (instructionName.equals("DefineLocal".toLowerCase())) {
list.add(new ActionDefineLocal());
} else if (instructionName.equals("DefineLocal2".toLowerCase())) {
@@ -227,7 +227,7 @@ public class ASMParser {
} else if (instructionName.equals("TypeOf".toLowerCase())) {
list.add(new ActionTypeOf());
} else if (instructionName.equals("With".toLowerCase())) {
list.add(new ActionWith(labels, address, lexer, constantPool, version));
list.add(new ActionWith(ignoreNops, labels, address, lexer, constantPool, version));
} else if (instructionName.equals("Enumerate2".toLowerCase())) {
list.add(new ActionEnumerate2());
} else if (instructionName.equals("Greater".toLowerCase())) {
@@ -241,7 +241,7 @@ public class ASMParser {
} else if (instructionName.equals("CastOp".toLowerCase())) {
list.add(new ActionCastOp());
} else if (instructionName.equals("DefineFunction2".toLowerCase())) {
list.add(new ActionDefineFunction2(labels, address, lexer, constantPool, version));
list.add(new ActionDefineFunction2(ignoreNops, labels, address, lexer, constantPool, version));
} else if (instructionName.equals("Extends".toLowerCase())) {
list.add(new ActionExtends());
} else if (instructionName.equals("ImplementsOp".toLowerCase())) {
@@ -249,17 +249,25 @@ public class ASMParser {
} else if (instructionName.equals("Throw".toLowerCase())) {
list.add(new ActionThrow());
} else if (instructionName.equals("Try".toLowerCase())) {
list.add(new ActionTry(labels, address, lexer, constantPool, version));
list.add(new ActionTry(ignoreNops, labels, address, lexer, constantPool, version));
} else if (instructionName.equals("FSCommand2".toLowerCase())) {
list.add(new ActionFSCommand2());
} else if (instructionName.equals("StrictMode".toLowerCase())) {
list.add(new ActionStrictMode(lexer));
} else if (instructionName.equals("Nop".toLowerCase())) {
list.add(new ActionNop());
if (!ignoreNops) {
list.add(new ActionNop());
}
} else {
throw new ParseException("Unknown instruction name :" + instructionName, lexer.yyline());
}
address += (list.get(list.size() - 1)).getBytes(version).length;
if (instructionName.equals("Nop".toLowerCase())) {
if (!ignoreNops) {
address += 1;
}
} else {
address += (list.get(list.size() - 1)).getBytes(version).length;
}
} else if (symb.type == ParsedSymbol.TYPE_EOL) {
} else if ((symb.type == ParsedSymbol.TYPE_BLOCK_END) || (symb.type == ParsedSymbol.TYPE_EOF)) {
return list;
@@ -269,27 +277,40 @@ public class ASMParser {
}
}
public static List<Action> parse(InputStream is, int version) throws IOException, ParseException {
public static List<Action> parse(boolean ignoreNops, InputStream is, int version) throws IOException, ParseException {
FlasmLexer lexer = new FlasmLexer(is);
List<Label> labels = new ArrayList<Label>();
List<Action> ret = parse(labels, 0, lexer, new ArrayList<String>(), version);
List<Action> ret = parse(ignoreNops, labels, 0, lexer, new ArrayList<String>(), version);
List<Action> links = Action.getActionsAllIfsOrJumps(ret);
Action.setActionsAddresses(ret, 0, version);
for (Action link : links) {
boolean found = false;
String identifier = null;
if (link instanceof ActionJump) {
identifier = ((ActionJump) link).identifier;
for (Label label : labels) {
if (((ActionJump) link).identifier.equals(label.name)) {
((ActionJump) link).offset = (int) (label.address - (((ActionJump) link).getAddress() + ((ActionJump) link).getBytes(version).length));
found = true;
break;
}
}
}
if (link instanceof ActionIf) {
identifier = ((ActionIf) link).identifier;
for (Label label : labels) {
if (((ActionIf) link).identifier.equals(label.name)) {
((ActionIf) link).offset = (int) (label.address - (((ActionIf) link).getAddress() + ((ActionIf) link).getBytes(version).length));
found = true;
break;
}
}
}
if ((link instanceof ActionJump) || (link instanceof ActionIf)) {
if (!found) {
//System.err.println("TARGET NOT FOUND - identifier:" + identifier+" addr: ofs"+Helper.formatAddress(link.getAddress()));
}
}
}
return ret;
}
@@ -45,7 +45,7 @@ public class ActionGetURL extends Action {
}
public ActionGetURL(FlasmLexer lexer) throws IOException, ParseException {
super(0x83, 0);
super(0x83, -1);
urlString = lexString(lexer);
targetString = lexString(lexer);
}
@@ -60,7 +60,7 @@ public class ActionGoToLabel extends Action {
}
public ActionGoToLabel(FlasmLexer lexer) throws IOException, ParseException {
super(0x8C, 0);
super(0x8C, -1);
label = lexString(lexer);
}
@@ -56,7 +56,7 @@ public class ActionGotoFrame extends Action {
}
public ActionGotoFrame(FlasmLexer lexer) throws IOException, ParseException {
super(0x81, 0);
super(0x81, -1);
frame = (int) lexLong(lexer);
}
@@ -60,7 +60,7 @@ public class ActionSetTarget extends Action {
}
public ActionSetTarget(FlasmLexer lexer) throws IOException, ParseException {
super(0x8B, 0);
super(0x8B, -1);
targetName = lexString(lexer);
}
@@ -59,7 +59,7 @@ public class ActionWaitForFrame extends Action {
}
public ActionWaitForFrame(FlasmLexer lexer) throws IOException, ParseException {
super(0x8A, 0);
super(0x8A, -1);
frame = (int) lexLong(lexer);
skipCount = (int) lexLong(lexer);
}
@@ -66,7 +66,7 @@ public class ActionGetURL2 extends Action {
}
public ActionGetURL2(FlasmLexer lexer) throws IOException, ParseException {
super(0x9A, 0);
super(0x9A, -1);
sendVarsMethod = (int) lexLong(lexer);
loadTargetFlag = lexBoolean(lexer);
loadVariablesFlag = lexBoolean(lexer);
@@ -68,7 +68,7 @@ public class ActionGotoFrame2 extends Action {
}
public ActionGotoFrame2(FlasmLexer lexer) throws IOException, ParseException {
super(0x9F, 0);
super(0x9F, -1);
sceneBiasFlag = lexBoolean(lexer);
playFlag = lexBoolean(lexer);
if (sceneBiasFlag) {
@@ -65,11 +65,12 @@ public class ActionIf extends Action {
@Override
public String getASMSource(List<Long> knownAddreses, List<String> constantPool, int version) {
return "If loc" + Helper.formatAddress(getAddress() + getBytes(version).length + offset) + (compileTime ? " ;compileTime" : "");
String ofsStr = Helper.formatAddress(getAddress() + getBytes(version).length + offset);
return "If loc" + ofsStr + (compileTime ? " ;compileTime" : "");
}
public ActionIf(FlasmLexer lexer) throws IOException, ParseException {
super(0x9D, 0);
super(0x9D, -1);
identifier = lexIdentifier(lexer);
}
@@ -69,11 +69,12 @@ public class ActionJump extends Action {
@Override
public String getASMSource(List<Long> knownAddreses, List<String> constantPool, int version) {
return "Jump loc" + Helper.formatAddress(getAddress() + getBytes(version).length + offset);
String ofsStr = Helper.formatAddress(getAddress() + getBytes(version).length + offset);
return "Jump loc" + ofsStr;
}
public ActionJump(FlasmLexer lexer) throws IOException, ParseException {
super(0x99, 0);
super(0x99, -1);
identifier = lexIdentifier(lexer);
}
@@ -17,8 +17,8 @@
package com.jpexs.decompiler.flash.action.swf4;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.treemodel.operations.NotTreeItem;
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;
@@ -37,6 +37,6 @@ public class ActionNot extends Action {
@Override
public void translate(Stack<GraphTargetItem> stack, List<GraphTargetItem> output, java.util.HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions) {
GraphTargetItem a = stack.pop();
stack.push(new NotTreeItem(this, a));
stack.push(new NotItem(this, a));
}
}
@@ -141,7 +141,7 @@ public class ActionPush extends Action {
}
public ActionPush(FlasmLexer lexer, List<String> constantPool) throws IOException, ParseException {
super(0x96, 0);
super(0x96, -1);
this.constantPool = constantPool;
values = new ArrayList<Object>();
int count = 0;
@@ -205,9 +205,6 @@ public class ActionPush extends Action {
ret += values.get(i).toString();
}
}
if (ret.equals("Push 138")) {
new Exception().printStackTrace();
}
return ret;
}
@@ -39,7 +39,7 @@ public class ActionWaitForFrame2 extends Action {
}
public ActionWaitForFrame2(FlasmLexer lexer) throws IOException, ParseException {
super(0x8D, 1);
super(0x8D, -1);
skipCount = (int) lexLong(lexer);
}
@@ -46,7 +46,7 @@ public class ActionConstantPool extends Action {
}
public ActionConstantPool(FlasmLexer lexer) throws IOException, ParseException {
super(0x88, 0);
super(0x88, -1);
while (true) {
ParsedSymbol symb = lexer.yylex();
if (symb.type == ParsedSymbol.TYPE_STRING) {
@@ -76,15 +76,15 @@ public class ActionDefineFunction extends Action {
code = (new SWFInputStream(new ByteArrayInputStream(sis.readBytes(codeSize)), version)).readActionList();
}
public ActionDefineFunction(List<Label> labels, long address, FlasmLexer lexer, List<String> constantPool, int version) throws IOException, ParseException {
super(0x9B, 0);
public ActionDefineFunction(boolean ignoreNops, List<Label> labels, long address, FlasmLexer lexer, List<String> constantPool, int version) throws IOException, ParseException {
super(0x9B, -1);
functionName = lexString(lexer);
int numParams = (int) lexLong(lexer);
for (int i = 0; i < numParams; i++) {
paramNames.add(lexString(lexer));
}
lexBlockOpen(lexer);
code = ASMParser.parse(labels, address + getPreLen(version), lexer, constantPool, version);
code = ASMParser.parse(ignoreNops, labels, address + getPreLen(version), lexer, constantPool, version);
}
@Override
@@ -40,7 +40,7 @@ public class ActionStoreRegister extends Action {
}
public ActionStoreRegister(FlasmLexer lexer) throws IOException, ParseException {
super(0x87, 1);
super(0x87, -1);
registerNumber = (int) lexLong(lexer);
}
@@ -40,10 +40,10 @@ public class ActionWith extends Action {
actions = (new SWFInputStream(new ByteArrayInputStream(sis.readBytes(size)), version)).readActionList();
}
public ActionWith(List<Label> labels, long address, FlasmLexer lexer, List<String> constantPool, int version) throws IOException, ParseException {
public ActionWith(boolean ignoreNops, List<Label> labels, long address, FlasmLexer lexer, List<String> constantPool, int version) throws IOException, ParseException {
super(0x94, 2);
lexBlockOpen(lexer);
actions = ASMParser.parse(labels, address + 5, lexer, constantPool, version);
actions = ASMParser.parse(ignoreNops, labels, address + 5, lexer, constantPool, version);
}
@Override
@@ -98,8 +98,8 @@ public class ActionDefineFunction2 extends Action {
code = (new SWFInputStream(new ByteArrayInputStream(sis.readBytes(codeSize)), version)).readActionList();
}
public ActionDefineFunction2(List<Label> labels, long address, FlasmLexer lexer, List<String> constantPool, int version) throws IOException, ParseException {
super(0x8E, 0);
public ActionDefineFunction2(boolean ignoreNops, List<Label> labels, long address, FlasmLexer lexer, List<String> constantPool, int version) throws IOException, ParseException {
super(0x8E, -1);
functionName = lexString(lexer);
int numParams = (int) lexLong(lexer);
registerCount = (int) lexLong(lexer);
@@ -117,7 +117,7 @@ public class ActionDefineFunction2 extends Action {
paramNames.add(lexString(lexer));
}
lexBlockOpen(lexer);
code = ASMParser.parse(labels, address + getPreLen(version), lexer, constantPool, version);
code = ASMParser.parse(ignoreNops, labels, address + getPreLen(version), lexer, constantPool, version);
}
@Override
@@ -26,7 +26,7 @@ import java.util.Stack;
public class ActionExtends extends Action {
public ActionExtends() {
super(0x69, 0);
super(0x69, -1);
}
@Override
@@ -121,10 +121,10 @@ public class ActionTry extends Action {
return surroundWithAction(baos.toByteArray(), version);
}
public ActionTry(List<Label> labels, long address, FlasmLexer lexer, List<String> constantPool, int version) throws IOException, ParseException {
public ActionTry(boolean ignoreNops, List<Label> labels, long address, FlasmLexer lexer, List<String> constantPool, int version) throws IOException, ParseException {
super(0x8F, 0);
lexBlockOpen(lexer);
tryBody = ASMParser.parse(labels, address + 4 + 6, lexer, constantPool, version);
tryBody = ASMParser.parse(ignoreNops, labels, address + 4 + 6, lexer, constantPool, version);
ParsedSymbol symb = lexer.yylex();
catchBlockFlag = false;
if (symb.type == ParsedSymbol.TYPE_INSTRUCTION_NAME) {
@@ -141,14 +141,14 @@ public class ActionTry extends Action {
throw new ParseException("Catched name or register expected", lexer.yyline());
}
lexBlockOpen(lexer);
catchBody = ASMParser.parse(labels, address + 4 + 6 + Action.actionsToBytes(tryBody, false, version).length, lexer, constantPool, version);
catchBody = ASMParser.parse(ignoreNops, labels, address + 4 + 6 + Action.actionsToBytes(tryBody, false, version).length, lexer, constantPool, version);
symb = lexer.yylex();
}
if (symb.type == ParsedSymbol.TYPE_INSTRUCTION_NAME) {
if (((String) symb.value).toLowerCase().equals("finally")) {
finallyBlockFlag = true;
lexBlockOpen(lexer);
finallyBody = ASMParser.parse(labels, address + 4 + 6 + Action.actionsToBytes(tryBody, false, version).length + Action.actionsToBytes(catchBody, false, version).length, lexer, constantPool, version);
finallyBody = ASMParser.parse(ignoreNops, labels, address + 4 + 6 + Action.actionsToBytes(tryBody, false, version).length + Action.actionsToBytes(catchBody, false, version).length, lexer, constantPool, version);
} else {
finallyBlockFlag = false;
lexer.yypushback(lexer.yylength());
@@ -18,8 +18,9 @@ package com.jpexs.decompiler.flash.action.treemodel.operations;
import com.jpexs.decompiler.flash.action.treemodel.TreeItem;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.UnaryOpItem;
public class BitNotTreeItem extends UnaryOpTreeItem {
public class BitNotTreeItem extends UnaryOpItem {
public BitNotTreeItem(GraphSourceItem instruction, TreeItem value) {
super(instruction, PRECEDENCE_UNARY, value, "~");
@@ -18,8 +18,9 @@ package com.jpexs.decompiler.flash.action.treemodel.operations;
import com.jpexs.decompiler.flash.action.treemodel.TreeItem;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.UnaryOpItem;
public class NegTreeItem extends UnaryOpTreeItem {
public class NegTreeItem extends UnaryOpItem {
public NegTreeItem(GraphSourceItem instruction, TreeItem value) {
super(instruction, PRECEDENCE_UNARY, value, "-");
@@ -1,45 +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 <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.action.treemodel.operations;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
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(GraphSourceItem instruction, GraphTargetItem value) {
super(instruction, PRECEDENCE_UNARY, value, "!");
}
@Override
public boolean toBoolean() {
boolean ret = !value.toBoolean();
return ret;
}
@Override
public GraphTargetItem invert() {
return value;
}
@Override
public GraphTargetItem getOriginal() {
return value;
}
}
@@ -18,8 +18,9 @@ package com.jpexs.decompiler.flash.action.treemodel.operations;
import com.jpexs.decompiler.flash.action.treemodel.TreeItem;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.UnaryOpItem;
public class PreDecrementTreeItem extends UnaryOpTreeItem {
public class PreDecrementTreeItem extends UnaryOpItem {
public PreDecrementTreeItem(GraphSourceItem instruction, TreeItem object) {
super(instruction, PRECEDENCE_UNARY, object, "--");
@@ -18,8 +18,9 @@ package com.jpexs.decompiler.flash.action.treemodel.operations;
import com.jpexs.decompiler.flash.action.treemodel.TreeItem;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.UnaryOpItem;
public class PreIncrementTreeItem extends UnaryOpTreeItem {
public class PreIncrementTreeItem extends UnaryOpItem {
public PreIncrementTreeItem(GraphSourceItem instruction, TreeItem object) {
super(instruction, PRECEDENCE_UNARY, object, "++");
@@ -933,8 +933,12 @@ public class Graph {
}
GraphPart loopBodyStart = null;
GraphPart next = part.getNextPartPath(loopContinues);
if ((reversed == loop) && (expr instanceof LogicalOpItem)) {
expr = ((LogicalOpItem) expr).invert();
if (reversed == loop) {
if (expr instanceof LogicalOpItem) {
expr = ((LogicalOpItem) expr).invert();
} else {
expr = new NotItem(null, expr);
}
}
List<GraphTargetItem> retx = ret;
if ((!loop) || (doWhile && (part.nextParts.size() > 1))) {
@@ -36,7 +36,9 @@ public abstract class GraphSource {
if (ins.isBranch() || ins.isJump()) {
List<Integer> branches = ins.getBranches(this);
for (int b : branches) {
visitCode(b, ip, refs);
if (b >= 0) {
visitCode(b, ip, refs);
}
}
break;
}
@@ -2,9 +2,26 @@ package com.jpexs.decompiler.flash.graph;
/**
*
* @author Jindra
* @author JPEXS
*/
public interface NotItem {
public class NotItem extends UnaryOpItem implements LogicalOpItem {
public GraphTargetItem getOriginal();
public NotItem(GraphSourceItem instruction, GraphTargetItem value) {
super(instruction, PRECEDENCE_UNARY, value, "!");
}
@Override
public boolean toBoolean() {
boolean ret = !value.toBoolean();
return ret;
}
@Override
public GraphTargetItem invert() {
return value;
}
public GraphTargetItem getOriginal() {
return value;
}
}
@@ -14,29 +14,24 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.action.treemodel.operations;
package com.jpexs.decompiler.flash.graph;
import com.jpexs.decompiler.flash.action.treemodel.ConstantPool;
import com.jpexs.decompiler.flash.action.treemodel.TreeItem;
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
import com.jpexs.decompiler.flash.graph.GraphSourceItemPos;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import java.util.List;
public abstract class UnaryOpTreeItem extends TreeItem {
public abstract class UnaryOpItem extends GraphTargetItem {
public GraphTargetItem value;
public String operator;
public UnaryOpTreeItem(GraphSourceItem instruction, int precedence, GraphTargetItem value, String operator) {
public UnaryOpItem(GraphSourceItem instruction, int precedence, GraphTargetItem value, String operator) {
super(instruction, precedence);
this.value = value;
this.operator = operator;
}
@Override
public String toString(ConstantPool constants) {
String s = value.toString(constants);
public String toString(List localData) {
String s = value.toString(localData);
if (value.precedence > precedence) {
s = "(" + s + ")";
}
@@ -146,7 +146,7 @@ public class DefineButtonTag extends CharacterTag implements ASMSource, BoundedT
baos.write(actionBytes);
ReReadableInputStream rri = new ReReadableInputStream(new ByteArrayInputStream(baos.toByteArray()));
rri.setPos(prevLength);
return SWFInputStream.readActionList(rri, version, prevLength);
return Action.removeNops(SWFInputStream.readActionList(rri, version, prevLength), version);
} catch (IOException ex) {
Logger.getLogger(DoActionTag.class.getName()).log(Level.SEVERE, null, ex);
return new ArrayList<Action>();
@@ -20,7 +20,6 @@ import com.jpexs.decompiler.flash.ReReadableInputStream;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.helpers.Helper;
import com.jpexs.decompiler.flash.tags.base.ASMSource;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -110,7 +109,7 @@ public class DoActionTag extends Tag implements ASMSource {
baos.write(actionBytes);
ReReadableInputStream rri = new ReReadableInputStream(new ByteArrayInputStream(baos.toByteArray()));
rri.setPos(prevLength);
return SWFInputStream.readActionList(rri, version, prevLength);
return Action.removeNops(SWFInputStream.readActionList(rri, version, prevLength), version);
} catch (IOException ex) {
Logger.getLogger(DoActionTag.class.getName()).log(Level.SEVERE, null, ex);
return new ArrayList<Action>();
@@ -116,7 +116,7 @@ public class DoInitActionTag extends CharacterTag implements ASMSource {
baos.write(actionBytes);
ReReadableInputStream rri = new ReReadableInputStream(new ByteArrayInputStream(baos.toByteArray()));
rri.setPos(prevLength);
return SWFInputStream.readActionList(rri, version, prevLength);
return Action.removeNops(SWFInputStream.readActionList(rri, version, prevLength), version);
} catch (IOException ex) {
Logger.getLogger(DoActionTag.class.getName()).log(Level.SEVERE, null, ex);
return new ArrayList<Action>();
@@ -133,7 +133,7 @@ public class BUTTONCONDACTION implements ASMSource {
@Override
public List<Action> getActions(int version) {
try {
return SWFInputStream.readActionList(new ReReadableInputStream(new ByteArrayInputStream(actionBytes)), version, 0);
return Action.removeNops(SWFInputStream.readActionList(new ReReadableInputStream(new ByteArrayInputStream(actionBytes)), version, 0), version);
} catch (IOException ex) {
Logger.getLogger(BUTTONCONDACTION.class.getName()).log(Level.SEVERE, null, ex);
return new ArrayList<Action>();
@@ -93,7 +93,7 @@ public class CLIPACTIONRECORD implements ASMSource {
public List<Action> getActions(int version) {
try {
return SWFInputStream.readActionList(new ReReadableInputStream(new ByteArrayInputStream(actionBytes)), version, 0);
return Action.removeNops(SWFInputStream.readActionList(new ReReadableInputStream(new ByteArrayInputStream(actionBytes)), version, 0), version);
} catch (IOException ex) {
Logger.getLogger(BUTTONCONDACTION.class.getName()).log(Level.SEVERE, null, ex);
return new ArrayList<Action>();