Search in sources :

Example 51 with FieldNode

use of jadx.core.dex.nodes.FieldNode in project jadx by skylot.

the class Deobfuscator method processClass.

private void processClass(ClassNode cls) {
    if (isR(cls.getParentClass())) {
        return;
    }
    ClassInfo clsInfo = cls.getClassInfo();
    DeobfClsInfo deobfClsInfo = clsMap.get(clsInfo);
    if (deobfClsInfo != null) {
        clsInfo.changeShortName(deobfClsInfo.getAlias());
        PackageNode pkgNode = deobfClsInfo.getPkg();
        if (!clsInfo.isInner() && pkgNode.hasAnyAlias()) {
            clsInfo.changePkg(pkgNode.getFullAlias());
        }
    } else if (!clsInfo.isInner()) {
        // check if package renamed
        PackageNode pkgNode = getPackageNode(clsInfo.getPackage(), false);
        if (pkgNode != null && pkgNode.hasAnyAlias()) {
            clsInfo.changePkg(pkgNode.getFullAlias());
        }
    }
    for (FieldNode field : cls.getFields()) {
        if (field.contains(AFlag.DONT_RENAME)) {
            continue;
        }
        renameField(field);
    }
    mthProcessQueue.addAll(cls.getMethods());
    for (ClassNode innerCls : cls.getInnerClasses()) {
        processClass(innerCls);
    }
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) FieldNode(jadx.core.dex.nodes.FieldNode) ClassInfo(jadx.core.dex.info.ClassInfo)

Example 52 with FieldNode

use of jadx.core.dex.nodes.FieldNode in project jadx by skylot.

the class JsonMappingGen method addFields.

private static void addFields(ClassNode cls, JsonClsMapping jsonCls) {
    List<FieldNode> fields = cls.getFields();
    if (fields.isEmpty()) {
        return;
    }
    jsonCls.setFields(new ArrayList<>(fields.size()));
    for (FieldNode field : fields) {
        JsonFieldMapping jsonField = new JsonFieldMapping();
        jsonField.setName(field.getName());
        jsonField.setAlias(field.getAlias());
        jsonCls.getFields().add(jsonField);
    }
}
Also used : FieldNode(jadx.core.dex.nodes.FieldNode) JsonFieldMapping(jadx.core.codegen.json.mapping.JsonFieldMapping)

Example 53 with FieldNode

use of jadx.core.dex.nodes.FieldNode in project jadx by skylot.

the class JavaClass method loadLists.

private synchronized void loadLists() {
    if (listsLoaded) {
        return;
    }
    listsLoaded = true;
    decompile();
    JadxDecompiler rootDecompiler = getRootDecompiler();
    int inClsCount = cls.getInnerClasses().size();
    if (inClsCount != 0) {
        List<JavaClass> list = new ArrayList<>(inClsCount);
        for (ClassNode inner : cls.getInnerClasses()) {
            if (!inner.contains(AFlag.DONT_GENERATE)) {
                JavaClass javaClass = rootDecompiler.convertClassNode(inner);
                javaClass.loadLists();
                list.add(javaClass);
            }
        }
        this.innerClasses = Collections.unmodifiableList(list);
    }
    int inlinedClsCount = cls.getInlinedClasses().size();
    if (inlinedClsCount != 0) {
        List<JavaClass> list = new ArrayList<>(inlinedClsCount);
        for (ClassNode inner : cls.getInlinedClasses()) {
            JavaClass javaClass = rootDecompiler.convertClassNode(inner);
            javaClass.loadLists();
            list.add(javaClass);
        }
        this.inlinedClasses = Collections.unmodifiableList(list);
    }
    int fieldsCount = cls.getFields().size();
    if (fieldsCount != 0) {
        List<JavaField> flds = new ArrayList<>(fieldsCount);
        for (FieldNode f : cls.getFields()) {
            if (!f.contains(AFlag.DONT_GENERATE)) {
                JavaField javaField = new JavaField(this, f);
                flds.add(javaField);
            }
        }
        this.fields = Collections.unmodifiableList(flds);
    }
    int methodsCount = cls.getMethods().size();
    if (methodsCount != 0) {
        List<JavaMethod> mths = new ArrayList<>(methodsCount);
        for (MethodNode m : cls.getMethods()) {
            if (!m.contains(AFlag.DONT_GENERATE)) {
                JavaMethod javaMethod = new JavaMethod(this, m);
                mths.add(javaMethod);
            }
        }
        mths.sort(Comparator.comparing(JavaMethod::getName));
        this.methods = Collections.unmodifiableList(mths);
    }
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) FieldNode(jadx.core.dex.nodes.FieldNode) MethodNode(jadx.core.dex.nodes.MethodNode) ArrayList(java.util.ArrayList)

