马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
这是我的加密代码
generate_license.py
[RenPy] 纯文本查看 复制代码 import sys
import platform
import subprocess
import hashlib
import hmac
import os
# 获取当前文件所在的路径并将其加入 sys.path
current_dir = os.path.dirname(os.path.realpath(__file__))
sys.path.append(current_dir)
try:
import license # 尝试导入license模块
except ImportError:
print("未找到 license.py 模块,授权功能不可用。请确保该文件在正确位置。")
sys.exit(1) # 如果找不到license模块,退出程序
# 获取当前机器码
machine_code = license.get_machine_code()
if machine_code:
# 加密机器码
encrypted_code = license.encrypt_machine_code(machine_code)
# 生成签名,确保文件没有被篡改
secret_key = b"VxvK@7y9LZgPq#6b8TqK*2XmMf8dF!7q" # 请使用自己设定的秘钥
signature = license.generate_signature(encrypted_code, secret_key)
# 输出调试信息,检查生成的加密码和签名
print(f"机器码:{machine_code}")
print(f"加密后的机器码:{encrypted_code}")
print(f"生成的签名:{signature}")
# 获取AppData目录
appdata_path = os.getenv('APPDATA')
if not appdata_path:
print("无法获取 AppData 路径")
sys.exit(1)
# 在AppData目录下创建一个文件夹,存放license.key
license_file_path = os.path.join(appdata_path, "kc.key")
# 将加密后的机器码和签名保存到 license.key 文件中
with open(license_file_path, "w") as f:
f.write(f"{encrypted_code}\n{signature}")
print(f"授权文件 (license.key) 已生成在:{license_file_path}")
# 创建标记文件,表示授权状态,保持在原位置
marker_file_path = ".b站方小术汉化_付费即为盗版"
with open(marker_file_path, "w") as marker_file:
marker_file.write("请于itch或steam非国区德区支持正版游戏, 汉化为b站方小术和b站btwelve免费共同汉化, 请勿为汉化付费.") # 简单的标记内容
print(f"授权标记文件 (.b站方小术汉化_付费即为盗版) 已生成在:{marker_file_path}")
# 检查是否存在 fake.key 文件,如果没有 license.key 就生成 fake.key
fake_key_file_path = os.path.join(appdata_path, "fake.key")
if not os.path.exists(license_file_path):
# 如果没有 license.key 文件,就生成 fake.key
with open(fake_key_file_path, "w") as fake_key_file:
fake_key_file.write("This is a fake key, please purchase the official version.")
print(f"生成假授权文件 (fake.key) 已在:{fake_key_file_path}")
else:
print("license.key 文件已存在,未生成假授权文件。")
# 将license.key文件设置为隐藏文件(Windows 和 Linux/macOS 兼容)
if platform.system() == "Windows":
os.system(f'attrib +h "{license_file_path}"') # 设置为隐藏文件
else:
os.system(f'mv "{license_file_path}" .license.key') # 在 Linux/macOS 中,使用"."隐藏文件
else:
print("无法获取机器码,授权失败。")
license.py
[RenPy] 纯文本查看 复制代码 import hashlib
import sys
import platform
import subprocess
import hmac
import os
def get_machine_code():
if platform.system() == 'Windows':
# 获取 Windows 系统的机器码
command = 'wmic bios get serialnumber'
result = subprocess.check_output(command, shell=True).decode().strip()
return result
elif platform.system() == 'Linux':
# 获取 Linux 系统的机器码
command = 'dmidecode -s system-serial-number'
result = subprocess.check_output(command, shell=True).decode().strip()
return result
elif platform.system() == 'Darwin': # macOS 系统
# 获取 macOS 系统的机器码
command = 'system_profiler SPHardwareDataType | grep "Serial Number (system)"'
result = subprocess.check_output(command, shell=True).decode().strip()
return result
else:
return None # 其他系统暂不支持
# 使用哈希加密机器码
def encrypt_machine_code(machine_code):
hash_object = hashlib.sha256(machine_code.encode())
encrypted_code = hash_object.hexdigest()
return encrypted_code
# 生成签名,用于防止篡改
def generate_signature(data, secret_key):
return hmac.new(secret_key, data.encode(), hashlib.sha256).hexdigest()
# 检查授权,确保机器码匹配
def check_license():
# 检查标记文件是否存在
if not os.path.exists(".b站方小术汉化_付费即为盗版"):
print("Key file missing, can not launch the game!")
sys.exit() # 强制退出游戏
# 检查 fake.key 文件,若存在,强制退出游戏
appdata_path = os.getenv('APPDATA')
if appdata_path:
fake_key_file_path = os.path.join(appdata_path, "fake.key")
if os.path.exists(fake_key_file_path):
print("The system has detected that the game is unauthorized. Please refrain from launching the game.")
sys.exit() # 强制退出游戏
# 获取当前机器码
current_machine_code = get_machine_code()
if not current_machine_code:
print("无法获取机器码")
return False
# 获取AppData目录
appdata_path = os.getenv('APPDATA')
if not appdata_path:
print("无法获取 AppData 路径")
return False
# 读取存储的加密机器码和签名
license_file_path = os.path.join(appdata_path, "kc.key")
try:
with open(license_file_path, "r") as f:
saved_encrypted_code = f.readline().strip() # 读取加密机器码
saved_signature = f.readline().strip() # 读取存储的签名
except FileNotFoundError:
print("未找到授权文件")
return False
# 加密当前机器码并比对
encrypted_current_code = encrypt_machine_code(current_machine_code)
# 检查加密机器码是否匹配
if encrypted_current_code != saved_encrypted_code:
print("盗版可耻, 请支持正版免费汉化")
sys.exit() # 强制退出游戏
# 验证签名,确保授权文件未被篡改
secret_key = b"VxvK@7y9LZgPq#6b8TqK*2XmMf8dF!7q" # 必须与生成签名时使用的秘钥一致
generated_signature = generate_signature(saved_encrypted_code, secret_key)
if generated_signature != saved_signature:
print("授权文件被篡改,无法启动游戏")
sys.exit() # 强制退出游戏
return True
script1.rpy
[RenPy] 纯文本查看 复制代码 init python:
import os
import license
# 检查是否存在标记文件 (.b站方小术汉化_付费即为盗版),但没有 license.key 文件时,生成 fake.key
appdata_path = os.getenv('APPDATA')
if appdata_path:
# 获取标记文件和授权文件路径
marker_file_path = ".b站方小术汉化_付费即为盗版"
license_file_path = os.path.join(appdata_path, "kc.key")
# 如果标记文件存在但没有 license.key 文件,则生成 fake.key 文件
if os.path.exists(marker_file_path) and not os.path.exists(license_file_path):
fake_key_file_path = os.path.join(appdata_path, "fake.key")
if not os.path.exists(fake_key_file_path):
with open(fake_key_file_path, "w") as fake_key_file:
fake_key_file.write("This is a fake key, please purchase the official version.")
print(f"生成假授权文件 fake.key:{fake_key_file_path}")
# 如果授权文件不存在且机器码发生变化,生成新的授权文件
if not os.path.exists(".b站方小术汉化_付费即为盗版"):
import generate_license # 导入生成授权的脚本
generate_license # 执行生成授权
# 检查授权,确保机器码匹配并没有 fake.key
if not license.check_license(): # 检查授权
renpy.quit() # 如果授权失败,则退出游戏
报错代码是这样的
报错代码
我其实完全不懂python的编程,只是略懂如何制作一个普通的renpy小游戏,这些代码都是我用gpt试错试出来的,希望大佬们能给一个解决的思路
|