Commit 5169dc52 authored by Skylot's avatar Skylot

fix: remove invalid chars from class names (#488)

parent f72abb28
......@@ -126,7 +126,7 @@ public class NameMapper {
* </ul><p>
*/
public static String removeInvalidCharsMiddle(String name) {
if (isValidIdentifier(name) && isAllCharsPrintable(name)) {
if (isValidIdentifier(name)) {
return name;
}
int len = name.length();
......
......@@ -92,10 +92,11 @@ public class RenameVisitor extends AbstractVisitor {
if (firstChar == '$') {
return 'C' + NameMapper.removeInvalidCharsMiddle(clsName);
}
if (!NameMapper.isValidIdentifier(clsName)) {
return 'C' + clsName;
String cleanClsName = NameMapper.removeInvalidChars(clsName, "C");
if (!NameMapper.isValidIdentifier(cleanClsName)) {
return 'C' + cleanClsName;
}
return NameMapper.removeInvalidChars(clsName, "C");
return cleanClsName;
}
private void checkFields(ClassNode cls) {
......
package jadx.tests.integration.names;
import org.junit.jupiter.api.Test;
import jadx.api.JadxDecompiler;
import jadx.api.JadxInternalAccess;
import jadx.core.dex.nodes.ClassNode;
import jadx.core.dex.nodes.RootNode;
import jadx.tests.api.SmaliTest;
public class TestClassNameWithInvalidChar extends SmaliTest {
/*
public class do- {}
public class i-f {}
*/
@Test
public void test() {
JadxDecompiler d = loadSmaliFiles("names", "TestClassNameWithInvalidChar");
RootNode root = JadxInternalAccess.getRoot(d);
for (ClassNode cls : root.getClasses(false)) {
decompileAndCheckCls(d, cls);
}
}
@Test
public void testWithDeobfuscation() {
enableDeobfuscation();
JadxDecompiler d = loadSmaliFiles("names", "TestClassNameWithInvalidChar");
RootNode root = JadxInternalAccess.getRoot(d);
for (ClassNode cls : root.getClasses(false)) {
decompileAndCheckCls(d, cls);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment