This tutorial will tell you step by step how to practice “the decompiled” for other small program source code, including “unpack” and “source reduction” two, mainly refer to see snow BBS posts, V2EX, making website, tutorials, tools, I appreciate the reference link to see the bottom of the article, and added some of my own understanding and summary.

Knowledge Collection is a team official account. Every week, original articles will be shared, and our articles will be first published on the official account. Stay tuned for more.

As we know, after the small program is developed in the wechat developer tool, we click the “upload” button, and the wechat developer tool will “compile”, compress and confuse the JS code, and integrate WXML, WXSS and resource files into a.wxapkg file and upload it to the wechat server.

So to “decompile” the applet, we first need to get the corresponding. Wxapkg package of the applet.

Before there is an article on V2EX https://www.v2ex.com/t/419056 introduces how to use a direct download URL of each small program. Wxapkg, but soon was the envelope.

Therefore, we can only start from the mobile phone, find the wechat client on the mobile phone to download the local small program package.

Get the.wxapkg file for the applet

Tools: a jailbroken iPhone or a Root Android phone

This paper takes iPhone 4S, iOS 8.4.1 as an example, and wechat version V6.6.6.

Open Cydia on a jailbroken iPhone, search for and install file browsing apps such as iFile or Filza, open iFile or Filza, and jump to the local App installation directory: / var/mobile/Containers/Data/Application /, at this point, you can see the current iPhone installed App list, as shown in the figure below:

Find the “Wechat” directory (on my phone: 297286CE-9055-400A-99FA-d2D7C0735DCF folder), click to enter, which is the “Sandbox” of wechat on this iPhone. I believe iOS developers are very familiar with this directory. This directory contains folders such as Documents, Library, and TMP. These folders are usually used to store different data and files, which will not be described here. We searched the keyword wxapkg in the current “sandbox” directory of wechat, and found the downloaded small program package of wechat in the current iPhone, as shown in the picture below:

2. Wxapkg and 25. Wxapkg are named by numbers. Where do you put it? Let’s move on.

After simple analysis, we found that the small program package downloaded by wechat is stored in the following directory:

/path/to/WeiChat SandBox/Library/WechatPrivate/{UserId}/WeApp/LocalCache/release/
Copy the code

Where, {UserId} is the MD5 value (32-bit string) of the current login wechat account Id. For example, the complete directory of the small program package on my mobile phone is:

/var/mobile/Containers/Data/Application/297286CE-9055-400A-99FA-D2D7C0735DCF/Library/WechatPrivate/c15d9cced65acecd30d2d 6522df2f973/WeApp/LocalCache/release/Copy the code

The contents of this directory are as follows:

There is a range of wX… The folders at the beginning of these WX… The 18-bit string is the corresponding AppId of each applets, in each WX… Each folder contains the.wxapkg package for the current apet, which is named after a number that indicates the number of times the current apet was released by the developer (it is different from the version number specified when the developer released the apet). For example, there are two versions of our “Knowledge set” apet, so wx48… 2. Wxapkg file stored in 85DB file:

In addition, we found that on iOS, wechat also allocated a Sandbox folder for each applet to manage the data and files stored locally by the applet, as shown in the figure:

Its path is:

/path/to/WeiChat SandBox/Library/WechatPrivate/{UserId}/WeApp/Sandbox/wx... (Small program AppId)Copy the code

By The Way, The directory for storing small program packages on Android phones is (Root permission is required to access) :

/data/data/com.tencent.mm/MicroMsg/{UserId}/appbrand/pkg/
Copy the code

Copy the.wxapkg file to your computer

Through the above analysis, we can know where the small program’s compressed package. Wxapkg is stored, and then we need to copy the.wxapkg file from the mobile phone to the computer.

After opening Cydia search and installing OpenSSH on iPhone, go to iPhone > Settings > wireless LAN to view the WiFi connected to your current phone and record the IP address, for example, mine is: 192.168.1.17, then open the terminal on your Mac (connected to the same WiFi as your iPhone) and log in to your phone via SSH (see the instructions on the OpenSSH download page on Cydia for details) :

SSH [email protected]Copy the code

We can then copy the file from the iPhone to our computer using SCP commands, for example, from the command line on my Mac (no SSH login to the iPhone, directly from the Mac terminal) :

scp [email protected]: / var/mobile/Containers/Data/Application/ce 297286-9055-400 - a - 99 - fa - D2D7C0735DCF/Library/WechatPrivate/c15 d9cced65acecd30d2d6522df2f973/WeApp/LocalCache/release/wx48... 85db/2.wxapkg /Users/Zubin/Desktop/WeApp/Copy the code

I could copy the “knowledge applet” package, 2.wxapkg, to the “appellate P” folder on my Mac desktop.

Of course, if you have a tool like iTool or PP Assistant installed on your computer, this may not be so troublesome (unverified) when connecting to a jailbroken iPhone seems to give you direct access to directories and files on the phone.

Wxapkg solution package

With a lot of effort, we finally got the.wxapkg package for each applet, which we can now analyze. First, what exactly is a.wxapkg file? You might think it’s something like the.apk for Android or the.ipa for iOS, which is essentially a.zip package? It’s not! , it is a binary file, the actual file structure is shown as follows:

The picture is taken from the article wechat small program source reading notes, and the author of this article also provides to understand the package script (various languages) posted on GitHub:

I downloaded the unpacking script for Python 2, placed it in the same directory as the.wxapkg file, and then executed the following name on the command line to get the unpacked file:

python unwxapkg.py 2.wxapkg
Copy the code

Take “knowledge set” applets as an example, after unpacking, the obtained file directory is as follows (has been basically the same as my “knowledge set” applets project directory) :

After unpacking each small program, the files are almost the same, mainly including the following files:

  • app-service.js: a summary of all JS files in the applets project, which has been confused;
  • app-config.json: small program projectapp.jsonAnd the SUMMARY of THE JSON configuration files on each page, which can be directly viewed.
  • page-frame.html: for all pages.wxmlapp.wxssSummary of style files, poor readability, need to restore;
  • *.html: contains information corresponding to each page.wxssInformation, good readability;
  • Resource file: All kinds of images, audio files and other resources

conclusion

This article mainly introduces how to get the.wxapkg package file of the small program, and how to unpack the confused code and resource files of the small program after “compilation”. The next article “micro channel small program” decompile “actual combat (ii) : source restore” will introduce how to restore the contents of the.wxapkg package to the content before “compilation”.

Refer to the link

  • Look at the snow BBS
  • V2EX
  • GitHub