I'm fairly knew to using smali, so apologies if this is a beginners question.
I am using Apktool to turn an apk file into smali, with the aim being to insert logging calls into the code.
To do this, I have incremented .locals by one (to add a new register) then am trying to move all the register back to their original positions.
I have issues when trying to move parameters that use two registers (longs and doubles). If I include code to move them, the apk recompiles but does not open on an emulator. I'm not having this issue when moving other types.
For example, the below works fine. If I add move-wide/from16 v6, p1
in line 68, the app will no longer open (the below is after I have incremented the .locals from 5).
.method public breakerTheSecond(JLjava/lang/String;)V
59 .locals 6
60 .param p1, "pk" # J
61 .param p3, "ab" # Ljava/lang/String;
62
63 .prologue
64 move-object/from16 v8, p3
65
66 move-object/from16 v5, p0
67
68
69
70 .line 56
71 const/4 v0, 0x1
72
73 .local v0, "a":I
74 const/4 v1, 0x2
75
76 .line 58
77 .local v1, "b":I
78 invoke-virtual {v5}, Lcom/test/bbutton
/MyActivity;->getApplicationContext()Landroid/content/Context;
79
80 move-result-object v2
81
82 const-string v3, "test"
83
84 const/4 v4, 0x0
85
86 invoke-static {v2, v3, v4}, Landroid/widget
/Toast;->makeText(Landroid/content/Context;Ljava
/lang/CharSequence;I)Landroid/widg et/Toast;
87
88 move-result-object v2
89
90 .line 59
91 invoke-virtual {v2}, Landroid/widget/Toast;->show()V
92
93 .line 61
94 return-void
95 .end method
Thanks for you help!
Long and double values are referenced using only their first register. So when you do the move-object/from16 v5, p0
on line 66, it is moving the entire double value from p0, p1 to v5, v6.
Referencing the second half of a 64-bit value isn't allowed, so when you try to do move-wide/from16 v6, p1
, it sees that p1 is the second half of the value in p0, and gets grumpy with you :)