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

Have an option to display smali code side-by-side with decompiled code #197

Closed
mingyuan-xia opened this issue Jan 3, 2018 · 3 comments · Fixed by #635
Closed

Have an option to display smali code side-by-side with decompiled code #197

mingyuan-xia opened this issue Jan 3, 2018 · 3 comments · Fixed by #635

Comments

@mingyuan-xia
Copy link
Contributor

Since some decompilation might fail or be inaccurate, it would be nice to have an option to view the original smali code of a class/method.

@skylot
Copy link
Owner

skylot commented Jan 3, 2018

Jadx already has option called "Fallback mode" (switch in preferences or --fallback in console).
Using this option you will get code similar to smali.
For example, decompiled code:

    public byte[] toDex(Writer humanOut, boolean verbose) throws IOException {
        boolean annotate = humanOut != null;
        ByteArrayAnnotatedOutput result = toDex0(annotate, verbose);
        if (annotate) {
            result.writeAnnotationsTo(humanOut);
        }
        return result.getArray();
    }

In fallback mode:

    public byte[] toDex(java.io.Writer r4, boolean r5) throws java.io.IOException {
        r3 = this;
        if (r4 == 0) goto L_0x0011;
    L_0x0002:
        r0 = 1;
    L_0x0003:
        r1 = r3.toDex0(r0, r5);
        if (r0 == 0) goto L_0x000c;
    L_0x0009:
        r1.writeAnnotationsTo(r4);
    L_0x000c:
        r2 = r1.getArray();
        return r2;
    L_0x0011:
        r0 = 0;
        goto L_0x0003;
    }

And smali for compare:

.method public toDex(Ljava/io/Writer;Z)[B
    .registers 6
    .param p1, "humanOut"    # Ljava/io/Writer;
    .param p2, "verbose"    # Z
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 10
    if-eqz p1, :cond_11

    const/4 v0, 0x1

    .line 11
    .local v0, "annotate":Z
    :goto_3
    invoke-direct {p0, v0, p2}, Ljadx/core/DexFile;->toDex0(ZZ)Lcom/android/dx/util/ByteArrayAnnotatedOutput;

    move-result-object v1

    .line 12
    .local v1, "result":Lcom/android/dx/util/ByteArrayAnnotatedOutput;
    if-eqz v0, :cond_c

    .line 13
    invoke-virtual {v1, p1}, Lcom/android/dx/util/ByteArrayAnnotatedOutput;->writeAnnotationsTo(Ljava/io/Writer;)V

    .line 15
    :cond_c
    invoke-virtual {v1}, Lcom/android/dx/util/ByteArrayAnnotatedOutput;->getArray()[B

    move-result-object v2

    return-object v2

    .line 10
    .end local v0    # "annotate":Z
    .end local v1    # "result":Lcom/android/dx/util/ByteArrayAnnotatedOutput;
    :cond_11
    const/4 v0, 0x0

    goto :goto_3
.end method

I thought jadx fallback is more readable than smali, but it lost type and debug information.
So if you really want smali I can do it as additional mode and using smali library.
It will be better for cases when jadx is failed to process dex.

P.S. Also you can make control flow graph:
test

@enovella
Copy link

enovella commented Jan 3, 2018

When decompilation miserably fails, IMHO it is way convenient to display normal Smali code.

@mingyuan-xia
Copy link
Contributor Author

I just notice the fall-back mode. It is pretty handy. Yet, one can either have fall-back or decompilation for the entire APK/Dex. Is there a way to keep the fall-back code in memory (even for the decompilation mode) and add a toolbar button to display that alongside the decompiled code?

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

Successfully merging a pull request may close this issue.

3 participants