Top Banner
Android ADB
34
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Android - ADB

Android ADB

Page 2: Android - ADB

Hello!I am Yossi Gruner

Page 3: Android - ADB

Agenda

▣ what is adb▣ adb commands▣ adb scripts ▣ adb files▣ adb over WiFi▣ screen capture/record▣ logcat▣ shell command

□ am□ pm□ dumpsys□ more…

▣ exercise

Page 4: Android - ADB

What is ADB

Page 5: Android - ADB

What is ADB

▣ Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device.

Page 6: Android - ADB

3 elements of ADB

▣ adb clients□ executable with subcommand □ ”adb shell”, ”adb logcat” : the end point of host

side▣ adb server

□ running on host on back-ground□ act as proxy between adb clients and adbd

▣ adb daemon (adbd)□ running on target device□ started by init, if die, restarted by init again

Page 7: Android - ADB

How it connect

Page 8: Android - ADB

How it connect

Page 9: Android - ADB

ADB Commands

▣ adb devices□ Print All the connected devices

▣ adb shell □ run remote shell interactively

▣ adb jdwp□ list PIDs of processes hosting a JDWP transport

▣ adb install/uninstall□ un/install the application

▣ adb start-server □ ensure that there is a server running

▣ adb kill-server □ kill the server if it is running

Page 10: Android - ADB

Adb scripts

▣ adb wait-for-device□ block until device is online

▣ adb start-server □ ensure that there is a server running

▣ adb kill-server □ kill the server if it is running

▣ adb get-state□ prints: offline | bootloader | device

▣ adb get-serialno□ prints: <serial-number>

▣ adb get-devpath□ prints: <device-path>

Page 11: Android - ADB

Adb scripts

▣ adb status-window □ continuously print device status for a specified

device▣ adb remount

□ remounts the /system and /vendor (if present) partitions on the device read-write

▣ adb reboot [bootloader|recovery] □ reboots the device, optionally into the bootloader

or recovery program▣ adb reboot-bootloader -

□ reboots the device into the bootloader▣ adb root

□ restarts the adbd daemon with root permissions▣ adb usb

□ restarts the adbd daemon listening on USB

Page 12: Android - ADB

Adb - Files

▣ Copy file to device□ adb push <local> <remote>

▣ Copy file from device□ adb pull <remote> <local>

Page 13: Android - ADB

adb over WiFi

▣ Android Device□ adb shell netcfg

get the android IP address (x.x.x.x)□ adb shell setprop service.adb.tcp.port 5555□ adb shell stop adbd && start adbd

▣ PC device□ adb connect x.x.x.x□ adb -s x.x.x.x:5555 logcat□ adb -s x.x.x.x:5555 logcat |grep -vE "/dalvik"□ adb -s x.x.x.x:5555 shell

Page 14: Android - ADB

BugReport

▣ Command□ adb shell bugreport > bugreport.txt□ java -jar chkbugreport.jar bugreport.txt

▣ JAR download □ https://github.com/sonyxperiadev/ChkBugReport/

downloads

Page 15: Android - ADB

ScreenCapture

▣ Command:□ adb shell screencap -p /sdcard/screen.png□ adb pull /sdcard/screen.png□ adb shell rm /sdcard/screen.png

▣ Other way□ adb shell screencap -p | sed 's/\r$//' > screen.png□ adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g'

> screen.png

Page 16: Android - ADB

ScreenRecord

▣ Command:□ adb shell screenrecord /sdcard/recording.mp4 □ adb pull /sdcard/recording.mp4□ adb shell rm /sdcard/recording.mp4

Page 17: Android - ADB

Adb Key Event

▣ Power Button□ adb shell input keyevent 26

▣ Unlock screen□ adb shell input keyevent 82

▣ Volume down□ adb shell input keyevent 25

▣ List of Keyevent□ http://developer.android.com/reference/android/

view/KeyEvent.html

Page 18: Android - ADB

Logcat - Logging