Example 54 with FieldNode

use of jadx.core.dex.nodes.FieldNode in project jadx by skylot.

the class ModVisitor method fixFieldUsage.

/**
 * If field is not visible from use site => cast to origin class
 */
private static void fixFieldUsage(MethodNode mth, IndexInsnNode insn) {
    InsnArg instanceArg = insn.getArg(insn.getType() == InsnType.IGET ? 0 : 1);
    if (instanceArg.contains(AFlag.SUPER)) {
        return;
    }
    if (instanceArg.isInsnWrap() && ((InsnWrapArg) instanceArg).getWrapInsn().getType() == InsnType.CAST) {
        return;
    }
    FieldInfo fieldInfo = (FieldInfo) insn.getIndex();
    ArgType clsType = fieldInfo.getDeclClass().getType();
    ArgType instanceType = instanceArg.getType();
    if (Objects.equals(clsType, instanceType)) {
        // cast not needed
        return;
    }
    FieldNode fieldNode = mth.root().resolveField(fieldInfo);
    if (fieldNode == null) {
        // unknown field
        TypeCompareEnum result = mth.root().getTypeCompare().compareTypes(instanceType, clsType);
        if (result.isEqual() || (result == TypeCompareEnum.NARROW_BY_GENERIC && !instanceType.isGenericType())) {
            return;
        }
    } else if (isFieldVisibleInMethod(fieldNode, mth)) {
        return;
    }
    // insert cast
    IndexInsnNode castInsn = new IndexInsnNode(InsnType.CAST, clsType, 1);
    castInsn.addArg(instanceArg.duplicate());
    castInsn.add(AFlag.SYNTHETIC);
    castInsn.add(AFlag.EXPLICIT_CAST);
    InsnArg castArg = InsnArg.wrapInsnIntoArg(castInsn);
    castArg.setType(clsType);
    insn.replaceArg(instanceArg, castArg);
    InsnRemover.unbindArgUsage(mth, instanceArg);
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) FieldNode(jadx.core.dex.nodes.FieldNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) TypeCompareEnum(jadx.core.dex.visitors.typeinference.TypeCompareEnum) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) FieldInfo(jadx.core.dex.info.FieldInfo)

Example 55 with FieldNode

use of jadx.core.dex.nodes.FieldNode in project jadx by skylot.

the class ReSugarCode method replaceConstInArg.

private static InsnArg replaceConstInArg(MethodNode mth, InsnArg valueArg) {
    if (valueArg.isLiteral()) {
        FieldNode f = mth.getParentClass().getConstFieldByLiteralArg((LiteralArg) valueArg);
        if (f != null) {
            InsnNode fGet = new IndexInsnNode(InsnType.SGET, f.getFieldInfo(), 0);
            InsnArg arg = InsnArg.wrapArg(fGet);
            f.addUseIn(mth);
            return arg;
        }
    }
    return valueArg.duplicate();
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) FieldNode(jadx.core.dex.nodes.FieldNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode)

Aggregations

FieldNode (jadx.core.dex.nodes.FieldNode)70 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)30 InsnNode (jadx.core.dex.nodes.InsnNode)28 ClassNode (jadx.core.dex.nodes.ClassNode)26 FieldInfo (jadx.core.dex.info.FieldInfo)23 InsnArg (jadx.core.dex.instructions.args.InsnArg)20 MethodNode (jadx.core.dex.nodes.MethodNode)14 ArrayList (java.util.ArrayList)11 ArgType (jadx.core.dex.instructions.args.ArgType)10 InsnWrapArg (jadx.core.dex.instructions.args.InsnWrapArg)10 Nullable (org.jetbrains.annotations.Nullable)10 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)9 ClassInfo (jadx.core.dex.info.ClassInfo)6 ConstClassNode (jadx.core.dex.instructions.ConstClassNode)6 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)6 FieldReplaceAttr (jadx.core.dex.attributes.nodes.FieldReplaceAttr)5 MethodInfo (jadx.core.dex.info.MethodInfo)5 InsnType (jadx.core.dex.instructions.InsnType)5 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)5 BlockNode (jadx.core.dex.nodes.BlockNode)4