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 ff4cb6d1b..0135fb93d 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 @@ -214,6 +214,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.TraitFunction; import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter; import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; import com.jpexs.decompiler.flash.abc.types.traits.Traits; +import com.jpexs.decompiler.flash.action.Deobfuscation; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.dumpview.DumpInfo; import com.jpexs.decompiler.flash.ecma.EcmaScript; @@ -1234,15 +1235,26 @@ public class AVM2Code implements Cloneable { } private int toSourceCount = 0; - public HashMap getLocalRegNamesFromDebug(ABC abc) { - HashMap localRegNames = new HashMap<>(); + public Map getLocalRegNamesFromDebug(ABC abc) { + Map localRegNames = new HashMap<>(); + for (AVM2Instruction ins : code) { if (ins.definition instanceof DebugIns) { if (ins.operands[0] == 1) { - localRegNames.put(ins.operands[2] + 1, abc.constants.getString(ins.operands[1])); + String v = abc.constants.getString(ins.operands[1]); + if (!Deobfuscation.isValidName(v)) { //ignore obfuscated names + return new HashMap<>(); + } + //Same name already exists, it may be wrong names inserted by obfuscator + if (localRegNames.values().contains(v)) { + return new HashMap<>(); + } + localRegNames.put(ins.operands[2] + 1, v); } } } + + //TODO: Make this immune to using existing multinames (?) return localRegNames; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java index c708fd97a..b613e2333 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java @@ -38,6 +38,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -151,9 +152,11 @@ public class MethodBody implements Cloneable { pos++; } - HashMap debugRegNames = getCode().getLocalRegNamesFromDebug(abc); - for (int k : debugRegNames.keySet()) { - ret.put(k, debugRegNames.get(k)); + if (Configuration.getLocalNamesFromDebugInfo.get()) { + Map debugRegNames = getCode().getLocalRegNamesFromDebug(abc); + for (int k : debugRegNames.keySet()) { + ret.put(k, debugRegNames.get(k)); + } } return ret; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodInfo.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodInfo.java index 3a6811177..1224ebf7a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodInfo.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodInfo.java @@ -268,8 +268,8 @@ public class MethodInfo { } public GraphTextWriter getParamStr(GraphTextWriter writer, AVM2ConstantPool constants, MethodBody body, ABC abc, List fullyQualifiedNames) { - HashMap localRegNames = new HashMap<>(); - if (body != null) { + Map localRegNames = new HashMap<>(); + if (body != null && Configuration.getLocalNamesFromDebugInfo.get()) { localRegNames = body.getCode().getLocalRegNamesFromDebug(abc); } Map pdata; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java index 89ceca74d..89e1c376b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -355,6 +355,10 @@ public class Configuration { @ConfigurationDefaultString("debugConsole") public static final ConfigurationItem lastDebuggerReplaceFunction = null; + @ConfigurationDefaultBoolean(true) + @ConfigurationCategory("script") + public static final ConfigurationItem getLocalNamesFromDebugInfo = null; + private enum OSId { WINDOWS, OSX, UNIX diff --git a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties index 05782fdce..b0eb07cfd 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/AdvancedSettingsDialog.properties @@ -284,3 +284,6 @@ config.description.randomDebuggerPackage = This renames Debugger package to rand config.name.lastDebuggerReplaceFunction = (Internal) Last selected trace replacement config.description.lastDebuggerReplaceFunction = Function name which was last selected in replace trace function with debugger + +config.name.getLocalNamesFromDebugInfo = AS3: Get local register names from debug info +config.description.getLocalNamesFromDebugInfo = If debug info present, renames local registers from _loc_x_ to real names. This can be turned off because some obfuscators use invalid register names there. \ No newline at end of file