chapter5~chapter6 静态分析与动态分析

157 阅读3分钟

静态分析

静态分析目前用的比较多的是jadx,这款工具使用起来也比较简单,而且开源,反编译效果也很好,下载链接:github.com/skylot/jadx

因为动态分析,笔者使用的IDA,所以这里还是以IDA来记录自己的一些心得

使用的apk还是之前的apk,因为我们自己的代码主要是在classes3.dex,所以直接使用IDA打开

image.png

常用快捷键

  • G 键:jump to address 窗口

image.png

  • Ctrl+S:选择对话框,IDA将dex分成了11个段,每个段都有对应的偏移量与DexHeader结构,最后两个段的偏移量可以通过计算得出

image.png

  • Alt+T:文本搜索

image.png

动态分析

动态分析这块,折磨了笔者很久,最后还是调试通过了

先说一下遇到的问题,但是这也不是通用的解决方案,实在解决不了,可以多换个几个手机试试,如果遇到几次成功的,后面又怎么调试不了了,可以尝试将apk卸载,重新安装,感觉这东西比较玄乎:

问题1:JDWP error: THREAD NOT SUSPENDED If the specified thread has not been suspended by an event

针对这个问题可以了解一下什么JDWP:https://www.jianshu.com/p/134bd5b913c5

解决办法:

    端口转发:adb forward tcp:8700 jdwp:26408(注:这个是需要调试的apk的进程号)
    查看进程号的方法:
        win:adb shell ps|findstr com.example.chapter2
        linux:adb shell ps|grep com.example.chapter2

问题2:调试的时候Bad type问题,可以查看文档

https://hex-rays.com/products/ida/support/idadoc/1669.shtml

关注信息在这里:

    Please note that we have to specify type of variable if it is not known.
    Use C-style casts:
        (Object*)v0
        (String)v6
        (char*)v17
        (int)v7

    We do not need to specify the real type of an object variable,
    the "(Object*)" cast is enough.  IDA can derive the real object type
    itself.

目前网上找到比较多的调试方案是这种:www.freebuf.com/articles/en… 可以参考下,我简单做个步骤总结

1. adb端口转发:adb forward tcp:23946 tcp:23946 
2. 挂起程序:adb shell am start -D -n com.example.chapter2/.MainActivity
3. 运行monitor.bat程序,查看进行号(注:目前高版本的sdk已经没有这个,笔者安装的是:android-sdk_r24.4.1-windows)
4. 打开IDA,进行相应的debug配置
5. 使用jdb进行连接:jdb -connect com.sun.jdi.SocketAttach:hostname=127.0.0.1,port=8600

记得一定要把IDA目录下的dbgsrv目录下android_server push到手机上,具体根据自己手机的arm架构选择对应的位数

关于调试模式开启问题

adb shell getprop ro.debuggable 查看,如果是0,则改为1,具体修改方法参考:blog.csdn.net/jinmie0193/…

下面是使用书中讲到操作流程,补充了没有提到的步骤

  • Debugger -> Debugger Options -> set specific options

image.png

  • Debugger -> Process options

设置端口为8700

image.png

  • Debugger -> Start Process

这种会有弹窗,确认ok就行,最后手机会弹出:Waiting for debugger的提示

等待一会,IDA会出现这个弹窗

image.png

证明已经进入了Debugger模式

  • 打断点:比如我们断点打在这个位置:0x7F0E0085

image.png

  • 接着调试,根据自己的需求操作就行
可能用到命令

F9:Continue process
F7:Step into
F8:Step over

  • 添加Locals和Watch view,观察寄存器的变化

image.png

部分截图如下

image.png

image.png

断点checkSN函数

image.png

image.png