diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java index d82cb23ec..469ce901c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/graph/AVM2Graph.java @@ -501,6 +501,14 @@ public class AVM2Graph extends Graph { finCatchName = AVM2Item.localRegName(new HashMap<>(), sl.regIndex); } } + } else { + //No kill ins + if (!ncatchedCommands.isEmpty() && (ncatchedCommands.get(0) instanceof SetLocalAVM2Item)) { + SetLocalAVM2Item sl = (SetLocalAVM2Item) ncatchedCommands.get(0); + if (sl.value.getThroughDuplicate().getNotCoerced() instanceof ExceptionAVM2Item) { + ncatchedCommands.remove(0); + } + } } } } @@ -1176,4 +1184,29 @@ public class AVM2Graph extends Graph { protected List filter(List list) { return avm2code.clearTemporaryRegisters(list); } + + @Override + protected void checkSwitch(BaseLocalData localData, SwitchItem switchItem, Map otherSides, List output) { + if (output.isEmpty()) { + return; + } + if (!(output.get(output.size() - 1) instanceof SetLocalAVM2Item)) { + return; + } + AVM2LocalData avm2LocalData = (AVM2LocalData) localData; + SetLocalAVM2Item setLocal = (SetLocalAVM2Item) output.get(output.size() - 1); + int setLocalIp = avm2LocalData.code.code.indexOf(setLocal.getSrc()); + Set allUsages = new HashSet<>(avm2LocalData.setLocalPosToGetLocalPos.get(setLocalIp)); + for (GraphTargetItem otherSide : otherSides.values()) { + if (otherSide instanceof LocalRegAVM2Item) { + LocalRegAVM2Item otherLog = (LocalRegAVM2Item) otherSide; + int getLocalIp = avm2LocalData.code.code.indexOf(otherLog.getSrc()); + allUsages.remove((Integer) getLocalIp); + } + } + if (allUsages.isEmpty()) { + output.remove(output.size() - 1); + switchItem.switchedObject = setLocal.value; + } + } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java index 70e965d32..55109e03b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java @@ -2374,6 +2374,7 @@ public class Graph { Map caseExpressions = new HashMap<>(); Map caseExpressionLeftSides = new HashMap<>(); Map caseExpressionRightSides = new HashMap<>(); + GraphTargetItem it = switchedItem; int defaultBranch = 0; boolean hasExpr = false; @@ -2444,6 +2445,7 @@ public class Graph { defaultBranch = ((IntegerValueTypeItem) it).intValue(); } + Map caseExpressionOtherSides = caseExpressions; if (!caseExpressionRightSides.isEmpty()) { GraphTargetItem firstItem; firstItem = (GraphTargetItem) caseExpressionRightSides.values().toArray()[0]; @@ -2457,6 +2459,7 @@ public class Graph { if (sameRight) { caseExpressions = caseExpressionLeftSides; + caseExpressionOtherSides = caseExpressionRightSides; switchedItem = firstItem; hasExpr = true; } else { @@ -2471,6 +2474,7 @@ public class Graph { } if (sameLeft) { caseExpressions = caseExpressionRightSides; + caseExpressionOtherSides = caseExpressionLeftSides; switchedItem = firstItem; hasExpr = true; } @@ -2591,7 +2595,9 @@ public class Graph { } } SwitchItem sw = new SwitchItem(null, localData.lineStartInstruction, swLoop, switchedItem, caseValues, caseCommands, valueMappings); + checkSwitch(localData, sw, caseExpressionOtherSides, currentRet); currentRet.add(sw); + //TADY swLoop.phase = 2; if (next != null) { currentRet.addAll(printGraph(foundGotos, gotoTargets, partCodes, partCodePos, visited, localData, stack, allParts, part, next, stopPart, loops, null, staticOperation, path, recursionLevel + 1)); @@ -2938,6 +2944,10 @@ public class Graph { return ret; } + protected void checkSwitch(BaseLocalData localData, SwitchItem switchItem, Map otherSides, List output) { + + } + protected void checkGraph(List allBlocks) { }