当前位置:网站首页>The skill of using ADB and the principle of USB communication
The skill of using ADB and the principle of USB communication
2022-06-21 08:36:00 【WCanTouch】
About adb The tips and new findings on will be updated later , This article will be updated for a long time
One 、adb The technique used
1. Query the currently displayed Activity
adb shell dumpsys activity top | head -n 10
dumpactivity
2. Back up and restore all installed apk
Find the third party installed on the device apk Package name : adb shell pm list packages -3
basis apk Package name finding apk: adb shell pm path $pkg
export apk file : adb shell pull $path
Export the apk Install the file into the new device : adb install -r $file
Script :
#!/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;
doubt , The first 7 Rows query by package name apk When installing the path , Add a... At the end of the command & character , You can't find all without adding apk route , I don't know why .
3. adb debugging wifi Patterns and usb Mode switch
Mobile terminal (root)
install terminal
cut wifi: setprop service.adb.tcp.port 5555
cut wifi The restart still works :setprop persist.adb.tcp.port 5555
cut usb: setprop service.adb.tcp.port -1
stop adbd
start adbd
Switch on the computer wifi
cut wifi: adb tcpip 5555
cut usb: adb usb
Computer end connection equipment
wifi Pattern : adb connect mobile phone ip:5555
usb Pattern : adopt usb Connect the phone
Two 、adbs End sum adbd End ,usb Exploration of communication principle
1. distinguish usb equipment , find USB Equipment information
lsusb
usb_device_info
Record ID, Visit the website to view usb Device type ( What is the device )
http://www.linux-usb.org
It is possible to confirm the Vendors And equipment type ( The printer /Mass Storage etc. )
2. Linux The kernel recognizes the device
udevadm monitor --kernel
usb_kernel_monitor
Then go and check device Information about
udevadm info -q all -p
usb_kernel_info
3. adbs Access to the device file
start-up adbs, Check the process access device file
adb start-server ps -ef | grep adb lsof -p $pid
adb_access_device_file
4. adbs Source code analysis
The call stack
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)
from usb_vendors.c In file , You can know vendor Information is " curing "adbs Inside .( Can that explain why linux Unwanted adb What about the driver )
adbs_init_vendors
usb_linux.c Function list of the file
adbs_usb_linux_functions
Read the function inside , The main packaging linux usb Universal access device The way .
5. adbd Access to the device file
adb shell su (root jurisdiction ) lsof > /sdcard/lsof.data adb pull /sdcard/lsof.data less lsof.data
adbd_access_file
6. adbd Source code analysis
The call stack
main(adb.c)
main_adb(adb.c)
usb_init(usb_linux_client.c)
usb_adb_init(usb_linux_client.c)usb_adb_init The content of , Can be determined adbd Indeed visited /dev/android_adb file ( Equipment node )
usb_linux_client.c File definition read function , From the implementation point of view, it is mainly through /dev/android_adb Document communication with the outside world .
adbd_usb_linux_client_function
7. Series connection adbs and 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 and f_adb.c The code path is /drivers/usb/gadget/ Be careful : The code here is kernel Source code , No Android Source code (aosp). If you also downloaded linux kernel, You will find that there are no these two files .
1, Memory
Access to the device shell Environmental Science :
adb -s [ Equipment serial number ] shellGet the process number of the current target package :
ps | grep com.xxx.xxxView the memory information of the current process :
dumpsys meminfo Process number / package View the maximum memory limit for a single application :
getprop | grep heapgrowthlimit2, CPU
Displays the of the current process CPU Information :
top -n 10 -d 5 | grep [PID] [ notes ]:-n Indicates the number of refreshes ,-d Indicates the refresh interval Displays the total of the current process CPU Occupancy rate :
dumpsys cpuinfo Process number / package Start a activity, Show start time :
am start -W [ package /Activity] [ notes ]:e.g. com.xxx.xxx/com.xxx.xxx.xxx.activity
WaitTime: Including the previous application Activity pause Time and new Activity Start time
TotalTime: The time it takes to start a new application , Including process startup and Activity Start of
ThisTime: It means a series of starts Activity The last Activity The start-up time of 3, Traffic
Get the process number of the current target package :
ps | grep com.xxx.xxxaccording to PID obtain UID【1】
cat /proc/PID/statusGet download traffic
cat /proc/uid_stat /UID/tcp_rcvGet upload traffic
cat /proc/uid_stat/UID/tcp_sndAndroid Each application is assigned a different UID, here UID and Linux Of UID Somewhat different .
边栏推荐
- An aunt's towel holds up the 100 billion market behind 400million Chinese women
- Using elastic stack to analyze Olympic data (II)
- Unity write multithreading considerations
- 8 methods of getting user ID in WordPress
- Figure out how MySQL works
- Introduction to testing - Software Test Model
- 客户端建设及调优实践
- [Mgt] model Mgt for code interpretation
- Tidb3.0- 4.0 memory control / modification log saving days / maximum index length
- android 数据库升级
猜你喜欢

声临其境 — 音频沉浸体验

测试入门——软件测试模型

Ads Filter Design Wizard tool 2

请问这些要求用mysql能实现吗

Abstractqueuedsynchronizer (AQS) source code detailed analysis - condition queue process analysis

Tsinghua University | van: visual attention network

Showctf web primer series

Images, graphics and Applications (II)

Summary of mobile application development

Storage of C language integer in memory
随机推荐
Idea common code templates
LeetCode数组经典题目(一)
STL教程3-类型转换static_cast、dynamic_cast、const_cast、reinterpret_cast方法
Unmanned, automation technology affects the world
Fd: file descriptor
Unity 5 自帶的Mono也可以支持C# 6
FD:文件描述符
MySQL filter query (start with a letter, start with a number, start without a number, and start without a letter)
南京理工大学MOOC慕课:程序设计基础(Ⅰ)第8章测试选择题答案及解析
Represent each record in the dataframe as a dictionary
Mono of unity 5 can also support C # 6
写文章的markdown规则
测试入门——软件测试模型
[DB written interview 220] how to back up control files in oracle? What are the ways to back up control files?
This article takes you to interpret the advertising advantages of tiktok
[DB written interview 367] in the three-level schema structure of the database, the description of all data logical structures and features in the database is ()
GQL+Nodejs+MySQL数据库
Kotlin middle tail recursive function
4.6 lodash usage documents
优化食品生产行业库存管理的6种方法









