"""Validate NSIS CRC, complete solid-deflate stream, and every application file.""" from pathlib import Path import hashlib,json,struct,zlib folder=Path(__file__).parent root=Path('C:/wechat_rpa') installer=root/'dist/installer/甄AI客服-安装包-v1.4.29.exe' application=root/'dist/ZhenAI-WeCom-Assistant-v1.4.29' size=installer.stat().st_size with installer.open('rb') as stream: prefix=stream.read(200000) start=prefix.find(b'NullsoftInst')-8 assert start>=512 and start%512==0 flags,magic,a,b,c,header_size,following=struct.unpack('<7I',prefix[start:start+28]) assert magic==0xdeadbeef and following==size-start stream.seek(size-4); expected_crc=struct.unpack('3000 files=[p for p in application.rglob('*') if p.is_file()] missing=[] for file in files: with file.open('rb') as stream: digest=hashlib.file_digest(stream,'sha256').hexdigest() if digest not in hashes: missing.append(str(file.relative_to(application))) assert not missing, f'Application files missing or changed: {missing}' assert len(files)>4000 result={'version':'1.4.29','installerCrc32':f'{crc:08x}','crcPassed':True, 'completeDeflateStream':True,'completeLengthPrefixedBlocks':True, 'blocks':blocks,'applicationFilesMatchedBySha256':len(files),'missingFiles':missing, 'installerSha256':hashlib.sha256(installer.read_bytes()).hexdigest(), 'validationMethod':'NSIS CRC, complete raw-deflate blocks, and all application payload SHA256 hashes', 'installed':False,'realMessagesSent':0} (folder/'nsis-payload-integrity.json').write_text(json.dumps(result,ensure_ascii=False,indent=2),encoding='utf-8') print(json.dumps(result,ensure_ascii=False))