use of jadx.api.plugins.input.data.attributes.types.SourceFileAttr in project jadx by skylot.
the class CodeGenUtils method addSourceFileInfo.
public static void addSourceFileInfo(ICodeWriter code, ClassNode node) {
if (!node.checkCommentsLevel(CommentsLevel.INFO)) {
return;
}
SourceFileAttr sourceFileAttr = node.get(JadxAttrType.SOURCE_FILE);
if (sourceFileAttr != null) {
String fileName = sourceFileAttr.getFileName();
String topClsName = node.getTopParentClass().getClassInfo().getShortName();
if (topClsName.contains(fileName)) {
// ignore similar name
return;
}
code.startLine("/* compiled from: ").add(fileName).add(" */");
}
}
use of jadx.api.plugins.input.data.attributes.types.SourceFileAttr in project jadx by skylot.
the class Deobfuscator method getAliasFromSourceFile.
@Nullable
private String getAliasFromSourceFile(ClassNode cls) {
SourceFileAttr sourceFileAttr = cls.get(JadxAttrType.SOURCE_FILE);
if (sourceFileAttr == null) {
return null;
}
if (cls.getClassInfo().isInner()) {
return null;
}
String name = sourceFileAttr.getFileName();
if (name.endsWith(".java")) {
name = name.substring(0, name.length() - ".java".length());
} else if (name.endsWith(".kt")) {
name = name.substring(0, name.length() - ".kt".length());
}
if (!NameMapper.isValidAndPrintable(name)) {
return null;
}
for (DeobfClsInfo deobfClsInfo : clsMap.values()) {
if (deobfClsInfo.getAlias().equals(name)) {
return null;
}
}
ClassNode otherCls = cls.root().resolveClass(cls.getPackage() + '.' + name);
if (otherCls != null) {
return null;
}
cls.remove(JadxAttrType.SOURCE_FILE);
return name;
}
use of jadx.api.plugins.input.data.attributes.types.SourceFileAttr in project jadx by skylot.
the class DexClassData method getAttributes.
@Override
public List<IJadxAttribute> getAttributes() {
List<IJadxAttribute> list = new ArrayList<>();
String sourceFile = getSourceFile();
if (sourceFile != null && !sourceFile.isEmpty()) {
list.add(new SourceFileAttr(sourceFile));
}
DexAnnotationsConvert.forClass(getType(), list, getAnnotations());
return list;
}
use of jadx.api.plugins.input.data.attributes.types.SourceFileAttr in project jadx by skylot.
the class ClassNode method checkSourceFilenameAttr.
private boolean checkSourceFilenameAttr() {
SourceFileAttr sourceFileAttr = get(JadxAttrType.SOURCE_FILE);
if (sourceFileAttr == null) {
return true;
}
String fileName = sourceFileAttr.getFileName();
if (fileName.endsWith(".java")) {
fileName = fileName.substring(0, fileName.length() - 5);
}
if (fileName.isEmpty() || fileName.equals("SourceFile")) {
return false;
}
if (clsInfo != null) {
String name = clsInfo.getShortName();
if (fileName.equals(name)) {
return false;
}
ClassInfo parentCls = clsInfo.getParentClass();
while (parentCls != null) {
String parentName = parentCls.getShortName();
if (parentName.equals(fileName) || parentName.startsWith(fileName + '$')) {
return false;
}
parentCls = parentCls.getParentClass();
}
if (fileName.contains("$") && fileName.endsWith('$' + name)) {
return false;
}
if (name.contains("$") && name.startsWith(fileName)) {
return false;
}
}
return true;
}
Aggregations