ADB (Android Debug Bridge) is a powerful command-line tool that lets developers communicate with an Android device for debugging, app testing, and security analysis. Below is a comprehensive guide covering essential commands, security implications, and advanced usage.
ADB (Android Debug Bridge) is part of the Android SDK Platform-Tools, allowing you to:
- Perform device automation
- Debug apps
- Transfer files
- Run shell commands
- Install/uninstall apps
- Capture logs and screenshots
- Access hidden settings
1. Setting Up ADB
Prerequisites
- Android device (with USB debugging enabled)
- USB cable (or wireless ADB setup)
- ADB installed (part of Android SDK Platform-Tools)
Installation
Download SDK Platform Tools:
- macOS/Linux:
brew install android-platform-tools # macOS (Homebrew)
sudo apt install adb fastboot # Debian/UbuntuEnable USB Debugging
- Go to Settings → About Phone → Tap “Build Number” 7 times (to enable Developer Options).
- Go to Developer Options → Enable USB Debugging.
- Connect via USB and authorize the computer when prompted.
Verify Connection
adb devices
(Should list your device ID.)
2. Essential ADB Commands
Basic Device Control
| Command | Description |
|---|---|
adb reboot | Reboot the device |
adb reboot recovery | Boot into recovery mode |
adb reboot bootloader | Boot into fastboot mode |
adb shell | Open a Linux shell on the device |
adb logcat | View system logs (use -c to clear) |
adb install app.apk | Install an APK |
adb uninstall | Uninstall an app |
File Operations
| Command | Description |
|---|---|
adb push local.txt /sdcard/ | Copy file to device |
adb pull /sdcard/file.txt . | Copy file from device |
adb shell ls /sdcard/ | List files on device |
App Management
| Command | Description |
|---|---|
adb shell pm list packages | List all installed apps |
adb shell pm path com.example | Get APK path of an app |
adb shell dumpsys package | Get detailed app info |
adb shell am start -n com.example/.MainActivity | Launch an app |
3. Advanced ADB for Security & Debugging
Checking for Malware
- List running processes:
adb shell ps- Check network connections:
adb shell netstat -tuln- Monitor real-time logs for suspicious activity:
adb logcat | grep -i "hack\|malware\|virus"Revoking Dangerous Permissions
adb shell pm revoke <package> android.permission.READ_SMS(Replace with any permission like CAMERA, LOCATION, etc.)
Disabling/Enabling Apps (No Root Needed)
adb shell pm disable-user --user 0 com.malicious.app
adb shell pm enable com.malicious.app Screen Capture & Recording
adb exec-out screencap -p > screenshot.png
adb shell screenrecord /sdcard/video.mp4 (Press Ctrl+C to stop recording.)
4. Wireless ADB (No USB Needed)
- Connect via USB first:
adb tcpip 5555- Disconnect USB and connect over Wi-Fi:
adb connect <Device_IP>:5555- Disconnect when done:
adb disconnect5. Security Risks & Best Practices
✅ Only enable USB debugging when needed (disable after use).
✅ Never authorize ADB on untrusted computers.
✅ Use ADB over USB instead of Wi-Fi in public places.
❌ Avoid using ADB as root unless necessary (can cause system instability).
6. Troubleshooting ADB Issues
| Problem | Solution |
|---|---|
| Device not detected | Check USB cable, enable USB debugging, try adb kill-server |
| Unauthorized error | Revoke USB debugging authorizations in Developer Options |
| ADB commands not working | Reinstall ADB drivers or update platform-tools |