Print Smali values to logcat

Raz Razman picture Raz Razman · Jun 20, 2016 · Viewed 11.5k times · Source

In the example code below, how can I add a command to print the values of v0, v1 etc to logcat?

const v1, 0x7f05002e

iget-object v2, p0, Lcom/company/myapp/MainActivity;->d:Lcom/company/myapp/f;

invoke-virtual {v2}, Lcom/company/myapp/f;->getPanelModel()Lcom/company/myapp/h;

move-result-object v2

invoke-virtual {v2}, Lcom/company/myapp/h;->b()I

move-result v2

invoke-virtual {v0, v1, v2}, Lcom/company/e/k;->a(II)V

iget-object v0, p0, Lcom/company/myapp/MainActivity;->c:Lcom/company/e/k;

Answer

Ilia Barahovski picture Ilia Barahovski · Jul 11, 2016

Add at the end:

const-string v8, "log-tag"

invoke-static {v1}, Ljava/lang/String;->valueOf(I)Ljava/lang/String;
move-result-object v9

invoke-static {v8, v9}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

From your sample v1 is integer so the function String;->valueOf(I) is used to convert it to String before using log. Also Log;->d outputs at debug log level; possibly another level is needed.