From 9b75584339059ff9de649ecbe30701f167fb8455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Fri, 6 Jan 2023 22:36:35 +0100 Subject: [PATCH] Fixed #1933 AS3 - Detection of variable names from debug info on multiple debug ins with same regindex --- CHANGELOG.md | 2 ++ .../decompiler/flash/abc/avm2/AVM2Code.java | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 443bf6e76..89b4ef7b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file. - GFX - DefineExternalImage2 display and correct handling if standalone - [#1931] DefineSprite rectange calculation (incorrect export dimensions) - [#1929], [#1932] Wrong subsprite frames display +- [#1933] AS3 - Detection of variable names from debug info on multiple debug ins with same regindex ## [18.3.0] - 2023-01-01 ### Added @@ -2844,6 +2845,7 @@ All notable changes to this project will be documented in this file. [#1931]: https://www.free-decompiler.com/flash/issues/1931 [#1929]: https://www.free-decompiler.com/flash/issues/1929 [#1932]: https://www.free-decompiler.com/flash/issues/1932 +[#1933]: https://www.free-decompiler.com/flash/issues/1933 [#1913]: https://www.free-decompiler.com/flash/issues/1913 [#1905]: https://www.free-decompiler.com/flash/issues/1905 [#1915]: https://www.free-decompiler.com/flash/issues/1915 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index 9b296104a..6c90d8ea1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -1451,23 +1451,30 @@ public class AVM2Code implements Cloneable { private int toSourceCount = 0; public Map getLocalRegNamesFromDebug(ABC abc) { - Map localRegNames = new HashMap<>(); + Map regIndexToName = new HashMap<>(); + Map regNameToIndex = new HashMap<>(); for (AVM2Instruction ins : code) { if (ins.definition instanceof DebugIns) { if (ins.operands[0] == 1) { String v = abc.constants.getString(ins.operands[1]); + int regIndex = ins.operands[2] + 1; // Same name already exists, it may be wrong names inserted by obfuscator - if (localRegNames.values().contains(v)) { - return new HashMap<>(); + if (regNameToIndex.containsKey(v)) { + int existingIndex = regNameToIndex.get(v); + if (existingIndex != regIndex) { //if it exists and has different regIndex + return new HashMap<>(); //ignore debug info + } + //it may exist and had same reg index, this is okay } - localRegNames.put(ins.operands[2] + 1, v); + regNameToIndex.put(v, regIndex); + regIndexToName.put(regIndex, v); } } } // TODO: Make this immune to using existing multinames (?) - return localRegNames; + return regIndexToName; } private Map> killedRegs = new HashMap<>();