Search in sources :

Example 36 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 37 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)

Example 38 with FieldNode

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

the class RegionGen method makeSwitch.

private CodeWriter makeSwitch(SwitchRegion sw, CodeWriter code) throws CodegenException {
    SwitchNode insn = (SwitchNode) sw.getHeader().getInstructions().get(0);
    InsnArg arg = insn.getArg(0);
    code.startLine("switch (");
    addArg(code, arg, false);
    code.add(") {");
    code.incIndent();
    int size = sw.getKeys().size();
    for (int i = 0; i < size; i++) {
        List<Object> keys = sw.getKeys().get(i);
        IContainer c = sw.getCases().get(i);
        for (Object k : keys) {
            code.startLine("case ");
            if (k instanceof FieldNode) {
                FieldNode fn = (FieldNode) k;
                if (fn.getParentClass().isEnum()) {
                    code.add(fn.getAlias());
                } else {
                    staticField(code, fn.getFieldInfo());
                    // print original value, sometimes replace with incorrect field
                    FieldInitAttr valueAttr = fn.get(AType.FIELD_INIT);
                    if (valueAttr != null && valueAttr.getValue() != null) {
                        code.add(" /*").add(valueAttr.getValue().toString()).add("*/");
                    }
                }
            } else if (k instanceof Integer) {
                code.add(TypeGen.literalToString((Integer) k, arg.getType(), mth));
            } else {
                throw new JadxRuntimeException("Unexpected key in switch: " + (k != null ? k.getClass() : null));
            }
            code.add(':');
        }
        makeRegionIndent(code, c);
    }
    if (sw.getDefaultCase() != null) {
        code.startLine("default:");
        makeRegionIndent(code, sw.getDefaultCase());
    }
    code.decIndent();
    code.startLine('}');
    return code;
}
Also used : FieldNode(jadx.core.dex.nodes.FieldNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) IContainer(jadx.core.dex.nodes.IContainer) SwitchNode(jadx.core.dex.instructions.SwitchNode) FieldInitAttr(jadx.core.dex.nodes.parser.FieldInitAttr)

Example 39 with FieldNode

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

the class InsnGen method instanceField.

private void instanceField(CodeWriter code, FieldInfo field, InsnArg arg) throws CodegenException {
    ClassNode pCls = mth.getParentClass();
    FieldNode fieldNode = pCls.searchField(field);
    while (fieldNode == null && pCls.getParentClass() != pCls && pCls.getParentClass() != null) {
        pCls = pCls.getParentClass();
        fieldNode = pCls.searchField(field);
    }
    if (fieldNode != null) {
        FieldReplaceAttr replace = fieldNode.get(AType.FIELD_REPLACE);
        if (replace != null) {
            switch(replace.getReplaceType()) {
                case CLASS_INSTANCE:
                    useClass(code, replace.getClsRef());
                    code.add(".this");
                    break;
                case VAR:
                    addArg(code, replace.getVarRef());
                    break;
            }
            return;
        }
    }
    addArgDot(code, arg);
    if (fieldNode != null) {
        code.attachAnnotation(fieldNode);
    }
    code.add(field.getAlias());
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) ConstClassNode(jadx.core.dex.instructions.ConstClassNode) FieldNode(jadx.core.dex.nodes.FieldNode) FieldReplaceAttr(jadx.core.dex.attributes.nodes.FieldReplaceAttr)

Example 40 with FieldNode

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

the class InsnGen method makeStaticFieldAccess.

public static void makeStaticFieldAccess(CodeWriter code, FieldInfo field, ClassGen clsGen) {
    ClassInfo declClass = field.getDeclClass();
    boolean fieldFromThisClass = clsGen.getClassNode().getClassInfo().equals(declClass);
    if (!fieldFromThisClass) {
        // Android specific resources class handler
        if (!handleAppResField(code, clsGen, declClass)) {
            clsGen.useClass(code, declClass);
        }
        code.add('.');
    }
    FieldNode fieldNode = clsGen.getClassNode().dex().resolveField(field);
    if (fieldNode != null) {
        code.attachAnnotation(fieldNode);
    }
    code.add(field.getAlias());
}
Also used : FieldNode(jadx.core.dex.nodes.FieldNode) ClassInfo(jadx.core.dex.info.ClassInfo)

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