From dc720378ca622e3ca326d3df586e6160ebdc3fea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sat, 27 Apr 2013 22:52:12 +0200 Subject: [PATCH] removetraps...this fix graph path fix --- .../decompiler/flash/abc/avm2/AVM2Code.java | 2 +- .../instructions/localregs/GetLocal0Ins.java | 4 + .../flash/action/swf4/ActionPush.java | 82 ++++++++++--------- .../jpexs/decompiler/flash/graph/Graph.java | 36 ++++---- 4 files changed, 69 insertions(+), 55 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index 4b163f739..e99709af0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -1175,7 +1175,7 @@ public class AVM2Code implements Serializable { visited[ip] = true; AVM2Instruction ins = code.get(ip); if (debugMode) { - System.out.println("translating ip " + ip + " ins " + ins.toString() + " stack:" + Highlighting.stripHilights(stack.toString()) + " scopeStack:" + Highlighting.stripHilights(scopeStack.toString())); + System.err.println("translating ip " + ip + " ins " + ins.toString() + " stack:" + Highlighting.stripHilights(stack.toString()) + " scopeStack:" + Highlighting.stripHilights(scopeStack.toString())); } if (ins.definition instanceof NewFunctionIns) { if (ip + 1 <= end) { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal0Ins.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal0Ins.java index aafc9ffce..791c0229a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal0Ins.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/instructions/localregs/GetLocal0Ins.java @@ -42,6 +42,10 @@ public class GetLocal0Ins extends InstructionDefinition implements GetLocalTypeI @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) { + if ((classIndex >= abc.instance_info.length) || classIndex < 0) { + stack.push(new ThisTreeItem(null)); + return; + } if (isStatic) { stack.push(new ClassTreeItem(abc.instance_info[classIndex].getName(constants))); } else { 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 c2ede71d7..e75ba4138 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf4/ActionPush.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.action.swf4; +import com.jpexs.decompiler.flash.EndOfStreamException; import com.jpexs.decompiler.flash.SWFInputStream; import com.jpexs.decompiler.flash.SWFOutputStream; import com.jpexs.decompiler.flash.action.Action; @@ -33,6 +34,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Stack; +import java.util.logging.Level; +import java.util.logging.Logger; public class ActionPush extends Action { @@ -46,46 +49,49 @@ public class ActionPush extends Action { int type; values = new ArrayList(); sis = new SWFInputStream(new ByteArrayInputStream(sis.readBytes(actionLength)), version); - while ((type = sis.readUI8()) > -1) { - switch (type) { - case 0: - values.add(sis.readString()); - break; - case 1: - values.add(sis.readFLOAT()); - break; - case 2: - values.add(new Null()); - break; - case 3: - values.add(new Undefined()); - break; - case 4: - values.add(new RegisterNumber(sis.readUI8())); - break; - case 5: - int b = sis.readUI8(); - if (b == 0) { - values.add((Boolean) false); - } else { - values.add((Boolean) true); - } + try { + while ((type = sis.readUI8()) > -1) { + switch (type) { + case 0: + values.add(sis.readString()); + break; + case 1: + values.add(sis.readFLOAT()); + break; + case 2: + values.add(new Null()); + break; + case 3: + values.add(new Undefined()); + break; + case 4: + values.add(new RegisterNumber(sis.readUI8())); + break; + case 5: + int b = sis.readUI8(); + if (b == 0) { + values.add((Boolean) false); + } else { + values.add((Boolean) true); + } - break; - case 6: - values.add(sis.readDOUBLE()); - break; - case 7: - long el = sis.readSI32(); - values.add((Long) el); - break; - case 8: - values.add(new ConstantIndex(sis.readUI8())); - break; - case 9: - values.add(new ConstantIndex(sis.readUI16())); - break; + break; + case 6: + values.add(sis.readDOUBLE()); + break; + case 7: + long el = sis.readSI32(); + values.add((Long) el); + break; + case 8: + values.add(new ConstantIndex(sis.readUI8())); + break; + case 9: + values.add(new ConstantIndex(sis.readUI16())); + break; + } } + } catch (EndOfStreamException ex) { } } diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java b/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java index 16e22c482..38f17e4bd 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java @@ -99,7 +99,7 @@ public class Graph { break loopi; } if (lastpref == null) { - lastpref = r.path.parent(i - 1); + lastpref = r.path.parent(i); } else { if (!r.path.startsWith(lastpref)) { i--; @@ -112,7 +112,7 @@ public class Graph { i = part.path.length(); } if (modify && ((uniqueRefs.size() > 1) && (prvni >= 0))) { - GraphPath newpath = uniqueRefs.get(prvni).path.parent(i - 1); + GraphPath newpath = uniqueRefs.get(prvni).path.parent(i); if (!part.path.equals(newpath)) { if (part.path.startsWith(newpath)) { GraphPath origPath = part.path; @@ -466,7 +466,7 @@ public class Graph { } if (part == null) { //return ret; - } else if (part.leadsTo(code, part, getLoopsContinues(loops))) { + } else if ((part.nextParts.size() == 1) && part.leadsTo(code, part, getLoopsContinues(loops))) { Loop l = new Loop(loops.size(), part, null); List trueExp = new ArrayList(); trueExp.add(new TrueItem(null)); @@ -548,7 +548,7 @@ public class Graph { if (part.nextParts.size() == 2) { - if ((stack.size() >= 2) && (stack.get(stack.size() - 1) instanceof NotItem) && (((NotItem) (stack.get(stack.size() - 1))).getOriginal() == stack.get(stack.size() - 2))) { + if ((stack.size() >= 2) && (stack.get(stack.size() - 1) instanceof NotItem) && (((NotItem) (stack.get(stack.size() - 1))).getOriginal().getNotCoerced() == stack.get(stack.size() - 2).getNotCoerced())) { ret.addAll(output); GraphPart sp0 = getNextNoJump(part.nextParts.get(0)); GraphPart sp1 = getNextNoJump(part.nextParts.get(1)); @@ -596,7 +596,7 @@ public class Graph { } } return ret; - } else if ((stack.size() >= 2) && (stack.get(stack.size() - 1) == stack.get(stack.size() - 2))) { + } else if ((stack.size() >= 2) && (stack.get(stack.size() - 1).getNotCoerced() == stack.get(stack.size() - 2).getNotCoerced())) { ret.addAll(output); GraphPart sp0 = getNextNoJump(part.nextParts.get(0)); GraphPart sp1 = getNextNoJump(part.nextParts.get(1)); @@ -765,19 +765,23 @@ public class Graph { } } List onFalse = new ArrayList(); - if (lopFalse != null) { - onFalse.add(lopFalse); + if ((!onTrue.isEmpty()) && onTrue.get(onTrue.size() - 1) instanceof ExitItem) { + next = part.nextParts.get(0); } else { - if (debugMode) { - System.err.println("ONFALSE: (inside " + part + ")"); - } - if ((next == part.nextParts.get(0)) || (part.nextParts.get(0).path.equals(part.path) || part.nextParts.get(0).path.length() < part.path.length())) { - onFalse = new ArrayList(); + if (lopFalse != null) { + onFalse.add(lopFalse); } else { - onFalse = (printGraph(prepareBranchLocalData(localData), falseStack, allParts, part, part.nextParts.get(0), next == null ? stopPart : next, loops, forFinalCommands)); - } - if (debugMode) { - System.err.println("/ONFALSE (inside " + part + ")"); + if (debugMode) { + System.err.println("ONFALSE: (inside " + part + ")"); + } + if ((next == part.nextParts.get(0)) || (part.nextParts.get(0).path.equals(part.path) || part.nextParts.get(0).path.length() < part.path.length())) { + onFalse = new ArrayList(); + } else { + onFalse = (printGraph(prepareBranchLocalData(localData), falseStack, allParts, part, part.nextParts.get(0), next == null ? stopPart : next, loops, forFinalCommands)); + } + if (debugMode) { + System.err.println("/ONFALSE (inside " + part + ")"); + } } } if (isEmpty(onTrue) && isEmpty(onFalse) && (trueStack.size() > stackSizeBefore) && (falseStack.size() > stackSizeBefore)) {