-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathandroid_baidubrowser.py
274 lines (256 loc) · 10.5 KB
/
android_baidubrowser.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
# coding=utf-8
__author__ = 'YangLiyuan'
from PA_runtime import *
import clr
try:
clr.AddReference('model_browser')
clr.AddReference('bcp_browser')
clr.AddReference('ScriptUtils')
except:
pass
del clr
import bcp_browser
import model_browser
from ScriptUtils import tp, exc, print_run_time, CASE_NAME
# app数据库版本
VERSION_APP_VALUE = 3
def analyze_baidubrowser(node, extract_deleted, extract_source):
"""
android 华为 (data/data/com.baidu.browser.apps/)
"""
res = []
pr = ParserResults()
try:
parser = BaiduBrowserParser(node, db_name='BaiduBrowser')
res = parser.parse(bcp_browser.NETWORK_APP_BAIDU, VERSION_APP_VALUE)
except:
TraceService.Trace(TraceLevel.Debug,
'analyze_baidubrowser 解析新案例 "{}" 出错: {}'.format(CASE_NAME, traceback.format_exc()))
if res:
pr.Models.AddRange(res)
pr.Build('百度浏览器')
return pr
class BaiduBrowserParser(model_browser.BaseBrowserParser):
def __init__(self, node, db_name):
super(BaiduBrowserParser, self).__init__(node, db_name)
self.root = node.Parent.Parent # data/data/com.baidu.browser.apps/
def parse_main(self):
# self.parse_Account('app_webview_baidu/Cookies', 'account_userinfo')
self.parse_Bookmark('databases/dbbrowser.db', 'bookmark')
self.parse_Browserecord('databases/dbbrowser.db', 'history')
self.parse_Cookie(['app_webview_baidu/Cookies', 'app_webview/Cookies'], 'cookies')
self.parse_DownloadFile('databases/flyflowdownload.db', 'bddownloadtable')
self.parse_SearchHistory('databases/dbbrowser.db', 'url_input_record')
def parse_Bookmark(self, db_path, table_name):
""" dbbrowser.db - bookmark
RecNo FieldName
1 account_uid TEXT
2 create_time INTEGER
3 date INTEGER
4 edit_cmd TEXT
5 edit_time INTEGER
6 _id INTEGER
7 parent INTEGER
8 parent_uuid TEXT
9 platform TEXT
10 position INTEGER
11 reserve TEXT
12 sync_time INTEGER
13 sync_uuid TEXT
14 title TEXT
15 type INTEGER
16 url TEXT
17 visits INTEGER
"""
if not self._read_db(db_path):
return
for rec in self._read_table(table_name):
if self._is_empty(rec, 'url', 'title') or not self._is_url(rec, 'url'):
continue
if self._is_duplicate(rec, '_id'):
continue
bookmark = model_browser.Bookmark()
bookmark.id = rec['_id'].Value
# bookmark.owneruser = rec['account_uid'].Value
bookmark.time = rec['create_time'].Value
bookmark.title = rec['title'].Value
bookmark.url = rec['url'].Value
bookmark.source = self.cur_db_source
bookmark.deleted = 1 if rec.IsDeleted else 0
try:
self.csm.db_insert_table_bookmarks(bookmark)
except:
exc()
try:
self.csm.db_commit()
except:
exc()
def parse_Browserecord(self, db_path, table_name):
""" dbbrowser.db - history - 浏览记录
RecNo FieldName SQLType Size
1 create_time INTEGER
2 date INTEGER
3 _id INTEGER
4 reserve TEXT
5 should_ask_icon INTEGER
6 title TEXT
7 url TEXT
8 visits INTEGER
"""
if not self._read_db(db_path):
return
for rec in self._read_table(table_name):
if canceller.IsCancellationRequested:
return
if self._is_empty(rec, 'url', 'create_time') or not self._is_url(rec, 'url'):
continue
if self._is_duplicate(rec, 'create_time'):
continue
browser_record = model_browser.Browserecord()
browser_record.id = rec['_id'].Value
browser_record.name = rec['title'].Value
browser_record.url = rec['url'].Value
browser_record.datetime = rec['date'].Value
browser_record.visit_count = rec['visits'].Value if rec['visits'].Value > 0 else 1
browser_record.source = self.cur_db_source
browser_record.deleted = 1 if rec.IsDeleted else 0
try:
self.csm.db_insert_table_browserecords(browser_record)
except:
exc()
try:
self.csm.db_commit()
except:
exc()
@print_run_time
def parse_DownloadFile(self, db_path, table_name):
""" databases/flyflowdownload.db - bddownloadtable
下载目录: /storage/emulated/0/baidu/flyflow/downloads/
RecNo FieldName SQLType
1 manual INTEGER
2 quiet INTEGER
3 attribute TEXT
4 completetime LONG
5 createdtime LONG
6 style TEXT
7 filename TEXT
8 key TEXT
9 priority INTEGER
10 progressmap TEXT
11 referer TEXT
12 savepath TEXT
13 status INTEGER
14 total LONG
15 current LONG
16 type TEXT
17 url TEXT
"""
# tp 'table_name:', self.root.AbsolutePath
if not self._read_db(db_path):
return
for rec in self._read_table(table_name):
if self._is_empty(rec, 'filename', 'url') or not self._is_url(rec, 'url'):
continue
if self._is_duplicate(rec, 'createdtime'):
continue
# tp('filename', rec['filename'].Value)
downloads = model_browser.DownloadFile()
downloads.url = rec['url'].Value
downloads.filename = rec['filename'].Value
downloads.filefolderpath = self._convert_2_nodepath(rec['savepath'].Value, downloads.filename)
downloads.totalsize = rec['total'].Value
downloads.createdate = rec['createdtime'].Value
downloads.donedate = rec['completetime'].Value
costtime = downloads.donedate - downloads.createdate
downloads.costtime = costtime if costtime > 0 else None # 毫秒
# downloads.owneruser = rec['name'].Value
downloads.source = self.cur_db_source
downloads.deleted = 1 if rec.IsDeleted else 0
try:
self.csm.db_insert_table_downloadfiles(downloads)
except:
exc()
try:
self.csm.db_commit()
except:
exc()
def parse_SearchHistory(self, db_path, table_name):
"""
dbbrowser.db - url_input_record - 输入记录
RecNo FieldName
1 date INTEGER
2 _id INTEGER
3 title TEXT
4 url TEXT
5 visits INTEGER
"""
if not self._read_db(db_path):
return
for rec in self._read_table(table_name):
if canceller.IsCancellationRequested:
return
if self._is_empty(rec, 'url', 'title') or not self._is_url(rec, 'url'):
continue
if self._is_duplicate(rec, '_id'):
continue
search_history = model_browser.SearchHistory()
search_history.id = rec['_id'].Value
search_history.name = rec['title'].Value
search_history.url = rec['url'].Value
search_history.datetime = rec['date'].Value
search_history.source = self.cur_db_source
search_history.deleted = 1 if rec.IsDeleted else 0
try:
self.csm.db_insert_table_searchhistory(search_history)
except:
exc()
try:
self.csm.db_commit()
except:
exc()
def _convert_2_nodepath(self, raw_path, file_name):
try:
# huawei: /data/user/0/com.baidu.searchbox/files/template/profile.zip
paths = [
'/data/com.baidu.searchbox/files/template/',
'/storage/emulated/0/baidu/flyflow/downloads/',
'data/media/0/baidu/'
]
fs = self.root.FileSystem
# 新版本
file_nodes = list(fs.Search(raw_path))
if file_nodes:
file_node = file_nodes[0]
if file_node.Type == NodeType.File:
return file_node.AbsolutePath
# 老版本
if not file_name:
raw_path_list = raw_path.split(r'/')
file_name = raw_path_list[-1]
for path in paths:
# tp(self.root.FileSystem.AbsolutePath)
# tp(os.path.join(path, file_name))
#path_node = self.root.FileSystem.GetByPath(os.path.join(path, file_name))
path_node = self.root.FileSystem.GetByPath('data.tar')
# tp(self.root.FileSystem.Children)
if path_node:
if path_node.Type == NodeType.File:
return path_node.AbsolutePath
_path = None
if len(file_name) > 0:
try:
invalid_file_name = re.search(r'[\\/:*?"<>|\r\n]+', file_name)
if invalid_file_name:
return file_name
node = fs.Search(r'baidu.*?/{}$'.format(file_name))
for i in node:
_path = i.AbsolutePath
except:
pass
if _path:
return _path
return _path if _path else file_name
except:
tp('android_baidubrowser.py _conver_2_nodeapth error, file_name:', file_name)
exc()
return file_name