This article will explain in detail how to unpack and decompile the online wechat small program, and deal with the independent subcontracting loading, plug-ins and other cases of the solution, and finally get his source code to learn, yes, is to learn. 😄 This tutorial is also for learning purposes only. The so-called work to do a good job, must first sharpen its tools, let’s prepare what we need to prepare:

A mobile phone with ROOT permission. (You can use the Android emulator) decomcompiled scripts in node. js environment: github.com/141Mr-liu/w… (We use subcontract loading support here, of course ordinary can also be used)

Gets the package that needs to decompile the applets

  1. First of all, in order to decompile the micro channel applet source code, we must first have a package of the micro channel applet, then how should we get the package? We need a phone with ROOT privileges, but in 9012, there will be very few ROOT phones, so we can use the Android emulator to do this. Here I recommend the Night god simulator, because it will be more convenient for the management of permissions and files.
  2. We first open the emulator or the phone, because the phone’s built-in browser can’t see some hidden directories, so we download the RE browser, which is also the reason for the ROOT permission. Open the RE browser, access is normal, enter/data/data/com. Tencent. The mm/MicroMsg appbrand, you’ll see a similar a8b3488516c9d81e1d5f511891583cf9 folder, This are classified with reference to the user, if there are multiple, can delete all, entering a8b3488516c9d81e1d5f511891583cf9 folder, enter the PKG folder, the folder is used to prevent WeChat small package, suffix for * *. Wxapkg * * is small package, It is suggested to delete all the packages except the largest one (about 7-8m), so as to facilitate finding the packages we need later.
  3. After the preparation, we open wechat, open the small program we want to decompile, this is the PKG directory will appear a new WXapkg package, copy this package to the computer. Night simulator can be achieved through shared folder.

Preparation before decompilation

  1. Install Node.js (foolproof installation, not explained)
  2. Use the CMD command line to go to the decompiled script directory we downloaded and output the following commands to install dependencies:
npm install esprima
npm install css-tree
npm install cssbeautify
npm install vm2
npm install uglify-es
npm install js-beautify
Copy the code

After the installation is complete, we can officially start decomcompiling our wechat applet

  1. You are advised to save the small program package in a convenient location, such as the disk directory or script directory, to facilitate subsequent operations
  2. CMD go to the script directory and use node wuwxapkg. js C:\1.wxapkg to unpack the small program package, where C:\1.wxapkg is the small program to be unpacked.
  3. If there are no bugs, a package name folder will appear in the package directory, which is the final decompiled source.
  4. If there is independent subcontracting in the applet, we should do the following:
Sh testpkg/master-xxx.wxapkg 3. Sh testpkg/sub-1-xxx. wxapkg-s =.. /master-xxx Sub-1-xxx. wxapkg indicates the path of the sub-package wxapkg. -s= indicates the path of the sub-package in the main packageCopy the code
  1. Of course, you can unpack the main package and subpackage directly, and then replace the files in the main package subpackage.

FAQ Resolution

BUG1 # $gwx is not defined

Use the editor to open the wuwxss.js file, find the runVM function, and replace the function contents with:

let wxAppCode = {};
      let handle = {cssFile: name};
      let gg = new GwxCfg();
      let tsandbox = {
         $gwx: GwxCfg.prototype["$gwx"].__mainPageFrameReady__: GwxCfg.prototype["$gwx"].$GWX is not defined
         __vd_version_info__: GwxCfg.prototype["$gwx"].// Resolve __vd_version_info__ is not defined
         __wxAppCode__: wxAppCode,
         setCssToHead: cssRebuild.bind(handle)
      }
 
      let vm = new VM({sandbox: tsandbox});
      vm.run(code);
      for (let name in wxAppCode) {
         if (name.endsWith(".wxss")) {
            handle.cssFile = path.resolve(frameName, "..", name); wxAppCode[name](); }}Copy the code

I’ll just recompile it.

BUG2: no such file or directory, open ‘… \plugin:\wxa75efa648b60994b…. Json ‘, the plugin reported an error.

This problem is that you search all over the Internet, no one will tell you, anyway, when I solved it, BAIDU and Google searched all over, but failed to find a solution, the Internet is full of some copy of the basic content of the station post… No such file or directory, open ‘… \plugin:\wxa75efa648b60994b…. Json ‘, you product, you fine product, words **\plugin:** this directory is what, also is the reason of this directory, caused the blogger in Baidu and Google to find the answer for a long time, finally rely on their own solution. In The Windows system, and support folder named:, so the corresponding plugin folder is renamed by the system to “plugin”, so the program can not find this folder, surprise, surprise, solution is very simple. There are two ways to solve this problem:

  1. Modify the contents of the script to change plugin: to another format. (This method is invalid, can not be modified by script, the plugin: is actually the wechat wXapkg inside the thing, if the small program references the third party plug-in, there will be this folder)
  2. Execute files and scripts on Linux because Linux doesn’t have that much shit to do.