Detailed tutorial on decompiling small programs and handling various exceptions and errors

Article directory
1. Preparation work
(1) Installing Nodejs
(2) Decryption and reverse tools
2. Decryption of mini program cache files
(1) Locating the mini program cache path
(2) Source code decryption
(3) Source code decompilation
3. Summary
4. Exceptions Handling
1.TypeError: subPackage.pages is not iterable exception
2.function(env,dd,global){$gwxc=0;var root={"tag":"wx-page"};root.children=[] exception
3.SyntaxError: Unexpected token '}' Exception handling
4. Error: This application has not registered any plugins yet. Exception handling
5. Bad attr data-event-paramswith message Exception handling
1. Preparation
(1) Install Nodejs
Node.js is a Chrome-based The JavaScript running environment of the V8 engine is usually JavaScript running on the server side. This article requires the nodejs environment to provide npm tools to install related dependencies, so nodejs needs to be installed first.
Node.js official download address:
https://nodejs.org/zh-cn/download/
Then you can choose the corresponding version according to the operating system you are using. Here I choose the windows version:

After setting the installation path, click next all the way.
Then enter in cmd:

node -v

Insert image description here

If the version information appears, the installation is successful.
Note: When executing global installation commands such as npm install xxx -g, the module will be installed in npm and npm_cache under the C:\Users\username\AppData\Roaming path by default, which is inconvenient to manage and takes up space on the C drive. , so here I refer to other people's configuration, custom global module installation directory, and create two new folders node_global and node_cache in the node.js installation directory.
Then execute the following commands in cmd (note that the first two commands are changed to your own paths):

Set the mirror source to Taobao npm mirror to improve download speed

npm config set registry=https://registry.npm.taobao.org

This article is just for using npm to install things. In fact, it ends here. If you need more functions, you will need to configure environment variables later. Please refer to other articles. This article will not cover too much.
By the way, if you need to perform version-related operations, please refer to the following commands:

Command description

nvm install 14.15.5 安装指定的版本的nodejs
nvm use 10.5.0  使用指定版本的nodejs
nvm list	查看已经安装的版本
nvm list installed	查看已经安装的版本
nvm list available	查看网络可以安装的版本
nvm arch	查看当前系统的位数和当前nodejs的位数
nvm install [arch]	安装制定版本的node 并且可以指定平台 version 版本号 arch 平台
nvm on	打开nodejs版本控制
nvm off	关闭nodejs版本控制
nvm proxy [url]	查看和设置代理
nvm node_mirror [url]	设置或者查看setting.txt中的node_mirror,如果不设置的默认是 https://nodejs.org/dist/
nvm npm_mirror [url]	设置或者查看setting.txt中的npm_mirror,如果不设置的话默认的是:https://github.com/npm/npm/archive/.
nvm uninstall	卸载制定的版本
nvm use [version] [arch]	切换制定的node版本和位数
nvm root [path]	设置和查看root路径
nvm version	查看当前的版本

(2) Decryption and reverse engineering tools:
After obtaining the cache file of the mini program, you need to use a decryption tool to perform a round of decryption before reverse engineering.
Decryption tool download address: (G public account: programmer Wu , reply: decompile tutorial to receive)

Note: If the above address is invalid, you can send me a private message in time.

3. Decryption of mini program cache files
(1) Locate the mini program cache path.
First determine the cache directory of the mini program, open settings on WeChat, and then find file management:

Click Open Folder to open the Applet folder:

The local cache file of the mini program is stored here:

(2) Source code decryption
Then open a small program. It is not convenient to reveal which small program is used here. You can find the small program you are interested in and play it by yourself.
First open the target applet, and then click on some more pages to let the applet generate cache files locally. Then check the local folder and you will see that a folder has been generated. You can determine which folder is in it by the time when the folder was created. The data belongs to the cache directory of the applet just accessed:

Then, we need to decrypt these cached data first. The method is very simple. Open the decryption tool:

Then click 'Select encrypted applet package' and select the cache directory of the applet you just located. As shown in the figure, decryption has been successful:

The decrypted files are in the wxpack folder in the same directory as the decryption program:
Insert image description here

(3) Source code decompilation:
First decompress the downloaded wxappUnpacker, then enter the folder, copy the address of the folder, and then open the cmd window as an administrator (press win+R directly to open the run window, then enter cmd, press ctrl+shift+enter), and then jump to wxappUnpacker, as shown below:

Note that you must run the cmd window as an administrator, otherwise it may cause command execution errors later.
Then start installing dependencies and execute the following commands in order:

npm install
npm install esprima
npm install css-tree
npm install cssbeautify
npm install vm2
npm install uglify-es
npm install js-beautify

Because I have already installed it here, it will be different from yours. Just make sure there is no error message after execution.
Then construct the command based on the previously decrypted file as follows:

node ./wuWxapkg.js E:\WeiXinXiaoChengXu\wxpack\wx3b25611579a1b7ec.wxapkg 

The format of this command is:

node ./wuWxapkg.js 主包路径

The other is the subpackaged decompilation instructions:

node ./wuWxapkg.js 分包路径 -s=主包路径

Sometimes what we get after decryption is the subpackage after the main package (I don’t know why specifically, it depends on the situation), then at this time we can easily use the -s parameter to specify the storage path.
Now we will execute the command constructed according to the first command format in cmd;

At this point you can see that a folder has been generated, with the current content as follows:
Insert image description here

At this point, you can freely import it into the WeChat developer tools for learning and observation.

3. Summary
This article shares the method of decompiling and obtaining the source code from the local cache file of the WeChat applet. When installing dependencies, you need to use npm, and npm does not need to be installed separately, because when installing Node, npm will be installed together. Therefore, we need to install a nodejs, and then use decryption and decompilation tools to obtain the source code of the mini program by following the steps of first decrypting and then decompiling. We apologize for any shortcomings.

4. Exception summary processing

1.TypeError: subPackage.pages is not iterable 异常

 for (let page of subPackage.pages) {
    
    
^

TypeError: subPackage.pages is not iterable

This exception is actually a simple exception caused by the empty subPackage parameter. It only needs to be simply modified to the following content (G public account to receive the complete program: Programmer Wu) (Reply: Decompile tutorial, obtain the source code file to solve this problem )

if(subPackage.pages){
    
    
     for (let page of subPackage.pages) {
    
    
     let items = page.replace(root, '');
     newPages.push(items);
     let subIndex = pages.indexOf(root + items);
     if (subIndex !== -1) {
    
    
         pages.splice(subIndex, 1);
     }
 }
 }

2.function(env,dd,global){$gwxc=0;var root={“tag”:“wx-page”};root.children=[] The reason for this exception is that most wxappUnpacker-master on the Internet
currently The packages are already old. It is difficult to parse newly developed small programs or upgraded small programs using the old version of wxappUnpacker-master. The main reason for the error is that when parsing the page-frame.html file, The extracted content imported into the VM.run function is not in a legal JavaScript code format, resulting in an exception. Please send a private message to the G public account to learn how to handle it (G public account: Programmer Wu) (For packages that cannot be parsed, send I, I will handle it)

3.SyntaxError: Unexpected token '}'
The reason for this exception is exactly the same as the second exception above. It is caused by the fact that the intercepted string passed into JavaScript is not a legal code. If you need help, To handle it, you can send a private message (G public account: Programmer Wu) (if the package cannot be parsed, send it to me and I will handle it)

4.Error: This application has not registered any plugins yet. Exception handling
is because the compiled applet has loaded plugins. Now the APPID you are using does not apply for this plugin, resulting in the exception. Simple method, find it directly For the corresponding plug-in, apply for it in the mini program background; or simply delete the code that loads the plug-in; (requirePlugin)

5.Bad attr data-event-paramswith message exception handling
This error is generally due to the format of the data-event-params parameter setting not conforming to the format in the wxml file, similar to the following:

<view data-event-params="{
     
     {index:index}}" wx:for-item="icon" wx:key="index">

The main thing is that the format { {index:index}} is not supported in wxml. It can be processed by changing it to { {index}}.

6. Unexpected token }exception error handling (return content is empty)
and more exception handling methods are being updated continuously.

Guess you like

Origin blog.csdn.net/Liang_ming_/article/details/132789160