Useful commands

All the following commands are integrated in HacknDroid.

ADB shell

adb shell

On a specific device ID:

adb shell devices
adb shell -s <device_serial_number>

The option -s <device_serial_number> can be added to every ADB command.

APK from AAB

java -jar bundletool.jar build-apks --bundle=<aab_file> --output=<output_path>.apks --ks=<keystore_path>.jks --ks-pass=pass:<keystore_password> --ks-key-alias=<key_alias> --key-pass=pass:<key_password>

App data

Retrieve app data (storage):

adb shell
su root
cp -r /data/data/<app_id> /sdcard/temp
chmod 666 /sdcard/temp
exit
adb pull /sdcard/temp <local_path>

Reset app data

adb shell pm clear <app_id>

App Information

If the APK file was decompiled, look at AndroidManifest.xml.

Otherwise:

aapt dump badging <apk_path>

Backup

Create a backup

Description

Command

All the applications

adb backup -apk -f -shared -all <backup_name>.ab

Specific Application

adb backup -apk -f <backup_name>.ab <app_id>

The device will ask you to insert a <password> that you are going to use in the following command to create a TAR archive from the AB file.

java -jar abe.jar unpack <backup_name>.ab <backup_name>.tar <password>

The you can extract the TAR file as you want.

Restore a backup

adb restore <backup_name>.ab

Compile APK

java -jar apktool.jar b <code_folder> -o <compiled_apk_filepath>
zipalign -v 4 <compiled_apk_filepath> <zipaligned_apk_filepath>

The next step is the signing of the apk.

Connectivity & Battery

Option

Command

Airplane Mode ON

adb shell settings put global airplane_mode_on 1

Airplane Mode OFF

adb shell settings put global airplane_mode_on 0

Battery Status

adb shell dumpsys battery

Network information

adb shell dumpsys connectivity

Wifi OFF

adb shell svc wifi disable

Wifi ON

adb shell svc wifi enable

Wifi Settings

adb shell am start -a android.settings.WIFI_SETTINGS

CPU information

adb shell cat /proc/cpuinfo

Decompile APK

java -jar apktool.jar d <apk_filepath> -o <destination_folder>

Device information

adb shell getprop <property>
Property
Description

ro.product.model

Device Model

ro.product.brand

Brand

ro.product.manufacturer

Manufacturer

ro.build.version.release

Android Version

ro.build.id

Build ID

ro.build.version.sdk

SDK Version

ro.build.date

Build Date

ro.serialno

Device Serial Number

External storage

adb shell 'echo $EXTERNAL_STORAGE'

File transfer

From mobile device to PC:

adb pull <mobile_path> <local_path>

From PC to mobile device:

adb push <local_path> <mobile_path>

Install/Uninstall application

Uninstall an application from the mobile device:

adb uninstall <app_id>

Install from the APK file path:

adb install <path.apk>

Open the Play Store page of a specific application:

adb shell am start -a android.intent.action.VIEW -d "market://details?id=<app_id>"

Example:

adb shell am start -a android.intent.action.VIEW -d "market://details?id=com.mcdonalds.mobileapp"

Keystore creation

keytool -genkeypair -v -keystore <keystore_path>.jks -alias <my_app_alias> -keyalg RSA -keysize 2048 -validity 10000 -storepass "my_secure_password" -keypass "my_secure_password" -dname "CN=John Doe, OU=Development, O=MyCompany, L=New York, ST=NY, C=US"

Launch an application

adb shell monkey -p <app_id> -v <num_pseudo_random_events>

Example:

adb shell monkey -p com.example.app -v 1

List applications on the mobile device

Description

Command

All the applications

adb shell pm list packages

Running applications

adb shell "ps -A | awk '{print $9}'"

System applications

adb shell pm list packages -s

3rd-party applications

adb shell pm list packages -3

Logs

Retrieve the PID of the application

adb shell pidof <app_id>
Action
Command

Default logs

adb logcat --pid=<pid>

Crash logs

adb logcat --pid=<pid> *:E

Memory dump

adb shell dumpsys meminfo <app_id>

Merge APK

java -jar apkeditor.jar m -f -i <dir_with_apks> -o <merged_apk_name>.apk

Mirroring

On default command port (27183)

scrcpy

If errors on binding like the following Open

  • mirror on a different port:

    scrcpy --port=<port>
  • or restart Host Network Service (HNS) if on Windows and then run scrcpy:

    net stop hns
    net start hns
    scrcpy

Owner UID of the application

adb shell "pm list packages -U | grep <app_id> | cut -d: -f3"

Package name from the Owner UID of the application

adb shell "pm list packages -U | grep <owner_uid> | cut -d: -f2 | cut -d' ' -f1"
apksigner verify --print-certs <apk_filepath>

RAM information

adb shell cat /proc/meminfo

Reboot/Shutdown

Action
Command

Reboot the device

adb reboot

Reboot the device into bootloader/fastboot mode

adb reboot bootloader

Reboot the device into recovery mode

adb reboot recovery

Shutdown the device

adb shell reboot -p

Screen recording

adb shell screenrecord /sdcard/video.mp4

Screenshot

adb shell screencap -p /sdcard/screenshot.png

Sign APK

apksigner sign --ks <keystore_file> --ks-pass pass:<keystore_password> --key-pass pass:<key_password> --v1-signing-enabled true --v2-signing-enabled true <apk_path>

Stop an application

adb shell am force-stop <app_id>

Storage info

adb shell df

Verify APK signature

apksigner verify --verbose <apk_filepath>

Last updated