Search in sources :

Example 46 with FieldNode

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

the class ExtractFieldInit method moveStaticFieldsInit.

private static void moveStaticFieldsInit(ClassNode cls) {
    MethodNode classInitMth = cls.getClassInitMth();
    if (classInitMth == null) {
        return;
    }
    for (FieldNode field : cls.getFields()) {
        if (field.contains(AFlag.DONT_GENERATE)) {
            continue;
        }
        if (field.getAccessFlags().isStatic()) {
            List<InsnNode> initInsns = getFieldAssigns(classInitMth, field, InsnType.SPUT);
            if (initInsns.size() == 1) {
                InsnNode insn = initInsns.get(0);
                if (checkInsn(insn)) {
                    InstructionRemover.remove(classInitMth, insn);
                    addFieldInitAttr(classInitMth, field, insn);
                }
            }
        }
    }
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) MethodNode(jadx.core.dex.nodes.MethodNode) FieldNode(jadx.core.dex.nodes.FieldNode)

Example 47 with FieldNode

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

the class ConstInlineVisitor method replaceConst.

private static boolean replaceConst(MethodNode mth, InsnNode constInsn, long literal) {
    SSAVar sVar = constInsn.getResult().getSVar();
    List<RegisterArg> use = new ArrayList<RegisterArg>(sVar.getUseList());
    int replaceCount = 0;
    for (RegisterArg arg : use) {
        InsnNode useInsn = arg.getParentInsn();
        if (useInsn == null || useInsn.getType() == InsnType.PHI || useInsn.getType() == InsnType.MERGE) {
            continue;
        }
        LiteralArg litArg;
        ArgType argType = arg.getType();
        if (argType.isObject() && literal != 0) {
            argType = ArgType.NARROW_NUMBERS;
        }
        if (use.size() == 1 || arg.isTypeImmutable()) {
            // arg used only in one place
            litArg = InsnArg.lit(literal, argType);
        } else if (useInsn.getType() == InsnType.MOVE && !useInsn.getResult().getType().isTypeKnown()) {
            // save type for 'move' instructions (hard to find type in chains of 'move')
            litArg = InsnArg.lit(literal, argType);
        } else {
            // in most cases type not equal arg.getType()
            // just set unknown type and run type fixer
            litArg = InsnArg.lit(literal, ArgType.UNKNOWN);
        }
        if (useInsn.replaceArg(arg, litArg)) {
            fixTypes(mth, useInsn, litArg);
            replaceCount++;
            if (useInsn.getType() == InsnType.RETURN) {
                useInsn.setSourceLine(constInsn.getSourceLine());
            }
            FieldNode f = null;
            ArgType litArgType = litArg.getType();
            if (litArgType.isTypeKnown()) {
                f = mth.getParentClass().getConstFieldByLiteralArg(litArg);
            } else if (litArgType.contains(PrimitiveType.INT)) {
                f = mth.getParentClass().getConstField((int) literal, false);
            }
            if (f != null) {
                litArg.wrapInstruction(new IndexInsnNode(InsnType.SGET, f.getFieldInfo(), 0));
            }
        }
    }
    return replaceCount == use.size();
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) SSAVar(jadx.core.dex.instructions.args.SSAVar) FieldNode(jadx.core.dex.nodes.FieldNode) ArrayList(java.util.ArrayList) LiteralArg(jadx.core.dex.instructions.args.LiteralArg) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode)

Example 48 with FieldNode

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

the class Deobfuscator method processClass.

private void processClass(DexNode dex, ClassNode cls) {
    ClassInfo clsInfo = cls.getClassInfo();
    String fullName = getClassFullName(clsInfo);
    if (!fullName.equals(clsInfo.getFullName())) {
        clsInfo.rename(dex, fullName);
    }
    for (FieldNode field : cls.getFields()) {
        FieldInfo fieldInfo = field.getFieldInfo();
        String alias = getFieldAlias(field);
        if (alias != null) {
            fieldInfo.setAlias(alias);
        }
    }
    for (MethodNode mth : cls.getMethods()) {
        MethodInfo methodInfo = mth.getMethodInfo();
        String alias = getMethodAlias(mth);
        if (alias != null) {
            methodInfo.setAlias(alias);
        }
        if (mth.isVirtual()) {
            resolveOverriding(dex, cls, mth);
        }
    }
}
Also used : FieldNode(jadx.core.dex.nodes.FieldNode) MethodNode(jadx.core.dex.nodes.MethodNode) MethodInfo(jadx.core.dex.info.MethodInfo) FieldInfo(jadx.core.dex.info.FieldInfo) ClassInfo(jadx.core.dex.info.ClassInfo)

Example 49 with FieldNode

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

the class AnnotationsParser method parse.

public void parse(int offset) throws DecodeException {
    Section section = dex.openSection(offset);
    // TODO read as unsigned int
    int classAnnotationsOffset = section.readInt();
    int fieldsCount = section.readInt();
    int annotatedMethodsCount = section.readInt();
    int annotatedParametersCount = section.readInt();
    if (classAnnotationsOffset != 0) {
        cls.addAttr(readAnnotationSet(classAnnotationsOffset));
    }
    for (int i = 0; i < fieldsCount; i++) {
        FieldNode f = cls.searchFieldById(section.readInt());
        f.addAttr(readAnnotationSet(section.readInt()));
    }
    for (int i = 0; i < annotatedMethodsCount; i++) {
        MethodNode m = cls.searchMethodById(section.readInt());
        m.addAttr(readAnnotationSet(section.readInt()));
    }
    for (int i = 0; i < annotatedParametersCount; i++) {
        MethodNode mth = cls.searchMethodById(section.readInt());
        // read annotation ref list
        Section ss = dex.openSection(section.readInt());
        int size = ss.readInt();
        MethodParameters params = new MethodParameters(size);
        for (int j = 0; j < size; j++) {
            params.getParamList().add(readAnnotationSet(ss.readInt()));
        }
        mth.addAttr(params);
    }
}
Also used : FieldNode(jadx.core.dex.nodes.FieldNode) MethodNode(jadx.core.dex.nodes.MethodNode) MethodParameters(jadx.core.dex.attributes.annotations.MethodParameters) Section(com.android.dex.Dex.Section)

Example 50 with FieldNode

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

the class InsnGen method instanceField.

private void instanceField(ICodeWriter code, FieldInfo field, InsnArg arg) throws CodegenException {
    ClassNode pCls = mth.getParentClass();
    FieldNode fieldNode = pCls.root().resolveField(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);
    }
    if (fieldNode == null) {
        code.add(field.getAlias());
    } else {
        code.add(fieldNode.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)

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