From 0c1024d75a19ab8fbfd5058ba479a91a97a77fb9 Mon Sep 17 00:00:00 2001 From: newbieshan Date: Fri, 16 Feb 2024 19:12:29 +0800 Subject: [PATCH] Add support for the Linux platform --- core/chromium.py | 17 +++++++++-------- requirements.txt | 3 +-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/chromium.py b/core/chromium.py index 5903a70bc..3ea61e58c 100644 --- a/core/chromium.py +++ b/core/chromium.py @@ -12,7 +12,7 @@ __all__ = ['get_browsers_cookies'] -import win32crypt +from cryptography.hazmat.primitives.ciphers.aead import AESGCM from Crypto.Cipher import AES sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) @@ -81,18 +81,19 @@ def convert_chrome_utc(chrome_utc): unix_utc = datetime.fromtimestamp(second) return unix_utc - def decrypt_key(local_state): - """从Local State文件中提取并解密出Cookies文件的密钥""" - # Chrome 80+ 的Cookies解密方法参考自: https://stackoverflow.com/a/60423699/6415337 + """从Local State文件中提取并解密出Cookies文件的密钥,适用于Linux""" + # 读取Local State文件中的密钥 with open(local_state, 'rt', encoding='utf-8') as file: encrypted_key = json.loads(file.read())['os_crypt']['encrypted_key'] - encrypted_key = base64.b64decode(encrypted_key) # Base64 decoding - encrypted_key = encrypted_key[5:] # Remove DPAPI - decrypted_key = win32crypt.CryptUnprotectData(encrypted_key, None, None, None, 0)[1] # Decrypt key + encrypted_key = base64.b64decode(encrypted_key) + encrypted_key = encrypted_key[5:] + key = encrypted_key + nonce = b' ' * 12 + aesgcm = AESGCM(key) + decrypted_key = aesgcm.decrypt(nonce, encrypted_key, None) return decrypted_key - def get_cookies(cookies_file, decrypter, host_pattern='javdb%.com'): """从cookies_file文件中查找指定站点的所有Cookies""" # 复制Cookies文件到临时目录,避免直接操作原始的Cookies文件 diff --git a/requirements.txt b/requirements.txt index dbe0f78ba..e3b3e1738 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,5 +16,4 @@ PySocks==1.7.1 requests==2.31.0 tqdm==4.59.0 urllib3==1.25.11 -pywin32==303 -pywin32-ctypes==0.2.0 +cryptography==41.0.7