图例:引文中: 红色为命令 紫色为说明 黄色为操作 粉色为强调
目录
新建文件夹(system/app)
删除文件(system/app)
安装应用(system/app)
放置安装包并安装应用(system/app)
替换安装包(system/app)
查看当前活动TopActivity
查看应用信息Package
查看版本信息VersionCode
查看启动活动LauncherActivity
查看app包名
附:adb操作命令详解及大全 https://blog.csdn.net/janronehoo/article/details/6863772
问题描述:在Android设备系统system/app中新建一个文件夹
参考:https://www.cnblogs.com/xtfnpgy/p/9289203.html
步骤:
①准备工作:本次使用Android Studio 3.3的【Terminal终端】来执行命令;
②使用以下命令:
adb root
adb remount
adb shell // 进入shell -------------------------
mkdir /system/app/My_APP // 新建文件夹“My_APP” 【注意】多级的一次只能创建一级
exit // 退出shell -------------------------
效果如下:
D:\Android Studio\MyApplication\xxx\xxxx>adb root
D:\Android Studio\MyApplication\xxx\xxxx>adb remount
remount succeededD:\Android Studio\MyApplication\xxx\xxxx>adb shell
Xiaomi:/ # mkdir /system/app/My_APP
Xiaomi:/ # exit
问题描述:想要删除Android设备系统system/app里的apk,会报rm failed for XXX.apk, Read-only file system这样的错误
参考:https://blog.csdn.net/u013681630/article/details/77943640
步骤:(未验证)
①准备工作:配置好android 环境变量;②使用【Windows+R】进入cmd界面;
②连续使用以下命令:
adb root
adb remount
adb shell // 进入shell -------------------------
cd system/app
rm ***.apk // 删除具体文件“***.apk”
exit // 退出shell -------------------------
效果如下:
D:\Android Studio\My Application\xxx\xxx>adb root
D:\Android Studio\My Application\xxx\xxx>adb remount
remount succeededD:\Android Studio\My Application\xxx\xxx>adb shell
Xiaomi:/ # cd system/app
Xiaomi:/system/app # ls
AntHalService CaptivePortalLogin DownloadProviderUi Gmail2 LogSettings
SeempService WallpaperBackup datastatusnotification xdivert
DeviceInfo GFTest LiveWallpapersPicker Photos abcdef
Xiaomi:/system/app # cd abcdef
Xiaomi:/system/app/abcdef # ls
xyz.apk
Xiaomi:/system/app/abcdef # rm xyz.apk
Xiaomi:/system/app/abcdef # exit
附:删除文件夹使用以下命令:
rm -r ABCXYZ // 删除文件夹“ABCXYZ”
附录:使用adb命令删除Android系统data目录下文件及文件夹 https://blog.csdn.net/beijinghsj/article/details/78964068
问题描述:在 Android 中,如果要使用系统限制的权限(比如 android.permission.WRITE_SECURE_SETTINGS),我们需要把程序安装到 /system/app/ 下。
参考:https://xiaxingwork.iteye.com/blog/1740618
步骤:(未验证)
①准备工作:需要准备一台已经获得 Root 权限的手机,通过 USB 连接手机和电脑,使用 adb 控制手机;
②使用以下命令:
$ adb push SecureSetting.apk /sdcard/ // 上传要安装的文件,为安装做准备。
$ adb shell
$ su // 切换到 root 用户。如果没有获得 Root 权限,这一步不会成功。
# mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system // 让分区可写。
# cat /sdcard/SecureSetting.apk > /system/app/xxx.apk // 这一步可以用 cp 实现,但一般设备中没有包含该命令。如果使用 mv 会出现错误:failed on '/sdcard/NetWork.apk' - Cross-device link。
# mount -o remount,ro -t yaffs2 /dev/block/mtdblock3 /system // 还原分区属性,只读。
# exit
$ exit
问题描述:已在“/system/app/”中的指定文件夹中存在一个安装包,已有目录,不需要再mkdir了
参考:
步骤:
①准备工作:本次使用Android Studio 3.3的【Terminal终端】来执行命令;
②先后执行如下命令:
adb root
adb remount
adb push [D:\xxxx.apk] [/system/app/MyDirectory] // 注:第一个[]内地址为新包所在的电脑上的位置;第二个[]内的地址为目标文件夹地址,"[]"方括号不用写
adb reboot // 重启
效果如下:
D:\Android Studio\MyApplication\***\****>adb root
D:\Android Studio\MyApplication\***\****>adb remount
remount succeededD:\Android Studio\MyApplication\***\****>adb push D:\My123.apk /system/app/My123 // push到指定文件夹
D:\My123.apk: 1 file pushed. 5.8 MB/s (8957684 bytes in 1.472s)D:\Android Studio\MyApplication\***\****>adb shell // 以下为进入文件夹验证一下文件有没有push成功-----
Xiaomi:/ # cd /system/app/My123/
Xiaomi:/system/app/My123 # ls
My123.apk // 发现确实push成功了
Xiaomi:/system/app/My123 # exit // 退出shellD:\Android Studio\MyApplication\***\****>adb reboot
注意:
问题描述:已在“/system/app/”中存在一个安装包,现要用新的安装包替换掉原来的旧包,已有目录,不需要再mkdir了
参考:
步骤:
①准备工作:本次使用Android Studio 3.3的【Terminal终端】来执行命令;
②先后执行如下命令:
adb root
adb remount
adb push [D:\xxxx.apk] [/system/app/MyDirectory/xxx.apk] // 注:第一个[]内地址为新包所在的电脑上的位置;第二个[]内的地址为目标替换地址,"[]"方括号不用写
adb reboot // 重启
效果如下:
D:\Android Studio\MyApplication\***\****>adb root
D:\Android Studio\MyApplication\***\****>adb remount
remount succeededD:\Android Studio\MyApplication\***\****>adb push D:\123456.apk /system/app/Signed_xxx/123456.apk
D:\123456.apk: 1 file pushed. 6.9 MB/s (8957520 bytes in 1.243s)
D:\Android Studio\MyApplication\***\****>adb reboot
意外情况:
①重启使用“关机--开机”方法未成功;使用“adb reboot”命令可以成功
②关于使用Windows CMD终端报错“system/bin/sh: adb: not found”,可参考:https://blog.csdn.net/qq_29216083/article/details/61414014
问题描述:拿到别人的代码后,快速定位模拟器当前显示的页面的Activity
步骤:先数据线连接电脑;再执行如下命令;最后根据包名筛选到自己的目标Activity
命令:
adb shell dumpsys activity top | grep ACTIVITY // [Linux环境/Git Bash等]
adb shell dumpsys activity top | findstr ACTIVITY // [Windows环境]
效果:
C:\Users\Administrator>adb shell dumpsys activity top | findstr ACTIVITY
ACTIVITY com.****.sohu.launcher/.MainActivity 66c7f5d pid=20**0 // 这货可能是个广告吧
ACTIVITY com.android.systemui/.recents.RecentsActivity 7a09d1f pid=3**7 // 包名systemui,应该不是
ACTIVITY com.sec.android.app.launcher/.activities.LauncherActivity 81afe73 pid=4**4 // 包名launcher,也不是
ACTIVITY com.ela.***/pro.**.service.activity.xxxxActivity dcdd8e0 pid=2**5 // 是自己的包名,就是它了
问题描述:查看安装后的应用信息
步骤:先数据线连接电脑;再执行如下命令;最后根据包名筛选到自己所需要的信息
命令:
adb shell dumpsys package com.xxx.xxxx // com.xxx.xxxx为要查询应用的包名
效果:
C:\Users\Administrator>adb shell
Xiaomi:/ $ dumpsys package com.xxx.xxxx
Activity Resolver Table:
Non-Data Actions:
android.intent.action.MAIN:
e477ac4 com.xxx.xxxx/com.xxx.xxxx.activity.WelcomeActivity filter 8cde863 // LauncherActivity了
Action: "android.intent.action.MAIN"
Action: "android.intent.action.VIEW"
Category: "android.intent.category.LAUNCHER"
android.intent.action.VIEW:
e477ac4 com.xxx.xxxx/com.xxx.xxxx.activity.WelcomeActivity filter 8cde863
Action: "android.intent.action.MAIN"
Action: "android.intent.action.VIEW"
Category: "android.intent.category.LAUNCHER"Receiver Resolver Table:
Non-Data Actions:
com.xxx.myxxx.broadcast.SDK_XXXXXX_LOGOUT_ONLY:
36f2dad com.xxx.xxx/com.xxx.xxx.broadcast.xxxLogoutReceiver filter 3923692
Action: "com.xxx.xxx.broadcast.SDK_XXXXXX_LOGOUT_ONLY"
com.xxx.xxx.broadcast.SDK_XXXXXX_LOGIN_ONLY:
70f58e2 com.xxx.xxx/com.xxx.xxx.broadcast.xxxReceiver filter 8c1341d
Action: "com.xxx.xxx.broadcast.SDK_XXXXXX_LOGIN_ONLY"Registered ContentProviders:
com.xxx.xxx/com.pizidea.imagepicker.ImagePickerProvider:
Provider{f69e473 com.xxx.xxx/com.pizidea.imagepicker.ImagePickerProvider}
......ContentProvider Authorities:
[com.xxx.xxx.downloadfileprovider]:
Provider{cce212e com.xxx.xxx/com.xxx.xxx.download.DownloadFileProvider}
applicationInfo=ApplicationInfo{7a7666b com.xxx.xxx}
.......Key Set Manager:
[com.xxx.xxx]
Signing KeySets: 16Packages:
Package [com.xxx.xxx] (97454cf):
userId=10068
pkg=Package{387a6c7 com.xxx.xxx}
codePath=/data/app/com.xxx.xxx-KHF3s-p1K6WcAu4a5VdS4w==
resourcePath=/data/app/com.xxx.xxx-KHF3s-p1K6WcAu4a5VdS4w==
legacyNativeLibraryDir=/data/app/com.xxx.xxx-KHF3s-p1K6WcAu4a5VdS4w==/lib
primaryCpuAbi=null
secondaryCpuAbi=null
versionCode=10037 minSdk=21 targetSdk=28 // 版本信息
versionName=1.0.21
splits=[base]
apkSigningVersion=1
applicationInfo=ApplicationInfo{7a7666b com.xxx.xxx}
flags=[ SYSTEM HAS_CODE ALLOW_CLEAR_USER_DATA UPDATED_SYSTEM_APP ALLOW_BACKUP LARGE_HEAP ]
privateFlags=[ PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION ]
dataDir=/data/user/0/com.xxx.xxx
supportsScreens=[small, medium, large, xlarge, resizeable, anyDensity]
timeStamp=2019-04-09 11:50:11
firstInstallTime=2019-04-06 16:51:30
lastUpdateTime=2019-04-09 11:50:17
installerPackageName=com.google.android.packageinstaller
signatures=PackageSignatures{f795e5c [3acd5fc8]}
installPermissionsFixed=true installStatus=1
pkgFlags=[ SYSTEM HAS_CODE ALLOW_CLEAR_USER_DATA UPDATED_SYSTEM_APP ALLOW_BACKUP LARGE_HEAP ]
requested permissions:
android.permission.INTERNET
.....
android.permission.ACCESS_WIFI_STATE: granted=true
android.permission.WAKE_LOCK: granted=true
User 0: ceDataInode=5112277 installed=true hidden=false suspended=false stopped=false restricted=false notLaunched=false enabled=0 instant=false virtual=false
lastDisabledCaller: com.google.android.packageinstaller
gids=[3003]
runtime permissions:
android.permission.READ_EXTERNAL_STORAGE: granted=true
android.permission.READ_PHONE_STATE: granted=true
android.permission.WRITE_EXTERNAL_STORAGE: granted=trueHidden system packages:
Package [com.xxx.xxx] (ee42006):
userId=10068
pkg=Package{a7cd4f4 com.xxx.xxx}
codePath=/system/app/xxx
resourcePath=/system/app/xxx
legacyNativeLibraryDir=/system/app/xxx/lib
primaryCpuAbi=null
secondaryCpuAbi=null
versionCode=10037 minSdk=21 targetSdk=28
versionName=1.0.20
splits=[base]
apkSigningVersion=1
applicationInfo=ApplicationInfo{8730cf6 com.xxx.xxx}
flags=[ SYSTEM HAS_CODE ALLOW_CLEAR_USER_DATA UPDATED_SYSTEM_APP ALLOW_BACKUP LARGE_HEAP ]
privateFlags=[ PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION ]
dataDir=/data/user/0/com.xxx.xxx
supportsScreens=[small, medium, large, xlarge, resizeable, anyDensity]
timeStamp=2019-04-06 16:51:30
firstInstallTime=2019-04-06 16:51:30
lastUpdateTime=2019-04-06 16:51:30
signatures=PackageSignatures{f795e5c [3acd5fc8]}
installPermissionsFixed=true installStatus=1
pkgFlags=[ SYSTEM HAS_CODE ALLOW_CLEAR_USER_DATA ALLOW_BACKUP LARGE_HEAP ]
requested permissions:
android.permission.INTERNET
......
android.permission.REQUEST_INSTALL_PACKAGES
install permissions:
android.permission.WRITE_SETTINGS: granted=true
...
android.permission.ACCESS_WIFI_STATE: granted=true
android.permission.WAKE_LOCK: granted=true
User 0: ceDataInode=5112277 installed=true hidden=false suspended=false stopped=false restricted=false notLaunched=false enabled=0 instant=false virtual=false
lastDisabledCaller: com.google.android.packageinstaller
gids=[3003]
runtime permissions:
android.permission.READ_EXTERNAL_STORAGE: granted=true
android.permission.READ_PHONE_STATE: granted=true
android.permission.WRITE_EXTERNAL_STORAGE: granted=truePackage Changes:
Sequence number=5
User 0:
seq=1, package=com.google.android.gms
seq=2, package=com.xxx.xxx
seq=3, package=com.android.vending
seq=4, package=com.xxx.sdk.demo
Dexopt state:
[com.xxx.xxx]
path: /data/app/com.xxx.xxx-KHF3s-p1K6WcAu4a5VdS4w==/base.apk
arm64: /data/app/com.xxx.xxx-KHF3s-p1K6WcAu4a5VdS4w==/oat/arm64/base.odex[status=kOatUpToDate, compilation_fil
ter=speed-profile]
Compiler stats:
[com.xxx.xxx]
base.apk - 3713
xxxxxx.apk - 1635
【拓展】对于已经拿到apk安装包的情况,可以直接把apk安装包拖进“Android Studio”中查看其AndroidManifest.xml文件查看
问题描述:查看一个已经安装在手机中的应用的版本信息VersionCode
步骤:根据上一操作的启示,可以使用如下命令筛选:
命令:
adb shell dumpsys package com.xxx.xxxx | grep version // [Linux环境/Git Bash等]
adb shell dumpsys package com.xxx.xxxx | findstr version // [Windows环境]
效果:
C:\Users\Administrator>adb shell dumpsys package com.xxx.xxxx | findstr version
versionCode=2 minSdk=19 targetSdk=27
versionName=1.0.1
【补充】VersionName对于开发者来说没啥用,也可以方便地在应用内的“关于”页面或者系统的设置页面的具体应用信息中找到
问题描述:查看一个已经安装在手机中的应用的启动活动LauncherActivity
参考:https://blog.csdn.net/yangsummer2426/article/details/80929869
步骤:
①准备工作:使用【Windows+R】进入cmd界面
②【方式一】依次使用以下命令:
adb shell // 进入shell
dumpsys package com.xxx.xxx // 使用包名com.xxx.xxx
效果如下:
C:\Users\Administrator>adb shell
Xiaomi:/ $ dumpsys package com.xxx.xxxx
Activity Resolver Table:
Non-Data Actions:
android.intent.action.MAIN:
e477ac4 com.xxx.xxxx/com.xxx.xxxx.activity.WelcomeActivity filter 8cde863 // 找到LauncherActivity了
Action: "android.intent.action.MAIN"
Action: "android.intent.action.VIEW"
Category: "android.intent.category.LAUNCHER"
android.intent.action.VIEW:
e477ac4 com.xxx.xxxx/com.xxx.xxxx.activity.WelcomeActivity filter 8cde863
Action: "android.intent.action.MAIN"
Action: "android.intent.action.VIEW"
Category: "android.intent.category.LAUNCHER"
...
...
②【方式二】依次使用以下命令:
使用Monkey命令 monkey -p com.xxx.xxx -vvv 1 可以设置日志的详细程度,当我们指定为 -VVV 的时候,并且指定模拟随机事件为一次
adb shell // 进入shell
monkey -p com.xxx.xxx -vvv 1 // com.xxx.xxx为包名
效果如下:
C:\Users\Administrator>adb shell
Xiaomi:/ $ monkey -p com.xxx.xxxx -vvv 1
bash arg: -p
bash arg: com.xxx.xxx
bash arg: -vvv
bash arg: 1
args: [-p, com.xxx.xxx, -vvv, 1]
arg: "-p"
arg: "com.xxx.xxx"
arg: "-vvv"
arg: "1"
data="com.xxx.xxx"
:Monkey: seed=1555038566556 count=1
:AllowPackage: com.xxx.xxx
:IncludeCategory: android.intent.category.LAUNCHER
:IncludeCategory: android.intent.category.MONKEY
// Event percentages:
// 0: 15.0%
...
// 11: 13.0%
:Switch: #Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.xxx.xxx/com.xxx.xxx.activity.WelcomeActivity;end
// Allowing start of Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.xxx.xxx/com.xxx.xxx.activity.WelcomeActivity } in package com.xxx.xxx // 找到启动Activity
Events injected: 1
:Sending rotation degree=0, persist=false
:Dropped: keys=0 pointers=0 trackballs=0 flips=0 rotations=0
## Network stats: elapsed time=137ms (0ms mobile, 0ms wifi, 137ms not connected)
// Monkey finished
问题描述:查看已经安装在手机中的应用的包名PackageName
参考:https://blog.csdn.net/yangsummer2426/article/details/80929869
步骤:
①准备工作:使用【Windows+R】进入cmd界面
②使用以下命令:
adb shell pm list package -f
可获取手机内所有apk对应的包名和路径,ctrl+f后输入你要查找的app的关键词可快速找到你想要的app包名
效果如下:
C:\Users\Administrator>adb shell pm list package -f
package:/system/priv-app/OverlayCMLauncher3/OverlayCMLauncher3.apk=com.hmct.overlaylauncher3
package:/system/app/TelemetryService/TelemetryService.apk=com.qualcomm.qti.haven.telemetry.service
package:/system/priv-app/CtsShimPrivPrebuilt/CtsShimPrivPrebuilt.apk=com.android.cts.priv.ctsshim
package:/system/app/YouTube/YouTube.apk=com.google.android.youtube
package:/system/framework/framework-res.apk=android
...... // 发现大多都安装在【/system/priv-app/】和【/system/app/】文件夹下
package:/system/priv-app/ContactsProvider/ContactsProvider.apk=com.android.providers.contacts
package:/system/app/CaptivePortalLogin/CaptivePortalLogin.apk=com.android.captiveportallogin
package:/system/app/LatinImeGoogle/LatinImeGoogle.apk=com.google.android.inputmethod.latin