Search in sources :

Example 6 with FieldNode

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

the class ClassModifier method removeSyntheticFields.

private static void removeSyntheticFields(ClassNode cls) {
    if (!cls.getClassInfo().isInner() || cls.getAccessFlags().isStatic()) {
        return;
    }
    // remove fields if it is synthetic and type is a outer class
    for (FieldNode field : cls.getFields()) {
        if (field.getAccessFlags().isSynthetic() && field.getType().isObject()) {
            ClassInfo clsInfo = ClassInfo.fromType(cls.dex(), field.getType());
            ClassNode fieldsCls = cls.dex().resolveClass(clsInfo);
            ClassInfo parentClass = cls.getClassInfo().getParentClass();
            if (fieldsCls != null && parentClass.equals(fieldsCls.getClassInfo()) && field.getName().startsWith("this$")) /* TODO: don't check name */
            {
                int found = 0;
                for (MethodNode mth : cls.getMethods()) {
                    if (removeFieldUsageFromConstructor(mth, field, fieldsCls)) {
                        found++;
                    }
                }
                if (found != 0) {
                    field.addAttr(new FieldReplaceAttr(parentClass));
                    field.add(AFlag.DONT_GENERATE);
                }
            }
        }
    }
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) FieldNode(jadx.core.dex.nodes.FieldNode) MethodNode(jadx.core.dex.nodes.MethodNode) FieldReplaceAttr(jadx.core.dex.attributes.nodes.FieldReplaceAttr) ClassInfo(jadx.core.dex.info.ClassInfo)

Example 7 with FieldNode

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

the class ConstStorage method getConstField.

@Nullable
public FieldNode getConstField(ClassNode cls, Object value, boolean searchGlobal) {
    DexNode dex = cls.dex();
    if (value instanceof Integer) {
        String str = resourcesNames.get(value);
        if (str != null) {
            return new ResRefField(dex, str.replace('/', '.'));
        }
    }
    if (!replaceEnabled) {
        return null;
    }
    boolean foundInGlobal = globalValues.contains(value);
    if (foundInGlobal && !searchGlobal) {
        return null;
    }
    ClassNode current = cls;
    while (current != null) {
        Values classValues = classes.get(current);
        if (classValues != null) {
            FieldNode field = classValues.get(value);
            if (field != null) {
                if (foundInGlobal) {
                    return null;
                }
                return field;
            }
        }
        ClassInfo parentClass = current.getClassInfo().getParentClass();
        if (parentClass == null) {
            break;
        }
        current = dex.resolveClass(parentClass);
    }
    if (searchGlobal) {
        return globalValues.get(value);
    }
    return null;
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) FieldNode(jadx.core.dex.nodes.FieldNode) DexNode(jadx.core.dex.nodes.DexNode) ResRefField(jadx.core.dex.nodes.ResRefField) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with FieldNode

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

the class JavaClass method load.

private void load() {
    JadxDecompiler rootDecompiler = getRootDecompiler();
    int inClsCount = cls.getInnerClasses().size();
    if (inClsCount != 0) {
        List<JavaClass> list = new ArrayList<JavaClass>(inClsCount);
        for (ClassNode inner : cls.getInnerClasses()) {
            if (!inner.contains(AFlag.DONT_GENERATE)) {
                JavaClass javaClass = new JavaClass(inner, this);
                javaClass.load();
                list.add(javaClass);
                rootDecompiler.getClassesMap().put(inner, javaClass);
            }
        }
        this.innerClasses = Collections.unmodifiableList(list);
    }
    int fieldsCount = cls.getFields().size();
    if (fieldsCount != 0) {
        List<JavaField> flds = new ArrayList<JavaField>(fieldsCount);
        for (FieldNode f : cls.getFields()) {
            if (!f.contains(AFlag.DONT_GENERATE)) {
                JavaField javaField = new JavaField(f, this);
                flds.add(javaField);
                rootDecompiler.getFieldsMap().put(f, javaField);
            }
        }
        this.fields = Collections.unmodifiableList(flds);
    }
    int methodsCount = cls.getMethods().size();
    if (methodsCount != 0) {
        List<JavaMethod> mths = new ArrayList<JavaMethod>(methodsCount);
        for (MethodNode m : cls.getMethods()) {
            if (!m.contains(AFlag.DONT_GENERATE)) {
                JavaMethod javaMethod = new JavaMethod(this, m);
                mths.add(javaMethod);
                rootDecompiler.getMethodsMap().put(m, javaMethod);
            }
        }
        Collections.sort(mths, new Comparator<JavaMethod>() {

            @Override
            public int compare(JavaMethod o1, JavaMethod o2) {
                return o1.getName().compareTo(o2.getName());
            }
        });
        this.methods = Collections.unmodifiableList(mths);
    }
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) FieldNode(jadx.core.dex.nodes.FieldNode) ArrayList(java.util.ArrayList) MethodNode(jadx.core.dex.nodes.MethodNode)

Example 9 with FieldNode

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

the class BinaryXMLParser method decodeAttribute.

private void decodeAttribute(int attributeNS, int attrValDataType, int attrValData) {
    if (attrValDataType == TYPE_REFERENCE) {
        // reference custom processing
        String name = styleMap.get(attrValData);
        if (name != null) {
            writer.add("@*");
            if (attributeNS != -1) {
                writer.add(nsPrefix).add(':');
            }
            writer.add("style/").add(name.replaceAll("_", "."));
        } else {
            FieldNode field = localStyleMap.get(attrValData);
            if (field != null) {
                String cls = field.getParentClass().getShortName().toLowerCase();
                writer.add("@");
                if ("id".equals(cls)) {
                    writer.add('+');
                }
                writer.add(cls).add("/").add(field.getName());
            } else {
                String resName = resNames.get(attrValData);
                if (resName != null) {
                    writer.add("@").add(resName);
                } else {
                    writer.add("0x").add(Integer.toHexString(attrValData));
                }
            }
        }
    } else {
        String str = valuesParser.decodeValue(attrValDataType, attrValData);
        writer.add(str != null ? str : "null");
    }
}
Also used : FieldNode(jadx.core.dex.nodes.FieldNode)

Example 10 with FieldNode

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

the class InsnUtils method getConstValueByInsn.

/**
	 * Return constant value from insn or null if not constant.
	 *
	 * @return LiteralArg, String, ArgType or null
	 */
@Nullable
public static Object getConstValueByInsn(DexNode dex, InsnNode insn) {
    switch(insn.getType()) {
        case CONST:
            return insn.getArg(0);
        case CONST_STR:
            return ((ConstStringNode) insn).getString();
        case CONST_CLASS:
            return ((ConstClassNode) insn).getClsType();
        case SGET:
            FieldInfo f = (FieldInfo) ((IndexInsnNode) insn).getIndex();
            FieldNode fieldNode = dex.resolveField(f);
            if (fieldNode != null) {
                FieldInitAttr attr = fieldNode.get(AType.FIELD_INIT);
                if (attr != null) {
                    return attr.getValue();
                }
            } else {
                LOG.warn("Field {} not found in dex {}", f, dex);
            }
            break;
    }
    return null;
}
Also used : FieldNode(jadx.core.dex.nodes.FieldNode) ConstStringNode(jadx.core.dex.instructions.ConstStringNode) ConstClassNode(jadx.core.dex.instructions.ConstClassNode) FieldInfo(jadx.core.dex.info.FieldInfo) FieldInitAttr(jadx.core.dex.nodes.parser.FieldInitAttr) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FieldNode (jadx.core.dex.nodes.FieldNode)24 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)10 ClassNode (jadx.core.dex.nodes.ClassNode)10 InsnNode (jadx.core.dex.nodes.InsnNode)10 MethodNode (jadx.core.dex.nodes.MethodNode)9 FieldInfo (jadx.core.dex.info.FieldInfo)8 InsnArg (jadx.core.dex.instructions.args.InsnArg)7 ClassInfo (jadx.core.dex.info.ClassInfo)5 ConstClassNode (jadx.core.dex.instructions.ConstClassNode)5 ArgType (jadx.core.dex.instructions.args.ArgType)4 ArrayList (java.util.ArrayList)4 FieldReplaceAttr (jadx.core.dex.attributes.nodes.FieldReplaceAttr)3 MethodInfo (jadx.core.dex.info.MethodInfo)3 InsnWrapArg (jadx.core.dex.instructions.args.InsnWrapArg)3 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)3 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)3 BlockNode (jadx.core.dex.nodes.BlockNode)3 FieldInitAttr (jadx.core.dex.nodes.parser.FieldInitAttr)3 FilledNewArrayNode (jadx.core.dex.instructions.FilledNewArrayNode)2 SwitchNode (jadx.core.dex.instructions.SwitchNode)2