android.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. # Android Debug Bridge
  2. https://source.android.com/setup/build/adb
  3. https://developer.android.com/studio/command-line/adb
  4. # Enabling debug mode
  5. Settings > About Phone > Software information >
  6. Scroll down to 'Build number' and tap that box 7 times
  7. # Enabling debug mode (Android version 11)
  8. Settings > About Phone > Version >
  9. Scroll down to 'Build number' and tap that box 7 times >
  10. Enter PIN to confirm
  11. # Enabling usb debugging
  12. Setting > Search > Type 'developer options' > Select the 'Developer options'
  13. under 'Developer options' (and not the one under 'Screen reader') > Scroll
  14. down to 'USB debugging' directly under the 'Debugging header' and slide the
  15. switch from Off (left) to On (right) > Press 'OK' to confirm you want to enable
  16. USB debugging.
  17. # Connecting via ADB (USB mode)
  18. $ adb start-server
  19. $ adb connect <ip address> # skip if connect to usb
  20. $ adb devices
  21. $ adb shell
  22. $ ls
  23. $ pm list packages
  24. $ pm list packages | grep <search-term>
  25. $ pm list packages -s | grep <search-term> # system apps
  26. $ pm uninstall -k --user 0 <pkgname> # keep app data intact
  27. $ pm uninstall --user 0 <pkgname> # removing bloated app
  28. $ pm path <pkgname> # path to the apk file
  29. $ exit
  30. $ adb kill-server
  31. pm list packages -f # see their associated file
  32. pm list packages -d # filter to only show disabled packages
  33. pm list packages -e # filter to only show enabled packages
  34. pm list packages -i # see the installer for the packages
  35. pm list packages -u # also include uninstalled packages
  36. Note: The command pm list packages -f will often fill up several screens. That
  37. is not useful for forensic examination. So, the first step is to exit the shell
  38. using exit. Then, with any command, you can export the output to a text file.
  39. When executing shell commands from outside the shell, you should precede the
  40. command with adb shell.
  41. adh shell pm list packages -f > package.txt
  42. # list of all connected devices
  43. adb devices -l
  44. # list all the installed packages
  45. adb shell pm list packages
  46. # list the package names as well as the path to the installed APK files
  47. adb shell pm list packages -f
  48. # list only the system packages
  49. adb shell pm list packages -s
  50. # list system package names with the installed package location
  51. adb shell pm list packages -f -s
  52. # list only 3rd party (non-system) packages
  53. adb shell pm list packages -3
  54. # list 3rd party package names with the installed package location
  55. adb shell pm list packages -f -3
  56. # list all the disabled package names
  57. adb shell pm list packages -d
  58. # list all the enabled package names
  59. adb shell pm list packages -e
  60. # information
  61. adb shell getprop ro.product.model
  62. adb shell getprop ro.build.version.release
  63. adb shell getprop ro.serialno
  64. adb shell getprop ro.board.platform
  65. adb shell getprop ro.build.description
  66. adb shell getprop ro.product.locale.language
  67. adb shell getprop ro.product.locale.region
  68. adb shell getprop ro.board.platform
  69. adb shell getprop ro.build.version.codename
  70. # command parameters format to backup data without unlock/root
  71. adb backup [-f <file>] [-apk | -noapk] [-shared | -noshared] [-all]
  72. [-system | -nosystem] [<packages...>]
  73. # backup system and app data but not the apps themselves
  74. adb backup -all
  75. (by default it saves device data to the current directory as backup.ab)
  76. # backup system and app data to a file but not the apps themselves
  77. adb backup -all -f /home/user/android_backup/backup_file.ab
  78. # backup system and app data including the apps themselves
  79. adb backup -all -apk
  80. # backup system and app data alone and does not backup apps (default)
  81. adb backup -all -noapk
  82. # backup data on the SD card (enable backup of the device's shared storage contents)
  83. adb backup -all -shared
  84. # does not backup data on the SD card (default)
  85. adb backup -all -noshared
  86. # -system sets whether or not the -all flag also includes system applications or not
  87. adb backup -all -system # include system applications
  88. # -nosystem (default)
  89. adb backup -all -nosystem # no system applications
  90. # backup a specific application package
  91. adb backup <packages...>
  92. adb backup -noapk com.android.vending -f backup_google_play_store.ab
  93. The above command indicates that we want ot backup "com.android.vending" package to
  94. "backup_google_play_store.ab" file as indicated with the -f flag. The .ab says it is
  95. an Android Backup file. The -noapk flag indicates that we don't want the .apk file to
  96. be backed up. Now we should see a confirmation dialog prompt to start the backup. The
  97. backup will not start until we press "Back up my data".
  98. # example backup command
  99. adb backup -apk -shared -all -f /home/user/android_backup/backup_file.ab
  100. # restore the backup data
  101. adb restore /home/user/android_backup/backup_file.ab
  102. # restore a specific application package
  103. adb restore backup_google_play_store.ab
  104. # files
  105. $ adb shell
  106. $ cd storage/self/primary/
  107. $ cd sdcard/ [same directory as above]
  108. Asus - 49.42 GB used of 64 GB [77% used]
  109. # Apps to be remove
  110. Calculator - com.asus.calculator 172 KB (rm)
  111. Calendar - com.google.android.calendar 14.97 MB (rm)
  112. Chrome - com.android.chrome 85.77 MB (rm)
  113. Drive - com.google.android.apps.docs 16.76 MB (rm)
  114. Duo - com.google.android.apps.tachyon 10.85 MB (rm)
  115. facebook - com.facebook.katana 119 KB (rm)
  116. Facebook App Installer - com.facebook.system (rm)
  117. Facebook App Manager - com.facebook.appmanager (rm)
  118. Gboard - com.google.android.inputmethod.latin 9.74 MB (rm)
  119. Gmail - com.google.android.gm 18.83 MB (rm)
  120. Google - com.google.android.googlequicksearchbox 62.82 MB (rm)
  121. Google Play Movies & TV - com.google.android.videos 22.34 MB (rm)
  122. Google Play Music - com.google.android.music 18.65 MB (rm)
  123. Google Play Store - com.android.vending 3.34 MB (rm)
  124. Google Text-to-speech Engine - com.google.android.tts (rm)
  125. Instagram - com.instagram.android 119 KB (rm)
  126. Maps - com.google.android.apps.maps 41.68 MB (rm)
  127. Messenger - com.facebook.orca 119 KB (rm)
  128. Photos - com.google.android.apps.photos 25.83 MB (rm)
  129. Youtube - com.google.android.youtube 24.89 MB (rm)
  130. # fdroidcl [https://github.com/mvdan/fdroidcl]
  131. fdroidcl update # fetch and update the fdroid index
  132. fdroidcl search # show all available apps
  133. fdroidcl search <search_term> # search for an app in the index
  134. fdroidcl show <appid_term> # display info about an app
  135. fdroidcl download <appid_term> # download an APK file
  136. fdroidcl install <appid_term> # install an app
  137. fdroidcl uninstall <appid_term> # uninstall an app
  138. fdroidcl search -u # show all available updates
  139. fdroidcl install -u # install all available updates
  140. Commands:
  141. update Update the index
  142. search [<regexp...>] Search available apps
  143. show <appid...> Show detailed info about an app
  144. install [<appid...>] Install or upgrade apps
  145. uninstall <appid...> Uninstall an app
  146. download <appid...> Download an app
  147. devices List connected devices
  148. list (categories) List all known values of a kind
  149. defaults Reset to the default settings
  150. version Print version information
  151. An appid is just an app's unique package name. A specific version of an app
  152. can be selected by following the appid with a colon and the version code. The
  153. 'search' and 'show' commands can be used to find these strings.
  154. For example:
  155. $ fdroidcl search redreader
  156. $ fdroidcl show org.quantumbadger.redreader
  157. $ fdroidcl install org.quantumbadger.redreader:85
  158. List of search options:
  159. $ fdroidcl search [option]
  160. -q print package names only
  161. -i filter installed apps
  162. -u filter apps with updates
  163. -d select apps last updated in the last <n> days; a negative value drops them
  164. -c filter apps by category
  165. -o sort order (added, updated)
  166. List all installed apps:
  167. To list all installed apps on a device we can use the following command:
  168. $ fdroidcl search -i -q
  169. # adb version
  170. $ adb version
  171. # get state
  172. $ adb shell settings get global airplane_mode_on [0/1 - disabled/enabled]
  173. $ adb shell settings get global mobile_data [0/1 - disabled/enabled]
  174. $ adb shell settings get global wifi_on [0/1 - disabled/enabled]
  175. $ adb shell settings get global bluetooth_on [0/1 - disabled/enabled]
  176. $ adb shell settings get global cell_on [0/1 - disabled/enabled]
  177. # enable/disable wifi
  178. $ adb shell svc wifi enable
  179. $ adb shell svc wifi disable
  180. # enable/disable data
  181. $ adb shell svc data enable
  182. $ adb shell svc data disable
  183. # enable/disable airplane
  184. # enable:
  185. $ adb shell settings put global airplane_mode_on 1
  186. $ adb shell am broadcast -a android.intent.action.AIRPLANE_MODE
  187. # disable:
  188. $ adb shell settings put global airplane_mode_on 0
  189. $ adb shell am broadcast -a android.intent.action.AIRPLANE_MODE
  190. # enable/disable bluetooth
  191. # enable:
  192. $ adb shell settings put global bluetooth_disabled_profiles 1
  193. # disable:
  194. $ adb shell settings put global bluetooth_disabled_profiles 0
  195. # bash script that checks state and then switch on/off:
  196. #!/bin/bash
  197. function toggle_wifi {
  198. if [[ $(adb shell settings get global wifi_on) == "1" ]]; then
  199. adb shell svc wifi disable
  200. else
  201. adb shell svc wifi enable; fi
  202. }
  203. function toggle_data {
  204. if [[ $(adb shell settings get global mobile_data) == "1" ]]; then
  205. adb shell svc data disable
  206. else
  207. adb shell svc data enable; fi
  208. }
  209. toggle_wifi
  210. toggle_data
  211. exit 0;
  212. Reference:
  213. https://stackoverflow.com/questions/23528824/is-there-an-adb-command-to-enable-
  214. disable-mobile-datarooted-device
  215. https://android.stackexchange.com/questions/228469/how-to-switchnot-only-on-or-
  216. off-the-mobile-data-and-wifi-using-adb
  217. # delete contact via adb
  218. # to query contact
  219. $ adb shell content query --uri content://com.android.contacts/contacts
  220. # to add contact (where's id = 8)
  221. $ adb shell content edit --uri content://com.android.contacts/contacts/8
  222. # to remove contact (where's id = 1)
  223. $ adb shell content delete --uri content://com.android.contacts/contacts/1
  224. # to remove all contacts at once
  225. $ adb shell pm clear com.android.providers.contacts
  226. # take screenshots and recordings
  227. Let's start recordingg a video of our device screen by running the following
  228. command:
  229. $ adb shell screenrecord /sdcard/Movies/video.mp4
  230. This will record the device screen and save the video file to the path
  231. /sdcard/Movies/video.mp4. To stop recording press Ctrl+C to finish the command.
  232. In order to take a screenshot of some screen of our app we just need to navigate
  233. to the desired screen, and then run the command:
  234. $ adb shell screencap -p /sdcard/Pictures/screenshot.png
  235. The command above will take a screenshot of the current screen and save it at
  236. the path /sdcard/Pictures/screenshot.png. If you tried running the command, you
  237. may have noticed that no output text is displayed, so how can we check if the
  238. screenshot was really captured? Fortunately, we can use ADB to several commands
  239. that are well known by users who are familiar with Unix commands, like the ls
  240. which we will use to list the files from the Pictures directory:
  241. $ adb shell ls /sdcard/Pictures/
  242. screenshot.png
  243. $ adb shell mkdir /sdcard/Pictures/Screenshots
  244. $ adb shell ls /sdcard/Pictures/
  245. Screenshots
  246. screenshot.png
  247. # list file
  248. $ adb shell ls /sdcard/Download/*.pdf
  249. # move file
  250. $ adb shell mv /sdcard/Pictures/screenshot.png /sdcard/Pictures/Screenshots/
  251. # copy file
  252. $ adb shell cp /sdcard/Pictures/screenshot.png /sdcard/Pictures/Screenshots/
  253. # delete file
  254. $ adb shell rm /sdcard/Pictures/screenshot.png
  255. # delete directory
  256. $ adb shell rm -r /sdcard/Pictures/Screenshots
  257. # print log to console output (press ctrl+c to stop it)
  258. $ adb logcat
  259. # transfer files from android to device:
  260. adb pull <remote file> <local location>
  261. mkdir android
  262. cd android
  263. adb pull "/sdcard/DCIM/Camera/20210329_134800.jpg"
  264. adb pull "/sdcard/Download/"
  265. adb pull "/sdcard/Videos/"
  266. ls
  267. 20210329_134800.jpg Download/ Videos/
  268. # transfer files from device to android:
  269. adb push <local file> <remote location>
  270. # 11 cool adb tricks to try on your android phone
  271. https://www.smartprix.com/bytes/cool-adb-commands-tips-tricks/
  272. # How to remove bloatware from Realme, Xiaomi, Samsung and other phones
  273. https://www.smartprix.com/bytes/how-to-remove-bloatware-from-realme-xiaomi-and-
  274. samsung-phones/
  275. # Useful adb commands for android testing
  276. https://blog.testproject.io/2021/08/10/useful-adb-commands-for-android-testing/
  277. # adb netstat command
  278. adb shell netstat
  279. # ls command
  280. ls -a # show hidden files
  281. ls -lh # show sizes in a human readable format
  282. ls -R # recursively show sub directories
  283. ls -ltr # show last modification date
  284. ls -n # see UID or GID of files
  285. ls -t # sort by time and date
  286. # ps command
  287. ps -A # show active processes
  288. ps -E # show active processes
  289. ps -U root -u root # see processes running with root privileges
  290. ps -e --forest # see the process tree
  291. ps -f --forest -c sshd # see the process tree for a specific process (sshd)
  292. ps -C sshd # see child processes for a specific process
  293. ps -r # see all running processes
  294. $ adb shell
  295. $ cd system/app/Facebook/
  296. # get the name/details of the current running activity
  297. adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
  298. # start an application
  299. adb shell am start -n com.packge.name/com.package.name.ActivityName
  300. # scroll screen
  301. adb shell input swipe 300 300 500 1000 # scroll screen up
  302. adb shell input swipe 500 1000 300 300 # scroll screen down
  303. # send text using virtual keyboard
  304. adb shell input text "text to be send"
  305. # send keyevent as physical keyboard
  306. adb shell input keyevent 66 # 66 is key_code for "Enter"