-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
93 lines (71 loc) · 2.55 KB
/
utils.py
File metadata and controls
93 lines (71 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import winreg
import base64
from Crypto.Cipher import DES
from Crypto.Util.Padding import pad, unpad
def secret_key_get(key):
h = get_hash_str(key)
filled = str_fill(h, "X", 8)
return filled[:8]
def secret_encrypt(source_string: str, key: str = "") -> str:
"""
还原 VB.NET 的 SecretEncrypt 函数
"""
final_key_str = secret_key_get(key)
key_bytes = final_key_str.encode('utf-8')
iv_bytes = "95168702".encode('utf-8')
cipher = DES.new(key_bytes, DES.MODE_CBC, iv_bytes)
source_bytes = source_string.encode('utf-8')
padded_source = pad(source_bytes, DES.block_size, style='pkcs7')
encrypted_bytes = cipher.encrypt(padded_source)
result = base64.b64encode(encrypted_bytes).decode('utf-8')
return result
def secret_decrypt(source_string: str, key: str = "") -> str:
"""
还原 VB.NET 的 SecretDecrypt 函数
"""
final_key_str = secret_key_get(key)
key_bytes = final_key_str.encode('utf-8')
iv_bytes = "95168702".encode('utf-8')
cipher = DES.new(key_bytes, DES.MODE_CBC, iv_bytes)
encrypted_bytes = base64.b64decode(source_string)
padded_source = cipher.decrypt(encrypted_bytes)
source_bytes = unpad(padded_source, DES.block_size)
result = source_bytes.decode('utf-8')
return result
def read_reg(root, path, name, default=""):
try:
with winreg.OpenKey(root, path) as k:
val, _ = winreg.QueryValueEx(k, name)
return str(val)
except:
return default
def write_reg(root, path, name, value):
with winreg.CreateKey(root, path) as k:
winreg.SetValueEx(k, name, 0, winreg.REG_SZ, value)
def get_unique_mark(unique_addr, custom_key: str):
return secret_encrypt(f"{unique_addr}|Snapshot 2.10.6|{custom_key}", "Your Best Nightmare")
def get_hash_str(_s: str) -> str:
"""
龙猫氏哈希算法还原
Args:
_s (str): 要哈希的字符串
Returns:
str: 哈希结果(字符串)
"""
_h = 5381
for char in _s:
# 1. 模拟 64位截断 (保持无符号状态进行位运算)
_h = ((_h << 5) ^ _h ^ ord(char)) & 0xFFFFFFFFFFFFFFFF
# 2. XOR 操作
result = _h ^ 0xA98F501BC684032F
result = result & 0xFFFFFFFFFFFFFFFF # 再次确保是 64 位范围内
return str(result)
def str_fill(s, code, length):
if len(s) <= length:
padded = s.ljust(length, code[0])
part = padded[len(s):]
return part + s
else:
return s[:length]
def b64_to_int(s: str) -> int:
return int.from_bytes(base64.b64decode(s), byteorder="big")