当前位置:网站首页>How to use ADB shell to query process traffic
How to use ADB shell to query process traffic
2022-06-21 08:36:00 【WCanTouch】
1、 Get applied Pid.
Can pass adb shell ps Get all process information , Of course, it contains the application pid And the package name . Then search the returned information ( Find by package name ).
C:\Users>adb shell ps
USER PID PPID VSIZE RSS WCHAN PC NAME
root 1 0 17336 1668 SyS_epoll_ 0000000000 S /init
root 2 0 0 0 kthreadd 0000000000 S kthreadd
root 3 2 0 0 smpboot_th 0000000000 S ksoftirqd/0
root 5 2 0 0 worker_thr 0000000000 S kworker/0:0H
root 7 2 0 0 rcu_gp_kth 0000000000 S rcu_preempt
root 8 2 0 0 rcu_gp_kth 0000000000 S rcu_sched
root 9 2 0 0 rcu_gp_kth 0000000000 S rcu_bh
root 10 2 0 0 nocb_leade 0000000000 S rcuop/0
root 11 2 0 0 nocb_leade 0000000000 S rcuos/0
root 12 2 0 0 nocb_leade 0000000000 S rcuob/0
root 13 2 0 0 smpboot_th 0000000000 S rcuc/0
root 14 2 0 0 rcu_boost_ 0000000000 S rcub/0
root 15 2 0 0 smpboot_th 0000000000 S migration/0
root 16 2 0 0 smpboot_th 0000000000 S migration/1
root 17 2 0 0 smpboot_th 0000000000 S rcuc/1
root 18 2 0 0 smpboot_th 0000000000 S ksoftirqd/1
root 20 2 0 0 worker_thr 0000000000 S kworker/1:0H
root 21 2 0 0 rcu_nocb_k 0000000000 S rcuop/1
root 22 2 0 0 rcu_nocb_k 0000000000 S rcuos/1Are the screenshots above still captured ; Find the one you signed up for PID, Use... In the back
2、 Get applied Uid.
Android System catalog file /proc/pid/status( Be careful : Marked red pid It's No 1 What we got in step pid, Is a greater than 0 The number of ) Contains information about uid Information about . With pid=15904 For example , adopt adb shell cat /proc/15904/status You can get the following information :
C:\Users>adb shell
msm8953_64:/ $ cat /proc/15904/status
cat /proc/15904/status
Name: com.******
State: S (sleeping)
Tgid: 15904
Pid: 15904
PPid: 755
TracerPid: 0
Uid: 10092 10092 10092 10092
Gid: 10092 10092 10092 10092
Ngid: 0
FDSize: 256
Groups: 3002 3003 9997 50092
VmPeak: 1666848 kB
VmSize: 1218200 kB
VmLck: 0 kB
VmPin: 0 kB
VmHWM: 129268 kB
VmRSS: 125288 kB
VmData: 244900 kB
VmStk: 8196 kB
VmExe: 20 kB
VmLib: 144944 kB
VmPTE: 972 kB
VmSwap: 380 kB
Threads: 64
SigQ: 0/10488
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000001204
SigIgn: 0000000000000000
SigCgt: 20000002000084f8
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 0000000000000000
Seccomp: 0
Cpus_allowed: ff
Cpus_allowed_list: 0-7
voluntary_ctxt_switches: 2751
nonvoluntary_ctxt_switches: 417
By analyzing the above information, you can get Uid.
3、 Read flow value .
Android System catalog file /proc/uid_stat/uid/ There are usually two files under the tcp_snd and tcp_rcv.( Be careful : Marked red uid Is obtained in step 2 Uid The number ). adopt adb shell cat /proc/uid_stat/10092/tcp_snd and adb shell cat /proc/uid_stat/10092/tcp_rcv You can obtain uplink traffic and downlink traffic respectively .
127|msm8953_64:/ $ ls /proc/uid_stat/10092
ls /proc/uid_stat/10092
tcp_rcv tcp_sndmsm8953_64:/ $ cat /proc/uid_stat/10092/tcp_snd
cat /proc/uid_stat/10092/tcp_snd
119973585msm8953_64:/ $ cat /proc/uid_stat/10092/tcp_snd
cat /proc/uid_stat/10092/tcp_rcv
123436113We will provide the following information adb Some commands for :
adb devices List all devices
adb -s Equipment name shell Enter the corresponding equipment
cd proc Enter the attribute directory of the device
cd uid_stat Get into user id Status directory , When each application is installed, the system will assign a corresponding... To each application uid
ls List uid_stat Corresponding to all applications in the directory user id Catalog
cd uid Enter the corresponding application uid Catalog
ls View correspondence uid In the catalog tcp_rcv and tcp_snd Catalog
cat tcp_rcv View the data information received by the application
cat tcp_snd View the data information sent by the application Reprint it later Analysis of other great gods tcp_send Code :
private Long getTotalBytesManual(int localUid) {
// Log.e("BytesManual*****", "localUid:" + localUid);
File dir = new File("/proc/uid_stat/");
String[] children = dir.list();
StringBuffer stringBuffer = new StringBuffer();
for (int i = 0; i < children.length; i++) {
stringBuffer.append(children[i]);
stringBuffer.append(" ");
}
// Log.e("children*****", children.length + "");
// Log.e("children22*****", stringBuffer.toString());
if (!Arrays.asList(children).contains(String.valueOf(localUid))) {
return 0L;
}
File uidFileDir = new File("/proc/uid_stat/" + String.valueOf(localUid));
File uidActualFileReceived = new File(uidFileDir, "tcp_rcv");
File uidActualFileSent = new File(uidFileDir, "tcp_snd");
String textReceived = "0";
String textSent = "0";
try {
BufferedReader brReceived = new BufferedReader(new FileReader(uidActualFileReceived));
BufferedReader brSent = new BufferedReader(new FileReader(uidActualFileSent));
String receivedLine;
String sentLine;
if ((receivedLine = brReceived.readLine()) != null) {
textReceived = receivedLine;
// Log.e("receivedLine*****", "receivedLine:" + receivedLine);
}
if ((sentLine = brSent.readLine()) != null) {
textSent = sentLine;
// Log.e("sentLine*****", "sentLine:" + sentLine);
}
} catch (IOException e) {
e.printStackTrace();
// Log.e("IOException*****", e.toString());
}
// Log.e("BytesManualEnd*****", "localUid:" + localUid);
return Long.valueOf(textReceived).longValue() + Long.valueOf(textSent).longValue();
}
Please point out what the gods have done wrong , thank you
边栏推荐
- Unmanned, automation technology affects the world
- Diary (C language summary)
- 《网络是怎么样连接的》读书笔记 - FTTH
- PS prompts "script error -50 general Photoshop error, how to solve it?
- Represent each record in the dataframe as a dictionary
- 微信小程序
- apk 反编译 上的填坑之路
- Linux环境下MySQL的安装过程
- 8 methods of getting user ID in WordPress
- 4.9 commander. js
猜你喜欢

Understanding and use of advanced pointer

Two image enhancement methods: image point operation and image graying

Windows10 LAN shared folder process

Fd: file descriptor

Markdown rule for writing articles

Three ways to solve cross domain problems

声临其境 — 音频沉浸体验

Decrypt FTP

5 minutes to understand MySQL - row to column

tidb4.0.0遇见的问题、报错总结(tiup部署)
随机推荐
关于sql的问题:两张表的字段关联问题
Figure out how MySQL works
Tidb3.0- 4.0 memory control / modification log saving days / maximum index length
Higher order functions in kotlin (first-class citizens)
南京理工大学MOOC慕课:程序设计基础(Ⅰ)第8章测试选择题答案及解析
[DB written interview 274] in Oracle, what is deferred segment creation?
Diary (C language summary)
source Insight 快捷键 对照
Ads Filter Design Wizard tool 2
[early knowledge of activities] list of recent activities of livevideostack
日記(C語言總結)
Retrofit擴展閱讀
An aunt's towel holds up the 100 billion market behind 400million Chinese women
Extensions in kotlin
window10局域网共享文件夹流程
Kotlin---- detailed explanation of data types
Topic34——31. 下一个排列
This article takes you to interpret the advertising advantages of tiktok
Unity开发相关的博客收集
解密FTP