Search in sources :

Example 1 with RenameReasonAttr

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

the class RenameVisitor method checkClassName.

private static void checkClassName(Deobfuscator deobfuscator, ClassNode cls, JadxArgs args) {
    ClassInfo classInfo = cls.getClassInfo();
    String clsName = classInfo.getAliasShortName();
    String newShortName = fixClsShortName(args, clsName);
    if (newShortName == null) {
        // rename failed, use deobfuscator
        String deobfName = deobfuscator.getClsAlias(cls);
        classInfo.changeShortName(deobfName);
        cls.addAttr(new RenameReasonAttr(cls).notPrintable());
        return;
    }
    if (!newShortName.equals(clsName)) {
        classInfo.changeShortName(newShortName);
        cls.addAttr(new RenameReasonAttr(cls).append("invalid class name"));
    }
    if (classInfo.isInner() && args.isRenameValid()) {
        // check inner classes names
        ClassInfo parentClass = classInfo.getParentClass();
        while (parentClass != null) {
            if (parentClass.getAliasShortName().equals(newShortName)) {
                String clsAlias = deobfuscator.getClsAlias(cls);
                classInfo.changeShortName(clsAlias);
                cls.addAttr(new RenameReasonAttr(cls).append("collision with other inner class name"));
                break;
            }
            parentClass = parentClass.getParentClass();
        }
    }
    checkPackage(deobfuscator, cls, classInfo, args);
}
Also used : RenameReasonAttr(jadx.core.dex.attributes.nodes.RenameReasonAttr) ClassInfo(jadx.core.dex.info.ClassInfo)

Example 2 with RenameReasonAttr

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

the class RenameVisitor method checkMethods.

private static void checkMethods(Deobfuscator deobfuscator, ClassNode cls, JadxArgs args) {
    List<MethodNode> methods = new ArrayList<>(cls.getMethods().size());
    for (MethodNode method : cls.getMethods()) {
        if (!method.getAccessFlags().isConstructor()) {
            methods.add(method);
        }
    }
    for (MethodNode mth : methods) {
        String alias = mth.getAlias();
        boolean notValid = args.isRenameValid() && !NameMapper.isValidIdentifier(alias);
        boolean notPrintable = args.isRenamePrintable() && !NameMapper.isAllCharsPrintable(alias);
        if (notValid || notPrintable) {
            deobfuscator.forceRenameMethod(mth);
            mth.addAttr(new RenameReasonAttr(mth, notValid, notPrintable));
        }
    }
    // Rename methods with same signature
    if (args.isRenameValid()) {
        Set<String> names = new HashSet<>(methods.size());
        for (MethodNode mth : methods) {
            AccessInfo accessFlags = mth.getAccessFlags();
            if (accessFlags.isBridge() || accessFlags.isSynthetic() || mth.contains(AFlag.DONT_GENERATE)) /* this flag not set yet */
            {
                continue;
            }
            String signature = mth.getMethodInfo().makeSignature(true, false);
            if (!names.add(signature)) {
                deobfuscator.forceRenameMethod(mth);
                mth.addAttr(new RenameReasonAttr("collision with other method in class"));
            }
        }
    }
}
Also used : MethodNode(jadx.core.dex.nodes.MethodNode) RenameReasonAttr(jadx.core.dex.attributes.nodes.RenameReasonAttr) ArrayList(java.util.ArrayList) AccessInfo(jadx.core.dex.info.AccessInfo) HashSet(java.util.HashSet)

Example 3 with RenameReasonAttr

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

the class OverrideMethodVisitor method checkMethodSignatureCollisions.

private void checkMethodSignatureCollisions(MethodNode mth, boolean rename) {
    String mthName = mth.getMethodInfo().getAlias();
    String newSignature = MethodInfo.makeShortId(mthName, mth.getArgTypes(), null);
    for (MethodNode otherMth : mth.getParentClass().getMethods()) {
        String otherMthName = otherMth.getAlias();
        if (otherMthName.equals(mthName) && otherMth != mth) {
            String otherSignature = otherMth.getMethodInfo().makeSignature(true, false);
            if (otherSignature.equals(newSignature)) {
                if (rename) {
                    if (otherMth.contains(AFlag.DONT_RENAME) || otherMth.contains(AType.METHOD_OVERRIDE)) {
                        otherMth.addWarnComment("Can't rename method to resolve collision");
                    } else {
                        otherMth.getMethodInfo().setAlias(makeNewAlias(otherMth));
                        otherMth.addAttr(new RenameReasonAttr("avoid collision after fix types in other method"));
                    }
                }
                otherMth.addAttr(new MethodBridgeAttr(mth));
                return;
            }
        }
    }
}
Also used : MethodNode(jadx.core.dex.nodes.MethodNode) RenameReasonAttr(jadx.core.dex.attributes.nodes.RenameReasonAttr) MethodBridgeAttr(jadx.core.dex.attributes.nodes.MethodBridgeAttr)

Example 4 with RenameReasonAttr

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

the class CodeGenUtils method addRenamedComment.

public static void addRenamedComment(ICodeWriter code, NotificationAttrNode node, String origName) {
    if (!node.checkCommentsLevel(CommentsLevel.INFO)) {
        return;
    }
    code.startLine("/* renamed from: ").add(origName);
    RenameReasonAttr renameReasonAttr = node.get(AType.RENAME_REASON);
    if (renameReasonAttr != null) {
        code.add("  reason: ");
        code.add(renameReasonAttr.getDescription());
    }
    code.add(" */");
}
Also used : RenameReasonAttr(jadx.core.dex.attributes.nodes.RenameReasonAttr)

Example 5 with RenameReasonAttr

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

the class RenameVisitor method checkFields.

private static void checkFields(Deobfuscator deobfuscator, ClassNode cls, JadxArgs args) {
    Set<String> names = new HashSet<>();
    for (FieldNode field : cls.getFields()) {
        FieldInfo fieldInfo = field.getFieldInfo();
        String fieldName = fieldInfo.getAlias();
        boolean notUnique = !names.add(fieldName);
        boolean notValid = args.isRenameValid() && !NameMapper.isValidIdentifier(fieldName);
        boolean notPrintable = args.isRenamePrintable() && !NameMapper.isAllCharsPrintable(fieldName);
        if (notUnique || notValid || notPrintable) {
            deobfuscator.forceRenameField(field);
            field.addAttr(new RenameReasonAttr(field, notValid, notPrintable));
            if (notUnique) {
                field.addAttr(new RenameReasonAttr(field).append("collision with other field name"));
            }
        }
    }
}
Also used : FieldNode(jadx.core.dex.nodes.FieldNode) RenameReasonAttr(jadx.core.dex.attributes.nodes.RenameReasonAttr) FieldInfo(jadx.core.dex.info.FieldInfo) HashSet(java.util.HashSet)

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