How to recover cached images from Phone Link app

Thumbnails are automatically cached to the phone link (formerly Your Phone) app and are visible, however the moment they are clicked on they are blurred until the phone connects. The images are stored as blobs in a sql database in the Phone link app files called photos.db, there might be as few, I recommend trying the program with each of them.

First go to:

C:\Users\{username}\AppData\Local\Packages\Microsoft.YourPhone_8wekyb3d8bbwe\LocalCache\Indexed

In this directory there are many folder with random names like "93f6fad9-8fbd-408b-a6d3-acca266cc273" find the ones with a "System" folder then a "Database" folder then copy out the photos.db file within. As mentioned above there may be multiple of these folders with photos.db files in them.

Then:

Either; run the program from the same directory as the photos.db file, place the photos.db in your home directory or replace "photos.db" with your path to the file. Leave a comment below if you have trouble setting up your python environment or would prefer an exe.

import sqlite3
import os

# Connect to the database
conn = sqlite3.connect('photos.db')
cursor = conn.cursor()

cursor.execute("SELECT thumbnail, media, name FROM media")

# Create an output directory
thumb_dir = "thumbnails"
os.makedirs(thumb_dir, exist_ok=True)
media_dir = "media"
os.makedirs(media_dir, exist_ok=True)

for row in cursor:
    thumbnail_blob = row[0]  # BLOB data
    media_blob = row[1]
    image_id = row[2] 
    filepath = os.path.join(thumb_dir, image_id)
    # Save the BLOB to disk
    with open(filepath, 'wb') as f:
        try:
            f.write(thumbnail_blob)
        except:
            pass

    filepath = os.path.join(media_dir, image_id)
    # Save the BLOB to disk
    with open(filepath, 'wb') as f:
        try:
            f.write(media_blob)
        except:
            pass

    print(f"Saved: {filepath}")

conn.close()

Comments