core: ignore debug info with bad variable names

This commit is contained in:
Skylot
2018-06-16 17:50:43 +03:00
parent 45f5e0cb04
commit ee74c4d870
3 changed files with 21 additions and 3 deletions
@@ -5,6 +5,8 @@ import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import static jadx.core.utils.StringUtils.notEmpty;
public class NameMapper {
private static final Pattern VALID_JAVA_IDENTIFIER = Pattern.compile(
@@ -76,11 +78,15 @@ public class NameMapper {
}
public static boolean isValidIdentifier(String str) {
return VALID_JAVA_IDENTIFIER.matcher(str).matches() && isAllCharsPrintable(str);
return notEmpty(str)
&& VALID_JAVA_IDENTIFIER.matcher(str).matches()
&& isAllCharsPrintable(str);
}
public static boolean isValidFullIdentifier(String str) {
return VALID_JAVA_FULL_IDENTIFIER.matcher(str).matches() && isAllCharsPrintable(str);
return notEmpty(str)
&& VALID_JAVA_FULL_IDENTIFIER.matcher(str).matches()
&& isAllCharsPrintable(str);
}
public static boolean isPrintableChar(int c) {
@@ -4,6 +4,7 @@ import java.util.List;
import com.android.dex.Dex.Section;
import jadx.core.deobf.NameMapper;
import jadx.core.dex.attributes.nodes.SourceFileAttr;
import jadx.core.dex.instructions.args.InsnArg;
import jadx.core.dex.instructions.args.RegisterArg;
@@ -280,7 +281,14 @@ public class DebugInfoParser {
}
if (mergeRequired) {
reg.mergeDebugInfo(var.getType(), var.getName());
applyDebugInfo(reg, var);
}
}
private static void applyDebugInfo(RegisterArg reg, LocalVar var) {
String varName = var.getName();
if (NameMapper.isValidIdentifier(varName)) {
reg.mergeDebugInfo(var.getType(), varName);
}
}
}
@@ -198,4 +198,8 @@ public class StringUtils {
sb.append(c);
}
}
public static boolean notEmpty(String str) {
return str != null && !str.isEmpty();
}
}