ADB(Android Debugging Bridge)

ADB (Android Debugging Bridge) plays the most important role in modifying your Android Device.
In simple words, Android Debug Bridge (ADB) is a versatile command-line tool that lets you communicate with a device.

ADB allows you to

  • Install, copy, and delete files;
  • Install a program on a device;
  • Record a video or take a screenshot of the phone;
  • Debug a device in case of its malfunction;
  • Examine logs on the phone;
  • Upgrade the firmware of the programs and system elements;
  • Get full access to information about OS and a device.



Install ADB on Windows

  • To install visit ADB Platform Tools for Windows. 

Android Platform Tools

Android Platform Tools is a package containing command-line utilities necessary for communicating with Android devices from a computer. These tools include ADB (Android Debug Bridge), Fastboot, and other debugging and diagnostic utilities. Developers use Platform Tools for tasks such as installing apps, debugging, transferring files, and more.


  • Download and Extract the file.
  • Move/Copy the directory to C:\ drive and Rename it to "adb".
  • Set up Environment Variable.


To do this Go to This PC and right-click. Click on properties.


Click on Advanced System Settings. Click Environment Variable.

Search in System Variable " Path " and type semicolon paste the path of ADB and Save it.

Run it. Run " adb ".



Install ADB on Linux

1) Installing ADB on Linux is quite simple. For Debian based operating system, use the following command:

┌──(mrdev㉿kali)-[~]
└─$ sudo apt-get install android-tools-adb

Or, if it doesn’t work,

┌──(mrdev㉿kali)-[~]
└─$ sudo apt-get install adb

2) Let’s test whether it works or not using the following command:

┌──(mrdev㉿kali)-[~]
└─$ adb
Android Debug Bridge version 1.0.41
Version 28.0.2-debian
Installed as /usr/lib/android-sdk/platform-tools/adb
 
global options:
 -a         listen on all network interfaces, not just localhost
 -d         use USB device (error if multiple devices connected)
 -e         use TCP/IP device (error if multiple TCP/IP devices available)
 -s SERIAL  use device with given serial (overrides $ANDROID_SERIAL)
 -t ID      use device with given transport id
 -H         name of adb server host [default=localhost]
 -P         port of adb server [default=5037]
 -L SOCKET  listen on given socket for adb server [default=tcp:localhost:5037]
 
general commands:
 devices [-l]             list connected devices (-l for long output)
 help                     show this help message
 version                  show version num

networking:
 connect HOST[:PORT]      connect to a device via TCP/IP [default port=5555]
 disconnect [HOST[:PORT]]
     disconnect from given TCP/IP device [default port=5555], or all
 forward --list           list all forward socket connections
 forward [--no-rebind] LOCAL REMOTE

     forward socket connection using:
       tcp:<port> (<local> may be "tcp:0" to pick any open port)
       localabstract:<unix domain socket name>
       localreserved:<unix domain socket name>
       localfilesystem:<unix domain socket name>

       dev:<character device name>
       jdwp:<process pid> (remote only)

 forward --remove LOCAL   remove specific forward socket connection
 forward --remove-all     remove all forward socket connections

 ppp TTY [PARAMETER...]   run PPP over USB
 reverse --list           list all reverse socket connections from device
 reverse [--no-rebind] REMOTE LOCAL
     reverse socket connection using:
       tcp:<port> (<remote> may be "tcp:0" to pick any open port)
       localabstract:<unix domain socket name>
       localreserved:<unix domain socket name>
       localfilesystem:<unix domain socket name>

 reverse --remove REMOTE  remove specific reverse socket connection
 reverse --remove-all     remove all reverse socket connections from device

 

file transfer:
 push [--sync] LOCAL... REMOTE
     copy local files/directories to device
     --sync: only push files that are newer on the host than the device

 pull [-a] REMOTE... LOCAL
     copy files/dirs from device
     -a: preserve file timestamp and mode

 sync [all|data|odm|oem|product_services|product|system|vendor]
     sync a local build from $ANDROID_PRODUCT_OUT to the device (default all)
     -l: list but don't copy

shell:
 shell [-e ESCAPE] [-n] [-Tt] [-x] [COMMAND...]

     run remote shell command (interactive shell if no command given)
     -e: choose escape character, or "none"; default '~'
     -n: don't read from stdin
     -T: disable PTY allocation
     -t: force PTY allocation
     -x: disable remote exit codes and stdout/stderr separation

 emu COMMAND              run emulator console command

