From 322991be68f80d4f1265f3d605d8c204d47efc86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Wed, 3 Feb 2021 07:27:22 +0100 Subject: [PATCH] register usage detection - do not walk dead code --- .../flash/abc/avm2/graph/AVM2Graph.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) 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 40f225fad..d70203edb 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 @@ -537,17 +537,26 @@ public class AVM2Graph extends Graph { Map setLocalPosToRegisterId = new HashMap<>(); - for (int ip = 0; ip < avm2code.code.size(); ip++) { - AVM2Instruction ins = avm2code.code.get(ip); - if (ins.definition instanceof SetLocalTypeIns) { - int regId = ((SetLocalTypeIns) ins.definition).getRegisterId(ins); - setLocalPosToGetLocalPos.put(ip, new TreeSet<>()); - setLocalPosToRegisterId.put(ip, regId); + for (GraphPart p : allParts) { + if (p.start < 0) { + continue; + } + for (int ip = p.start; ip <= p.end; ip++) { + AVM2Instruction ins = avm2code.code.get(ip); + if (ins.definition instanceof SetLocalTypeIns) { + int regId = ((SetLocalTypeIns) ins.definition).getRegisterId(ins); + setLocalPosToGetLocalPos.put(ip, new TreeSet<>()); + setLocalPosToRegisterId.put(ip, regId); + } } } for (int ip : setLocalPosToGetLocalPos.keySet()) { GraphPart part = searchPart(ip + 1, allParts); + + if (part == null) { //might be last part of script (?) + continue; + } walkLocalRegsUsage(localData, setLocalPosToGetLocalPos.get(ip), part, part, new HashSet<>(), ip + 1, setLocalPosToRegisterId.get(ip)); }