The original
Recently in the study of micro channel small program development, actual combat stepped on the pit, imitation wrote a small orange bike program front.
In the process of copying, because the small program is completely black box, unlike the browser can view the code in the developer tools, get the material. So it’s purely speculative. At times like this, it feels good to be able to copy like a web project
Suddenly thought of can get the small program source file, and then try to decompile it back to the source code, and finally pour into the wechat developer tools to run as a learning reference, so they have access to the small program source code this wonderful experience.
Search a variety of small procedures to decompile tutorial, but the feeling is not quite suitable for me to learn small white, stepped on a lot of pits. Here I organized and simplified access to micro channel small program source code recorded.
Applets source file
Let’s start with a very simple question,Where is the source file of the applets stored?
- Well, it should be hosted on one of wechat’s servers.
It’s not possible to go directly to the wechat server to get it. Is there any indirect way?
- There is, simple thinking about the scene we use small program will understand, when we open a micro channel small program, there is a loading process, in fact, micro channel has downloaded it from the server to the phone, and then in
Mobile phone local
Running. - So we should be able to start from
Mobile phone local
Found applets that have been downloaded
So where are the small program files stored on the phone?
- Let’s just use Android phones as an example. After all, Poor people don’t own aN iPhone
- The directory location is given directly (curly braces are placeholders) :
/ data/data/com. Tencent. Mm/MicroMsg / {{a 32-bit hexadecimal string name folder}} / appbrand/PKG /
- In this directory, you’ll find some
xxxxxxx.wxapkg
Type of files, these files, is the wechat applet to run the required file - Wxapkg is a binary file with its own structure.
- This blog post has a detailed introduction to.wxAPkg, thank you for your interest in it
Recommended method of obtaining
- Access to the directories mentioned above requires the use of a third-party file manager, such as:
RE File manager
And Android needs to get root permission, apple mobile phone jailbreak, this is too laborious, do not recommend to get from the real phone, we can use the market with root permissionAndroid emulator
Let’s do this.
Open to
Can’t wait to get started
Prepare the material
- Node.js runtime environment
- If nodeJS is not installed, install it first
- Download it at nodejs.org/en/
- Decompiled scripts (this is the guy who ate)
- Here’s a Github offering
qwerty472123
There are also other versions of Node.js, such aspython
Version, I’m simply using node.js version as an example - Address: github.com/qwerty47212…
- Android emulator (requires built-in root permission)
- I’m using
God of Night simulator
, you can use Netease mumu or whatever, it’s all the same - Download address: www.yeshen.com/cn/download…
Detailed steps:
Get the.wxapkg file using the Android emulator
- Open the installed Android emulator and install it in the emulator
QQ
,WeChat
,RE manager
QQ
,WeChat
Search the emulator’s app store to download and install itRE manager
Download address:Pan.baidu.com/s/1PPBx08rN…- After downloading, drag it directly into the open emulator window and it will be installed automatically
- Let’s set up the emulator
- I personally think it’s better
God of Night simulator
For example, - First go inside the emulator and set the superuser permissions
- The purpose of these operations is to make
RE manager
The ROOT permission is successfully obtained
- Next, open wechat in the simulator, and run the small program you want to obtain in wechat (at this step, wechat will download the source file package of the target small program from the server to the local).
- Take, for example, the little program I mentioned for this bike
- Run the small program in the emulator wechat, then switch back to the emulator desktop and run the RE browser to go to the directory
/ data/data/com. Tencent. Mm/MicroMsg / {{a 32-bit hexadecimal string folder}} / appbrand/PKG /
- You arrive at the destination folder
- You’ll find some files with the suffix. Wxapkg in them, some of which are dependencies of the applet, and will be larger than the applet itself
- General small program files are relatively small, we choose this 700KB long press, and then click the option in the upper right corner to compress it into a ZIP package, and then send the compressed package through QQ to my computer
- Note: QQ will prompt you that the file is unavailable if you do not compress it
- Therefore, this function of QQ makes it very convenient for us to get the source files, without having to go to the computer directory to find the emulator file directory.
- Decompression. Such a few simple operations, the success of the small program to get the source file.
Unpack wxapkg using a decompiled script
- By now you should have downloaded or cloned the decomcompiled script from Github to a local directory
- Open the nodejs command window. If you have VScode, it is easier to use vscode directly. If you do not have vscode installed, open the following command line window
-
Use the CD command to go to the directory where you clone or download the decompiled script
-
Install dependencies
npm install Copy the code
-
With the dependencies installed, the final step is to decompile the.wxapkg file
-
Enter in the current directory
node wuWxapkg.js [-d] <files... > //files is the file name you want to decompileCopy the code
For example, I have a decompressed file _163200311_32.wxapkg in the root directory of drive D, so run the command
node .\wuWxapkg.js D:\_163200311_32.wxapkg Copy the code
Tip: note that the oblique bar is not typed backwards, you can type the first few characters of the file name, and then Tab will automatically complete the file name
- Press enter to run
- The decompile script will restore the.wxapkg file to the source file that wechat developer tools can run in one step. The directory address is the same as the address of the file you decompile
- See these file structures, is not very familiar! We will open the new project in wechat developer tool
- Run successfully, source code acquisition completed
If there are some problems: you can try, click the developer tools details to remove es6 to ES5 check, check the security domain name
Checked or not running? Then switch to the base library in details and try again
At this point we’ve got a source file of the applets we want, decompiled it, restored it and then decompiled the other applets, which is pretty simple in general
- Use the emulator to find the applet. Wxapkg file
- Decompile. Wxapkg files using nodejs decompile scripts
With this method, most applets will be decomcompiled normally, but there are some special cases. For details, see qwerTY472123 Github readme.md
The words in the back
From the reference to understand, as early as a jump jump small game fire, someone through small program appID and version number, structure URL directly from the server side download the source wXAPkg file. But this method was quickly blocked.
The line of the source code can be so simple to get, that the small program source code security or there are some hidden dangers. However, the small program itself is a derivative of the front-end ecology. The front-end code is often only responsible for the presentation of human-computer interaction. Even if the code is leaked, it is often not enough to cause too much impact on the system. And now the small program development framework in the packaging will often be compiled and confused, the code after the replacement of variables is difficult to read, we get the code through decompression and the browser directly view a web page running code is almost the same, it is difficult to see the specific logic.
So the methods introduced here just want to provide small program novice like me to get some copy material and record some hands-on exploration thinking
Small program as a new force in the wechat ecosystem, not only by the authorities, but also by many developers and content entrepreneurs have high hopes, in consideration of the security of the code, the method of access, not sure whether it will work.