0%

Android ADB 使用

如何使用ADB

1. 开启ADB服务

1
2
3
4
$ adb devices
List of devices attached
* daemon not running; starting now at tcp:5037
* daemon started successfully
1
2
3
$ adb start-server
* daemon not running; starting now at tcp:5037
* daemon started successfully

2. 停止ADB服务

1
adb kill-server

3. 连接ADB客户端

默认连接
这句命令默认会连5555端口,谷歌官方模拟器就是用这个端口

1
adb connect 127.0.0.1

夜神模拟器

1
2
$ adb connect 127.0.0.1:62001
connected to 127.0.0.1:62001
1
2
3
$ adb devices
List of devices attached
127.0.0.1:62001 device

逍遥模拟器

1
adb connect 127.0.0.1:21503

4. 模拟器开启Root权限

5. 可能出现的问题

原因是本地有多个版本的ADB连接 ,检查是否有360等等,如果有的话,就关闭360

1
adb server version (36) doesn't match this client (39); killing...

6. 使用adb shell调试

7. 用GDB调试程序,dump内存

可以在网络上搜索适合你的手机CPU体系结构的gdb可执行程序,用adb push到手机上使用;

Windows 上传,使用CMD

1
2
3
d:\android_sdk\platform-tools>adb.exe push D:\app\android-ndk-r10e\prebuilt\andr
oid-x86\gdbserver\gdbserver /data/local/tmp/
D:\app\android-ndk-r10e\prebuilt\andro...hed. 3.0 MB/s (409940 bytes in 0.132s)

修改权限 755

1
chmod 755 /data/local/tmp/gdbserver

Android系统上开启 gdbserver 服务 ,监听来自1234端口的消息

1
/data/local/tmp/gdbserver :1234 --attach pid

1
2
3
root@android:/ # /data/local/tmp/gdbserver :1234 --attach 1905
Attached; pid = 1905
Listening on port 1234

开启新的Shell 脚本执行端口转发

1
adb forward tcp:1234 tcp:1234

在NDK目录 $NDKROOT/toolchains目录下查找 gdb 客户端程序,如我的 Android 设备是ARM体系的,然后要在X86体系的PC上使用gdb客户端,所以打开的客户端就是: $NDKROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin 目录下的程序 arm-linux-androideabi-gdb.exe
在gdb提示符下输入下面的命令:

1
2
3
4
5
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
warning: Could not load vsyscall page because no executable was specified
try using the "file" command first.
0xb769135b in ()

首先编译arm-linux-androideabi-gdbandroid-ndk-r9中自带了 gdbserverarm-linux-androideabi-gdb ,但是使用 gdbserverarm-linux-androideabi-gdb 调试手机的时候,用gcore出现Command notimplemented for this target,原因是ndk里面自带的arm-linux-androideabi-gdbgcore 移除了,所以需要自己编译一个 arm-linux-androideabi-gdb

1
2
3
(gdb) gcore
warning: Signal SIGTRAP does not exist on this system.
Target does not support core file generation.

重新编译gdb

8. gdb dump 破解源码

欢迎关注我的其它发布渠道