Skip to content

Commit

Permalink
Add support for the Linux platform
Browse files Browse the repository at this point in the history
  • Loading branch information
newbieshan authored and Yuukiy committed Feb 16, 2024
1 parent 37c2554 commit 0c1024d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
17 changes: 9 additions & 8 deletions core/chromium.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__), '..')))
Expand Down Expand Up @@ -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文件
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0c1024d

Please sign in to comment.