Skip to content

SQlite3


Retrieve table names

adb shell sqlite3 -line <database_file> "SELECT name FROM sqlite_master WHERE type='table';"

Dump all data from a table

adb shell sqlite3 -line <database_file> "SELECT * FROM <table_name>;"

Dumps all schemas and tables from all .db

find /data/data -type f -name "*.db" -exec sh -c 'echo "Dumping schema for $1"; sqlite3 -line "$1" ".schema"' _ {} \;

Dump data from multiple databases

#!/bin/bash

find /data/data -type f -name "*.db" -exec sh -c '
     echo "-----------------------------------"
    dbfile="$1"
    echo -e "Processing database file: \e[1;32m$dbfile\e[0m"
    for table in $(sqlite3 "$dbfile" ".tables"); do
        echo "Dumping data from table: $table"
          echo "-----------------------------------"
        sqlite3 -line "$dbfile" "SELECT * FROM \"$table\""
    done
' _ {} \;

Dump data from multiple databases (parallel execution)

#!/bin/sh

directory="/data/data"
find "$directory" -name "*.db" -print0 | xargs -0 -n1 -P4 sh -c '
    database_file="$1"
    echo "-----------------------------------"
    echo "Dumping data from database: $database_file"
    echo "-----------------------------------"
    table_names=$(sqlite3 "$database_file" ".tables")
    for table_name in $table_names; do
        echo "Dumping data from table: $table_name"
        sqlite3 -line "$database_file" "SELECT * FROM \"$table_name\";"
        echo
    done
' sh|grep -i "1939"

Access the log file containing previous commands

adb shell su -c cat /data/user_de/0/com.android.providers.telephony/Log/FileLog0.log          

Read carrier information

adb shell su -c cat //data/user_de/0/com.android.providers.telephony/files/carrierconfig-com.android

Read Lock Settings from the telephony database

adb shell sqlite3 -line /data/user_de/0/com.android.providers.telephony/databases/telephony.db 'select * from locksettings;'

Read SIM card information from the telephony database

sqlite3 -line /data/user_de/0/com.android.providers.telephony/databases/telephony.db 'select * from android_metadata'
sqlite3 -line /data/user_de/0/com.android.providers.telephony/databases/telephony.db 'select * from carrier'
sqlite3 -line /data/user_de/0/com.android.providers.telephony/databases/telephony.db 'select * from original'
sqlite3 -line /data/user_de/0/com.android.providers.telephony/databases/telephony.db 'select * from siminfo'
sqlite3 /data/vendor/radio/qcril.db 'select ICCID from qcril_manual_prov_table'
grep -vx -f <(adb shell sqlite3 <database_file> .dump) <(adb shell sqlite3 <database_file> .schema) 

Update dg.db file

adb shell sqlite3 /data/data/com.google.android.gms/databases/dg.db "update main set c='0' where a like '%attest%';" 

Grab all file extensions of a specific kind and download them to PC

for i in `adb shell su -c find /data /system -name '*.key'`; do 
   mkdir -p ".`dirname $i`";adb shell su -c cat $i > ".$i";
done

Find all database files (*.db) recursively in the specified directory

directory="/data/data"
database_files=$(adb shell find "$directory" -name "*.db")

# Iterate over each database file
for database_file in $database_files; do
  echo "Database file: $database_file"

  # Get the table names from the database file
  table_names=$(adb shell sqlite3 -line "$database_file" "SELECT name FROM sqlite_master WHERE type='table';")

  # Iterate over each table and dump the data
  for table_name in $table_names; do
    echo "Dumping data from table: $table_name"
    adb shell sqlite3 -line "$database_file" "SELECT * FROM $table_name;"
    echo
  done

  echo "-----------------------------------"
done

Dump data from multiple databases (null-separated)

directory="/data/data"
find "$directory" -name '*.db' -print0 | xargs -0 -n1 -P 10 sh -c '
    database_file="$0"
    echo "Database file: $database_file"

    table_names=$(adb shell sqlite3 -line "$database_file" "SELECT name FROM sqlite_master WHERE type='"'"'table'"'"';")
    for table_name in $table_names; do
        echo "Dumping data from table: $table_name"
        adb shell sqlite3 -line "$database_file" "SELECT * FROM $table_name;"
        echo
    done

    echo "-----------------------------------"
' \;

Send a long press event for KEYCODE_VOLUME_UP

adb shell input keyevent --longpress KEYCODE_VOLUME_UP

Send a long press event for KEYCODE_VOLUME_DOWN

adb shell input keyevent --longpress KEYCODE_VOLUME_DOWN

Send key events for volume up/down

for i in {0..50}
do
  echo "Trying function ID: $i"
  adb shell service call audio $i i32 3 i32 1 i32 1
  sleep 1
done

Send key events using getevent

adb shell getevent -l | awk '{ system("adb shell input keyevent " $4) }'