欢迎光临散文网 会员登陆 & 注册

解决华为旧备份数据导出问题

2023-07-24 12:10 作者:Goyasha  | 我要投稿

使用低版本华为备份软件得到的微信备份文件为一个com.tencent.mm.apk文件和一个com.tencent.mm.db文件。

用sqlite数据库管理工具打开com.tencent.mm.db,发现只有三个表,其中apk_file_info表中储存了所有文件名和索引号,apk_file_data中则存储了文件数据。索引号为-1的是目录,索引号大于0的是有用的文件。


在apk_file_data中索引号相同的是同一个文件,每个文件被切成若干个8K以内的碎片进行存储,导出时需要拼接起来再导出。


导出文件数据的python代码如下:

import sqlite3
import os
conn = sqlite3.connect('com.tencent.mm.db')
cursor = conn.cursor()
cursor.execute("SELECT count(*) FROM apk_file_info")
all = cursor.fetchone()[0]
cursor.execute("SELECT file_path,file_index FROM apk_file_info")
result = cursor.fetchall()
count = 0
while (count < all):
  if (result[count][1] > 0):
      fullname = result[count][0]
      findex = result[count][1]
      dirname,filename = os.path.split(fullname)
      fpath="." + dirname
      fname="." + fullname
      isExists=os.path.exists(fpath)
      if not isExists:
          os.makedirs(fpath)
      with open(fname, "wb") as output_file:
        cursor.execute("SELECT count(*) FROM apk_file_data WHERE file_index = " + str(findex))
        total = cursor.fetchone()[0]
        cursor.execute("SELECT file_data FROM apk_file_data WHERE file_index = " + str(findex))
        acount=0
        while (acount < total):
          ablob = cursor.fetchone()
          output_file.write(ablob[0])
          acount = acount+1
  count = count + 1
cursor.close()
conn.close()

将代码保存为out.py后与com.tencent.mm.db文件放在同一目录下,python out.py运行即可在当前目录下导出所有文件。生成目录为data/data/com.tencent.mm。


比较懒,没有加注释和提示信息。实际使用时请自行添加提示信息和异常处理代码。如果导出文件数据较多程序效率比较低,可自行优化,代码仅供参考。

解决华为旧备份数据导出问题的评论 (共 条)

分享到微博请遵守国家法律