mirror of
https://github.com/Yuukiy/JavSP.git
synced 2026-10-19 07:11:31 +08:00
Add support for the Linux platform
This commit is contained in:
+9
-8
@@ -12,7 +12,7 @@ from datetime import datetime
|
||||
__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文件
|
||||
|
||||
+1
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user