desword / android-apktool

Automatically exported from code.google.com/p/android-apktool
Other
1 stars 0 forks source link

[REQ] "In-line" switches (code blocks instead of labels) #645

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Not an issue but a feature request - so very low priority (if even worthy of 
adoption)

One of the most annoying tasks in Smali/Bytecode IMO is dealing with large 
and/or frequent switch statements, especially with larger methods. I propose a 
future language enhancement for in-lining switch code into the switch data 
itself. Behold an example:

Before;
    :checkCategoryId
    .sparse-switch
        0x7f0e0006 -> :clickedHome
        0x7f0e0007 -> :clickedApps
        0x7f0e0008 -> :clickedFeatured
        0x7f0e0009 -> :clickedSettings
        0x7f0e01bf -> :clickedVideo
        0x7f0e01c3 -> :clickedMusic
    .end sparse-switch

    :checkSourceIndex
    .packed-switch 0x0
        :wasHome
        :wasApps
        :wasFeatured
        :wasVideo
        :wasMusic
        :wasSettings
    .end packed-switch

After;
:checkCategoryId
    .sparse-switch
        0x7f0e0006 -> .codeblock
            const/4 v1, 0x0
            iget-object v2, p0, Lcom/company/name/someclass;->somefield:Landroid/widget/TextView;
            goto :isValidClick
        .end codeblock
        [etc...]
    .end sparse-switch

    :checkSourceIndex
    .packed-switch 0x0
        .codeblock
            const/4 v1, 0x0
        .end codeblock
        [etc...]
    .end packed-switch

So, up to you if it's worth a (distant) future consideration. Either way I 
won't press it. Thanks!

Original issue reported on code.google.com by dconnoll...@gmail.com on 20 Jun 2014 at 8:34

GoogleCodeExporter commented 9 years ago
That packed switch const example was supposed to be a resId, nevermind that.

Original comment by dconnoll...@gmail.com on 20 Jun 2014 at 8:35

GoogleCodeExporter commented 9 years ago
Toss this over to Smali.

Its the internal smali/baksmali tool. Apktool simply wraps it. 

https://code.google.com/p/smali/

Original comment by connor.tumbleson on 23 Jun 2014 at 1:45