From fbf87d620cfb7ad01447074c7d966d22c4638709 Mon Sep 17 00:00:00 2001 From: super322 Date: Tue, 14 Jan 2025 17:05:44 +0800 Subject: [PATCH] 0.0.1 --- main.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index b85d9c3..cf3b9b6 100644 --- a/main.py +++ b/main.py @@ -14,15 +14,19 @@ class NavicatPassword: cipher = AES.new(self.aes_key, AES.MODE_CBC, self.aes_iv) decrypted = cipher.decrypt(data) # 处理填充字符和不可打印字符 - # 仅去除常见的填充字符 + # 去除填充字符和控制字符 decrypted = decrypted.rstrip(b'\x00\x03\x04\x05') - # 直接尝试解码,不进行任何字符过滤 + # 过滤掉控制字符(0x00-0x1F),保留可打印字符 + decrypted = bytes(b for b in decrypted if b >= 32 or b == 9 or b == 10 or b == 13) + + # 尝试多种编码方式 encodings = ['utf-8', 'latin1', 'cp1252', 'gbk', 'big5'] for encoding in encodings: try: - # 直接返回解码结果,保留所有字符 - return decrypted.decode(encoding) + decoded = decrypted.decode(encoding) + # 保留所有可打印字符 + return decoded except UnicodeDecodeError: continue # 最后尝试,替换无法解码的字符