Created
September 14, 2018 16:25
-
-
Save Mygod/fa3407542922f7ec3c0930b3ca71beda to your computer and use it in GitHub Desktop.
Export QQ chat history on Huawei unrooted device
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
#!/usr/bin/env python | |
import errno | |
import os | |
import sys | |
import codecs | |
import sqlite3 | |
def export(db): | |
query = 'select file_index, data_index, file_data, file_length, file_path, file_link from apk_file_data left natural join apk_file_info order by file_index, data_index;' | |
conn = sqlite3.connect(db) | |
cur = conn.cursor() | |
cur.execute(query) | |
last_index = -1 | |
f = None | |
for index, row in enumerate(cur): | |
if last_index != row[0]: | |
if f is not None: | |
f.close() | |
filename = u'.%s' % row[4] | |
try: | |
os.makedirs(os.path.dirname(filename)) | |
except OSError as exc: | |
if exc.errno != errno.EEXIST: | |
raise | |
print('%d\t%d' % (row[0], row[1])) | |
assert(row[1] == 0) | |
f = codecs.open(u'.%s' % row[4], 'wb') | |
else: | |
assert(data_index + 1 == row[1]) | |
last_index = row[0] | |
data_index = row[1] | |
f.write(row[2]) | |
assert(len(row[2]) == row[3]) | |
if f is not None: | |
f.close() | |
cur.close() | |
if __name__ == '__main__': | |
export(sys.argv[1]) | |
pass |
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
#!/usr/bin/env python | |
import errno | |
import hashlib | |
import os | |
import sys | |
import codecs | |
import sqlite3 | |
IMEI = 'FILL IN HERE' | |
def decrypt(foo): | |
if isinstance(foo, str): | |
return ''.join([chr(ord(x) ^ ord(IMEI[i % 15])) for i, x in enumerate(foo)]) | |
if isinstance(foo, bytes): | |
foo = b''.join([bytes([x ^ ord(IMEI[i % 15])]) for i, x in enumerate(foo)]) | |
try: | |
return foo.decode('utf-8') | |
except UnicodeDecodeError: | |
pass | |
return foo | |
def export(db, qq): | |
query = 'SELECT * FROM mr_friend_%s_New;' % hashlib.md5(qq.encode('utf-8')).hexdigest() | |
conn = sqlite3.connect(db) | |
cur = conn.cursor() | |
cur.execute(query) | |
for row in cur: | |
row = list(row) | |
for index, item in enumerate(row): | |
row[index] = decrypt(item) | |
print(row) | |
cur.close() | |
if __name__ == '__main__': | |
export(sys.argv[1], sys.argv[2]) | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment