Search in sources :

Example 16 with FieldInfo

use of jadx.core.dex.info.FieldInfo in project jadx by skylot.

the class EnumVisitor method removeEnumMethods.

private void removeEnumMethods(ClassNode cls, ArgType clsType, FieldNode valuesField) {
    String valuesMethod = "values()" + TypeGen.signature(ArgType.array(clsType));
    FieldInfo valuesFieldInfo = valuesField.getFieldInfo();
    // remove compiler generated methods
    for (MethodNode mth : cls.getMethods()) {
        MethodInfo mi = mth.getMethodInfo();
        if (mi.isClassInit()) {
            continue;
        }
        String shortId = mi.getShortId();
        if (mi.isConstructor()) {
            if (isDefaultConstructor(mth, shortId)) {
                mth.add(AFlag.DONT_GENERATE);
            }
            markArgsForSkip(mth);
        } else if (shortId.equals(valuesMethod) || usesValuesField(mth, valuesFieldInfo) || simpleValueOfMth(mth, clsType)) {
            mth.add(AFlag.DONT_GENERATE);
        }
    }
}
Also used : MethodNode(jadx.core.dex.nodes.MethodNode) MethodInfo(jadx.core.dex.info.MethodInfo) FieldInfo(jadx.core.dex.info.FieldInfo)

Example 17 with FieldInfo

use of jadx.core.dex.info.FieldInfo in project jadx by skylot.

the class EnumVisitor method createFakeField.

private FieldNode createFakeField(ClassNode cls, String name) {
    FieldNode enumFieldNode;
    FieldInfo fldInfo = FieldInfo.from(cls.root(), cls.getClassInfo(), name, cls.getType());
    enumFieldNode = new FieldNode(cls, fldInfo, 0);
    enumFieldNode.add(AFlag.SYNTHETIC);
    enumFieldNode.addInfoComment("Fake field, exist only in values array");
    return enumFieldNode;
}
Also used : FieldNode(jadx.core.dex.nodes.FieldNode) FieldInfo(jadx.core.dex.info.FieldInfo)

Example 18 with FieldInfo

use of jadx.core.dex.info.FieldInfo in project jadx by skylot.

the class EnumVisitor method processEnumFieldByField.

@Nullable
private EnumField processEnumFieldByField(ClassNode cls, InsnNode sgetInsn, BlockNode staticBlock, List<InsnNode> toRemove) {
    if (sgetInsn.getType() != InsnType.SGET) {
        return null;
    }
    FieldInfo fieldInfo = (FieldInfo) ((IndexInsnNode) sgetInsn).getIndex();
    FieldNode enumFieldNode = cls.searchField(fieldInfo);
    if (enumFieldNode == null) {
        return null;
    }
    InsnNode sputInsn = searchFieldPutInsn(cls, staticBlock, enumFieldNode);
    if (sputInsn == null) {
        return null;
    }
    ConstructorInsn co = getConstructorInsn(sputInsn);
    if (co == null) {
        return null;
    }
    RegisterArg sgetResult = sgetInsn.getResult();
    if (sgetResult == null || sgetResult.getSVar().getUseCount() == 1) {
        toRemove.add(sgetInsn);
    }
    toRemove.add(sputInsn);
    return createEnumFieldByConstructor(cls, enumFieldNode, co);
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) FieldNode(jadx.core.dex.nodes.FieldNode) ConstructorInsn(jadx.core.dex.instructions.mods.ConstructorInsn) FieldInfo(jadx.core.dex.info.FieldInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with FieldInfo

use of jadx.core.dex.info.FieldInfo in project jadx by skylot.

the class EnumVisitor method searchEnumField.

@Nullable
private FieldNode searchEnumField(ClassNode cls, SSAVar ssaVar, List<InsnNode> toRemove) {
    InsnNode sputInsn = ssaVar.getUseList().get(0).getParentInsn();
    if (sputInsn == null || sputInsn.getType() != InsnType.SPUT) {
        return null;
    }
    FieldInfo fieldInfo = (FieldInfo) ((IndexInsnNode) sputInsn).getIndex();
    FieldNode enumFieldNode = cls.searchField(fieldInfo);
    if (enumFieldNode == null) {
        return null;
    }
    toRemove.add(sputInsn);
    return enumFieldNode;
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) FieldNode(jadx.core.dex.nodes.FieldNode) FieldInfo(jadx.core.dex.info.FieldInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 20 with FieldInfo

use of jadx.core.dex.info.FieldInfo in project jadx by skylot.

the class EnumVisitor method searchFieldPutInsn.

@Nullable
private InsnNode searchFieldPutInsn(ClassNode cls, BlockNode staticBlock, FieldNode enumFieldNode) {
    for (InsnNode sputInsn : staticBlock.getInstructions()) {
        if (sputInsn != null && sputInsn.getType() == InsnType.SPUT) {
            FieldInfo f = (FieldInfo) ((IndexInsnNode) sputInsn).getIndex();
            FieldNode fieldNode = cls.searchField(f);
            if (Objects.equals(fieldNode, enumFieldNode)) {
                return sputInsn;
            }
        }
    }
    return null;
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) FieldNode(jadx.core.dex.nodes.FieldNode) FieldInfo(jadx.core.dex.info.FieldInfo) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FieldInfo (jadx.core.dex.info.FieldInfo)41 FieldNode (jadx.core.dex.nodes.FieldNode)24 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)20 InsnNode (jadx.core.dex.nodes.InsnNode)16 InsnArg (jadx.core.dex.instructions.args.InsnArg)15 InsnWrapArg (jadx.core.dex.instructions.args.InsnWrapArg)8 ClassNode (jadx.core.dex.nodes.ClassNode)8 ArgType (jadx.core.dex.instructions.args.ArgType)7 ArrayList (java.util.ArrayList)7 InsnType (jadx.core.dex.instructions.InsnType)6 MethodNode (jadx.core.dex.nodes.MethodNode)6 Nullable (org.jetbrains.annotations.Nullable)6 ConstClassNode (jadx.core.dex.instructions.ConstClassNode)5 ConstStringNode (jadx.core.dex.instructions.ConstStringNode)5 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)5 BlockNode (jadx.core.dex.nodes.BlockNode)5 HashMap (java.util.HashMap)5 List (java.util.List)5 EncodedValue (jadx.api.plugins.input.data.annotations.EncodedValue)4 MethodInfo (jadx.core.dex.info.MethodInfo)4