這篇文章主要講解了Pyinstaller如何加密打包應用,內容清晰明了,對此有興趣的小伙伴可以學習一下,相信大家閱讀完之后會有幫助。
pyinstaller是一個非常簡單的打包python的py文件的庫。用起來就幾條命令就夠了,
官方文檔:pyinstaller

抓取真實api后
def obfuscation(py_file, save_path):
print("讀取文件:", py_file)
with open(py_file, "r", encoding="utf-8") as f:
py_content = f.read()
print("進行混淆中...")
url = "https://pyob.oxyry.com/obfuscate"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36",
"Referer": "http://pyob.oxyry.com/",
"content-type": "application/json",
"cookie": "_ga=GA1.2.1306886713.1588752647; _gid=GA1.2.46944674.1588899118"
}
data = json.dumps({
"append_source": "false",
"preserve": "",
"remove_docstrings": "true",
"rename_default_parameters": "false",
"rename_nondefault_parameters": "true",
"source": py_content
})
result = json.loads(requests.post(url, data=data, headers=headers).text)["dest"]
result = "# cython: language_level=3\n" + result
print("混淆成功...")
with open(save_path, "w", encoding="utf-8") as f:
f.write(result)
print("混淆文件已寫入{}\n".format(save_path))
if __name__ == '__main__':
obfuscation("my.py", "../混淆/my.py")
obfuscation("approach.py", "../混淆/approach.py")編譯pyd
build_pyd.py
from distutils.core import setup from Cython.Build import cythonize setup( name='any words.....', ext_modules=cythonize(["my.py","approach.py" ]) )
執行打包
import json
import os
# 清理舊pyd文件
import uuid
import requests
def clearPyd():
for file in os.listdir():
if ".pyd" in file:
print("刪除.pyd:", file)
os.remove(file)
print("***********************************************************************")
# 構建pyd文件
def buildPyd():
os.system("python build_pyd.py build_ext --inplace")
# 重命名pyd文件
def renamePyd():
print("***********************************************************************")
for file in os.listdir():
if ".pyd" in file:
print("重新命名pyd:", file)
os.rename(file, file[:file.find(".")] + ".pyd")
for file in os.listdir():
if ".c" in file:
print("刪除.c文件:", file)
os.remove(file)
print("***********************************************************************")
# 執行打包
def pyinstaller(key, ico):
os.system("pyinstaller -F --key {} -i {} main.py".format(key, ico))
# 刪除bulid和spec文件
def clearBuildAndSpec():
import shutil
shutil.rmtree('build')
print("刪除bulid文件夾")
os.remove("main.spec")
print("刪除spec文件")
if __name__ == '__main__':
clearPyd() # 清理舊pyd文件
buildPyd() # 構建pyd文件
renamePyd() # 重命名pyd文件
pyinstaller(uuid.uuid4()[0:16], "1.ico") # 執行打包
clearPyd() # 清理pyd文件
clearBuildAndSpec() # 刪除bulid和spec文件看完上述內容,是不是對Pyinstaller如何加密打包應用有進一步的了解,如果還想學習更多內容,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。