Fixed #1970 AS2 Renaming invalid identifiers for direct strings (no constant indices)

Fixed #1970 AS2 Renaming invalid identifiers IndexOutOfBounds on invalid constant index (obfuscated code, etc.)
This commit is contained in:
Jindra Petřík
2023-02-12 19:07:50 +01:00
parent 5ff41c89dd
commit 851dc7e922
3 changed files with 22 additions and 33 deletions

View File

@@ -2747,6 +2747,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
}
private int renameAS2Identifiers(RenameType renameType, Map<DottedChain, DottedChain> selected) throws InterruptedException {
boolean wrongConstantIndices = false;
HashMap<ASMSource, ActionList> actionsMap = new HashMap<>();
List<GraphSourceItem> allFunctions = new ArrayList<>();
List<MyEntry<DirectValueActionItem, ConstantPool>> allVariableNames = new ArrayList<>();
@@ -2963,7 +2964,11 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
pool.constants.add(changed);
ci.index = pool.constants.size() - 1;
} else {
pool.constants.set(ci.index, changed);
if (ci.index >= pool.constants.size()) {
wrongConstantIndices = true;
} else {
pool.constants.set(ci.index, changed);
}
}
} else {
pu.replacement.set(it.getKey().pos, changed);
@@ -2983,6 +2988,9 @@ public final class SWF implements SWFContainerItem, Timelined, Openable {
}
deobfuscation.deobfuscateInstanceNames(false, deobfuscated, renameType, getTags(), selected);
if (wrongConstantIndices) {
logger.warning("Cannot properly rename some invalid AS2 identifiers as there exist unresolved constant indices. It might be fixed by turning Deobfuscation on and try to rename identifiers again.");
}
return ret;
}