@@ -52,69 +52,6 @@ def get_github_proxy_urls():
5252sys .stdout .reconfigure (encoding = "utf-8" )
5353subprocess .run ("chcp 65001" , shell = True )
5454
55- # x64 or x86 signatures and replacements
56- SIG_ARM64 = bytes ([0x98 , 0x01 , 0x00 , 0x35 , 0xB2 , 0xED , 0xFF , 0x97 ])
57- FIX_ARM64 = bytes ([0x98 , 0x01 , 0x00 , 0x35 , 0x20 , 0x00 , 0x80 , 0xD2 ])
58- SIG_X64 = bytes ([0x48 , 0x89 , 0xCE , 0x48 , 0x8B , 0x11 , 0x4C , 0x8B , 0x41 , 0x08 , 0x49 , 0x29 , 0xD0 , 0x48 , 0x8B , 0x49 , 0x18 , 0xE8 ])
59- FIX_X64 = bytes ([0x48 , 0x89 , 0xCE , 0x48 , 0x8B , 0x11 , 0x4C , 0x8B , 0x41 , 0x08 , 0x49 , 0x29 , 0xD0 , 0x48 , 0x8B , 0x49 , 0x18 , 0xB8 , 0x01 , 0x00 , 0x00 , 0x00 ])
60- SIG_X86 = bytes ([0x89 , 0xCE , 0x8B , 0x01 , 0x8B , 0x49 , 0x04 , 0x29 , 0xC1 , 0x51 , 0x50 , 0xFF , 0x76 , 0x0C , 0xE8 ])
61- FIX_X86 = bytes ([0x89 , 0xCE , 0x8B , 0x01 , 0x8B , 0x49 , 0x04 , 0x29 , 0xC1 , 0x51 , 0x50 , 0xFF , 0x76 , 0x0C , 0xB8 , 0x01 , 0x00 , 0x00 , 0x00 ])
62-
63-
64- def scan_and_replace (buffer , pattern , replacement ):
65- index = 0
66- while index < len (buffer ):
67- index = buffer .find (pattern , index )
68- if index == - 1 :
69- break
70- buffer [index : index + len (replacement )] = replacement
71- print (f"Found at 0x{ index :08X} " )
72- index += len (replacement )
73-
74-
75- def get_pe_arch (pe_file ):
76- e_lfanew_offset = 0x3C
77- pe_header_offset = struct .unpack ("<I" , pe_file [e_lfanew_offset :e_lfanew_offset + 4 ])[0 ]
78- machine_offset = pe_header_offset + 4
79- machine = struct .unpack ("<H" , pe_file [machine_offset :machine_offset + 2 ])[0 ]
80- return machine
81-
82-
83- def patch_pe_file (file_path ):
84- # 存在 64 位系统安装 32 位 QQ 的可能,需考虑
85- try :
86- # 创建备份文件的路径
87- backup_path = file_path + ".bak"
88-
89- # 如果备份文件已存在,覆盖它
90- if os .path .exists (backup_path ):
91- os .remove (backup_path )
92- # print(f"已删除旧的备份文件: {backup_path}")
93-
94- # 创建新的备份
95- os .rename (file_path , backup_path )
96- print (f"已将原版备份在: { backup_path } " )
97-
98- with open (backup_path , "rb" ) as file :
99- pe_file = bytearray (file .read ())
100-
101- machine = get_pe_arch (pe_file )
102- if machine == 0x8664 : # x64
103- scan_and_replace (pe_file , SIG_X64 , FIX_X64 )
104- elif machine == 0x014C : # x86
105- scan_and_replace (pe_file , SIG_X86 , FIX_X86 )
106- elif machine == 0xAA64 : # ARM64
107- scan_and_replace (pe_file , SIG_ARM64 , FIX_ARM64 )
108-
109- with open (file_path , "wb" ) as output_file :
110- output_file .write (pe_file )
111-
112- print ("修补成功!" )
113- except Exception as e :
114- print (f"发生错误: { e } " )
115- input ("按 回车键 退出。" )
116-
117-
11855def get_qq_exe_path ():
11956 root = tk .Tk ()
12057 root .withdraw ()
@@ -138,50 +75,6 @@ def read_registry_key(hive, subkey, value_name):
13875 return None
13976
14077
141- def compare_versions (version1 , version2 ):
142- v1_parts = [int (part ) for part in version1 .split ("." )]
143- v2_parts = [int (part ) for part in version2 .split ("." )]
144-
145- # 对比版本号的每个部分
146- for i in range (max (len (v1_parts ), len (v2_parts ))):
147- v1_part = v1_parts [i ] if i < len (v1_parts ) else 0
148- v2_part = v2_parts [i ] if i < len (v2_parts ) else 0
149-
150- if v1_part < v2_part :
151- return False
152- elif v1_part > v2_part :
153- return True
154-
155- return False # 两个版本号相等
156-
157-
158- def check_for_updates ():
159- try :
160- # 获取最新版本号
161- latest_url = "https://github.com/Mzdyl/LiteLoaderQQNT_Install/releases/latest"
162- response = requests .get (latest_url , timeout = 2 )
163- latest_release = response .url .split ('/' )[- 1 ] # 获取重定向后的 URL 中的版本号
164-
165- if compare_versions (latest_release , current_version ):
166- print (f"发现新版本 { latest_release } !" )
167- # 提示用户是否下载更新
168- user_input = countdown_input ("是否要下载更新?输入 'y' 确认,5 秒内未输入则跳过更新。" ,"n" )
169-
170- if user_input == 'y' :
171- download_url = f"https://github.com/Mzdyl/LiteLoaderQQNT_Install/releases/download/{ latest_release } /install_windows.exe"
172- download_file (download_url , f"install_windows-{ latest_release } .exe" )
173- print ("版本已更新,请重新运行最新脚本。" )
174- input ("按 回车键 退出" )
175- sys .exit (0 )
176- else :
177- print ("跳过更新,继续安装。" )
178- else :
179- print ("当前已是最新版本,开始安装。" )
180- except Exception as e :
181- print (f"检查更新阶段发生错误: { e } " )
182- print ("将跳过检查更新,继续安装" )
183-
184-
18578def get_qq_path ():
18679 try :
18780 hive , subkey , value = winreg .HKEY_LOCAL_MACHINE , r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\QQ" , "UninstallString"
@@ -361,23 +254,6 @@ def cleanup_old_bak(qq_exe_path):
361254 except Exception as e :
362255 print (f"移除旧版备份时发生错误: { e } " )
363256
364-
365- def patch_index_js (file_path ):
366- try :
367- app_launcher_path = os .path .join (file_path , "resources" , "app" , "app_launcher" )
368- os .chdir (app_launcher_path )
369- print ("开始修补 index.js…" )
370- index_path = os .path .join (app_launcher_path , "index.js" )
371- # 备份原文件
372- print ("已将旧版文件备份为 index.js.bak " )
373- bak_index_path = index_path + ".bak"
374- shutil .copyfile (index_path , bak_index_path )
375- with open (index_path , "w" , encoding = "utf-8" ) as f :
376- f .write (f"require('{ os .path .join (file_path , 'resources' , 'app' , 'LiteLoaderQQNT' ).replace (os .sep , '/' )} ');\n " )
377- f .write ("require('./launcher.node').load('external_index', module);" )
378- except Exception as e :
379- print (f"修补 index.js 时发生错误: { e } " )
380-
381257
382258def create_launcher_js (file_path , version_path , launcher_name = "ml_install.js" ):
383259 try :
@@ -771,40 +647,29 @@ def main():
771647 qq_exe_path = get_qq_path ()
772648 file_path = os .path .dirname (qq_exe_path )
773649
774- skip_update_file = os .path .join (file_path , "SKIP_UPDATE" )
775- if os .path .exists (skip_update_file ):
776- print ("检测到 SKIP_UPDATE 文件,跳过更新" )
777- else :
778- check_for_updates ()
779-
780650 check_and_kill_qq ("QQ.exe" )
781651 if not github_actions :
782652 cleanup_old_bak (qq_exe_path )
783653 setup_environment_and_move_files (qq_exe_path )
784654 else :
785655 cleanup_old_bak (qq_exe_path )
786656
787- qq_file_size_bytes = os .path .getsize (qq_exe_path )
788- qq_file_size_mb = qq_file_size_bytes / (1024 * 1024 )
789- if qq_file_size_mb < 10 :
790- print ("QQ大小小于 10MB,判断为新版" )
791- latest_version = get_latest_version (file_path )
792- version_path = os .path .join (file_path , "versions" , latest_version )
793- qq_dll_path = os .path .join (version_path , 'QQNT.dll' )
794- create_launcher_js (file_path , version_path )
795- patch_package_json (version_path )
796- else :
797- print ("QQ大小大于 10MB,判断为旧版" )
798- patch_index_js (file_path )
657+
658+ latest_version = get_latest_version (file_path )
659+ version_path = os .path .join (file_path , "versions" , latest_version )
660+ create_launcher_js (file_path , version_path )
661+ patch_package_json (version_path )
662+
799663
800664 if os .path .exists (os .path .join (file_path , "dbghelp.dll" )):
801665 print ("检测到dbghelp.dll,推测你已修补QQ,跳过修补" )
802666 else :
803- if qq_file_size_mb < 10 :
804- patch_pe_file (qq_dll_path )
805- else :
806- patch_pe_file (qq_exe_path )
807-
667+ print ("请进频道内下载 dbghelp.dll 并放到" )
668+ print ("f{qq_exe_path}\n 内后再再次运行本程序" )
669+ print ("频道 http://t.me/LiteLoaderQQNT_Channel " )
670+ input ("按 回车键 退出。" )
671+ exit ()
672+
808673 install_liteloader (file_path )
809674 patch (file_path )
810675
0 commit comments