java - Strange assignment, TextView to Bundle, after decompiling, why? -


i created simple application, counter app, upon pressing button increments integer 1 , updates textview. code can seen below:

public class mainactivity extends activity {     public static int count = 0;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          final textview textview = (textview) findviewbyid(r.id.count);         textview.settext(integer.tostring(count));         final button button = (button) findviewbyid(r.id.button);         button.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 count++;                 textview.settext(integer.tostring(count));             }         });     }     ... } 

after decompiling same app dex2jar , jd-gui received following code back:

public class mainactivity extends activity {     public static int count = 0;      protected void oncreate(final bundle parambundle) {         super.oncreate(parambundle);         setcontentview(2130903040);         parambundle = (textview)findviewbyid(2131296257);         parambundle.settext(integer.tostring(count));         ((button)findviewbyid(2131296256)).setonclicklistener(new view.onclicklistener() {             public void onclick(view paramanonymousview) {                 mainactivity.count += 1;                 parambundle.settext(integer.tostring(mainactivity.count));             }         });     }     ... } 

on following line:

        parambundle = (textview)findviewbyid(2131296257);         parambundle.settext(integer.tostring(count)); 

how possible system set textview parambundle? , why happening? parambundle of type bundle , textview not subclass of bundle, further more bundle final according decompiled version. did go wrong upon decompiling? information decompiler wrong or why result?


edit:

# virtual methods .method protected oncreate(landroid/os/bundle;)v     .locals 3     .param p1, "savedinstancestate"    # landroid/os/bundle;      .prologue     .line 17     invoke-super {p0, p1}, landroid/app/activity;->oncreate(landroid/os/bundle;)v      .line 18     const/high16 v2, 0x7f030000      invoke-virtual {p0, v2}, lcom/example/rawa/helloworld/mainactivity;->setcontentview(i)v      .line 20     const v2, 0x7f090001      invoke-virtual {p0, v2}, lcom/example/rawa/helloworld/mainactivity;->findviewbyid(i)landroid/view/view;      move-result-object v1      check-cast v1, landroid/widget/textview;      .line 21     .local v1, "textview":landroid/widget/textview;     sget v2, lcom/example/rawa/helloworld/mainactivity;->count:i      invoke-static {v2}, ljava/lang/integer;->tostring(i)ljava/lang/string;      move-result-object v2      invoke-virtual {v1, v2}, landroid/widget/textview;->settext(ljava/lang/charsequence;)v      .line 22     const/high16 v2, 0x7f090000      invoke-virtual {p0, v2}, lcom/example/rawa/helloworld/mainactivity;->findviewbyid(i)landroid/view/view;      move-result-object v0      check-cast v0, landroid/widget/button;      .line 23     .local v0, "button":landroid/widget/button;     new-instance v2, lcom/example/rawa/helloworld/mainactivity$1;      invoke-direct {v2, p0, v1}, lcom/example/rawa/helloworld/mainactivity$1;-><init>(lcom/example/rawa/helloworld/mainactivity;landroid/widget/textview;)v      invoke-virtual {v0, v2}, landroid/widget/button;->setonclicklistener(landroid/view/view$onclicklistener;)v      .line 30     return-void .end method 

i'm no smali expert, novice. decoded application using apktool , received smali code above. understanding, savedinstance (parambundle) loaded in p1(=v3) , used in oncreate, , not used in way in line 20 or 21. me point towards decompling error? keep in mind apktool allows building application again , no data may lost when decompiling.

the cause type of local variables has changed, decompilers fail handle correctly.

here's oncreate code decompiled dex2jar + javap:

  protected void oncreate(android.os.bundle);     code:        0: aload_0        1: aload_1        2: invokespecial #20                 // method android/app/activity.oncreate:(landroid/os/bundle;)v        5: aload_0        6: ldc           #21                 // int 2130903040        8: invokevirtual #25                 // method setcontentview:(i)v       11: aload_0       12: ldc           #26                 // int 2131230720       14: invokevirtual #30                 // method findviewbyid:(i)landroid/view/view;       17: checkcast     #32                 // class android/widget/textview       20: astore_1       21: aload_1       22: getstatic     #12                 // field count:i       25: invokestatic  #38                 // method java/lang/integer.tostring:(i)ljava/lang/string;       28: invokevirtual #42                 // method android/widget/textview.settext:(ljava/lang/charsequence;)v       31: aload_0       32: ldc           #43                 // int 2131230721       34: invokevirtual #30                 // method findviewbyid:(i)landroid/view/view;       37: checkcast     #45                 // class android/widget/button       40: new           #6                  // class com/example/test/mainactivity$1       43: dup       44: aload_0       45: aload_1       46: invokespecial #48                 // method com/example/test/mainactivity$1."<init>":(lcom/example/test/mainactivity;landroid/widget/textview;)v       49: invokevirtual #52                 // method android/widget/button.setonclicklistener:(landroid/view/view$onclicklistener;)v       52: return 

here aload_0 local variable mainactivity object, , aload_1 local variable bundle object. source of problem occured @ code #20, when it stores reference of just-retrieved textview object local variable 1 (astore_1), storing bundle object!

this done since bundle object not used rest of method, therefore it's more efficient reuse local variable instead of new variable. means decompilers need work hard produce correct java code.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -