Skip to content

Instantly share code, notes, and snippets.

@YSaxon
Last active October 9, 2023 20:51
Show Gist options
  • Save YSaxon/e2e8ea4be1e4cc6bbdc3b0e50d730825 to your computer and use it in GitHub Desktop.
Save YSaxon/e2e8ea4be1e4cc6bbdc3b0e50d730825 to your computer and use it in GitHub Desktop.
notes on dumping files from android

adb pull /

Here's a script which will do an adb pull of all the various apks into their normal tree and also softlink them all together. do a mkdir root; cd root; mkdir apk_softlinks before running this

adb shell 'pm list packages' | grep -vE "^package:(com.android|com.qualcomm|com.google|com.qti|android)" | awk -F':' '{print $2}' | xargs -I '{}' sh -c 'path=$(adb shell pm path {} | cut -d: -f2 | tr -d "\r"); mkdir -p $(dirname "./${path#/}"); adb pull "$path" "./${path#/}"; ln -s "../${path#/}" "./apk_softlinks/$(basename $(dirname "./${path#/}")).apk"'; for file in apk_softlinks/*; do [ -L "$file" ] && [ ! -e "$file" ] && mv "$file" "${file%.PULL_FAILED}.PULL_FAILED"; done

I tried the following script but it messed up permissions, so don't use it (just leaving it here for my own reference to fix another time.

#!/bin/bash

# Declare local directory to copy files into
LOCAL_DIR="some/dir"

# Iterate over package names
PACKAGE_NAMES=$(adb shell 'pm list packages -f' | sed -e 's/.*=//' -e 's/\r$//')

# Iterate over package names
for PACKAGE_NAME in $PACKAGE_NAMES; do
    # Assemble package-specific directory
    PACKAGE_DIR="/data/data/$PACKAGE_NAME"
    SHARED_DIR="/sdcard/Shared/$PACKAGE_NAME"

    # Try to impersonate the app and change permissions
    adb shell "run-as $PACKAGE_NAME chmod -R a+r $PACKAGE_DIR" > /dev/null 2>&1
    if [ $? -eq 0 ]; then
        # If permissions were successfully changed, copy files to the shared directory
        adb shell "cp -r $PACKAGE_DIR $SHARED_DIR"

        # Pull files to local machine
        adb pull $SHARED_DIR $LOCAL_DIR

        # Revert permissions by removing read access for all users
        adb shell "run-as $PACKAGE_NAME chmod -R a-r $PACKAGE_DIR"
    else
        echo "Could not access or modify files for package $PACKAGE_NAME"
    fi
done
@YSaxon
Copy link
Author

YSaxon commented Oct 9, 2023

find .. -name "*apk" -type f | while read f; do echo $f | xargs basename | rev | cut -f 2- -d '.' | rev | read base && echo $base && mkdir $base && cd $base && jadx ../$f; cd fullpath/decomps; done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment