Skip to content

Commit

Permalink
feat(deobf): improve deobfuscated class names by including class prop…
Browse files Browse the repository at this point in the history
…erties and info about super class respectively implemented interfaces (PR #969)
  • Loading branch information
jpstotz authored Aug 21, 2020
1 parent 2d641bf commit 1774dc7
Showing 1 changed file with 66 additions and 1 deletion.
67 changes: 66 additions & 1 deletion jadx-core/src/main/java/jadx/core/deobf/Deobfuscator.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ private String makeClsAlias(ClassNode cls) {
if (alias == null) {
if (metadataClassName.isEmpty()) {
String clsName = classInfo.getShortName();
alias = String.format("C%04d%s", clsIndex++, prepareNamePart(clsName));
String prefix = makeClsPrefix(cls);
alias = String.format("%sC%04d%s", prefix, clsIndex++, prepareNamePart(clsName));
} else {
alias = metadataClassName;
}
Expand All @@ -425,6 +426,70 @@ private String makeClsAlias(ClassNode cls) {
return alias;
}

/**
* Generate a prefix for a class name that bases on certain class properties, certain
* extended superclasses or implemented interfaces.
*
* @param cls
* @return
*/
private String makeClsPrefix(ClassNode cls) {
if (cls.isEnum()) {
return "Enum";
}
String result = "";
if (cls.getAccessFlags().isAbstract()) {
result += "Abstract";
}

// Process current class and all super classes
ClassNode currentCls = cls;
outerLoop: while (currentCls != null) {
if (currentCls.getSuperClass() != null) {
String superClsName = currentCls.getSuperClass().getObject();
if (superClsName.startsWith("android.app.")) {
// e.g. Activity or Fragment
result += superClsName.substring(12);
break;
} else if (superClsName.startsWith("android.os.")) {
// e.g. AsyncTask
result += superClsName.substring(11);
break;
}
}
for (ArgType intf : cls.getInterfaces()) {
String intfClsName = intf.getObject();
if (intfClsName.equals("java.lang.Runnable")) {
result += "Runnable";
break outerLoop;
} else if (intfClsName.startsWith("java.util.concurrent.")) {
// e.g. Callable
result += intfClsName.substring(21);
break outerLoop;
} else if (intfClsName.startsWith("android.view.")) {
// e.g. View.OnClickListener
result += intfClsName.substring(13);
break outerLoop;
} else if (intfClsName.startsWith("android.content.")) {
// e.g. DialogInterface.OnClickListener
result += intfClsName.substring(16);
break outerLoop;
}
}
if (currentCls.getSuperClass() == null) {
break;
}
currentCls = cls.root().resolveClass(currentCls.getSuperClass());
}
return result;
}

/**
* Try to get class name form Kotlin meta data
*
* @param cls
* @return
*/
@Nullable
private String getRawClassNameFromMetadata(ClassNode cls) {
if (cls.getAnnotation(KOTLIN_METADATA_ANNOTATION) != null
Expand Down

0 comments on commit 1774dc7

Please sign in to comment.