Fixed #2094 AS3 Getting register names from debug info - do not allow assigning _locX_ name to other register than X

This commit is contained in:
Jindra Petřík
2023-10-06 10:08:44 +02:00
parent ae37812b82
commit 22c56761f3
4 changed files with 17 additions and 4 deletions

View File

@@ -1434,15 +1434,27 @@ public class AVM2Code implements Cloneable {
private int toSourceCount = 0;
public Map<Integer, String> getLocalRegNamesFromDebug(ABC abc) {
public Map<Integer, String> getLocalRegNamesFromDebug(ABC abc, int maxRegs) {
Map<Integer, String> regIndexToName = new HashMap<>();
Map<String, Integer> regNameToIndex = new HashMap<>();
Set<String> reservedRegNames = new HashSet<>();
for (int i = 0; i < maxRegs; i++) {
reservedRegNames.add(String.format(Configuration.registerNameFormat.get(), i));
}
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;
if (reservedRegNames.contains(v)) {
//do not allow reassigning reserved _loc%d_ format to other local regs
continue;
}
int regIndex = ins.operands[2] + 1;
// Same name already exists, it may be wrong names inserted by obfuscator
if (regNameToIndex.containsKey(v)) {
int existingIndex = regNameToIndex.get(v);

View File

@@ -277,7 +277,7 @@ public final class MethodBody implements Cloneable {
}
if (Configuration.getLocalNamesFromDebugInfo.get()) {
Map<Integer, String> debugRegNames = getCode().getLocalRegNamesFromDebug(abc);
Map<Integer, String> debugRegNames = getCode().getLocalRegNamesFromDebug(abc, max_regs);
for (int k : debugRegNames.keySet()) {
ret.put(k, debugRegNames.get(k));
}

View File

@@ -310,7 +310,7 @@ public class MethodInfo {
public GraphTextWriter getParamStr(GraphTextWriter writer, AVM2ConstantPool constants, MethodBody body, ABC abc, List<DottedChain> fullyQualifiedNames) {
Map<Integer, String> localRegNames = new HashMap<>();
if (body != null && Configuration.getLocalNamesFromDebugInfo.get()) {
localRegNames = body.getCode().getLocalRegNamesFromDebug(abc);
localRegNames = body.getCode().getLocalRegNamesFromDebug(abc, body.max_regs);
}
for (int i = 0; i < param_types.length; i++) {