查找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
import sys
class wxapkg:
wxapkg_path = ""
out_path = ""
def __init__(self,wxapkg_path):
self.wxapkg_path =wxapkg_path
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")
if self.is_wxapkg() == False:
fd.close()
return
#header
self.get_header(fd)
#get file name
file_num = self.get_file_num(fd)
#file resource
for i in range(0,file_num):
self.get_file(fd)
def close_wxapkg(self):
self.close()
def is_wxapkg(self):
fd = open(self.wxapkg_path,"rb")
key = fd.read(1)
if ord(key)==0xbe:
# print(" right format")
return True
else:
print("not wxapkg format")
return False
def bytesToInt(self ,byte_array):
num = (byte_array[0]<<24) + (byte_array[1]<<16) + (byte_array[2]<<8) + byte_array[3]
return num
def get_int(self,fd,length):
num = 0
for i in range(0,length):
num = (num<<8) + (ord(fd.read(1)))
return num
def create_path(self,path):
if path.find(os.sep):
dir_path = path[:path.rfind(os.sep)]
if not os.path.exists(dir_path):
os.makedirs(dir_path)
#read wxapkg
def get_header(self,fd):
header = fd.read(0x10)
def get_file_num(self,fd):
file_num = self.get_int(fd,2)
return file_num
#read file
def get_file(self,fd):
file_name_length = self.get_int(fd,4)
file_name = fd.read(file_name_length).decode().replace('/',os.sep,)
file_path = self.out_path+file_name
file_start =self.get_int(fd,4)
file_length = self.get_int(fd,4)
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))
self.create_path(file_path)
open(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()