fix(res): rename invalid res keys (PR #1027)

* Renames invalid res keys
* perf: store compiled resource name pattern for better performance

Co-authored-by: bagipro <bugi@MacBook-Pro.local>
Co-authored-by: Skylot <skylot@gmail.com>
This commit is contained in:
bagipro
2020-11-21 23:02:47 +03:00
committed by GitHub
parent 4bc6007a4d
commit 6f9619126a
@@ -7,6 +7,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -26,6 +27,8 @@ import jadx.core.xmlgen.entry.ValuesParser;
public class ResTableParser extends CommonBinaryParser {
private static final Logger LOG = LoggerFactory.getLogger(ResTableParser.class);
private static final Pattern VALID_RES_KEY_PATTERN = Pattern.compile("[\\w\\d-_.]+");
private static final class PackageChunk {
private final int id;
private final String name;
@@ -292,7 +295,7 @@ public class ResTableParser extends CommonBinaryParser {
if (renamedKey != null) {
return renamedKey;
}
if (!origKeyName.isEmpty()) {
if (VALID_RES_KEY_PATTERN.matcher(origKeyName).matches()) {
return origKeyName;
}
FieldNode constField = root.getConstValues().getGlobalConstFields().get(resRef);