如何反编译微信小程序

查找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()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值