app installation (see also `adb shell cmd package help`):
 install [-lrtsdg] [--instant] PACKAGE
     push a single package to the device and install it

 install-multiple [-lrtsdpg] [--instant] PACKAGE...
     push multiple APKs to the device for a single package and install them

 install-multi-package [-lrtsdpg] [--instant] PACKAGE...
     push one or more packages to the device and install them atomically
     -r: replace existing application
     -t: allow test packages
     -d: allow version code downgrade (debuggable packages only)
     -p: partial application install (install-multiple only)
     -g: grant all runtime permissions
     --instant: cause the app to be installed as an ephemeral install app
     --no-streaming: always push APK to device and invoke Package Manager as separate steps
     --streaming: force streaming APK directly into Package Manager
     --fastdeploy: use fast deploy
     --no-fastdeploy: prevent use of fast deploy
     --force-agent: force update of deployment agent when using fast deploy
     --date-check-agent: update deployment agent when local version is newer and using fast deploy
     --version-check-agent: update deployment agent when local version has different version code and using fast deploy
     --local-agent: locate agent files from local source build (instead of SDK location)

 uninstall [-k] PACKAGE
     remove this app package from the device
     '-k': keep the data and cache directories

backup/restore:
   to show usage run "adb shell bu help"

debugging:
 bugreport [PATH]
     write bugreport to given PATH [default=bugreport.zip];
     if PATH is a directory, the bug report is saved in that directory.
     devices that don't support zipped bug reports output to stdout.

 jdwp                     list pids of processes hosting a JDWP transport
 logcat                   show device log (logcat --help for more)

security:
 disable-verity           disable dm-verity checking on userdebug builds
 enable-verity            re-enable dm-verity checking on userdebug builds
 keygen FILE
     generate adb public/private key; private key stored in FILE,

scripting:
 wait-for[-TRANSPORT]-STATE
     wait for device to be in the given state
     STATE: device, recovery, rescue, sideload, bootloader, or disconnect
     TRANSPORT: usb, local, or any [default=any]

 get-state                print offline | bootloader | device
 get-serialno             print <serial-number>
 get-devpath              print <device-path>

 remount [-R]
      remount partitions read-write. if a reboot is required, -R will
      will automatically reboot the device.

 reboot [bootloader|recovery|sideload|sideload-auto-reboot]
     reboot the device; defaults to booting system image but
     supports bootloader and recovery too. sideload reboots
     into recovery and automatically starts sideload mode,
     sideload-auto-reboot is the same but reboots after sideloading.

 sideload OTAPACKAGE      sideload the given full OTA package
 root                     restart adbd with root permissions
 unroot                   restart adbd without root permissions
 usb                      restart adbd listening on USB
 tcpip PORT               restart adbd listening on TCP on PORT

internal debugging:
 start-server             ensure that there is a server running
 kill-server              kill the server if it is running
 reconnect                kick connection from host side to force reconnect
 reconnect device         kick connection from device side to force reconnect
 reconnect offline        reset offline/unauthorized devices to force reconnect

environment variables:
 $ADB_TRACE
     comma-separated list of debug info to log:
     all,adb,sockets,packets,rwx,usb,sync,sysdeps,transport,jdwp
 $ADB_VENDOR_KEYS         colon-separated list of keys (files or directories)
 $ANDROID_SERIAL          serial number to connect to (see -s)
 $ANDROID_LOG_TAGS        tags to be used by logcat (see logcat --help)
 $ADB_LOCAL_TRANSPORT_MAX_PORT max emulator scan port (default 5585, 16 emus)

┌──(mrdev㉿kali)-[~]
└─$



Run ADB

1) To fully use all the ADB functions on Android devices, it is necessary to make certain changes in the phone settings. Depending on the manufacturer, the configuration menu may vary. But in general, the main actions are the same:

Turn on Developer Options

a. Go to settings > About device > Software info. Tap 5 to 7 times on the Build number to turn on the Developer Option.

b. Now go back to the Developer Option > Turn on USB debugging.


c. Now, Plug in your Android Device and run “ADB devices” to display all information about devices connected to the PC and with their serial numbers. A popup screen appears to get access to the Android device.

2. Now you can here type all useful commands to intercept with Android.


Basic Commands to run on ADB


ADB Basics

Command

Description

adb devices

Lists connected devices, helping you identify which devices are currently recognized by ADB.

adb root

Restarts adbd (the ADB daemon) with root permissions, enabling access to system-level operations.

adb start-server

Initiates the ADB server, allowing communication between your computer and Android devices via ADB commands.

adb kill-server

Terminates the ADB server, useful if you encounter issues or need to reset the ADB server.

adb reboot

Reboots the connected Android device. Useful when changes require a device restart or to troubleshoot issues.

adb devices -l

Provides a detailed list of connected devices, including their product and model information.

adb shell

Opens a background terminal on the connected Android device, enabling direct interaction with its command line.

exit

Exits the background terminal and returns you to the local terminal or command prompt on your computer.

adb help

Displays a list of all available ADB commands along with brief descriptions, helping you discover new commands.

adb -s <device>

Redirects subsequent ADB commands to a specific device identified by its unique device ID.

adb –d

Directs ADB commands to the only attached USB device, useful when multiple devices are connected.

