Skip to content

Commit

Permalink
Fix #271: 修复Windows下无法读取Cookies的问题
Browse files Browse the repository at this point in the history
introduced in 0c1024d
  • Loading branch information
Yuukiy committed Apr 20, 2024
1 parent 6521d7a commit b81910a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
18 changes: 17 additions & 1 deletion core/chromium.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,19 @@ def convert_chrome_utc(chrome_utc):
unix_utc = datetime.fromtimestamp(second)
return unix_utc

def decrypt_key(local_state):
def decrypt_key_win(local_state):
"""从Local State文件中提取并解密出Cookies文件的密钥"""
# Chrome 80+ 的Cookies解密方法参考自: https://stackoverflow.com/a/60423699/6415337
import win32crypt
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
return decrypted_key


def decrypt_key_linux(local_state):
"""从Local State文件中提取并解密出Cookies文件的密钥,适用于Linux"""
# 读取Local State文件中的密钥
with open(local_state, 'rt', encoding='utf-8') as file:
Expand All @@ -94,6 +106,10 @@ def decrypt_key(local_state):
decrypted_key = aesgcm.decrypt(nonce, encrypted_key, None)
return decrypted_key


decrypt_key = decrypt_key_win if sys.platform == 'win32' else decrypt_key_linux


def get_cookies(cookies_file, decrypter, host_pattern='javdb%.com'):
"""从cookies_file文件中查找指定站点的所有Cookies"""
# 复制Cookies文件到临时目录,避免直接操作原始的Cookies文件
Expand Down
2 changes: 1 addition & 1 deletion make.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -x

python -m venv venv
source ./venv/bin/activate
pip install -r ./requirements.txt
pip install -r ./requirements-linux.txt
pip install pyinstaller

echo "JavSP version: "
Expand Down
21 changes: 21 additions & 0 deletions requirements-linux.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
altgraph==0.17
baidu-aip==2.2.18.0
certifi==2023.7.22
chardet==4.0.0
cloudscraper==1.2.71
colorama==0.4.4
future==0.18.3
idna==3.7
lxml==4.9.1
packaging==20.9
pefile==2019.4.18
Pillow==10.3.0
pretty-errors==1.2.19
pycryptodome==3.19.1
PySocks==1.7.1
requests==2.31.0
tqdm==4.59.0
urllib3==1.25.11
cryptography==42.0.4
retina-face==0.0.14
keras==2.15.0
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ PySocks==1.7.1
requests==2.31.0
tqdm==4.59.0
urllib3==1.25.11
cryptography==42.0.4
pywin32==303
pywin32-ctypes==0.2.0
retina-face==0.0.14
keras==2.15.0

0 comments on commit b81910a

Please sign in to comment.