Last active
July 11, 2023 14:58
-
-
Save Kardelio/b3d87ffee72367baf4c6437953e8ef3b to your computer and use it in GitHub Desktop.
Edit an apps shared preference entire file from a bash script (using run-as & sed)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# IMPORTANT: | |
# make sure to edit the variables below to make the script work for you and your app | |
package="my.package.com" | |
filename="sharedprefs.xml" | |
line=$(adb exec-out run-as "$package" cat "/data/data/$package/shared_prefs/$filename") | |
echo "$line" > /tmp/editpreffile.txt | |
$EDITOR /tmp/editpreffile.txt | |
newval=$(cat /tmp/editpreffile.txt) | |
echo "-${newval}-" | |
adb exec-out run-as "$package" sed -Ei -e "1s/.*/____/g" -e "/^_/!d" -e "s|____|${newval}|g" "/data/data/$package/shared_prefs/$filename" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment