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

[core] IfRegionMaker find the wrong outBlock #2384

Open
ewt45 opened this issue Dec 30, 2024 · 3 comments
Open

[core] IfRegionMaker find the wrong outBlock #2384

ewt45 opened this issue Dec 30, 2024 · 3 comments
Assignees

Comments

@ewt45
Copy link
Contributor

ewt45 commented Dec 30, 2024

Issue details

jadx failed to decompiled a method in this smali class.

/* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:10:0x0065  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0064 A[RETURN] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    protected void onCreate(Bundle bundle) {
        ViewFacade viewFacade;
        super.onCreate(bundle);
        ApplicationStateBase applicationState = getApplicationState();
        XServerComponent component = applicationState.getEnvironment().getComponent(XServerComponent.class);
        Class cls = (Class) getIntent().getSerializableExtra("facadeclass");
        if (cls != null) {
            try {
                viewFacade = (ViewFacade) cls.getDeclaredConstructor(XServer.class, ApplicationStateBase.class).newInstance(component.getXServer(), applicationState);
            } catch (Exception unused) {
                Assert.state(ENABLE_TRACING_METHODS);
            }
            getWindow().addFlags(128);
            getWindow().addFlags(4194304);
            setContentView(R.layout.main);
            if (checkForSuddenDeath()) {
                this.viewOfXServer = new ViewOfXServer(this, component.getXServer(), viewFacade, applicationState.getXServerViewConfiguration());
                this.periodicIabCheckTimer.start();
                return;
            }
            return;
        }
        viewFacade = null;
        getWindow().addFlags(128);
        getWindow().addFlags(4194304);
        setContentView(R.layout.main);
        if (checkForSuddenDeath()) {
        }
    }

by looking into smali, the correct java code should be like

if (cls != null) {
    try {
        viewFacade = (ViewFacade) cls.getDeclaredConstructor(XServer.class, ApplicationStateBase.class).newInstance(component.getXServer(), applicationState);
    } catch (Exception unused) {
        Assert.state(ENABLE_TRACING_METHODS);
        viewFacade = null;
    }
} else {
    viewFacade = null;
}
getWindow().addFlags(128);
//...

the reason is that in IfRegionMaker.isBadBranchBlock(), else block has two predecessors and one of them is not in info.getMergedBlocks(). so else branch is thought as bad branch and extracted as out block.
in this case, else block indeed is in the end of then block, but is not 100% to be executed, so should still keep as else block.

Relevant log output or stacktrace

No response

Provide sample and class/method full name

sample smali

Jadx version

latest commit(f4849d6)

@ewt45 ewt45 added bug Core Issues in jadx-core module labels Dec 30, 2024
@skylot
Copy link
Owner

skylot commented Dec 30, 2024

Issue with incorrect if restore is fixed in PR #2385.
But part with missing viewFacade = null; still not fixed. I will try to implement check and duplicate required block.
Also, it will nice to fix type inference issue 🙂

@ewt45
Copy link
Contributor Author

ewt45 commented Dec 30, 2024

the type inference warning only appears when this class's depedencies smali are missing. so maybe its not a big deal?
after de62954 , the type inference works correctly with the completed apk.

@skylot
Copy link
Owner

skylot commented Dec 30, 2024

type inference warning only appears when this class's depedencies smali are missing. so maybe its not a big deal?

Sure, but this warning is about incorrect type for this, such warning is pointless, so I will just disable it 🤣

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