ADB Commands

Unterstützen Sie HackTricks

Adb befindet sich normalerweise in:

#Windows
C:\Users\<username>\AppData\Local\Android\sdk\platform-tools\adb.exe

#MacOS
/Users/<username>/Library/Android/sdk/platform-tools/adb

Informationen erhalten von: http://adbshell.com/

Verbindung

adb devices

Dies listet die verbundenen Geräte auf; wenn "unauthorisiert" erscheint, bedeutet dies, dass Sie Ihr Mobilgerät entsperren und die Verbindung akzeptieren müssen.

Dies zeigt dem Gerät an, dass es einen adb-Server auf Port 5555 starten muss:

adb tcpip 5555

Verbinde dich mit dieser IP und diesem Port:

adb connect <IP>:<PORT>

Wenn Sie einen Fehler wie den folgenden in einer virtuellen Android-Software (wie Genymotion) erhalten:

adb server version (41) doesn't match this client (36); killing...

Es liegt daran, dass Sie versuchen, sich mit einem ADB-Server einer anderen Version zu verbinden. Versuchen Sie einfach, die adb-Binärdatei zu finden, die die Software verwendet (gehen Sie zu C:\Program Files\Genymobile\Genymotion und suchen Sie nach adb.exe)

Mehrere Geräte

Wann immer Sie mehrere Geräte, die mit Ihrem Computer verbunden sind finden, müssen Sie angeben, in welchem Sie den adb-Befehl ausführen möchten.

adb devices
List of devices attached
10.10.10.247:42135	offline
127.0.0.1:5555	device
adb -s 127.0.0.1:5555 shell
x86_64:/ # whoami
root

Port Tunneling

Falls der adb Port nur von localhost auf dem Android-Gerät zugänglich ist, aber Sie über SSH Zugriff haben, können Sie den Port 5555 weiterleiten und sich über adb verbinden:

ssh -i ssh_key username@10.10.10.10 -L 5555:127.0.0.1:5555 -p 2222
adb connect 127.0.0.1:5555

Paketmanager

Installieren/Deinstallieren

adb install [option] <path>

adb install test.apk

adb install -l test.apk # forward lock application

adb install -r test.apk # replace existing application

adb install -t test.apk # allow test packages

adb install -s test.apk # install application on sdcard

adb install -d test.apk # allow version code downgrade

adb install -p test.apk # partial application install

adb deinstallieren [Optionen] <PAKET>

adb uninstall com.test.app

adb uninstall -k com.test.app Keep the data and cache directories around after package removal.

Pakete

Gibt alle Pakete aus, optional nur diejenigen, deren Paketname den Text in <FILTER> enthält.

adb shell pm list packages [options] <FILTER-STR>

adb shell pm list packages <FILTER-STR>

adb shell pm list packages -f <FILTER-STR> #See their associated file.

adb shell pm list packages -d <FILTER-STR> #Filter to only show disabled packages.

adb shell pm list packages -e <FILTER-STR> #Filter to only show enabled packages.

adb shell pm list packages -s <FILTER-STR> #Filter to only show system packages.

adb shell pm list packages -3 <FILTER-STR> #Filter to only show third party packages.

adb shell pm list packages -i <FILTER-STR> #See the installer for the packages.

adb shell pm list packages -u <FILTER-STR> #Also include uninstalled packages.

adb shell pm list packages --user <USER_ID> <FILTER-STR> #The user space to query.

adb shell pm path <PACKAGE>

Gibt den Pfad zur APK des angegebenen Pakets aus.

adb shell pm path com.android.phone

adb shell pm clear <PACKAGE>

Löscht alle mit einem Paket verbundenen Daten.

adb shell pm clear com.test.abc

Dateimanager

adb pull <remote> [local]

Lädt eine bestimmte Datei von einem Emulator/ Gerät auf Ihren Computer herunter.

adb pull /sdcard/demo.mp4 ./

adb push <local> <remote>

Laden Sie eine bestimmte Datei von Ihrem Computer auf einen Emulator/ ein Gerät hoch.

adb push test.apk /sdcard

Screencapture/Screenrecord

adb shell screencap <filename>

Ein Screenshot des Gerätdisplays aufnehmen.

adb shell screencap /sdcard/screen.png

adb shell screenrecord [options] <filename>

Aufzeichnen des Displays von Geräten, die Android 4.4 (API-Stufe 19) und höher ausführen.

