Skip to content

Instantly share code, notes, and snippets.

@programminghoch10
Last active December 19, 2024 08:20
Show Gist options
  • Save programminghoch10/fa37e0da8b2efc5cb8077e59d000771d to your computer and use it in GitHub Desktop.
Save programminghoch10/fa37e0da8b2efc5cb8077e59d000771d to your computer and use it in GitHub Desktop.
Snapchat Data Extractor
#!/bin/bash
if [[ $(id -u) -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
if [ -z $(pm list packages | grep com.snapchat.android) ]; then
echo "Snapchat not found"
exit 1
fi
SDCARD=/storage/emulated/0
EXPORTDIR=$SDCARD/snapchat_exports
SNAPDATA=$(pm dump com.snapchat.android | grep dataDir= | head -n 1 | cut -d= -f2)
echo "Export folder: $EXPORTDIR"
echo "Snapchat data folder: $SNAPDATA"
rm -r $EXPORTDIR
mkdir -v $EXPORTDIR
cp -r $SNAPDATA/files/file_manager/chat_snap $EXPORTDIR
cp -r $SNAPDATA/files/file_manager/story_snap $EXPORTDIR
cp $SNAPDATA/files/file_manager/snap_first_frame/* $EXPORTDIR/story_snap
cp -r $SNAPDATA/files/file_manager/snap $EXPORTDIR
cp -r $SNAPDATA/files/file_manager/posted_story_snap $EXPORTDIR
cp -r $SNAPDATA/files/file_manager/memories_media $EXPORTDIR
cp -r $SNAPDATA/files/file_manager/memories_thumbnail $EXPORTDIR
#cp -r $SNAPDATA/files/file_manager/memories_overlay $EXPORTDIR
cp -r $SNAPDATA/files/file_manager/media_package_thumb $EXPORTDIR
cp -r $SNAPDATA/files/file_manager/external_sticker $EXPORTDIR
cp -r $SNAPDATA/files/file_manager/non_user_bitmoji $EXPORTDIR
for folder in $EXPORTDIR/*/;
do
for file in $folder*;
do
if (file "$file" | grep text);
then mv "$file" "$file.txt";
else
if (head -n 1 "$file" | grep mp4);
then mv "$file" "$file.mp4";
else
if (head -n 1 "$file" | grep JFIF);
then mv "$file" "$file.jfif"
else
if (head -n 1 "$file" | grep WEBP);
then mv "$file" "$file.webp"
else
if (head -n 1 "$file" | grep PNG);
then mv "$file" "$file.png"
fi
fi
fi
fi
fi
done
for file in "$folder*.txt"; do rm "$file"; done
done
exit 0
@programminghoch10
Copy link
Author

programminghoch10 commented Jun 1, 2021

Snapchat Data Extractor

A script to quickly copy and analyze photos and videos from Snapchat.

Story

After I had managed to make Snapchat unable to detect screenshots,
I thought Snapchat must save the original photos and videos it receives in some way.

So with the root access I have, I went through Snapchats saved data.
I found a lot of files named with some random characters and file extensions .0 .1 .2.

I noticed the files were actually mostly .jpg and .mp4 files.

So after finding some more folders with interesting data I decided to automate the extraction and analysis.

How the script works

This script automatically copies all interesting data from Snapchats data folders and analyses the files to repair their file extensions.

It will copy the following data from Snapchat:

Data gets copied from this snapchat folder: /data/data/com.snapchat.android/files/file_manager.
The folders in the resulting copy are named the same.

Folder What this folder contains Extra information
chat_snap All the snaps you receive directly
story_snap All the snaps your friends post in their stories
snap_first_frame The first frame of video story snaps This gets copied into story_snap.
snap Snaps you sent or received in direct chat
posted_story_snap The snaps you send in your story
memories_media Snaps you saved in your memories Full size images and videos of the memories. You must have opened the memory at least once for snapchat to download the highest resolution. These do not include overlays.
memories_overlay Overlays of snaps in your memories The overlays of snaps in your memories. They are saved separately and are reassembled by snapchat using metadata. I am not interested in analyzing the meta data and reassembling the pictures. If you want the overlays downloaded, uncomment the according copy line in the script.
memories_thumbnail Thumbnails of memories The previews snapchat uses in the memories gallery. When slowly scrolling through the memories once, all memories should have a thumbnail in here. The thumbnail might disappear when the memory has been opened once, as it then resides in memories_media.
media_package_thumb Temporary files snapchat saves to send your snaps These files get deleted quickly, so one may only find the latest sent snap if it was not that long ago.
external_sticker All the external stickers you have saved
non_user_bitmoji Bitmoji from the people you snap with Some Bitmojis might be missing.

It is currently able to analyze and repair following files:

  • txt
  • mp4
  • jfif
  • webp
  • png

The script automatically deletes all txt files afterwards, as they are only metadata files and not interesting at all.

Additional Info on how snapchat saves the data in chat_snap:
There are 3 types of files: .0, .1, .2.
When only an .0 file exists, this file is either an image or a video. Afaik this is only determinable via file headers.
When .0, .1 and .2 files with the same name exist, the .0 file is a text file containing metadata. This metadata is irrelevant, as its basically the same for all. The .1 file then is a video and the according picture in .2 is used as an overlay.

How to use it

The script is written in a way, such that it can be run completely on the phone.

You need superuser / root privileges for this to work!

  1. Enable Android USB Debugging
  2. Connect the device to your computer
  3. Open a terminal
  4. Run adb shell
  5. Run su to elevate to root privileges
  6. Run cd /sdcard or cd /storage/emulated/0
  7. Download the script with
    curl https://gist.githubusercontent.com/programminghoch10/fa37e0da8b2efc5cb8077e59d000771d/raw/61181d13cf3e45cfddcd3e9b0e6bea492d6189ab/snapchat_data_extractor.sh > snapchat_data_extractor.sh
  8. Run the script bash snapchat_data_extractor.sh
  9. The script now copies and processes Snapchats data
  10. When it finishes, you will find the result on your phone in a folder named snapchat_exports

Be aware:
The script deletes all contents in the folder snapchat_exports before copying the new data into it.
Before running the script, make sure you have saved all data within this folder.

To download the extracted data to your computer:

  1. Open a terminal in the folder where the results folder should be copied to
  2. Run adb pull /storage/emulated/0/snapchat_exports
  3. When it finishes, you will find the resulting data in the folder snapchat_exports

@knightoflongknives
Copy link

Loving your work on this. Curl: Inaccessible or fine not found.
What's the solution?

@jenluo20
Copy link

Hi,
I couldn't replicate files saved in the folder /data/data/com.snapchat.android/files/file_manager/snap no matter how I tried to send and receive snaps. I tried this on Snapchat version 12.56.0.57 on an Android 13.0.

@yarub123
Copy link

Would this work for saved voice chats? @programminghoch10

Thanks in advance dude.

@aqib13114
Copy link

aqib13114 commented Nov 4, 2024

hi i am new here just want help i want to extract conversation details of that file i have downloded snapchat data but this conversation shows only stamp date name no details really important plz help me out

@aqib13114
Copy link

hi i am new here just want help i want to extract conversation details of that file i have downloded snapchat data but this conversation shows only stamp date name no details really important plz help me out

plz someone help me out

@aqib13114
Copy link

only hope from that site so plz its very important for my life

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment