Skip to content

Commit

Permalink
fix: remove invalid chars from class names (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
skylot committed Mar 22, 2019
1 parent f72abb2 commit 5169dc5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion jadx-core/src/main/java/jadx/core/deobf/NameMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public static boolean isAllCharsPrintable(String str) {
* </ul><p>
*/
public static String removeInvalidCharsMiddle(String name) {
if (isValidIdentifier(name) && isAllCharsPrintable(name)) {
if (isValidIdentifier(name)) {
return name;
}
int len = name.length();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ private String fixClsShortName(String clsName) {
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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.class public Ldo-;
.super Ljava/lang/Object;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.class public Li-f;
.super Ljava/lang/Object;

0 comments on commit 5169dc5

Please sign in to comment.