▣ Filter by tagname□ adb logcat -s TAG_NAME □ adb logcat -s TAG_NAME_1 TAG_NAME_2

▣ Filter by priority□ adb logcat "*:PRIORITY"

V - Verbose (lowest priority) D - Debug I - Info W - Warning E - Error F - Fatal S - Silent (highest priority, on which nothing is

ever printed)

Page 19: Android - ADB

Logcat - Logging

▣ Filter using grep□ adb logcat | grep "SEARCH_TERM"□ Example

adb logcat | grep "Exception"

▣ Clearing the logcat buffer□ adb logcat -c

Page 20: Android - ADB

Logcat - Buffers

▣ radio - adb command “” □ View the buffer that contains radio/telephony

related messages. ▣ events

□ View the buffer containing events-related messages.

▣ main □ View the main log buffer (default)

Run Command “logcat -b <buffer>”

Page 21: Android - ADB

Shell Commands

▣ dumpstate□ Dumps state to a file.

▣ dmesg□ Prints kernel debugging messages to the screen

▣ start□ Starts an emulator/device instance.

▣ stop□ Stops execution of an emulator/device instance.

▣ restart□ restart an emulator/device instance.

Page 22: Android - ADB

Shell Commands

▣ top□ Prints all the running tasks on your device

▣ Service □ Help to communicate with phone services

service list service check <SERVICE_NAME> service call <SERVICE_NAME> CODE

Page 23: Android - ADB

Shell Commands - More

▣ More Commands □ adb shell ls /system/bin

Page 24: Android - ADB

AM - Activity Manager

▣ Start Activity□ am start <packageName/.ActivityClass>

▣ Start/Stop Service□ am startservice -n <packageName/.ServiceClass>□ am stopservice -n <packageName/.ServiceClass>

▣ Send broadcast□ am broadcast -a <action_name>

▣ Users□ am switch-user <USER_ID>□ am start-user <USER_ID>□ am stop-user <USER_ID>

▣ More Commands▣ adb shell am

Page 25: Android - ADB

PM - Package Manager

▣ pm list packages▣ pm list permission-groups▣ pm list users▣ pm install▣ pm create-user▣ pm remove-user USER_ID▣ pm get-max-users

▣ More Commands▣ adb shell pm

Page 26: Android - ADB

Dumpsys

▣ dumpsys□ will show all system data from the device

▣ you can filter it by adding□ dumpsys activity□ dumpsys batterystats□ dumpsys cpuinfo□ dumpsys wifi□ dumpsys meminfo □ dumpsys package ‘package’

▣ More:□ adb shell dumpsys -l

Page 27: Android - ADB

Joke commands

▣ adb hell□ same as ”adb shell” except ”hell” color :)

▣ adb lolcat□ same as ”adb logcat”

Page 28: Android - ADB

Task #1

1. Open Settings Applicationa. main application

2. Open Settings In Inner Activitya. WifiSettings

Page 29: Android - ADB

Task #2

1. Get System Application to pca. Dialer.apk

Page 30: Android - ADB

Task #3

1. Open my Application with intent and extraa. extra keys

i. stringii. booliii. floativ. string_array

▣ Download Apk□ https://goo.gl/IWTGle

▣ Code reference□ https://github.com/yossigruner/AdbSession

Page 31: Android - ADB

Task #4

1. enable the NFC2. disable the NFC

Page 32: Android - ADB

Answers

▣ Task #1□ adb shell am start -S com.android.settings/com.android.settings.Settings□ adb shell am start -a android.intent.action.MAIN -n

com.android.settings/.wifi.WifiSettings

▣ Task #2□ adb root□ adb remount□ adb pull /system/priv-app/Dialer/Dialer.apk

▣ Task #3□ adb shell am start -n

com.mike.adbsession/com.mike.adbsession.MainActivity --ez bool false --ef float 1.999 --es string hello --esa string_array hello,world

▣ Task #4□ enable - service call nfc 6

□ disable - service call nfc 5

Page 34: Android - ADB

Thanks!Any questions?

[email protected]