MCPcopy Create free account
hub / github.com/JaveleyQAQ/WeChatOpenDevTools-Python / WechatUtils

Class WechatUtils

utils/wechatutils.py:5–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3from utils.colors import Color
4
5class WechatUtils:
6 def __init__(self):
7 self.configs_path = self.get_configs_path()
8 self.version_list = self.get_version_list()
9
10 # self.pid , self.version = self.get_wechat_pid_and_version()
11 # if self.pid is None and self.version is None:
12 # self.print_process_not_found_message()
13
14 def get_configs_path(self):
15 current_path = os.path.abspath(__file__)
16 relative_path = '../configs/'
17 return os.path.join(os.path.dirname(current_path), relative_path)
18
19 def get_version_list(self):
20 configs_path = self.configs_path
21 version_list = os.listdir(configs_path)
22 versions_list = [int(file.split('_')[1]) for file in version_list if file.startswith('address_')]
23 return versions_list
24
25 def is_wechatEx_process(self, cmdline):
26 process_name = "WeChatAppEx"
27 return cmdline and process_name in cmdline[0] and "--type=" not in ' '.join(cmdline)
28 def get_wechat_pids_and_versions(self):
29 processes = (proc.info for proc in psutil.process_iter(['pid', 'cmdline']))
30 wechatEx_processes = (p for p in processes if self.is_wechatEx_process(p['cmdline']))
31 wechat_instances = []
32 for process in wechatEx_processes:
33 pid = process['pid']
34 version = self.extract_version_number(process['cmdline'])
35 if version in self.version_list:
36 wechat_instances.append((pid, version))
37 return wechat_instances
38
39 def get_wechat_pid_and_version(self):
40 wechat_instances = self.get_wechat_pids_and_versions()
41 return wechat_instances[0] if wechat_instances else (None, None)
42
43 def get_wechat_pids_and_versions_mac(self):
44 try:
45 pid_command = "ps aux | grep 'WeChatAppEx' | grep -v 'grep' | grep ' --client_version' | grep '-user-agent=' | awk '{print $2}'"
46 version_command = "ps aux | grep 'WeChatAppEx' | grep -v 'grep' | grep ' --client_version' | grep '-user-agent=' | grep -oE 'MacWechat/([0-9]+\.)+[0-9]+\(0x\d+\)' | grep -oE '(0x\d+)' | sed 's/0x//g'"
47 pids = subprocess.run(pid_command, shell=True, check=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.split()
48 versions = subprocess.run(version_command, shell=True, check=True, text=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).stdout.split()
49 return list(zip(map(int, pids), versions))
50 except subprocess.CalledProcessError as e:
51 print(Color.RED + f"Error getting MacOS WeChat instances: {e.stderr}" + Color.END)
52 return []
53
54 def print_process_not_found_message(self):
55 print(Color.RED + "[-] 未找到匹配版本的微信进程或微信未运行" + Color.END)
56
57 def find_installation_path(self, program_name):
58 try:
59 import winreg
60 reg_path = r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
61 reg_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, reg_path)
62

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected