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 83718f559..d974de0b8 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -1858,7 +1858,7 @@ public class AVM2Code implements Serializable { code.get(ip).replaceWith = appended.get(ip); } } catch (ConvertException cex) { - cex.printStackTrace(); + Logger.getLogger(AVM2Code.class.getName()).log(Level.SEVERE, "Error during restore control flow", cex); } invalidateCache(); try { @@ -1970,7 +1970,7 @@ public class AVM2Code implements Serializable { } return copy; } catch (Exception ex) { - ex.printStackTrace(); + Logger.getLogger(AVM2Code.class.getName()).log(Level.SEVERE, "Error during deepCopy", ex); return null; } } @@ -1979,6 +1979,7 @@ public class AVM2Code implements Serializable { public boolean jumpUsed = false; public boolean skipUsed = false; + public Set casesUsed = new HashSet<>(); } @SuppressWarnings("unchecked") @@ -2029,7 +2030,53 @@ public class AVM2Code implements Serializable { if (ins.isBranch() || ins.isJump()) { List branches = ins.getBranches(code); - if ((ins instanceof AVM2Instruction) && ((AVM2Instruction) ins).definition instanceof IfTypeIns + if ((ins instanceof AVM2Instruction) && (((AVM2Instruction) ins).definition instanceof LookupSwitchIns) + && (!stack.isEmpty()) && (stack.peek().isCompileTime()) && (!stack.peek().hasSideEffect())) { + int c = (int) stack.peek().toNumber(); + Decision dec = new Decision(); + if (decisions.containsKey(ins)) { + dec = decisions.get(ins); + } else { + decisions.put(ins, dec); + } + dec.casesUsed.add(c); + GraphTargetItem tar = stack.pop(); + + int numcases = branches.size() - 1; + int selCase = -1; + if (c < 0 || c >= numcases) { + selCase = 0; + } else { + selCase = 1 + c; + } + + if (secondPass) { + if (dec.casesUsed.size() == 1) { + int sel = -1; + for (int u : dec.casesUsed) { + sel = u; + } + int selOperand = -1; + if (sel < 0 || sel >= numcases) { + selOperand = 0; + } else { + selOperand = 2 + sel; + } + AVM2Instruction ains = (AVM2Instruction) ins; + if (ains.replaceWith == null) { + ains.replaceWith = new ArrayList<>(); + } + ains.replaceWith.add(new ControlFlowTag("appendjump", code.adr2pos(code.pos2adr(ip) + ((AVM2Instruction) ins).operands[selOperand]))); + for (GraphSourceItemPos pos : tar.getNeededSources()) { + if (pos.item != ins) { + pos.item.setIgnored(true); + } + } + } + } + ip = branches.get(selCase); + continue; + } else if ((ins instanceof AVM2Instruction) && ((AVM2Instruction) ins).definition instanceof IfTypeIns && (!(((AVM2Instruction) ins).definition instanceof JumpIns)) && (!stack.isEmpty()) && (stack.peek().isCompileTime()) && (!stack.peek().hasSideEffect())) { boolean condition = stack.peek().toBoolean(); if (debugMode) { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java index 7fbf718bb..dd1cfa414 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java @@ -383,7 +383,20 @@ public class AVM2Graph extends Graph { ret.addAll(output); return ret; } - + if(part.nextParts.size() == 2){ + if(stack.peek() instanceof StrictNeqTreeItem){ + System.out.println("1"); + if(part.nextParts.get(1).getHeight() >= 2){ + System.out.println("2"); + if(code.code.get(code.fixIPAfterDebugLine(part.nextParts.get(1).start)).definition instanceof PushIntegerTypeIns){ + System.out.println("3"); + if(code.code.get(part.nextParts.get(1).nextParts.get(0).end).definition instanceof LookupSwitchIns){ + System.out.println("4"); + } + } + } + } + } if (((part.nextParts.size() == 2) && (!stack.isEmpty()) && (stack.peek() instanceof StrictEqTreeItem) diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/StrictNeqTreeItem.java b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/StrictNeqTreeItem.java index 468b4d04d..711081e5b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/StrictNeqTreeItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/avm2/treemodel/operations/StrictNeqTreeItem.java @@ -34,6 +34,6 @@ public class StrictNeqTreeItem extends BinaryOpItem implements LogicalOpItem { @Override public boolean toBoolean() { - return (leftSide.toBoolean() != rightSide.toBoolean()) && (leftSide.toNumber() != rightSide.toNumber()); + return !((leftSide.toBoolean() == rightSide.toBoolean()) && (leftSide.toNumber() == rightSide.toNumber())); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java b/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java index d726a5a56..00c237048 100644 --- a/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java +++ b/trunk/src/com/jpexs/decompiler/flash/graph/Graph.java @@ -1743,8 +1743,8 @@ public class Graph { vis.add(p); } first = false; - } - SwitchItem sw = new SwitchItem(null, null, switchedItem, caseValues, caseCommands, defaultCommands, valueMappings); + } + SwitchItem sw = new SwitchItem(null, swLoop, switchedItem, caseValues, caseCommands, defaultCommands, valueMappings); currentRet.add(sw); swLoop.phase = 2; if (next != null) { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java index 3c5ea9281..3ed8d846c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFrame.java @@ -1732,6 +1732,11 @@ public class MainFrame extends AppFrame implements ActionListener, TreeSelection if (JOptionPane.showConfirmDialog(this, translate("message.confirm.autodeobfuscate") + "\r\n" + (autoDeobfuscateMenuItem.getState() ? translate("message.confirm.on") : translate("message.confirm.off")), translate("message.confirm"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { Configuration.setConfig("autoDeobfuscate", autoDeobfuscateMenuItem.getState()); clearCache(); + if (abcPanel != null) { + abcPanel.reload(); + } + reload(true); + doFilter(); } else { autoDeobfuscateMenuItem.setState(!autoDeobfuscateMenuItem.getState()); }