fix: remove invalid chars from class names (#488)
This commit is contained in:
@@ -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) {
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
.class public Ldo-;
|
||||
.super Ljava/lang/Object;
|
||||
@@ -0,0 +1,2 @@
|
||||
.class public Li-f;
|
||||
.super Ljava/lang/Object;
|
||||
Reference in New Issue
Block a user