当前位置:网站首页>adb使用技巧和usb通信原理
adb使用技巧和usb通信原理
2022-06-21 08:33:00 【WCanTouch】
关于adb上的使用技巧和新的发现还会在后面继续更新,这篇将会长期更新的
一、adb使用的技巧
1. 查询当前展示的Activity
adb shell dumpsys activity top | head -n 10
dumpactivity
2. 备份和还原所有安装的apk
找出设备上安装的第三方apk包名: adb shell pm list packages -3
依据apk包名找出apk: adb shell pm path $pkg
导出apk文件: adb shell pull $path
把导出的apk文件安装到新设备里: adb install -r $file
脚本:
#!/bin/sh
echo -n "" > apks
adb shell pm list packages -3 | sed -E "s/\r$//" \
| while read line
do
pkg=${line#*:}
line=$(adb shell pm path "$pkg"&)
path=${line#*:}
echo $pkg:$path >> apks
done
cat apks
cat apks | sed -E "s/\r$//" | while read line
do
pkg=${line%:*}
path=${line#*:}
adb pull "$path" "$pkg.apk"
echo $path
done
rm apks
#echo $apks;
疑惑, 第7行通过包名查询apk安装路径时, 在命令最后添加一个&字符, 不添加无法正常找出所有apk路径, 不知道什么原由。
3. adb调试wifi模式和usb模式切换
手机端(root)
安装terminal
切wifi: setprop service.adb.tcp.port 5555
切wifi重启依然生效:setprop persist.adb.tcp.port 5555
切usb: setprop service.adb.tcp.port -1
stop adbd
start adbd
电脑上切换wifi
切wifi: adb tcpip 5555
切usb: adb usb
电脑端连接设备
wifi模式: adb connect 手机ip:5555
usb模式: 通过usb连接手机
二、adbs端和adbd端,usb通信原理探索
1. 识别usb设备, 找到USB设备信息
lsusb
usb_device_info
记录ID,访问网站查看usb设备类型(设备是什么)
http://www.linux-usb.org
可以确实设备的Vendors和设备类型(打印机/Mass Storage等)
2. Linux内核识别设备
udevadm monitor --kernel
usb_kernel_monitor
接着去查询一下device的信息
udevadm info -q all -p
usb_kernel_info
3. adbs 访问的device文件
启动adbs,查看一下进程访问的device文件
adb start-server ps -ef | grep adb lsof -p $pid
adb_access_device_file
4. adbs源代码分析
调用栈
main(adb.c)
main_adb(adb.c)
[
usb_vendors_init(usb_vendors.c)
usb_init(usb_linux.c)
]
-----new thread----
device_poll_thread(usb_linux.c)
find_usb_device(usb_linux.c)
kick_disconnected_devices(usb_linux.c)
从usb_vendors.c文件中,可以知道vendor信息是被"固化"adbs里面。(那是否就可以解释为啥linux不需要adb驱动呢)
adbs_init_vendors
usb_linux.c文件的函数列表
adbs_usb_linux_functions
里面读取函数,主要封装linux usb 通用的访问device的方式。
5. adbd 访问的device文件
adb shell su (root权限) lsof > /sdcard/lsof.data adb pull /sdcard/lsof.data less lsof.data
adbd_access_file
6. adbd源代码分析
调用栈
main(adb.c)
main_adb(adb.c)
usb_init(usb_linux_client.c)
usb_adb_init(usb_linux_client.c)usb_adb_init的内容, 可以确定adbd确实访问了/dev/android_adb文件(设备结点)
usb_linux_client.c文件定义读取函数,从实现上看它主要通过/dev/android_adb文件与外界通信。
adbd_usb_linux_client_function
7. 串联adbs和adbd(android kernel)
init(android.c)
usb_composite_register[&android_usb_driver](android.c)
android_bind(android.c)
usb_add_config[cdev, &android_config_driver](android.c)
android_bind_config(android.c)
adb_function_add(f_adb.c)
misc_deregister[&adb_device](f_adb.c)
static struct miscdevice adb_device = {
.minor = MISC_DYNAMIC_MINOR,
.name = shortname,
.fops = &adb_fops,
};
static const char shortname[] = "android_adb";
android.c和f_adb.c代码所在路径是/drivers/usb/gadget/ 注意:这里的代码是kernel的源代码,不是Android的源代码(aosp)。如果你也下载了linux kernel, 会发现没有这两个文件的。
1,内存
进入该设备的shell环境:
adb -s [设备序列号] shell获取当前目标包的进程号:
ps | grep com.xxx.xxx查看当前进程的内存信息:
dumpsys meminfo 进程号/包查看单个应用最大内存限制:
getprop | grep heapgrowthlimit2, CPU
显示当前进程的CPU信息:
top -n 10 -d 5 | grep [PID] [注]:-n表示刷新次数,-d表示刷新间隔显示当前进程总的CPU占有率:
dumpsys cpuinfo 进程号/包启动一个activity,显示启动时间:
am start -W [包/Activity] [注]:e.g. com.xxx.xxx/com.xxx.xxx.xxx.activity
WaitTime: 包括前一个应用Activity pause的时间和新Activity启动的时间
TotalTime:新应用启动的耗时,包括进程的启动和Activity的启动
ThisTime:表示一连串启动Activity的最后一个Activity的启动耗时3, 流量
获取当前目标包的进程号:
ps | grep com.xxx.xxx根据PID得到UID【1】
cat /proc/PID/status获取下载流量
cat /proc/uid_stat /UID/tcp_rcv获取上传流量
cat /proc/uid_stat/UID/tcp_sndAndroid为每个应用都分配了不同的UID,这里UID和Linux的UID有所不同。
边栏推荐
- Kotlin---- detailed explanation of data types
- Client construction and Optimization Practice
- 4.9 commander. js
- AQS source code exploration_ 01 handwriting a simplified reentrantlock reentrant lock
- Detailed analysis of ThreadPoolExecutor source code of thread pool
- Character function and string function
- Unity 5 自带的Mono也可以支持C# 6
- c#实现callback回调
- Nodejs post request JSON type and form type
- Antd table how scroll bars appear in long tables
猜你喜欢

window10局域网共享文件夹流程

The difference between tuples and lists

Ads Filter Design Wizard tool 2
![[early knowledge of activities] list of recent activities of livevideostack](/img/8c/f8007931b1a5944f3a0a243a5afcc4.png)
[early knowledge of activities] list of recent activities of livevideostack

Abstractqueuedsynchronizer (AQS) source code analysis - cyclicbarrier source code analysis

Qsort sort string

Introduction to testing - Software Test Model

2022-2028 global cooling on-off valve industry research and trend analysis report

Unity 5 自帶的Mono也可以支持C# 6

showCTF 入门文件包含系列
随机推荐
面试经验---字节
STL教程2-MyArray框架实现
Doc common syntax, updating
Understanding and use of advanced pointer
Mono of unity 5 can also support C # 6
[DB written interview 366] stored procedures are codes stored in the database and have many advantages. Among the following statements, which are not the advantages of stored procedures are ()
2022-2028 global section valve industry research and trend analysis report
写文章的markdown规则
STL tutorial 2-myarray framework implementation
怎么搭建深度学习框架?
Introduction to testing - Software Test Model
[DB written interview 220] how to back up control files in oracle? What are the ways to back up control files?
PS prompts "script error -50 general Photoshop error, how to solve it?
Unity 5 自帶的Mono也可以支持C# 6
Leedcode 1 - sum of two numbers
JUnit中的@Transactional消失不见,@Rollback是否能单抗测试回滚的大旗?
An aunt's towel holds up the 100 billion market behind 400million Chinese women
Dumping backup database
CTF中命令执行知识点总结
Nodejs post request JSON type and form type









