Smali插桩打日志

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Smali插桩打日志相关的知识,希望对你有一定的参考价值。

一、smali目录下新建crack.smali,内容如下:

.class public Lcrack;
.super Ljava/lang/Object;
.source "crack.java" 

.method public static log1(Ljava/lang/String;)V #打印出info 1字符串
    .locals 1
    .prologue 

    const-string v0, "crack_log_str"
    invoke-static {v0, p0}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I
    return-void
.end method 

.method public static I(I)V   #打印出int型值
    .locals 2
    .prologue
    const-string v0, "crack_log_int"

    invoke-static {p0}, Ljava/lang/String;->valueOf(I)Ljava/lang/String; 

    move-result-object v1
    invoke-static {v0, v1}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I
    return-void
.end method

.method public static J(J)V #打印出long类型的值
.locals 2
.prologue

const-string v0, "crack_log_long"
invoke-static {p0, p1}, Ljava/lang/String;->valueOf(J)Ljava/lang/String; 

move-result-object v1
invoke-static {v0, v1}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I
return-void
.end method

二、使用方法(打印String):

invoke-static {v1}, Lcrack;->log1(Ljava/lang/String;)V

三、有时日志太多,要写入文件分析:

.class public Lcrack2;
.super Ljava/lang/Object;
.source "crack2.java"
.method public static puts(Ljava/lang/String;)V
    .locals 7
    .prologue

    :try_start_0

    const-string v3, "/sdcard/crack/debug.log"
    new-instance v2, Ljava/io/FileOutputStream;

    const/4 v5, 0x1
    invoke-direct {v2, v3, v5}, Ljava/io/FileOutputStream;-><init>(Ljava/lang/String;Z)V

    .line 19
    new-instance v4, Ljava/io/OutputStreamWriter;
    const-string v5, "gb2312"
    invoke-direct {v4, v2, v5}, Ljava/io/OutputStreamWriter;-><init>(Ljava/io/OutputStream;Ljava/lang/String;)V

    .line 21
    invoke-virtual {v4, p0}, Ljava/io/OutputStreamWriter;->write(Ljava/lang/String;)V
    const-string v5, "\r\n" 
    invoke-virtual {v4, v5}, Ljava/io/OutputStreamWriter;->write(Ljava/lang/String;)V

    .line 23
    invoke-virtual {v4}, Ljava/io/OutputStreamWriter;->flush()V

    .line 25
    invoke-virtual {v4}, Ljava/io/OutputStreamWriter;->close()V

    .line 27
    invoke-virtual {v2}, Ljava/io/FileOutputStream;->close()V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 37
    :cond_0
    :goto_0
    return-void

    .line 30
    :catch_0
    move-exception v0

     .line 34
    const-string v5, "debug"
    const-string v6, "file write error"
    invoke-static {v5, v6}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I 

    goto :goto_0
.end method

 #使用方法:invoke-static {vx}, Lcrack2;->puts(Ljava/lang/String;)V

 

以上是关于Smali插桩打日志的主要内容,如果未能解决你的问题,请参考以下文章

静态分析Android程序

smali注入log输出信息

Smali代码语法

AndroidStudio调试smali代码

动态调试smali代码

argparse 代码片段只打印部分日志