-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathandroid_contact.py
632 lines (593 loc) · 28.8 KB
/
android_contact.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
#coding=utf-8
__author__ = "xiaoyuge"
import os
import PA_runtime
import datetime
from PA_runtime import *
import clr
try:
clr.AddReference('model_contact')
clr.AddReference('System.Data.SQLite')
clr.AddReference('bcp_basic')
except:
pass
del clr
import model_contact
import bcp_basic
import System.Data.SQLite as SQLite
import hashlib
import os
import re
import binascii
import traceback
SQL_CREATE_TABLE_DATA = '''CREATE TABLE IF NOT EXISTS data(
raw_contact_id INTEGER,
mimetype_id INTEGER,
data1 TEXT,
data2 TEXT,
data3 TEXT,
data4 TEXT,
data15 TEXT,
deleted INTEGER
)'''
SQL_INSERT_TABLE_DATA = '''
INSERT INTO data(raw_contact_id, mimetype_id, data1, data2, data3, data4, data15, deleted)
VALUES(?, ?, ?, ?, ?, ?, ?, ?)'''
SQL_CREATE_TABLE_MIMETYPES = '''CREATE TABLE IF NOT EXISTS mimetypes(
_id INTEGER,
mimetype TEXT
)'''
SQL_INSERT_TABLE_MIMETYPES = '''
INSERT INTO mimetypes(_id, mimetype)
VALUES(?, ?)'''
SQL_SEARCH_TABLE_DATA = '''
select raw_contact_id, mimetype,
data1, data2, data3, data4, data15, deleted from data
left join mimetypes on data.mimetype_id = mimetypes._id order by raw_contact_id ASC'''
SQL_SEARCH_TABLE_DATA_HUAWEI_BACK = '''
select raw_contact_id, mimetype,
data1, data2, data3, data4 from data_tb order by raw_contact_id ASC
'''
VERSION_APP_VALUE = 1
class ContactParser(model_contact.MC):
def __init__(self, node, extractDeleted, extractSource):
self.node = node
self.extractDeleted = extractDeleted
self.extractSource = extractSource
self.cache_path = ds.OpenCachePath("联系人")
md5_db = hashlib.md5()
db_name = self.node.AbsolutePath
md5_db.update(db_name.encode(encoding = 'utf-8'))
self.cachedb = self.cache_path + "\\" + md5_db.hexdigest().upper() + ".db"
self.raw_contact = {}
self.deleted_db = self.cache_path + "\\" + "deleted.db"
self.oppo_dics = []
self.oppo_dic = {}
def parse(self):
if self.need_parse(self.cachedb, VERSION_APP_VALUE):
print(self.node.PathWithMountPoint)
self.db_create(self.cachedb)
#全盘案例 /com.android.provider.contacts/databases/contacts2.db/data
if re.findall("contacts2.db", self.node.AbsolutePath):
nodes = self.node.FileSystem.Search('/com.android.providers.contacts/databases/contacts2.db$')
print(list(nodes))
for node in nodes:
self.contact_node = node
self.create_deleted_db()
self.analyze_raw_contact_table()
self.analyze_contact_case1()
#备份案例 /contacts/contacts.db/AddressBook
elif re.findall("contacts.db", self.node.AbsolutePath):
self.analyze_contact_logic_case1()
#华为系统备份
elif re.findall("contact.db", self.node.AbsolutePath):
dbx = self.node.Parent.GetByPath("contact.dbx")
if dbx:
self.node = dbx
self.analyze_contact_huawei_bac()
#oppo系统备份
elif re.findall("contact.vcf", self.node.AbsolutePath):
self.analyze_contact_oppo_bac()
#vivo系统备份
elif re.findall("contact$", self.node.AbsolutePath):
self.analyze_contact_oppo_bac()
self.db_insert_table_version(model_contact.VERSION_KEY_DB, model_contact.VERSION_VALUE_DB)
self.db_insert_table_version(model_contact.VERSION_KEY_APP, VERSION_APP_VALUE)
self.db_commit()
self.db_close()
generate = model_contact.Generate(self.cachedb)
models = generate.get_models()
#bcp entry
temp_dir = ds.OpenCachePath('tmp')
PA_runtime.save_cache_path(bcp_basic.BASIC_CONTACT_INFORMATION, self.cachedb, temp_dir)
PA_runtime.save_cache_path(bcp_basic.BASIC_CONTACT_DETAILED_INFORMATION, self.cachedb, temp_dir)
generate = model_contact.Generate(self.cachedb)
models = generate.get_models()
return models
def create_deleted_db(self):
'''恢复删除数据'''
try:
if os.path.exists(self.deleted_db):
os.remove(self.deleted_db)
self.rdb = SQLite.SQLiteConnection('Data Source = {}'.format(self.deleted_db))
self.rdb.Open()
self.rdb_cmd = SQLite.SQLiteCommand(self.rdb)
self.rdb_cmd.CommandText = SQL_CREATE_TABLE_DATA
self.rdb_cmd.ExecuteNonQuery()
self.rdb_cmd.CommandText = SQL_CREATE_TABLE_MIMETYPES
self.rdb_cmd.ExecuteNonQuery()
#向恢复数据库中插入数据
self.insert_deleted_db()
except:
traceback.print_exc()
def insert_deleted_db(self):
'''向恢复数据库中插入数据'''
try:
db = SQLiteParser.Database.FromNode(self.contact_node, canceller)
ts = SQLiteParser.TableSignature('data')
self.rdb_trans = self.rdb.BeginTransaction()
for rec in db.ReadTableRecords(ts, self.extractDeleted, True):
try:
raw_contact_id = self._db_record_get_int_value(rec, 'raw_contact_id')
mimetype_id = self._db_record_get_int_value(rec, 'mimetype_id')
data1 = self._db_record_get_string_value(rec, 'data1')
data2 = self._db_record_get_string_value(rec, 'data2')
data3 = self._db_record_get_string_value(rec, 'data3')
data4 = self._db_record_get_string_value(rec, 'data4')
data15 = self._db_record_get_string_value(rec, 'data5')
deleted = rec.IsDeleted
params = (raw_contact_id, mimetype_id, data1, data2, data3, data4, data15, deleted)
self.db_insert_delete_table(SQL_INSERT_TABLE_DATA, params)
except:
traceback.print_exc()
ts = SQLiteParser.TableSignature('mimetypes')
for rec in db.ReadTableRecords(ts, self.extractDeleted, True):
try:
if rec.IsDeleted == 1:
continue
if rec['_id'].Value is not None and '_id' in rec:
_id = rec['_id'].Value
if rec['mimetype'].Value is not None and 'mimetype' in rec:
mimetype = rec['mimetype'].Value
params = (_id, mimetype)
self.db_insert_delete_table(SQL_INSERT_TABLE_MIMETYPES, params)
except:
traceback.print_exc()
self.rdb_trans.Commit()
self.rdb_cmd.Dispose()
self.rdb.Close()
except:
traceback.print_exc()
def db_insert_delete_table(self, sql, values):
try:
if self.rdb_cmd is not None:
self.rdb_cmd.CommandText = sql
self.rdb_cmd.Parameters.Clear()
for value in values:
param = self.rdb_cmd.CreateParameter()
param.Value = value
self.rdb_cmd.Parameters.Add(param)
self.rdb_cmd.ExecuteNonQuery()
except Exception as e:
print(e)
def analyze_raw_contact_table(self):
'''分析raw_contacts表获取联系次数与最近联系时间'''
try:
db = SQLiteParser.Database.FromNode(self.node, canceller)
if db is None:
return
ts = SQLiteParser.TableSignature('raw_contacts')
for rec in db.ReadTableRecords(ts, self.extractDeleted, True):
contacts = model_contact.Contact()
if canceller.IsCancellationRequested:
break
id = self._db_record_get_int_value(rec, 'contact_id')
times_contacted = self._db_record_get_int_value(rec, 'times_contacted')
last_time_contacted = self._db_record_get_int_value(rec, 'last_time_contacted')
if id not in self.raw_contact.keys():
self.raw_contact[id] = [times_contacted, last_time_contacted]
except Exception as e:
print(e)
except:
traceback.print_exc()
def analyze_contact_case1(self):
'''从提取的删除数据库中获取数据,整理到中间数据库中'''
try:
db = SQLite.SQLiteConnection('Data Source = {}'.format(self.deleted_db))
db.Open()
db_cmd = SQLite.SQLiteCommand(db)
if db is None:
return
db_cmd.CommandText = SQL_SEARCH_TABLE_DATA
sr = db_cmd.ExecuteReader()
data_dic = {} #{id:data}
data = {} #{"name":"xxx", "email":"xxx", "phone":"xxx", address:"xxx", organization:"xxx", occupation:"xxx", note:"xxx"}
#使用字典嵌套保存整理后的数据
while (sr.Read()):
try:
if canceller.IsCancellationRequested:
break
id = self._db_reader_get_int_value(sr, 0)
mimetype = self._db_reader_get_string_value(sr, 1)
data1 = self._db_reader_get_string_value(sr, 2)
data2 = self._db_reader_get_string_value(sr, 3)
data3 = self._db_reader_get_string_value(sr, 4)
data4 = self._db_reader_get_string_value(sr, 5)
data5 = self._db_reader_get_string_value(sr, 6)
deleted = self._db_reader_get_int_value(sr, 7)
if id not in data_dic.keys():
data = self._regularMatch(mimetype, data1, data2, data3, data4, data5)
if not data:
continue
data = dict(data.items()+[("deleted", deleted)])
data_dic[id] = data
else:
d = self._regularMatch(mimetype, data1, data2, data3, data4, data5)
if not d:
continue
if "phone" in d and "phone" in data_dic[id]:
if not re.findall(d["phone"].replace("+", ""), data_dic[id]["phone"]):
data_dic[id]["phone"] = data_dic[id]["phone"] + "," + d["phone"]
elif "formatphone" in d and "formatphone" in data_dic[id]:
if not re.findall(d["formatphone"], data_dic[id]["formatphone"]):
data_dic[id]["formatphone"] = data_dic[id]["formatphone"] + "," + d["formatphone"]
elif "email" in d and "email" in data_dic[id]:
if not re.findall(d["email"].replace("\\", ""), data_dic[id]["email"]):
data_dic[id]["email"] = data_dic[id]["email"] + "," + d["email"]
elif "address" in d and "address" in data_dic[id]:
if not re.findall(d["address"], data_dic[id]["address"]):
data_dic[id]["address"] = data_dic[id]["address"] + "," + d["address"]
else:
data_dic[id] = dict(data_dic[id].items()+d.items())
except:
traceback.print_exc()
sr.Close()
db_cmd.Dispose()
db.Close()
#将嵌套字典中的数据保存至中间数据库
for data in data_dic.items():
try:
key = data[0]
value = data[1]
contacts = model_contact.Contact()
contacts.raw_contact_id = key
contacts.mail = self._verify_dict(value, "email")
contacts.company = self._verify_dict(value, "organization")
contacts.title = self._verify_dict(value, "occupation")
phone_number = self._verify_dict(value, "phone")
formatphone = self._verify_dict(value, "formatphone")
contacts.phone_number = phone_number
#if formatphone is not None and formatphone is not '':
# contacts.phone_number = formatphone
#elif phone_number is not None:
# contacts.phone_number = phone_number
#else:
# contacts.phone_number = ""
contacts.name = self._verify_dict(value, "name")
contacts.address = self._verify_dict(value, "address")
contacts.notes = self._verify_dict(value, "note")
raw_contact = self._verify_dict(self.raw_contact, key)
if raw_contact is not None:
contacts.times_contacted = raw_contact[0]
contacts.last_time_contact = raw_contact[1]
contacts.source = self.contact_node.AbsolutePath
contacts.deleted = self._verify_dict(value, "deleted")
self.db_insert_table_call_contacts(contacts)
except:
pass
self.db_commit()
except:
traceback.print_exc()
def _regularMatch(self, mimetype, data1, data2, data3, data4, data5):
'''
通过mimetype匹配数据库中data字段内容类型
eg:
mimetype为vnd.android.cursor.item/phone_v2,
则数据库中data1字段储存号码(123-4567-8900),
data4字段存储格式化号码(+86-123-4567-8900)
最后匹配结果以字典格式返回
'''
try:
data = {}
#匹配姓名
if re.findall("name", mimetype):
if data1 is not '':
data["name"] = data1
#匹配邮件
elif re.findall("email", mimetype):
if data1 is not '':
data["email"] = data1
#匹配公司与职业
elif re.findall("organization", mimetype):
if data1 is not '':
data["organization"] = data1
if data4 is not '':
data["occupation"] = data4
#匹配备注
elif re.findall("note", mimetype):
if data1 is not None:
data["note"] = data1
#匹配联系方式
elif re.findall("phone", mimetype):
if data1 is not None:
data["phone"] = data1
if data4 is not None:
data["formatphone"] = data4
#联系地址
elif re.findall("address", mimetype):
if data1 is not None:
data["address"] = data1
#telegram
elif re.findall("telegram", mimetype):
if data1 is not None:
data["phone"] = data1
return data
except:
return {}
def analyze_contact_logic_case1(self):
'''逻辑提取案例'''
try:
db = SQLiteParser.Database.FromNode(self.node, canceller)
if db is None:
return
ts = SQLiteParser.TableSignature('AddressBook')
id = 0
for rec in db.ReadTableRecords(ts, self.extractDeleted, True):
contacts = model_contact.Contact()
id += 1
if canceller.IsCancellationRequested:
break
contacts.raw_contact_id = id
#邮箱
homeEmail = self._db_record_get_string_value(rec, "homeEmails")
jobEmail = self._db_record_get_string_value(rec, "jobEmails")
customEmail = self._db_record_get_string_value(rec, "customEmails")
otherEmail = self._db_record_get_string_value(rec, "otherEmails")
emails = homeEmail + jobEmail + customEmail + otherEmail
contacts.mail = emails.replace('\n', '').replace('][', ',').replace('[', '').replace(']', '').replace('\"', '').replace(' ', '')
contacts.company = self._db_record_get_string_value(rec, "organization")
#电话号码
phonenumber = self._db_record_get_string_value(rec, "phoneNumbers")
homenumber = self._db_record_get_string_value(rec, "homeNumbers")
jobnumber = self._db_record_get_string_value(rec, "jobNumbers")
othernumber = self._db_record_get_string_value(rec, "otherNumbers")
customnumber = self._db_record_get_string_value(rec, "customNumbers")
numbers = phonenumber + homenumber + jobnumber + othernumber + customnumber
pnumber = numbers.replace('\n', '').replace('][', ',').replace('[', '').replace(']', '').replace('\"', '').replace(' ', '')
pnumber = pnumber.split(',')
pnumber = list(set(pnumber))
contacts.phone_number = ','.join(pnumber)
contacts.name = self._db_record_get_string_value(rec, "name")
contacts.address = self._db_record_get_string_value(rec, "homeStreets")
contacts.notes = self._db_record_get_string_value(rec, "remark")
#pic_url = self.node.Parent.Parent.AbsolutePath + '/' + self._db_record_get_string_value(rec, "photoPath")
#contacts.head_pic = pic_url
contacts.source = self.node.AbsolutePath
contacts.deleted = rec.IsDeleted
self.db_insert_table_call_contacts(contacts)
self.db_commit()
except Exception as e:
print(e)
def analyze_contact_huawei_bac(self):
'''解析华为备份案例'''
try:
db = SQLiteParser.Database.FromNode(self.node, canceller)
if db is None:
return
ts = SQLiteParser.TableSignature('data_tb')
data_dic = {} #{id:data}
data = {} #{"name":"xxx", "email":"xxx", "phone":"xxx", address:"xxx", organization:"xxx", occupation:"xxx", note:"xxx"}
#使用字典嵌套保存整理后的数据
#while (sr.Read()):
for rec in db.ReadTableRecords(ts, self.extractDeleted, True):
try:
if canceller.IsCancellationRequested:
break
id = self._db_record_get_int_value(rec, "raw_contact_id")
mimetype = self._db_record_get_string_value(rec, "mimetype")
data1 = self._db_record_get_string_value(rec, "data1")
data2 = self._db_record_get_string_value(rec, "data2")
data3 = self._db_record_get_string_value(rec, "data3")
data4 = self._db_record_get_string_value(rec, "data4")
data5 = ""
if id not in data_dic.keys():
data = self._regularMatch(mimetype, data1, data2, data3, data4, data5)
if not data:
continue
data_dic[id] = data
else:
d = self._regularMatch(mimetype, data1, data2, data3, data4, data5)
if not d:
continue
if "phone" in d and "phone" in data_dic[id]:
if not re.findall(d["phone"], data_dic[id]["phone"]):
data_dic[id]["phone"] = data_dic[id]["phone"] + "," + d["phone"]
if "formatphone" in d and "formatphone" in data_dic[id]:
if not re.findall(d["formatphone"].replace("+", ""), data_dic[id]["formatphone"]):
data_dic[id]["formatphone"] = data_dic[id]["formatphone"] + "," + d["formatphone"]
elif "email" in d and "email" in data_dic[id]:
if not re.findall(d["email"], data_dic[id]["email"]):
data_dic[id]["email"] = data_dic[id]["email"] + "," + d["email"]
elif "address" in d and "address" in data_dic[id]:
if not re.findall(d["address"], data_dic[id]["address"]):
data_dic[id]["address"] = data_dic[id]["address"] + "," + d["address"]
else:
data_dic[id] = dict(data_dic[id].items()+d.items())
except:
traceback.print_exc()
#将嵌套字典中的数据保存至中间数据库
for data in data_dic.items():
try:
key = data[0]
value = data[1]
contacts = model_contact.Contact()
contacts.raw_contact_id = key
contacts.mail = self._verify_dict(value, "email")
contacts.company = self._verify_dict(value, "organization")
contacts.title = self._verify_dict(value, "occupation")
phone_number = self._verify_dict(value, "phone")
formatphone = self._verify_dict(value, "formatphone")
if formatphone is not None and formatphone is not '':
contacts.phone_number = formatphone
elif phone_number is not None:
contacts.phone_number = phone_number
else:
contacts.phone_number = ""
contacts.name = self._verify_dict(value, "name")
contacts.address = self._verify_dict(value, "address")
contacts.notes = self._verify_dict(value, "note")
contacts.source = self.node.AbsolutePath
self.db_insert_table_call_contacts(contacts)
except:
pass
self.db_commit()
except:
traceback.print_exc()
def analyze_contact_oppo_bac(self):
'''解析oppo系统自带案例'''
try:
vcf_dir = self.node.PathWithMountPoint
f = open(vcf_dir, 'r')
for line in f.readlines():
if re.findall('BEGIN:VCARD', line):
self.oppo_dic = {}
elif re.findall('END:VCARD', line):
self.oppo_dics.append(self.oppo_dic)
#获取姓名
elif re.findall("FN:", line) or re.findall("FN;", line):
self.vcf_helper("name", line)
#获取电话号码
elif re.findall("TEL:", line) or re.findall("TEL;", line):
self.vcf_helper("phone", line)
#获取email
elif re.findall("EMAIL:", line) or re.findall("EMAIL;", line):
self.vcf_helper("email", line)
#获取地址
elif re.findall("ADR:", line) or re.findall("ADR;", line):
self.vcf_helper("address", line)
#获取备注
elif re.findall("NOTE:", line) or re.findall("NOTE;", line):
self.vcf_helper("note", line)
#获取公司
elif re.findall("ORG:", line) or re.findall("ORG;", line):
self.vcf_helper("organization", line)
#获取职务
elif re.findall("TITLE:", line) or re.findall("TITLE;", line):
self.vcf_helper("occupation", line)
for value in self.oppo_dics:
try:
contacts = model_contact.Contact()
contacts.mail = self._verify_dict(value, "email")
contacts.company = self._verify_dict(value, "organization")
contacts.title = self._verify_dict(value, "occupation")
phone_number = self._verify_dict(value, "phone")
formatphone = self._verify_dict(value, "formatphone")
if formatphone is not None and formatphone is not '':
contacts.phone_number = formatphone
elif phone_number is not None:
contacts.phone_number = phone_number
else:
contacts.phone_number = ""
contacts.name = self._verify_dict(value, "name")
contacts.address = self._verify_dict(value, "address")
contacts.notes = self._verify_dict(value, "note")
contacts.source = self.node.AbsolutePath
self.db_insert_table_call_contacts(contacts)
except:
traceback.print_exc()
self.db_commit()
except:
traceback.print_exc()
def vcf_helper(self, key, line):
'''解析vcf名片工具方法'''
if re.findall("ENCODING=QUOTED-PRINTABLE", line):
hexStr = re.sub('.*:', '', line).replace("=", "").replace('\n', '').replace(";", "")
try:
strs = binascii.a2b_hex(hexStr.lower().strip()).decode("utf-8")
except:
strs = ''
else:
strs = re.sub('.*:', '', line).replace('\n', '').replace(";", "")
if key in self.oppo_dic:
self.oppo_dic[key] = self.oppo_dic[key] + ',' + strs
else:
self.oppo_dic[key] = strs
@staticmethod
def _verify_dict(dic, string, default_value = None):
return dic[string] if string in dic else default_value
@staticmethod
def _db_record_get_value(record, column, default_value=None):
if not record[column].IsDBNull:
return record[column].Value
return default_value
@staticmethod
def _db_record_get_string_value(record, column, default_value=''):
if not record[column].IsDBNull:
try:
value = str(record[column].Value)
#if record.Deleted != DeletedState.Intact:
# value = filter(lambda x: x in string.printable, value)
return value
except Exception as e:
return default_value
return default_value
@staticmethod
def _db_record_get_int_value(record, column, default_value=0):
if not record[column].IsDBNull:
try:
return int(record[column].Value)
except Exception as e:
return default_value
return default_value
@staticmethod
def _db_record_get_blob_value(record, column, default_value=None):
if not record[column].IsDBNull:
try:
value = record[column].Value
return bytes(value)
except Exception as e:
return default_value
return default_value
@staticmethod
def _db_reader_get_string_value(reader, index, default_value=''):
return reader.GetString(index) if not reader.IsDBNull(index) else default_value
@staticmethod
def _db_reader_get_int_value(reader, index, default_value=0):
return reader.GetInt64(index) if not reader.IsDBNull(index) else default_value
@staticmethod
def _db_reader_get_float_value(reader, index, default_value=0):
return reader.GetFloat(index) if not reader.IsDBNull(index) else default_value
def analyze_android_contact(node, extractDeleted, extractSource):
pr = ParserResults()
try:
if len(list(node.Search('/com.android.providers.contacts/databases/contacts2.db$'))) != 0:
progress.Start()
pr.Models.AddRange(ContactParser(node.Search('/com.android.providers.contacts/databases/contacts2.db$')[0], extractDeleted, extractSource).parse())
pr.Build('联系人')
return pr
elif len(list(node.Search('/contacts/contacts.db$'))) != 0:
progress.Start()
pr.Models.AddRange(ContactParser(node.Search('/contacts/contacts.db$')[0], extractDeleted, extractSource).parse())
pr.Build('联系人')
return pr
elif len(list(node.Search('contact.db$'))) != 0:
progress.Start()
pr.Models.AddRange(ContactParser(node.Search('contact.db$')[0], extractDeleted, extractSource).parse())
pr.Build('联系人')
return pr
elif len(list(node.Search('contact.vcf$'))) != 0:
progress.Start()
pr.Models.AddRange(ContactParser(node.Search('contact.vcf$')[0], extractDeleted, extractSource).parse())
pr.Build('联系人')
return pr
elif len(list(node.Search('contact$'))) != 0:
progress.Start()
pr.Models.AddRange(ContactParser(node.Search('contact$')[0], extractDeleted, extractSource).parse())
pr.Build('联系人')
return pr
else:
progress.Skip()
except:
progress.Skip()
def execute(node, extractDeleted):
return analyze_android_contact(node, extractDeleted, False)