查找wxapkg文件
wxapkg无论是debug版还是release版,是小程序还是小游戏,都在这个目录下,一串星号是小程序的hash。
/data/data/com.tencent.mm/MicroMsg/***********/appbrand/pkg
debug版文件后缀并不是.wxapkg
,但是打开文件可见第一个字节为0xBE
反编译
运行如下python脚本,就会解包。
# -*- coding: utf-8 -*-
# @Author: saidyou
# @Date: 2020-03-24 12:55:49
# @Last Modified by: saidyou
# @Last Modified time: 2020-03-24 14:54:06
import os,sys,struct
class wxapkg:
wxapkg_path = ""
out_path = ""
def __init__(self,wxapkg_path):
self.wxapkg_path = wxapkg_path
self.header = None
if wxapkg_path.endswith('.wxapkg'):
self.out_path = wxapkg_path[:wxapkg_path.rfind('.wxapkg')]
else:
self.out_path = wxapkg_path+'_decode'
def open_wxapkg(self):
fd = open(self.wxapkg_path,"rb")
# file header
self.header = struct.unpack("IIII", fd.read(0x10))
if self.header[0] == 0xbe:
#get file name
file_num = struct.unpack(">H", fd.read(2))[0]
#file resource
for i in range(0,file_num):
self.get_file(fd)
else:
raise Exception('unsupport format')
def create_path(self,name):
if name.startswith(os.sep):
name = name[1:]
path = os.path.join(self.out_path,name)
full_path = os.path.abspath(path)
dir_path = os.path.dirname(full_path)
if not os.path.exists(dir_path):
os.makedirs(dir_path)
return full_path
#read file
def get_file(self,fd):
file_name_length = struct.unpack('>I',fd.read(4))[0]
file_name = fd.read(file_name_length).decode().replace('/',os.sep,)
file_path = os.path.join(self.out_path,file_name)
file_start = struct.unpack(">I", fd.read(4))[0]
file_length = struct.unpack(">I", fd.read(4))[0]
tmp_seek = fd.tell()
fd.seek(file_start, os.SEEK_SET)
file_content = fd.read(file_length)
print("[start] %4x [length] %4x [file_name] %s"%(file_start,file_length,file_name))
full_file_path = self.create_path(file_path)
open(full_file_path,"wb").write(file_content)
fd.seek(tmp_seek, os.SEEK_SET)
if __name__ == '__main__':
if len(sys.argv)<2:
print("Please input wxapkg file path")
exit(0)
apk = wxapkg(sys.argv[1])
apk.open_wxapkg()