adb shell screenrecord /sdcard/demo.mp4
adb shell screenrecord --size <WIDTHxHEIGHT>
adb shell screenrecord --bit-rate <RATE>
adb shell screenrecord --time-limit <TIME> #Sets the maximum recording time, in seconds. The default and maximum value is 180 (3 minutes).
adb shell screenrecord --rotate # Rotates 90 degrees
adb shell screenrecord --verbose

(Drücken Sie Strg-C, um die Aufnahme zu stoppen)

Sie können die Dateien (Bilder und Videos) mit _adb pull_ herunterladen**

Shell

adb shell

Erhalten Sie eine Shell im Gerät

adb shell

adb shell <CMD>

Führen Sie einen Befehl auf dem Gerät aus

adb shell ls

pm

Die folgenden Befehle werden innerhalb einer Shell ausgeführt

pm list packages #List installed packages
pm path <package name> #Get the path to the apk file of tha package
am start [<options>] #Start an activity. Whiout options you can see the help menu
am startservice [<options>] #Start a service. Whiout options you can see the help menu
am broadcast [<options>] #Send a broadcast. Whiout options you can see the help menu
input [text|keyevent] #Send keystrokes to device

Prozesse

Wenn Sie die PID des Prozesses Ihrer Anwendung erhalten möchten, können Sie ausführen:

adb shell ps

Und suchen Sie nach Ihrer Anwendung

Oder Sie können tun

adb shell pidof com.your.application

Und es wird die PID der Anwendung ausgeben

System

adb root

Restartet den adbd-Daemon mit Root-Rechten. Dann müssen Sie sich erneut mit dem ADB-Server verbinden und Sie werden Root sein (sofern verfügbar).

adb sideload <update.zip>

flashing/restoring Android update.zip Pakete.

Logs

Logcat

Um die Nachrichten nur einer Anwendung zu filtern, erhalten Sie die PID der Anwendung und verwenden Sie grep (linux/macos) oder findstr (windows), um die Ausgabe von logcat zu filtern:

adb logcat | grep 4526
adb logcat | findstr 4526

adb logcat [option] [filter-specs]

adb logcat

Notes: Drücken Sie Ctrl-C, um die Überwachung zu stoppen

adb logcat *:V # lowest priority, filter to only show Verbose level

adb logcat *:D # filter to only show Debug level

adb logcat *:I # filter to only show Info level

adb logcat *:W # filter to only show Warning level

adb logcat *:E # filter to only show Error level

adb logcat *:F # filter to only show Fatal level

adb logcat *:S # Silent, highest priority, on which nothing is ever printed

adb logcat -b <Buffer>

adb logcat -b # radio View the buffer that contains radio/telephony related messages.

adb logcat -b # event View the buffer containing events-related messages.

adb logcat -b # main default

adb logcat -c # Clears the entire log and exits.

adb logcat -d # Dumps the log to the screen and exits.

adb logcat -f test.logs # Writes log message output to test.logs .

adb logcat -g # Prints the size of the specified log buffer and exits.

adb logcat -n <count> # Sets the maximum number of rotated logs to <count>.

dumpsys

Systemdaten dumpen

adb shell dumpsys [options]

adb shell dumpsys

adb shell dumpsys meminfo

adb shell dumpsys battery

Notes: Ein mobiles Gerät mit aktivierten Entwickleroptionen, das Android 5.0 oder höher ausführt.

adb shell dumpsys batterystats collects battery data from your device

Hinweise: Battery Historian konvertiert diese Daten in eine HTML-Visualisierung. SCHRITT 1 adb shell dumpsys batterystats > batterystats.txt SCHRITT 2 python historian.py batterystats.txt > batterystats.html

adb shell dumpsys batterystats --reset erases old collection data

adb shell dumpsys activity

Backup

Sichern Sie ein Android-Gerät von adb.

adb backup [-apk] [-shared] [-system] [-all] -f file.backup
# -apk -- Include APK from Third partie's applications
# -shared -- Include removable storage
# -system -- Include system Applciations
# -all -- Include all the applications

adb shell pm list packages -f -3      #List packages
adb backup -f myapp_backup.ab -apk com.myapp # backup on one device
adb restore myapp_backup.ab                  # restore to the same or any other device

Wenn Sie den Inhalt des Backups inspizieren möchten:

( printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" ; tail -c +25 myapp_backup.ab ) |  tar xfvz -
Unterstütze HackTricks

Last updated