Skip to content

Instantly share code, notes, and snippets.

@segfault-bilibili
Last active April 17, 2023 15:58
Show Gist options
  • Save segfault-bilibili/c7090af5958d768ca2caae4e27a11cfa to your computer and use it in GitHub Desktop.
Save segfault-bilibili/c7090af5958d768ca2caae4e27a11cfa to your computer and use it in GitHub Desktop.
#!/system/bin/sh
set -e
REGEX="[0-9a-f]{72}"
SAVED_DEV_ID_FILE="/data/adb/magireco_$2.txt"
COCOS_FILE="/data/data/com.aniplex.magireco/shared_prefs/Cocos2dxPrefsFile.xml"
DEV_ID_FILE="/data/data/com.aniplex.magireco/files/madomagi/C5XyOsaM.json"
UNFINISHED_QUEST_FILE="/data/data/com.aniplex.magireco/files/madomagi/data.bin"
check_unfinished_quest() {
if [ -f "${UNFINISHED_QUEST_FILE}" ]; then
echo "there is still an unfinished quest, abort" >&2
exit 3
fi
}
if [[ "$1" == "save" ]]; then
if grep -E -q "${REGEX}" "${COCOS_FILE}"; then
if [ -f "${SAVED_DEV_ID_FILE}" ]; then
echo "file already exists for name [$2], overwrite? (type yes to overwrite)" >&2
read CONFIRM
if [[ "${CONFIRM}" != "yes" ]]; then
echo "abort" >&2
exit 2
fi
fi
grep -E -o "${REGEX}" "${COCOS_FILE}" > "${SAVED_DEV_ID_FILE}"
else
echo "device id not found" >&2
exit 1
fi
elif [[ "$1" == "load" ]]; then
check_unfinished_quest
if [ -f "${SAVED_DEV_ID_FILE}" ]; then
sed -E -i "s/${REGEX}/$(cat ${SAVED_DEV_ID_FILE})/g" "${COCOS_FILE}" "${DEV_ID_FILE}"
else
echo "file not found" >&2
exit 1
fi
elif [[ "$1" == "reset" ]]; then
check_unfinished_quest
echo "reset device id? this will logout your account! (type yes to reset)" >&2
read CONFIRM
if [[ "${CONFIRM}" != "yes" ]]; then
echo "abort" >&2
exit 2
fi
sed -E -i "/${REGEX}/d" "${COCOS_FILE}"
if [ -f "${DEV_ID_FILE}" ]; then
rm -f "${DEV_ID_FILE}"
fi
else
echo "usage: magireco_jp_account_switch.sh save name" >&2
echo " magireco_jp_account_switch.sh load name" >&2
echo " magireco_jp_account_switch.sh reset" >&2
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment