-
Notifications
You must be signed in to change notification settings - Fork 10
/
ios.py
727 lines (610 loc) · 24 KB
/
ios.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
#!/usr/bin/python
# http://www.imactools.com/iphonebackupviewer/
# http://www.securitylearn.net/2012/05/05/iphone-backup-mbdb-file-structure/
# http://www.securitylearn.net/tag/iphone-backups-decrypting-the-keychain/
# https://theiphonewiki.com/wiki/ITunes_Backup
# http://www.mobile60s.com/iphone/jailbreaks-and-ios-hacks/list-of-files-and-their-roles-in-itunes-backups-and-how-to-use-them-54158.html
# http://codepen.io/samuelkraft/pen/Farhl
# http://stackoverflow.com/questions/3085153/how-to-parse-the-manifest-mbdb-file-in-an-ios-4-0-itunes-backup
# http://linuxsleuthing.blogspot.com/2012/10/whos-texting-ios6-smsdb.html
# http://www.securitylearn.net/2012/10/27/cookies-binarycookies-reader/
# http://www.slideshare.net/ohprecio/iphone-forensics-without-iphone-using-itunes-backup
# https://en.wikipedia.org/wiki/List_of_iOS_devices
import shutil
import os
import os.path
from os.path import expanduser
import re
import base64
import hashlib
import json
import sqlite3
import tempfile
from biplist import *
# Setup Global Vars
path = expanduser("~") + "/Library/Application Support/MobileSync/Backup/"
# iOS Specific Filenames
plistKeyChain = 'KeychainDomain-keychain-backup.plist' # 51a4616e576dd33cd2abadfea874eb8ff246bf0e
plistHistory = 'HomeDomain-Library/Safari/History.plist'
plistRestrictions = 'HomeDomain-Library/Preferences/com.apple.springboard.plist'
dbSMS = 'HomeDomain-Library/SMS/sms.db' # 3d0d7e5fb2ce288813306e4d4636395e047a3d28
dbAddressBook = 'HomeDomain-Library/AddressBook/AddressBook.sqlitedb' # 31bb7ba8914766d4ba40d6dfb6113c8b614be442
dbAddressBookImages = 'HomeDomain-Library/AddressBook/AddressBookImages.sqlitedb' # cd6702cea29fe89cf280a76794405adb17f9a0ee
dbCallHistory = 'WirelessDomain-Library/CallHistory/call_history.db' # 2b2b0084a1bc3a5ac8c27afdf14afb42c61a19ca
dbNotes = 'HomeDomain-Library/Notes/notes.sqlite' # ca3bc056d4da0bbf88b5fb3be254f3b7147e639c
dbCalendar = 'HomeDomain-Library/Calendar/Calendar.sqlitedb' # 2041457d5fe04d39d0ab481178355df6781e6858
dbVoicemail = 'HomeDomain-Library/Voicemail/voicemail.db' # 992df473bbb9e132f4b3b6e4d33f72171e97bc7a
dbPhotos = 'CameraRollDomain-Media/PhotoData/Photos.sqlite' # 12b144c0bd44f2b3dffd9186d3f9c05b917cee25
dbRecordings = 'MediaDomain-Media/Recordings/Recordings.db' # 303e04f2a5b473c5ca2127d65365db4c3e055c05
dbBookmarks = 'HomeDomain-Library/Safari/Bookmarks.db'
dbLocations = ''
class ios:
'Base class for all iOS backup file functions'
# Device Model Strings
devices = {
"iPhone1,1": "iPhone",
"iPhone1,2": "iPhone 3",
"iPhone2,1": "iPhone 3GS",
"iPhone3,1": "iPhone 4",
"iPhone3,2": "iPhone 4",
"iPhone3,3": "iPhone 4",
"iPhone4,1": "iPhone 4S",
"iPhone5,1": "iPhone 5",
"iPhone5,2": "iPhone 5",
"iPhone5,3": "iPhone 5C",
"iPhone5,4": "iPhone 5C",
"iPhone6,1": "iPhone 5S",
"iPhone6,2": "iPhone 5S",
"iPhone7,2": "iPhone 6",
"iPhone7,1": "iPhone 6 Plus",
"iPhone8,1": "iPhone 6S",
"iPhone8,2": "iPhone 6S Plus",
"iPhone8,4": "iPhone SE",
"iPhone9,1": "iPhone 7",
"iPhone9,3": "iPhone 7",
"iPhone9,2": "iPhone 7 Plus",
"iPhone9,4": "iPhone 7 Plus",
"iPod1,1": "iPod Touch 1G",
"iPod2,1": "iPod Touch 2G",
"iPod3,1": "iPod Touch 3G",
"iPod4,1": "iPod Touch 4G",
"iPod5,1": "iPod Touch 5G",
"iPod7,1": "iPod Touch 6G",
"iPad1,1": "iPad",
"iPad2,1": "iPad 2",
"iPad2,2": "iPad 2",
"iPad2,3": "iPad 2",
"iPad2,4": "iPad 2",
"iPad3,1": "iPad 3",
"iPad3,2": "iPad 3",
"iPad3,3": "iPad 3",
"iPad3,4": "iPad 4",
"iPad3,5": "iPad 4",
"iPad3,6": "iPad 4",
"iPad4,1": "iPad Air",
"iPad4,2": "iPad Air",
"iPad4,3": "iPad Air",
"iPad5,3": "iPad Air 2",
"iPad5,4": "iPad Air 2",
"iPad6,11": "iPad (2017)",
"iPad6,12": "iPad (2017)",
"iPad2,5": "iPad Mini",
"iPad2,6": "iPad Mini",
"iPad2,7": "iPad Mini",
"iPad4,4": "iPad Mini 2",
"iPad4,5": "iPad Mini 2",
"iPad4,6": "iPad Mini 2",
"iPad4,7": "iPad Mini 3",
"iPad4,8": "iPad Mini 3",
"iPad4,9": "iPad Mini 3",
"iPad5,1": "iPad Mini 4",
"iPad5,2": "iPad Mini 4",
"iPad6,7": "iPad Pro (12.9in)",
"iPad6,8": "iPad Pro (12.9in)",
"iPad6,3": "iPad Pro (9.7in)",
"iPad6,4": "iPad Pro (9.7in)"
}
deviceType = ''
deviceModel = ''
productType = ''
productVersion = ''
serialNumber = ''
deviceName = ''
lastBackupDate = ''
targetIdentifier = ''
# Hash iOS Filenames
plistKeyChain = hashlib.sha1(plistKeyChain.encode('utf-8')).hexdigest()
plistHistory = hashlib.sha1(plistHistory.encode('utf-8')).hexdigest()
plistRestrictions = hashlib.sha1(plistRestrictions.encode('utf-8')).hexdigest()
dbSMS = hashlib.sha1(dbSMS.encode('utf-8')).hexdigest()
dbAddressBook = hashlib.sha1(dbAddressBook.encode('utf-8')).hexdigest()
dbAddressBookImages = hashlib.sha1(dbAddressBookImages.encode('utf-8')).hexdigest()
dbCallHistory = hashlib.sha1(dbCallHistory.encode('utf-8')).hexdigest()
dbNotes = hashlib.sha1(dbNotes.encode('utf-8')).hexdigest()
dbCalendar = hashlib.sha1(dbCalendar.encode('utf-8')).hexdigest()
dbVoicemail = hashlib.sha1(dbVoicemail.encode('utf-8')).hexdigest()
dbPhotos = hashlib.sha1(dbPhotos.encode('utf-8')).hexdigest()
dbRecordings = hashlib.sha1(dbRecordings.encode('utf-8')).hexdigest()
def __init__(self):
self.index = 0
self.backups = os.listdir(path)
def select(self, index):
self.index = index
plistInfo = path + self.backups[index] + "/Info.plist"
if os.path.exists(plistInfo):
try:
info = readPlist(plistInfo)
m = re.match("(.*?)\d", info['Product Type'])
self.deviceType = m.group(1)
self.deviceModel = self.devices[info['Product Type']]
self.productType = info['Product Type'].replace(',', '').lower()
self.productVersion = info['Product Version']
self.serialNumber = info['Serial Number']
self.deviceName = info['Device Name']
self.lastBackupDate = info['Last Backup Date']
self.targetIdentifier = info['Target Identifier']
except Exception as e:
print ( e )
#self.dumpRestrictionPasscode(index)
# Return Backup Path
def path(self, index=-1):
if index == -1:
backup = path + self.backups[self.index] + "/"
else:
backup = path + self.backups[index] + "/"
return backup
# Dump Restriction Passcode
def dumpRestrictionPasscode(self, index):
plistRestrictions = path + self.backups[index] + "/" + self.plistRestrictions
#print ( "Restriction Passcode: " + plistRestrictions )
if os.path.exists(plistRestrictions):
try:
info = readPlist(plistRestrictions)
self.restrictionPasscode = info['SBParentalControlsPIN']
self.restrictionFailedAttempts = info['SBParentalControlsFailedAttempts']
#print ( "Restriction Passcode: " + info['SBParentalControlsPIN'] )
#print ( "Restriction Passcode: " + info['SBParentalControlsFailedAttempts'] )
except Exception as e:
print ( e )
# SMS, MMS, iMessages, and iMessage/FaceTime settings
# HomeDomain
# Library/Preferences/com.apple.imservice*
# Library/Preferences/com.apple.madrid.plist
# Library/Preferences/com.apple.MobileSMS.plist
# Library/SMS/*
# Library/SMS/Attachments/[random string associated with an MMS]/[MMS file name].[extension] - An MMS file
# Library/SMS/Attachments/[random string associated with an MMS]/[MMS file name]-preview-left.jpg - A preview/thumbnail of an MMS file
def dumpSMS(self, path, filename):
# iOS < v7 - Database Extraction
try:
print ( "SMS Database: " + self.path() + self.dbSMS )
db = sqlite3.connect(self.path() + self.dbSMS)
cursor = db.cursor()
try:
sql = '''SELECT message.ROWID,
message.flags,
ifnull(message.address,'') || ifnull(madrid_handle,'') as address,
message.subject,
message.text,
message.group_id,
message.recipients,
message.read,
message.association_id,
message.UIFlags,
datetime(message.date+978307200, 'unixepoch', 'localtime') as 'date'
FROM message
WHERE message.text is not NULL
ORDER BY message.date'''
cursor.execute(sql)
with open(path + filename, 'w') as outfile:
json.dump(cursor.fetchall(), outfile, default=base64.b64encode)
except Exception as e:
print ( e )
try:
# No 'madrid_handle' field in message table
sql = '''SELECT message.ROWID,
message.flags,
message.address as address,
message.subject,
message.text,
message.group_id,
message.recipients,
message.read,
message.association_id,
message.UIFlags,
datetime(message.date+978307200, 'unixepoch', 'localtime') as 'date'
FROM message
WHERE message.text is not NULL
ORDER BY message.date'''
cursor.execute(sql)
with open(path + filename, 'w') as outfile:
json.dump(cursor.fetchall(), outfile, default=base64.b64encode)
except Exception as e:
print ( e )
try:
# Dump SMS Message Group Data
sql = "SELECT * FROM msg_group"
cursor.execute(sql)
print ( "msg_group: " + path + "sms_group.json" )
with open(path + "sms_group.json", 'w') as outfile:
json.dump(cursor.fetchall(), outfile, default=base64.b64encode)
except Exception as e:
print ( e )
try:
# Dump SMS Attachment Data
sql = "SELECT * FROM msg_pieces"
cursor.execute(sql)
print ( "msg_pieces: " + path + "sms_pieces.json" )
with open(path + "sms_pieces.json", 'w') as outfile:
json.dump(cursor.fetchall(), outfile, default=base64.b64encode)
except Exception as e:
print ( e )
db.close()
try:
# Save all SMS Attachments iOS < 6.0
sql = "SELECT * FROM msg_pieces"
db = sqlite3.connect(self.path() + self.dbSMS)
db.row_factory = sqlite3.Row
cursor = db.cursor()
cursor.execute(sql)
for row in cursor:
if row['content_loc'] is not None:
# Write each attachment out to the sms folder
f = "MediaDomain-Library/SMS/Attachments/" + row['content_loc']
print ( f )
f = self.path() + hashlib.sha1(f).hexdigest()
print ( f )
if os.path.exists(f):
shutil.copyfile(f, path + "sms/" + row['content_loc'])
db.close()
except Exception as e:
print ( e )
except Exception as e:
print ( e )
# iOS >= v6 - Database Extraction
try:
print ( "SMS Database: " + self.path() + self.dbSMS )
db = sqlite3.connect(self.path() + self.dbSMS)
cursor = db.cursor()
sql = '''SELECT chat_message_join.chat_id as id,
handle.id as contact_id,
message.is_from_me,
message.text,
chat.state,
message.is_read,
message.is_sent,
datetime(message.date+978307200, 'unixepoch', 'localtime') as 'date',
datetime(message.date_read+978307200, 'unixepoch', 'localtime') as 'date_read',
datetime(message.date_delivered+978307200, 'unixepoch', 'localtime') as 'date_delivered'
FROM chat INNER JOIN chat_message_join ON chat.ROWID = chat_message_join.chat_id
INNER JOIN message ON chat_message_join.message_id = message.ROWID
INNER JOIN chat_handle_join ON chat.ROWID = chat_handle_join.chat_id AND chat_handle_join.handle_id = handle.ROWID,
handle
ORDER BY chat_message_join.chat_id, message.date'''
cursor.execute(sql)
with open(path + filename, 'w') as outfile:
json.dump(cursor.fetchall(), outfile, default=base64.b64encode)
try:
# Dump SMS Message Group Data
sql = "SELECT * FROM chat"
cursor.execute(sql)
print ( "chat: " + path + "sms_chat.json" )
with open(path + "sms_chat.json", 'w') as outfile:
json.dump(cursor.fetchall(), outfile, default=base64.b64encode)
except Exception as e:
print ( e )
try:
# Dump SMS Attachment Data
sql = "SELECT * FROM attachment"
cursor.execute(sql)
print ( "attachment: " + path + "sms_attachment.json" )
with open(path + "sms_attachment.json", 'w') as outfile:
json.dump(cursor.fetchall(), outfile, default=base64.b64encode)
except Exception as e:
print ( e )
db.close()
try:
# Save all SMS Attachments
sql = "SELECT * FROM attachment"
db = sqlite3.connect(self.path() + self.dbSMS)
db.row_factory = sqlite3.Row
cursor = db.cursor()
cursor.execute(sql)
for row in cursor:
if row['filename'] is not None:
# Write each attachment out to the sms folder
f = row['filename']
f = f.replace("/var/mobile/", "MediaDomain-")
f = f.replace("~/", "MediaDomain-")
#print ( f )
f = self.path() + hashlib.sha1(f).hexdigest()
#print ( f )
if os.path.exists(f):
head, tail = os.path.split(row['filename'])
shutil.copyfile(f, path + "sms/" + tail)
db.close()
except Exception as e:
print ( e )
except Exception as e:
print ( e )
# Contacts
# HomeDomain
# Library/AddressBook/*
def dumpAddressBook(self, path):
try:
print ( "Address Book Database: " + self.path() + self.dbAddressBook )
dbAB = sqlite3.connect(self.path() + self.dbAddressBook)
cursorAB = dbAB.cursor()
sql = '''SELECT ABPerson.ROWID as id,
ABPerson.DisplayName,
ABPerson.First,
ABPerson.Middle,
ABPerson.Last,
ABPerson.Nickname,
ABPerson.Organization,
ABPerson.Department,
ABPerson.JobTitle,
ABPerson.Note,
ABPerson.Birthday,
ABPersonFullTextSearch_content.c15Phone,
ABPersonFullTextSearch_content.c16Email,
ABPersonFullTextSearch_content.c18SocialProfile,
ABPersonFullTextSearch_content.c19URL,
datetime(ABPerson.CreationDate+978307200, 'unixepoch', 'localtime') AS creation_date,
datetime(ABPerson.ModificationDate+978307200, 'unixepoch', 'localtime') AS modified_date
FROM ABPerson INNER JOIN ABPersonFullTextSearch_content ON ABPerson.ROWID = ABPersonFullTextSearch_content.docid
ORDER BY ABPerson.ROWID'''
cursorAB.execute(sql)
with open(path + "contacts.json", 'w') as outfile:
json.dump(cursorAB.fetchall(), outfile, default=base64.b64encode)
try:
sql = "SELECT * FROM ABMultiValueEntry" # WHERE parent_id = 1 Order By 'key'"
cursorAB.execute(sql)
with open(path + "contact_address.json", 'w') as outfile:
json.dump(cursorAB.fetchall(), outfile, default=base64.b64encode)
except Exception as e:
print ( e )
try:
sql = "SELECT * FROM ABMultiValue" # WHERE record_id = 1 Order By label"
cursorAB.execute(sql)
with open(path + "contact_phone_email.json", 'w') as outfile:
json.dump(cursorAB.fetchall(), outfile, default=base64.b64encode)
except Exception as e:
print ( e )
dbAB.close()
except Exception as e:
print ( e )
# Dump Address Book Images
try:
dbABI = sqlite3.connect(self.path() + self.dbAddressBookImages)
dbABI.row_factory = sqlite3.Row
cursorABI = dbABI.cursor()
sql = "SELECT * FROM ABFullSizeImage" # WHERE record_id = 1"
cursorABI.execute(sql)
for row in cursorABI:
# Write each image out to the contacts folder
print ( path + "contacts/%s.jpg" % row['record_id'] )
f = open(path + "contacts/" + str(row['record_id']) + ".jpg", "w")
f.write(row['data'])
f.close()
dbABI.close()
except Exception as e:
print ( e )
# Call History
# WirelessDomain
# Library/CallHistory/*
def dumpCallHistory(self, filename):
try:
print ( "Call History Database: " + self.path() + self.dbCallHistory )
db = sqlite3.connect(self.path() + self.dbCallHistory)
cursor = db.cursor()
sql = '''SELECT call.ROWID as id,
call.id as contact_id,
call.address,
call.duration,
call.flags,
datetime(call.date+978307200, 'unixepoch', 'localtime') as 'date'
FROM call
ORDER BY call.date'''
cursor.execute(sql)
with open(filename, 'w') as outfile:
json.dump(cursor.fetchall(), outfile, default=base64.b64encode)
db.close()
except Exception as e:
print ( e )
# Calendar
# HomeDomain
# Library/Calendar/* <-The asterisk (*) means all files inside that folder
# Library/Preferences/com.apple.mobilecal*
def dumpCalendar(self, filename):
try:
print ( "Calendar Database: " + self.path() + self.dbCalendar )
db = sqlite3.connect(self.path() + self.dbCalendar)
cursor = db.cursor()
sql = '''SELECT ZNOTE.ZBODY as id,
ZNOTE.ZTITLE as title,
ZNOTE.ZSUMMARY as summary,
ZNOTEBODY.ZCONTENT as content,
ZNOTE.ZDELETEDFLAG as deleted,
datetime(ZNOTE.ZCREATIONDATE+978307200, 'unixepoch', 'localtime') as 'creation_date',
datetime(ZNOTE.ZMODIFICATIONDATE+978307200, 'unixepoch', 'localtime') as 'modified_date'
FROM ZNOTE INNER JOIN ZNOTEBODY ON ZNOTE.Z_PK = ZNOTEBODY.ZOWNER
ORDER BY ZNOTE.ZCREATIONDATE'''
cursor.execute(sql)
with open(filename, 'w') as outfile:
json.dump(cursor.fetchall(), outfile, default=base64.b64encode)
db.close()
except Exception as e:
print ( e )
# Camera Roll - When replacing, you should delete all files in the respected folders first
# CameraRollDomain
# Media/DCIM/*
# Media/PhotoData/*
# Library/Preferences/com.apple.mobileslideshow.plist
# Media/DCIM/[number1]APPLE/IMG_[number2].[extension]
# Media file in the Camera Roll, be it photo, screenshot, video, or saved from elsewhere.
# Number1 is the number of the Camera Roll, which depends on how many Camera Rolls you've had and ranges from 100-999.
# Number2 is the chronological number of the file in the Camera Roll, which ranges from 0001-9999.
# Media/PhotoData/Metadata/DCIM/[number >= 100]APPLE/IMG_[number of video in Camera Roll].JPG - Preview image of a video in the Camera Roll before you press the play button
# Media/PhotoData/Metadata/DCIM/[number >= 100]APPLE/IMG_[number of video in Camera Roll].THM - Thumbnail of a video in the Camera Roll
# Media/PhotoData/Metadata/PhotoData/Sync/[number >= 100]SYNCD/IMG_[number of video in Camera Roll].JPG - Corresponds to its parallel in Media/PhotoData/Metadata/DCIM/[number >= 100]APPLE/IMG_number of video in Camera Roll].JPG
# Media/PhotoData/Metadata/PhotoData/Sync/[number >= 100]SYNCD/IMG_[number of video in Camera Roll].THM - Corresponds to its parallel in Media/PhotoData/Metadata/DCIM/[number >= 100]APPLE/IMG_number of video in Camera Roll].THM
def dumpCameraRoll(self, path, filename):
try:
print ( "Photo Database: " + self.path() + self.dbPhotos )
db = sqlite3.connect(self.path() + self.dbPhotos)
cursor = db.cursor()
sql = '''SELECT ZGENERICASSET.Z_PK AS id,
ZGENERICASSET.ZKIND AS kind,
ZGENERICASSET.ZWIDTH AS width,
ZGENERICASSET.ZHEIGHT AS height,
ZGENERICASSET.ZORIENTATION AS orientation,
ZADDITIONALASSETATTRIBUTES.ZDURATION as duration,
ZADDITIONALASSETATTRIBUTES.ZORIGINALFILESIZE as filesize,
ZGENERICASSET.ZDIRECTORY AS directory,
ZGENERICASSET.ZFILENAME AS filename,
ZGENERICASSET.ZUNIFORMTYPEIDENTIFIER AS type,
ZGENERICASSET.ZTHUMBNAILINDEX AS thumbnail_index,
ZADDITIONALASSETATTRIBUTES.ZEMBEDDEDTHUMBNAILWIDTH,
ZADDITIONALASSETATTRIBUTES.ZEMBEDDEDTHUMBNAILHEIGHT,
ZADDITIONALASSETATTRIBUTES.ZEMBEDDEDTHUMBNAILLENGTH,
ZADDITIONALASSETATTRIBUTES.ZEMBEDDEDTHUMBNAILOFFSET,
datetime(ZGENERICASSET.ZDATECREATED+978307200, 'unixepoch', 'localtime') AS creation_date,
datetime(ZGENERICASSET.ZMODIFICATIONDATE+978307200, 'unixepoch', 'localtime') AS modified_date
FROM ZGENERICASSET INNER JOIN ZADDITIONALASSETATTRIBUTES ON ZGENERICASSET.ZADDITIONALATTRIBUTES = ZADDITIONALASSETATTRIBUTES.Z_PK
WHERE ZGENERICASSET.ZDATECREATED is not NULL
ORDER BY ZGENERICASSET.ZDATECREATED ASC'''
cursor.execute(sql)
with open(path + filename, 'w') as outfile:
json.dump(cursor.fetchall(), outfile, default=base64.b64encode)
db.close()
except Exception as e:
print ( e )
try:
db = sqlite3.connect(self.path() + self.dbPhotos)
db.row_factory = sqlite3.Row
cursor = db.cursor()
cursor.execute(sql)
for row in cursor:
# Copy each image to the roll folder
f = "CameraRollDomain-Media/" + row['directory'] + "/" + row['filename']
f = self.path() + hashlib.sha1(f).hexdigest()
if os.path.exists(f):
print ( f )
shutil.copyfile(f, path + "roll/" + row['filename'])
# Copy video thumbnails to roll folder
if row['kind'] == 1:
f = "CameraRollDomain-Media/PhotoData/Metadata/" + row['directory'] + "/" + row['title'] + ".THM"
f = self.path() + hashlib.sha1(f).hexdigest()
if os.path.exists(f):
print ( f )
shutil.copyfile(f, path + "roll/" + row['title'] + ".JPG")
else:
f = "CameraRollDomain-Media/PhotoData/Metadata/" + row['directory'] + "/" + row['title'] + ".JPG"
f = self.path() + hashlib.sha1(f).hexdigest()
if os.path.exists(f):
print ( f )
shutil.copyfile(f, path + "roll/" + row['title'] + ".JPG")
db.close()
except Exception as e:
print ( e )
# Voicemail
# HomeDomain
# Library/Voicemail/*
def dumpVoicemail(self, path, filename):
try:
print ( "Voicemail Database: " + self.path() + self.dbVoicemail )
db = sqlite3.connect(self.path() + self.dbVoicemail)
cursor = db.cursor()
sql = '''SELECT voicemail.ROWID as id,
voicemail.remote_uid,
voicemail.sender,
voicemail.duration,
voicemail.flags,
datetime(voicemail.date+978307200, 'unixepoch', 'localtime') as 'date',
datetime(voicemail.trashed_date+978307200, 'unixepoch', 'localtime') as 'trashed_date'
FROM voicemail
ORDER BY voicemail.date'''
cursor.execute(sql)
with open(path + filename, 'w') as outfile:
json.dump(cursor.fetchall(), outfile, default=base64.b64encode)
db.close()
except Exception as e:
print ( e )
try:
db = sqlite3.connect(self.path() + self.dbVoicemail)
db.row_factory = sqlite3.Row
cursor = db.cursor()
cursor.execute(sql)
for row in cursor:
# Write each image out to the contacts folder
vm = "HomeDomain-Library/Voicemail/" + str(row['id']) + ".amr"
vm = self.path() + hashlib.sha1(vm).hexdigest()
print ( vm )
if os.path.exists(vm):
shutil.copyfile(vm, path + "vm/" + str(row['id']) + ".amr")
db.close()
except Exception as e:
print ( e )
# Voice Memos
# MediaDomain
# Media/Recordings/*
# Media/Recordings/[date] [time].m4a - Voice Memo, named YYYYMMDD HHMMSS.m4a
def dumpMemos(self, path, filename):
try:
print ( "Voice Memo Database: " + self.path() + self.dbRecordings )
db = sqlite3.connect(self.path() + self.dbRecordings)
cursor = db.cursor()
sql = '''SELECT ZRECORDING.Z_PK as id,
ZRECORDING.ZCUSTOMLABEL as label,
ZRECORDING.ZDURATION as duration,
ZRECORDING.ZPATH as path,
datetime(ZRECORDING.ZDATE+978307200, 'unixepoch', 'localtime') as 'date'
FROM ZRECORDING
ORDER BY ZDATE'''
cursor.execute(sql)
with open(path + filename, 'w') as outfile:
json.dump(cursor.fetchall(), outfile, default=base64.b64encode)
db.close()
except Exception as e:
print ( e )
try:
db = sqlite3.connect(self.path() + self.dbRecordings)
db.row_factory = sqlite3.Row
cursor = db.cursor()
cursor.execute(sql)
for row in cursor:
# Write each image out to the contacts folder
vm = row['path']
vm = vm.replace("/var/mobile/", "MediaDomain-")
vm = self.path() + hashlib.sha1(vm).hexdigest()
print ( vm )
if os.path.exists(vm):
shutil.copyfile(vm, path + "rec/" + str(row['id']) + ".m4a")
db.close()
except Exception as e:
print ( e )
# Notes
# HomeDomain
# Library/Notes/*
# Library/Preferences/com.apple.mobilenotes.plist
def dumpNotes(self, filename):
try:
print ( "Notes Database: " + self.path() + self.dbNotes )
db = sqlite3.connect(self.path() + self.dbNotes)
cursor = db.cursor()
sql = '''SELECT ZNOTE.ZBODY as id,
ZNOTE.ZTITLE as title,
ZNOTE.ZSUMMARY as summary,
ZNOTEBODY.ZCONTENT as content,
ZNOTE.ZDELETEDFLAG as deleted,
datetime(ZNOTE.ZCREATIONDATE+978307200, 'unixepoch', 'localtime') as 'creation_date',
datetime(ZNOTE.ZMODIFICATIONDATE+978307200, 'unixepoch', 'localtime') as 'modified_date'
FROM ZNOTE INNER JOIN ZNOTEBODY ON ZNOTE.Z_PK = ZNOTEBODY.ZOWNER
ORDER BY ZNOTE.ZCREATIONDATE'''
cursor.execute(sql)
with open(filename, 'w') as outfile:
json.dump(cursor.fetchall(), outfile, default=base64.b64encode)
db.close()
except Exception as e:
print ( e )