Skip to content

[core] IfRegionMaker find the wrong outBlock #2384

Open
@ewt45

Description

@ewt45

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)

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions