use of jadx.core.deobf.ClsAliasPair in project jadx by skylot.
the class KotlinMetadataUtils method getClassAlias.
/**
* Try to get class info from Kotlin Metadata annotation
*/
@Nullable
public static ClsAliasPair getClassAlias(ClassNode cls) {
IAnnotation metadataAnnotation = cls.getAnnotation(KOTLIN_METADATA_ANNOTATION);
List<EncodedValue> d2Param = getParamAsList(metadataAnnotation, KOTLIN_METADATA_D2_PARAMETER);
if (d2Param == null || d2Param.isEmpty()) {
return null;
}
EncodedValue firstValue = d2Param.get(0);
if (firstValue == null || firstValue.getType() != EncodedType.ENCODED_STRING) {
return null;
}
try {
String rawClassName = ((String) firstValue.getValue()).trim();
if (rawClassName.isEmpty()) {
return null;
}
String clsName = Utils.cleanObjectName(rawClassName);
ClsAliasPair alias = splitAndCheckClsName(cls, clsName);
if (alias != null) {
RenameReasonAttr.forNode(cls).append("from Kotlin metadata");
return alias;
}
} catch (Exception e) {
LOG.error("Failed to parse kotlin metadata", e);
}
return null;
}
use of jadx.core.deobf.ClsAliasPair in project jadx by skylot.
the class KotlinMetadataUtils method splitAndCheckClsName.
// Don't use ClassInfo facility to not pollute class into cache
private static ClsAliasPair splitAndCheckClsName(ClassNode originCls, String fullClsName) {
if (!NameMapper.isValidFullIdentifier(fullClsName)) {
return null;
}
String pkg;
String name;
int dot = fullClsName.lastIndexOf('.');
if (dot == -1) {
pkg = "";
name = fullClsName;
} else {
pkg = fullClsName.substring(0, dot);
name = fullClsName.substring(dot + 1);
}
ClassInfo originClsInfo = originCls.getClassInfo();
String originName = originClsInfo.getShortName();
if (originName.equals(name) || name.contains("$") || !NameMapper.isValidIdentifier(name) || countPkgParts(originClsInfo.getPackage()) != countPkgParts(pkg) || pkg.startsWith("java.")) {
return null;
}
ClassNode newClsNode = originCls.root().resolveClass(fullClsName);
if (newClsNode != null) {
// class with alias name already exist
return null;
}
return new ClsAliasPair(pkg, name);
}
Aggregations