Search in sources :

Example 21 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 22 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 23 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 24 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)

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