Search in sources :

Example 6 with RenameReasonAttr

use of jadx.core.dex.attributes.nodes.RenameReasonAttr in project jadx by skylot.

the class RenameVisitor method checkClasses.

private static void checkClasses(Deobfuscator deobfuscator, RootNode root, JadxArgs args) {
    List<ClassNode> classes = root.getClasses(true);
    for (ClassNode cls : classes) {
        checkClassName(deobfuscator, cls, args);
        checkFields(deobfuscator, cls, args);
        checkMethods(deobfuscator, cls, args);
    }
    if (!args.isFsCaseSensitive() && args.isRenameCaseSensitive()) {
        Set<String> clsFullPaths = new HashSet<>(classes.size());
        for (ClassNode cls : classes) {
            ClassInfo clsInfo = cls.getClassInfo();
            if (!clsFullPaths.add(clsInfo.getAliasFullPath().toLowerCase())) {
                String newShortName = deobfuscator.getClsAlias(cls);
                clsInfo.changeShortName(newShortName);
                cls.addAttr(new RenameReasonAttr(cls).append("case insensitive filesystem"));
                clsFullPaths.add(clsInfo.getAliasFullPath().toLowerCase());
            }
        }
    }
    processRootPackages(deobfuscator, root, classes);
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) RenameReasonAttr(jadx.core.dex.attributes.nodes.RenameReasonAttr) HashSet(java.util.HashSet) ClassInfo(jadx.core.dex.info.ClassInfo)

Example 7 with RenameReasonAttr

use of jadx.core.dex.attributes.nodes.RenameReasonAttr in project jadx by skylot.

the class RenameVisitor method processRootPackages.

private static void processRootPackages(Deobfuscator deobfuscator, RootNode root, List<ClassNode> classes) {
    Set<String> rootPkgs = collectRootPkgs(classes);
    root.getCacheStorage().setRootPkgs(rootPkgs);
    if (root.getArgs().isRenameValid()) {
        // rename field if collide with any root package
        for (ClassNode cls : classes) {
            for (FieldNode field : cls.getFields()) {
                if (rootPkgs.contains(field.getAlias())) {
                    deobfuscator.forceRenameField(field);
                    field.addAttr(new RenameReasonAttr("collision with root package name"));
                }
            }
        }
    }
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) FieldNode(jadx.core.dex.nodes.FieldNode) RenameReasonAttr(jadx.core.dex.attributes.nodes.RenameReasonAttr)

Aggregations

RenameReasonAttr (jadx.core.dex.attributes.nodes.RenameReasonAttr)7 HashSet (java.util.HashSet)3 ClassInfo (jadx.core.dex.info.ClassInfo)2 ClassNode (jadx.core.dex.nodes.ClassNode)2 FieldNode (jadx.core.dex.nodes.FieldNode)2 MethodNode (jadx.core.dex.nodes.MethodNode)2 MethodBridgeAttr (jadx.core.dex.attributes.nodes.MethodBridgeAttr)1 AccessInfo (jadx.core.dex.info.AccessInfo)1 FieldInfo (jadx.core.dex.info.FieldInfo)1 ArrayList (java.util.ArrayList)1