Search in sources :

Example 1 with SourceFileAttr

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(" */");
    }
}
Also used : SourceFileAttr(jadx.api.plugins.input.data.attributes.types.SourceFileAttr)

Example 2 with SourceFileAttr

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;
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) SourceFileAttr(jadx.api.plugins.input.data.attributes.types.SourceFileAttr) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with SourceFileAttr

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;
}
Also used : IJadxAttribute(jadx.api.plugins.input.data.attributes.IJadxAttribute) ArrayList(java.util.ArrayList) SourceFileAttr(jadx.api.plugins.input.data.attributes.types.SourceFileAttr)

Example 4 with SourceFileAttr

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;
}
Also used : SourceFileAttr(jadx.api.plugins.input.data.attributes.types.SourceFileAttr) ClassInfo(jadx.core.dex.info.ClassInfo)

Aggregations

SourceFileAttr (jadx.api.plugins.input.data.attributes.types.SourceFileAttr)4 IJadxAttribute (jadx.api.plugins.input.data.attributes.IJadxAttribute)1 ClassInfo (jadx.core.dex.info.ClassInfo)1 ClassNode (jadx.core.dex.nodes.ClassNode)1 ArrayList (java.util.ArrayList)1 Nullable (org.jetbrains.annotations.Nullable)1