Issue #685 better local register names from debug handling, can be also turned off

This commit is contained in:
Jindra Petřík
2014-11-03 22:26:43 +01:00
parent 7c4bf38796
commit 29cd9556f2
5 changed files with 30 additions and 8 deletions
@@ -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<Integer, String> getLocalRegNamesFromDebug(ABC abc) {
HashMap<Integer, String> localRegNames = new HashMap<>();
public Map<Integer, String> getLocalRegNamesFromDebug(ABC abc) {
Map<Integer, String> 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;
}
@@ -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<Integer, String> debugRegNames = getCode().getLocalRegNamesFromDebug(abc);
for (int k : debugRegNames.keySet()) {
ret.put(k, debugRegNames.get(k));
if (Configuration.getLocalNamesFromDebugInfo.get()) {
Map<Integer, String> debugRegNames = getCode().getLocalRegNamesFromDebug(abc);
for (int k : debugRegNames.keySet()) {
ret.put(k, debugRegNames.get(k));
}
}
return ret;
}
@@ -268,8 +268,8 @@ public class MethodInfo {
}
public GraphTextWriter getParamStr(GraphTextWriter writer, AVM2ConstantPool constants, MethodBody body, ABC abc, List<String> fullyQualifiedNames) {
HashMap<Integer, String> localRegNames = new HashMap<>();
if (body != null) {
Map<Integer, String> localRegNames = new HashMap<>();
if (body != null && Configuration.getLocalNamesFromDebugInfo.get()) {
localRegNames = body.getCode().getLocalRegNamesFromDebug(abc);
}
Map<String,String> pdata;
@@ -355,6 +355,10 @@ public class Configuration {
@ConfigurationDefaultString("debugConsole")
public static final ConfigurationItem<String> lastDebuggerReplaceFunction = null;
@ConfigurationDefaultBoolean(true)
@ConfigurationCategory("script")
public static final ConfigurationItem<Boolean> getLocalNamesFromDebugInfo = null;
private enum OSId {
WINDOWS, OSX, UNIX