From 94c579623cf0f2c5cddf47f0de1cc84691102ef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sat, 17 Sep 2016 19:41:31 +0200 Subject: [PATCH] Collision fixer - fix also other similar names --- .../AbcMultiNameCollisionFixer.java | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AbcMultiNameCollisionFixer.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AbcMultiNameCollisionFixer.java index aa765a8c7..aa1fdf839 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AbcMultiNameCollisionFixer.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AbcMultiNameCollisionFixer.java @@ -19,10 +19,12 @@ package com.jpexs.decompiler.flash.abc.avm2.deobfuscation; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.types.Multiname; +import com.jpexs.decompiler.flash.abc.types.NamespaceSet; import com.jpexs.decompiler.flash.abc.usages.MultinameUsage; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.flash.tags.Tag; import java.util.HashSet; +import java.util.Objects; import java.util.Set; public class AbcMultiNameCollisionFixer { @@ -45,6 +47,7 @@ public class AbcMultiNameCollisionFixer { int ret = 0; for (int multiNameIndex : collidingMultinameIndices) { Multiname multiName = abc.constants.getMultiname(multiNameIndex); + int namespace = multiName.namespace_index; String oldName = abc.constants.getString(multiName.name_index); String selectedBaseName = oldName + "_" + multiName.namespace_index; String selectedName = selectedBaseName; @@ -56,7 +59,37 @@ public class AbcMultiNameCollisionFixer { newNames.add(selectedName); int newNameIndex = abc.constants.getStringId(selectedName, true); multiName.name_index = newNameIndex; - //TODO: fix all similar multinames + + //Find other names with same name and namespace which are not listed as colliding, but are related + for (int m = 1; m < abc.constants.getMultinameCount(); m++) { + if (collidingMultinameIndices.contains(m)) { + continue; + } + Multiname other = abc.constants.getMultiname(m); + if (other.hasOwnName() && other.hasOwnNamespace()) { + int otherNamespace = other.namespace_index; + if (namespace == otherNamespace) { + if (Objects.equals(oldName, abc.constants.getString(other.name_index))) { + other.name_index = newNameIndex; + ret++; + } + } + } else if (other.hasOwnName() && other.hasOwnNamespaceSet()) { + NamespaceSet otherNamespaceSet = abc.constants.getNamespaceSet(other.namespace_set_index); + //NamespaceSet with only one namespace - this one + if (otherNamespaceSet.namespaces.length == 1) { + int otherNamespace = otherNamespaceSet.namespaces[0]; + if (namespace == otherNamespace) { + if (Objects.equals(oldName, abc.constants.getString(other.name_index))) { + other.name_index = newNameIndex; + ret++; + } + } + } + //What if there are more namespaces in the set and how about runtime resolved names? + } + } + ret++; } if (ret > 0) {