Skip to content

Instantly share code, notes, and snippets.

@neckothy
Last active February 13, 2024 05:57
Show Gist options
  • Save neckothy/6c20a40c37c2d9af6ccc10f94f4c572d to your computer and use it in GitHub Desktop.
Save neckothy/6c20a40c37c2d9af6ccc10f94f4c572d to your computer and use it in GitHub Desktop.
Extract keyfile from Kindle for Android on a rooted device/emulator
#!/bin/bash
# https://github.com/noDRM/DeDRM_tools/discussions/440
# REQUIRES ROOTED DEVICE / EMULATOR
# get Notifications.pref.xml
xml=$(adb shell su -c 'cat /data/data/com.amazon.kindle/shared_prefs/Notifications.pref.xml')
# extract dsn from xml
dsn=$(echo -n "$xml" | grep -Po '(?<=<string name="serializedDeviceAttributes">{&quot;dsn&quot;:&quot;)[0-9a-f]{32}')
# convert to hexadecimal
hex=$(echo -n "$dsn" | od -A n -t x1 | sed 'N;s/[\n ]//g')
# output to file
echo "{\"DSN\": \"$hex\"}" > './kindle-for-android-key.k4i'
# alternatively, as a one-liner
# echo "{\"DSN\": \"$(adb shell su -c 'cat /data/data/com.amazon.kindle/shared_prefs/Notifications.pref.xml' | grep -Po '(?<=<string name="serializedDeviceAttributes">{&quot;dsn&quot;:&quot;)[0-9a-f]{32}' | tr -d '\n' | od -A n -t x1 | sed 'N;s/[\n ]//g')\"}" > kindle-for-android-key.k4i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment