Skip to content

Instantly share code, notes, and snippets.

@Kardelio
Last active July 11, 2023 14:58
Show Gist options
  • Save Kardelio/b3d87ffee72367baf4c6437953e8ef3b to your computer and use it in GitHub Desktop.
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)
#!/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