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] Code restructure failure when merging nested "if" regions #820

Closed
huku- opened this issue Dec 28, 2019 · 1 comment
Closed

[core] Code restructure failure when merging nested "if" regions #820

huku- opened this issue Dec 28, 2019 · 1 comment
Labels
bug Core Issues in jadx-core module

Comments

@huku-
Copy link

huku- commented Dec 28, 2019

Merging nested if regions that contain assignment instructions may lead to the following decompilation error:

/* JADX WARNING: Code restructure failed: missing block: B:2:0x0005, code lost:
    r2 = null;
 */

The following minified smali test-case can be used to trigger the buggy behavior.

.class public LTest;
.super LTestSuper;
.source "Test.java"

.method public AHc()V
    .locals 5

    const/4 v0, 0
    const/4 v1, 0
    const/4 v4, 0

    if-eqz v4, :cond_0

    const/4 v2, 0

    invoke-virtual {v2}, LTestClass1;->testMethod()LTestClass2;

    move-result-object v0

    if-eqz v0, :cond_0

    if-eq v1, v0, :cond_0

    iget-object v3, v2, LTestClass1;->testField:LTestClass3;

    if-eqz v3, :cond_0

    :cond_0
    return-void
.end method

Notice that the code above is only meant for debugging purposes and is semantically mundane.

As it turns out, this code hits a TODO in CodeShrinkVisitor.java and, more specifically, in method checkInline():

if (assignInline) {
    // TODO?
    return;
}

My current solution to this problem is removing the special check for assignInline. If the if clause above is commented out, everything seems to be working fine. To make sure that this modification generates sane code, I decompiled a widely used Android application using an upstream and a patched version of jadx. The code generated using the two jadx variants was diff'ed and the output was examined by hand.

@skylot, as usual, I'm still in the process of examining this further :)

@skylot
Copy link
Owner

skylot commented Feb 9, 2020

Fixed, check #845 discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Core Issues in jadx-core module
Projects
None yet
Development

No branches or pull requests

2 participants