Last active
December 19, 2017 07:39
-
-
Save vampjaz/ee8a1a0bdeb431c0cb02 to your computer and use it in GitHub Desktop.
Python files used to extract some data from iPhone backups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
import subprocess | |
import os | |
import pprint | |
import shutil | |
## required the directory 'data' to exist locally | |
## put in full file type to scan for (find it with typecount.py) and optional suffix to add | |
SCAN = 'gzip compressed data' | |
END = '.gz' | |
DB = "filetypes.db" | |
conn = sqlite3.connect(DB) | |
c = conn.cursor() | |
c.execute("SELECT path FROM folder") | |
PATH = c.fetchone()[0] | |
c.execute("SELECT name,len FROM files WHERE xtype=?",(SCAN,)) | |
for i in c.fetchall(): | |
print i | |
shutil.copyfile(os.path.join(PATH,i[0]),os.path.join(os.path.join(os.getcwd(),'data'),i[0]+END)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## run this to create a db for other programs to use | |
## requires `file`, so only works on mac i guess | |
import sqlite3 | |
import subprocess | |
import os | |
import pprint | |
## backup snapshot folder | |
PATH = "~/Library/Application Support/MobileSync/Backup/<insert folder here>/Snapshot" | |
DB = "filetypes.db" | |
if os.path.exists(DB): | |
os.remove(DB) | |
conn = sqlite3.connect(DB) | |
c = conn.cursor() | |
c.execute("CREATE TABLE files (name text, type text, xtype text, len int, atime int, mtime int)") | |
c.execute("CREATE TABLE folder (path text)") | |
c.execute("INSERT INTO folder VALUES (?)",(PATH,)) | |
for i in os.listdir(PATH): | |
try: | |
fp = os.path.join(PATH,i) | |
typ = subprocess.check_output(['file',fp]).split(': ')[1] | |
typ2 = typ.split(',')[0].strip() | |
st = os.stat(fp) | |
except KeyboardInterrupt: | |
break | |
except: | |
continue | |
c.execute("INSERT INTO files VALUES (?,?,?,?,?,?)",(i,typ,typ2,st.st_size,st.st_atime,st.st_mtime)) | |
conn.commit() | |
conn.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## lists tables within all sqlite dbs in the backup | |
import sqlite3 | |
import subprocess | |
import os | |
import pprint | |
DB = "filetypes.db" | |
conn = sqlite3.connect(DB) | |
c = conn.cursor() | |
c.execute("SELECT path FROM folder") | |
PATH = c.fetchone()[0] | |
print PATH | |
c.execute("SELECT name FROM files WHERE xtype='SQLite 3.x database'") | |
for i in c.fetchall(): | |
try: | |
print 'Database',i[0] | |
pconn = sqlite3.connect(os.path.join(PATH,i[0])) | |
pc = pconn.cursor() | |
pc.execute("SELECT name FROM sqlite_master WHERE type = 'table'") | |
#print c.fetchall() | |
print 'Tables:',', '.join(a[0] for a in pc.fetchall()) | |
pconn.close() | |
except KeyboardInterrupt: | |
break | |
#print 'Error opening...' | |
print '-'*30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## prints number of each type of file | |
import sqlite3 | |
import subprocess | |
import os | |
import pprint | |
DB = "filetypes.db" | |
conn = sqlite3.connect(DB) | |
c = conn.cursor() | |
c.execute("SELECT path FROM folder") | |
PATH = c.fetchone()[0] | |
typedict = {} | |
c.execute("SELECT xtype FROM files") | |
for i in c.fetchall(): | |
typ = i[0] | |
if typ in typedict: | |
typedict[typ] += 1 | |
else: | |
typedict[typ] = 1 | |
pprint.pprint(typedict) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment