前面介绍了使用IDA动态调试smali,这种方法设置简单,不用重打包,用起来方便,但是如果变量类型设置错误则会马上退出调试,这是让人不爽的地方,而使用Android studio则不会。
0x01 工具
①Android Studio最新版。
②apktool尽量使用最新版的。
③ideasmali插件。下载地址 https://github.com/JesusFreke/smali/wiki/smalidea
0x02 具体步骤
安装ideasmali插件,选择File->Settings->Plugins,安装之前下载的ideasmali插件。
①Android Studio最新版。
②apktool尽量使用最新版的。
③ideasmali插件。下载地址 https://github.com/JesusFreke/smali/wiki/smalidea
0x02 具体步骤
安装ideasmali插件,选择File->Settings->Plugins,安装之前下载的ideasmali插件。
![](https://i-blog.csdnimg.cn/blog_migrate/09143b9b0c1de6170f4f3665ba7826c4.png)
以调试状态启动app
![](https://i-blog.csdnimg.cn/blog_migrate/48c2fa1f57991914304caa66aa443af1.png)
通过ddms查看端口:
![](https://i-blog.csdnimg.cn/blog_migrate/313c0590190e147492afefd5c3efb9d6.png)
如果不用 ddms 可以通过adb shell执行 ps | grep kugou命令查看转发端口:
![](https://i-blog.csdnimg.cn/blog_migrate/21bf3d576daf966ef62f379dda08c7c2.png)
然后进行端口转发:
adb forward tcp:8700 jdwp:24551
记住这时候需要将DDMS关掉,不然会出现错误
![](https://i-blog.csdnimg.cn/blog_migrate/37f8ccb88c0665ff75020cce27e42bb3.png)
创建DebugSmali/src目录,使用apktool或者baksmali反编译要调试的apk到DebugSmali/src目录,使用Android Studio导入该目录,如图所示:
![](https://i-blog.csdnimg.cn/blog_migrate/fbc96d012df89e6f16ba555ea605c02b.png)
然后选择Create project from existing sources,之后一直选择next。
![](https://i-blog.csdnimg.cn/blog_migrate/4b47a83854abbab54ff18da6d3df9107.png)
成功导入工程后右键点击 src 目录,设定
Mark Directory As->Sources Root
![](https://i-blog.csdnimg.cn/blog_migrate/4505d8394cbec301bef8ac0d94b2ce5d.png)
配置远程调试的选项,选择Run-->Edit Configurations:
![](https://i-blog.csdnimg.cn/blog_migrate/e0b01302016f2470d15c5a3d0156ac52.png)
增加一个Remote调试的调试选项,端口选择:8700
![](https://i-blog.csdnimg.cn/blog_migrate/c354a0f1c100d604bcaa1e73e0f09cb2.png)
设置端口号
![](https://i-blog.csdnimg.cn/blog_migrate/136b0f98e2db8e41c370c5c4d635d217.png)
之后选择File-->Project Structure 配置JDK
![](https://i-blog.csdnimg.cn/blog_migrate/ac9c39db5171d3a0abfd854a858573d0.png)
![](https://i-blog.csdnimg.cn/blog_migrate/01129b76db1cc5f05ec1124a0ff670bf.png)
下好断点之后Run->Debug,
![](https://i-blog.csdnimg.cn/blog_migrate/c174ab49fa9fa5ec0b33aa8ba639c65e.png)
稍等几秒,断点触发后就可以单步调试
![](https://i-blog.csdnimg.cn/blog_migrate/973710b50c3629d322ba6de3b805ed7e.png)