adb –e

Directs ADB commands to the only attached emulator, facilitating testing and debugging on virtual devices.


Package Installation 

Command

Description

adb shell install <app>

Installs the specified app onto the connected Android device from the local system.

adb shell install <path_to_app>

Installs an app located at the specified path on the connected Android device.

adb shell install -r <path_to_app>

Reinstalls an app located at the specified path, replacing the existing version on the connected Android device.

adb shell uninstall <package_name>

Uninstalls the app identified by its package name from the connected Android device.


Paths

Command

Description

/data/data/<package_name>/databases

Represents the directory on the Android device where app-specific databases are stored.

/data/data/<package_name>/shared_prefs/

Represents the directory on the Android device where app-specific shared preferences files are stored.

/data/app

Refers to the directory on the Android device where APKs installed by the user are stored.

/system/app

Represents the directory on the Android device where pre-installed system APK files are stored.

/mnt/asec

Refers to the directory on the Android device where encrypted apps (App2SD) are stored.

/mnt/emmc

Represents the internal SD card directory on the Android device.

/mnt/sdcard

Represents the external or internal SD card directory on the Android device, depending on the device configuration.

/mnt/sdcard/external_sd

Represents the external SD card directory on the Android device, if present.

adb shell ls

Lists the contents of the current directory on the Android device.

adb shell ls -s

Lists the contents of the current directory along with the size of each file.

adb shell ls -R

Lists the contents of the current directory recursively, including subdirectories and their contents.


File Operations 

Command

Description

adb push <local> <remote>

Copies a file or directory from the local system to the specified location on the Android device.

adb pull <remote> <local>

Copies a file or directory from the specified location on the Android device to the local system.

run-as cat <file>

Accesses and displays the contents of a file located within the private package files of an installed app.


Package Info 

Command

Description

adb shell list packages

Lists the package names of all installed apps on the Android device.

adb shell list packages -r

Lists the package names of all installed apps along with the path to their corresponding APK files.

adb shell list packages -3

Lists the package names of third-party apps installed on the Android device.

adb shell list packages -s

Lists the package names of only the system apps installed on the Android device.

adb shell list packages -u

Lists the package names of all installed apps, including those that have been uninstalled but not yet removed.

adb shell dumpsys package packages

Provides detailed information about all installed packages on the Android device.

adb shell dump

Provides detailed information about a specific package identified by its package name.

adb shell path

Retrieves the file path to the APK file of a specific package identified by its package name.


Device Related Commands 

Command

Description

adb reboot-recovery

Reboots the connected Android device into recovery mode, enabling various system-level operations.

adb reboot fastboot

Reboots the connected Android device into fastboot mode, facilitating bootloader-related operations.

adb shell screencap -p "/path/to/screenshot.png"

Captures a screenshot of the device's current screen and saves it to the specified file path on the device.

adb shell screenrecord "/path/to/record.mp4"

Records the screen of the connected Android device and saves it as a video file at the specified location.

adb backup -apk -all -f backup.ab

Creates a backup of the device's settings and all installed apps, saving it to the specified file.

adb backup -apk -shared -all -f backup.ab

Creates a backup of the device's settings, installed apps, and shared storage, saving it to the specified file.

adb backup -apk -nosystem -all -f backup.ab

Creates a backup of only the non-system apps installed on the device, saving it to the specified file.

adb restore backup.ab

Restores a previous backup of the device's settings and apps from the specified file.

adb shell am start <intent>

Sends an intent to the Android system to start a specific activity based on the provided intent parameters.

adb shell am start -a android.intent.action.VIEW -d URL

Opens the default web browser on the device and navigates to the specified URL.

adb shell am start -t image/* -a android.intent.action.VIEW

Opens the default image viewer on the device, allowing the user to view images stored locally.


Configure Settings Commands 

Command

Description

adb shell dumpsys battery set level

Sets the battery level of the connected Android device to the specified value (0-100).

adb shell dumpsys battery set status

Sets the battery status of the connected Android device to the specified value (unknown, charging, etc.).

adb shell dumpsys battery reset

Resets the battery statistics of the connected Android device, clearing any accumulated data.

adb shell dumpsys battery set usb

Sets the USB connection status of the connected Android device to either ON or OFF.

adb shell wm size WxH

Sets the screen resolution of the connected Android device to the specified width (W) and height (H) in pixels.


Logs 

Command

Description

adb logcat [options] [filter] [filter]

Displays logs from the device, allowing you to monitor system and app activity for debugging purposes.

adb bugreport

Generates a bug report containing information about the device's current state, useful for debugging issues.


Permissions 

Command

Description

adb shell permissions groups

Lists all permission groups defined on the connected Android device, providing insight into app permissions.

adb shell list permissions -g -r

Lists detailed information about all permissions defined on the connected Android device, including their groups.

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Ok, Go it!