Search in sources :

Example 26 with MethodNode

use of jadx.core.dex.nodes.MethodNode 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 27 with MethodNode

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

the class CleanRegions method process.

public static void process(MethodNode mth) {
    if (mth.isNoCode() || mth.getBasicBlocks().isEmpty()) {
        return;
    }
    IRegionVisitor removeEmptyBlocks = new AbstractRegionVisitor() {

        @Override
        public boolean enterRegion(MethodNode mth, IRegion region) {
            if (!(region instanceof Region)) {
                return true;
            }
            for (Iterator<IContainer> it = region.getSubBlocks().iterator(); it.hasNext(); ) {
                IContainer container = it.next();
                if (container instanceof BlockNode) {
                    BlockNode block = (BlockNode) container;
                    if (block.getInstructions().isEmpty()) {
                        try {
                            it.remove();
                        } catch (UnsupportedOperationException e) {
                            LOG.warn("Can't remove block: {} from: {}, mth: {}", block, region, mth);
                        }
                    }
                }
            }
            return true;
        }
    };
    DepthRegionTraversal.traverse(mth, removeEmptyBlocks);
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) MethodNode(jadx.core.dex.nodes.MethodNode) IRegion(jadx.core.dex.nodes.IRegion) Region(jadx.core.dex.regions.Region) IContainer(jadx.core.dex.nodes.IContainer) IRegion(jadx.core.dex.nodes.IRegion)

Aggregations

MethodNode (jadx.core.dex.nodes.MethodNode)27 ClassNode (jadx.core.dex.nodes.ClassNode)12 FieldNode (jadx.core.dex.nodes.FieldNode)9 MethodInfo (jadx.core.dex.info.MethodInfo)7 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)7 InsnNode (jadx.core.dex.nodes.InsnNode)7 ClassInfo (jadx.core.dex.info.ClassInfo)5 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)5 BlockNode (jadx.core.dex.nodes.BlockNode)5 ConstClassNode (jadx.core.dex.instructions.ConstClassNode)4 ArgType (jadx.core.dex.instructions.args.ArgType)4 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)4 ArrayList (java.util.ArrayList)4 FieldInfo (jadx.core.dex.info.FieldInfo)3 InsnArg (jadx.core.dex.instructions.args.InsnArg)3 IRegion (jadx.core.dex.nodes.IRegion)3 IntegrationTest (jadx.tests.api.IntegrationTest)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 EnumClassAttr (jadx.core.dex.attributes.nodes.EnumClassAttr)2