Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize more opening of Wechat on PC by java

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to achieve more java on the PC side of Wechat". In the daily operation, I believe many people have doubts about how to achieve more open on the PC side of Wechat by java. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubt of "how to achieve more PC side of Wechat with java". Next, please follow the editor to study!

You can also open more Wechat computers.

Yesterday, I happened to learn from my good friend Kobayashi (Wechat official account: Kobayashi Coding) that his computer could have two WeChat accounts at the same time.

Open more Wechat on mobile phones. Mobile systems like Huawei and Xiaomi support it, but how to start two Wechat on computers running Windows makes me curious.

Kobayashi told me he did this and wrote a batch:

Start D:\ WeChat\ WeChat.exe

Start D:\ WeChat\ WeChat.exe

Then double-click the batch file directly to start two Wechat processes.

I tried it, and sure enough!

Then I added another line, and I was able to start three more:

Then I searched the Internet, and it turned out that this trick had been used a long time ago, and it seemed that I was on Mars. But why on earth can we drive more in this way? I really want to know this mystery.

TIPS: if you are not interested in the technical analysis section, you can skip it and go straight to the truth section.

Singleton Model of Wechat

Under normal circumstances, double-click the Wechat icon manually to start, and the process started later will check the global singleton mode. If it is found that the Wechat process already exists, it will directly activate the Wechat window of the corresponding process, navigate to the front of the desktop, and then exit.

But why can we start the two in the above way? Let's find out.

First of all, analyze how the single instance of Wechat described above is implemented.

Friends who have worked in Windows platform application development may be familiar with this. Generally, a mutex with a global unique name is created after the process is started. If the mutex is created successfully, it starts normally, and if the creation fails, it is judged whether the mutex already exists. If it already exists, it means that the corresponding program has been started before.

With this guess in mind, use the tool procexp to look at all the kernel objects opened by the Wechat process and find the mutex:

Sure enough, there is a mutex named _ WeChat_App_Instance_Identity_Mutex_Name, which, as you can guess, has something to do with Wechat's singleton pattern.

Next, start the artifact APIMonitor, which can help you monitor the API calls of the specified process, and check the two Windows API functions CreateMutex and GetLastError. When Wechat is already running, use this tool to start another Wechat process and take a look at the function calls:

As you can see, after creating the mutex with this name, the GetLastError function is then called and 0x000000b7 is returned. Check the manual, which means:

Indicates that it already exists.

Take a look at the stack of CreateMutex calls to see where the code is creating the global mutex:

As you can see from the stack, the call comes from WeChatWin.dll, a dynamic library in the Wechat directory. The specific location is the previous instruction at the offset 0x8e271b.

The next step is to present the artifact in the artifact, the famous disassembly software IDA, which supports x86, x64, ARM, MIPS and other processor architectures and program analysis on Windows, Linux, Android, MacOS, JVM and other system platforms.

Open the WeChatWin.dll file with IDA and navigate to the offset 0x8e271b:

As shown in the figure above, the action of creating a mutex occurs in the function sub_108e26d0.

The upper layer is the sub_108e2660 function that calls it:

The figure above reflects the judgment logic after the mutex is created:

If the return value of sub_108e26d0 is 0, there is no error, and the current function also returns 0 directly. If the return value of sub_108e26d0 is not 0, indicating that an error has occurred, determine whether the WeChatMainWndForPC and WeChatLoginWndForPC windows exist in turn, and if so, use the BringWindowToTop function to pop them up at the top. These two windows represent the main interface window and login interface window of Wechat, respectively. If an instance of Wechat already exists, it is bound to be in one of these two states.

The problem lies in the above judgment, the assembly code looks a little hot, let's F5 to restore the C code (restore effect can only be seen, as long as you can see the logic clearly):

As explained in the note in the image above, the return value of the function sub_108e2660 determines whether to start the Wechat instance process or exit directly.

there is only one truth

The truth will be revealed at this point. Let's sum it up.

There are two conditions for Wechat to judge whether to start or not:

If the mutex object can be created successfully, start Wechat if you cannot create the mutex: if the corresponding window is found, set it to the top, and exit yourself. If it is not found, start Wechat.

Use pseudocode to express:

If (CreateMutex ()) = = SUCCESS) {

Start Wechat

} else {

If (FindWindow ()) = = SUCCESS) {

Put an existing window on top

} else {

Start Wechat

}

}

For multiple processes started directly with scripts, although the kernel level of the operating system ensures the uniqueness of mutexes, due to the small difference in startup speed, the corresponding windows have not yet been created, resulting in entering the second startup logic above. As a result, multiple instances can be started.

Small discovery

In the process of analysis, an interesting thing was found:

In WeChatWin.dll, the function that creates the mutex above is called StartWaChat, which is also exported by the DLL as an export function:

At this point, on the "java how to achieve Wechat PC more open" study is over, I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report