Android 反汇编Smali语言中插入log打印

转自 http://www.xuebuyuan.com/2174077.html 

针对Android中Smali代码逆向分析,由于现在调试技术有限,一种相对简单的办法是在Smali中加入Log输出:

.locals 4
#...
const-string v3, "zhangmin"
invoke-static {v3, v1}, Landroid/util/Log;->v(Ljava/lang/String;Ljava/lang/String;)I

注意:在函数的开头要至少增加一个寄存器( .locals 的值增加一个)。
假如Log.d()函数的第二个参数为null,那么运行时会报错,可以用下面的方法解决:
invoke-static {v1}, Landroid/text/TextUtils;->isEmpty(Ljava/lang/CharSequence;)Z
move-result v2
if-nez v2, :errornull_1
const-string v3, "zhangmin"
invoke-static {v3, v1}, Landroid/util/Log;->v(Ljava/lang/String;Ljava/lang/String;)I
:errornull_1

如果查看int值,首先要将变量转为String,再来查看,需要添加2个寄存器:
.locals 5
#...
const-string v3, "zhangmin"
invoke-static {v1}, Ljava/lang/Integer;->toString(I)Ljava/lang/String;
move-result-object v4
invoke-static {v3, v4}, Landroid/util/Log;->v(Ljava/lang/String;Ljava/lang/String;)I

查看boolean值的打印类似int,先转换成String
.locals 5
#...
const-string v3, "zhangmin"
invoke-static {v1}, Ljava/lang/Boolean;->toString(Z)Ljava/lang/String;
move-result-object v4
invoke-static {v3, v4}, Landroid/util/Log;->v(Ljava/lang/String;Ljava/lang/String;)I

你可能感兴趣的:(Android 反汇编Smali语言中插入log打印)