Search in sources :

Example 11 with ClassInfo

use of jadx.core.dex.info.ClassInfo in project jadx by skylot.

the class RenameVisitor method checkClassName.

private void checkClassName(ClassNode cls) {
    ClassInfo classInfo = cls.getClassInfo();
    String clsName = classInfo.getAlias().getShortName();
    String newShortName = null;
    char firstChar = clsName.charAt(0);
    if (Character.isDigit(firstChar)) {
        newShortName = Consts.ANONYMOUS_CLASS_PREFIX + clsName;
    } else if (firstChar == '$') {
        newShortName = "C" + clsName;
    }
    if (newShortName != null) {
        classInfo.rename(cls.dex(), classInfo.makeFullClsName(newShortName, true));
    }
    if (classInfo.getAlias().getPackage().isEmpty()) {
        String fullName = classInfo.makeFullClsName(classInfo.getAlias().getShortName(), true);
        String newFullName = Consts.DEFAULT_PACKAGE_NAME + "." + fullName;
        classInfo.rename(cls.dex(), newFullName);
    }
}
Also used : ClassInfo(jadx.core.dex.info.ClassInfo)

Example 12 with ClassInfo

use of jadx.core.dex.info.ClassInfo in project jadx by skylot.

the class RenameVisitor method checkClasses.

private void checkClasses(RootNode root) {
    Set<String> clsNames = new HashSet<String>();
    for (ClassNode cls : root.getClasses(true)) {
        checkClassName(cls);
        if (!CASE_SENSITIVE_FS) {
            ClassInfo classInfo = cls.getClassInfo();
            String clsFileName = classInfo.getAlias().getFullPath();
            if (!clsNames.add(clsFileName.toLowerCase())) {
                String newShortName = deobfuscator.getClsAlias(cls);
                String newFullName = classInfo.makeFullClsName(newShortName, true);
                classInfo.rename(cls.dex(), newFullName);
                clsNames.add(classInfo.getAlias().getFullPath().toLowerCase());
            }
        }
    }
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) HashSet(java.util.HashSet) ClassInfo(jadx.core.dex.info.ClassInfo)

Example 13 with ClassInfo

use of jadx.core.dex.info.ClassInfo in project jadx by skylot.

the class ModVisitor method processAnonymousConstructor.

private static void processAnonymousConstructor(MethodNode mth, ConstructorInsn co) {
    MethodInfo callMth = co.getCallMth();
    MethodNode callMthNode = mth.dex().resolveMethod(callMth);
    if (callMthNode == null) {
        return;
    }
    ClassNode classNode = callMthNode.getParentClass();
    ClassInfo classInfo = classNode.getClassInfo();
    ClassNode parentClass = mth.getParentClass();
    if (!classInfo.isInner() || !Character.isDigit(classInfo.getShortName().charAt(0)) || !parentClass.getInnerClasses().contains(classNode)) {
        return;
    }
    if (!classNode.getAccessFlags().isStatic() && (callMth.getArgsCount() == 0 || !callMth.getArgumentsTypes().get(0).equals(parentClass.getClassInfo().getType()))) {
        return;
    }
    // TODO: calculate this constructor and other constructor usage
    Map<InsnArg, FieldNode> argsMap = getArgsToFieldsMapping(callMthNode, co);
    if (argsMap.isEmpty()) {
        return;
    }
    // all checks passed
    classNode.add(AFlag.ANONYMOUS_CLASS);
    callMthNode.add(AFlag.DONT_GENERATE);
    for (Map.Entry<InsnArg, FieldNode> entry : argsMap.entrySet()) {
        FieldNode field = entry.getValue();
        if (field == null) {
            continue;
        }
        InsnArg arg = entry.getKey();
        field.addAttr(new FieldReplaceAttr(arg));
        field.add(AFlag.DONT_GENERATE);
        if (arg.isRegister()) {
            RegisterArg reg = (RegisterArg) arg;
            SSAVar sVar = reg.getSVar();
            if (sVar != null) {
                sVar.add(AFlag.FINAL);
                sVar.add(AFlag.DONT_INLINE);
            }
            reg.add(AFlag.SKIP_ARG);
        }
    }
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) ConstClassNode(jadx.core.dex.instructions.ConstClassNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) MethodNode(jadx.core.dex.nodes.MethodNode) FieldNode(jadx.core.dex.nodes.FieldNode) SSAVar(jadx.core.dex.instructions.args.SSAVar) InsnArg(jadx.core.dex.instructions.args.InsnArg) FieldReplaceAttr(jadx.core.dex.attributes.nodes.FieldReplaceAttr) MethodInfo(jadx.core.dex.info.MethodInfo) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ClassInfo(jadx.core.dex.info.ClassInfo)

Example 14 with ClassInfo

use of jadx.core.dex.info.ClassInfo in project jadx by skylot.

the class AndroidResourcesUtils method handleAppResField.

public static boolean handleAppResField(CodeWriter code, ClassGen clsGen, ClassInfo declClass) {
    ClassInfo parentClass = declClass.getParentClass();
    if (parentClass != null && parentClass.getShortName().equals("R")) {
        clsGen.useClass(code, parentClass);
        code.add('.');
        code.add(declClass.getAlias().getShortName());
        return true;
    }
    return false;
}
Also used : ClassInfo(jadx.core.dex.info.ClassInfo)

Example 15 with ClassInfo

use of jadx.core.dex.info.ClassInfo in project jadx by skylot.

the class NameGen method makeNameForObject.

private String makeNameForObject(ArgType type) {
    if (type.isObject()) {
        String alias = getAliasForObject(type.getObject());
        if (alias != null) {
            return alias;
        }
        ClassInfo extClsInfo = ClassInfo.extCls(mth.dex(), type);
        String shortName = extClsInfo.getShortName();
        String vName = fromName(shortName);
        if (vName != null) {
            return vName;
        }
    }
    return StringUtils.escape(type.toString());
}
Also used : ClassInfo(jadx.core.dex.info.ClassInfo)

Aggregations

ClassInfo (jadx.core.dex.info.ClassInfo)21 ClassNode (jadx.core.dex.nodes.ClassNode)6 FieldNode (jadx.core.dex.nodes.FieldNode)5 MethodNode (jadx.core.dex.nodes.MethodNode)5 MethodInfo (jadx.core.dex.info.MethodInfo)4 ArrayList (java.util.ArrayList)4 FieldReplaceAttr (jadx.core.dex.attributes.nodes.FieldReplaceAttr)2 FieldInfo (jadx.core.dex.info.FieldInfo)2 InsnArg (jadx.core.dex.instructions.args.InsnArg)2 HashSet (java.util.HashSet)2 CatchHandler (com.android.dex.Code.CatchHandler)1 Try (com.android.dex.Code.Try)1 EnumClassAttr (jadx.core.dex.attributes.nodes.EnumClassAttr)1 EnumField (jadx.core.dex.attributes.nodes.EnumClassAttr.EnumField)1 SourceFileAttr (jadx.core.dex.attributes.nodes.SourceFileAttr)1 ConstClassNode (jadx.core.dex.instructions.ConstClassNode)1 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)1 InvokeType (jadx.core.dex.instructions.InvokeType)1 ArgType (jadx.core.dex.instructions.args.ArgType)1 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)1