Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

method.getBasicBlocks() is null when using jadx as a library #1482

Closed
icepng opened this issue May 13, 2022 · 2 comments
Closed

method.getBasicBlocks() is null when using jadx as a library #1482

icepng opened this issue May 13, 2022 · 2 comments

Comments

@icepng
Copy link

icepng commented May 13, 2022

I try to use jadx as a library following the document: https://github.com/skylot/jadx/wiki/Use-jadx-as-a-library.

for (JavaClass cls : jadx.getClasses()) {
    for (JavaMethod mth : cls.getMethods()) {
        System.out.println(mth.getName());
    }
}

However, all methods' basicBlocks are null, is there any extra options for generating blocks?

@skylot
Copy link
Owner

skylot commented May 13, 2022

@icepng basic blocks available only during decompilation process inside jadx passes. Right now there is no nice API to insert custom passes, but if you really want to, you can get passes list after jadx.load() like this:

List<IDexTreeVisitor> passes = jadx.getRoot().getPasses();

You need to implement IDexTreeVisitor and add it to passes list, or better insert at desired position. This list building in Jadx class depending on input options, so to insert it after desired pass you need to use method like this:

public static void addCustomPassAfter(List<IDexTreeVisitor> passes, Class<?> passCls, IDexTreeVisitor customPass) {
    for (int i = 0; i < passes.size(); i++) {
        IDexTreeVisitor pass = passes.get(i);
        if (pass.getClass().equals(passCls)) {
            passes.add(i + 1, customPass);
            break;
        }
    }
}

Complete example will be like this:

jadx.load();
List<IDexTreeVisitor> passes = jadx.getRoot().getPasses();
IDexTreeVisitor customPass = new AbstractVisitor() {
    @Override
    public void visit(MethodNode mth) {
        if (mth.isNoCode()) {
            return;
        }
        List<BlockNode> basicBlocks = mth.getBasicBlocks();
        System.out.println(basicBlocks);
    }
};
addCustomPassAfter(passes, TypeInferenceVisitor.class, customPass);
for (JavaClass cls : jadx.getClasses()) {
    // your pass will be executed during decompilation
    cls.decompile();
}

@icepng
Copy link
Author

icepng commented May 14, 2022

thank you and this is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants