Search in sources :

Example 6 with AccessInfo

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

the class ClassModifier method removeSyntheticMethods.

private static void removeSyntheticMethods(ClassNode cls) {
    for (MethodNode mth : cls.getMethods()) {
        if (mth.isNoCode()) {
            continue;
        }
        AccessInfo af = mth.getAccessFlags();
        // remove bridge methods
        if (af.isBridge() && af.isSynthetic() && !isMethodUniq(cls, mth)) {
            // TODO add more checks before method deletion
            mth.add(AFlag.DONT_GENERATE);
            continue;
        }
        // remove synthetic constructor for inner classes
        if (af.isSynthetic() && af.isConstructor() && mth.getBasicBlocks().size() == 2) {
            List<InsnNode> insns = mth.getBasicBlocks().get(0).getInstructions();
            if (insns.size() == 1 && insns.get(0).getType() == InsnType.CONSTRUCTOR) {
                ConstructorInsn constr = (ConstructorInsn) insns.get(0);
                List<RegisterArg> args = mth.getArguments(false);
                if (constr.isThis() && !args.isEmpty()) {
                    // remove first arg for non-static class (references to outer class)
                    if (args.get(0).getType().equals(cls.getParentClass().getClassInfo().getType())) {
                        args.get(0).add(AFlag.SKIP_ARG);
                    }
                    // remove unused args
                    for (RegisterArg arg : args) {
                        SSAVar sVar = arg.getSVar();
                        if (sVar != null && sVar.getUseCount() == 0) {
                            arg.add(AFlag.SKIP_ARG);
                        }
                    }
                    mth.add(AFlag.DONT_GENERATE);
                }
            }
        }
    }
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) MethodNode(jadx.core.dex.nodes.MethodNode) SSAVar(jadx.core.dex.instructions.args.SSAVar) AccessInfo(jadx.core.dex.info.AccessInfo) ConstructorInsn(jadx.core.dex.instructions.mods.ConstructorInsn)

Aggregations

AccessInfo (jadx.core.dex.info.AccessInfo)6 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)2 OverlayIcon (jadx.gui.utils.OverlayIcon)2 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)1 ArgType (jadx.core.dex.instructions.args.ArgType)1 SSAVar (jadx.core.dex.instructions.args.SSAVar)1 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)1 BlockNode (jadx.core.dex.nodes.BlockNode)1 InsnNode (jadx.core.dex.nodes.InsnNode)1 MethodNode (jadx.core.dex.nodes.MethodNode)1