欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Pyinstaller加密打包應(yīng)用的示例代碼

 更新時(shí)間:2020年06月11日 09:23:06   作者:深巷舊港丶  
這篇文章主要介紹了Pyinstaller加密打包應(yīng)用的示例代碼,代碼簡(jiǎn)單易懂,非常不錯(cuò),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

pyinstaller是一個(gè)非常簡(jiǎn)單的打包python的py文件的庫(kù)。用起來(lái)就幾條命令就夠了,

官方文檔:pyinstaller

代碼混淆

使用https://pyob.oxyry.com/ 進(jìn)行代碼的混淆(找不到什么可用的離線混淆庫(kù))

image.png

抓取真實(shí)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("進(jìn)行混淆中...")
 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("混淆文件已寫(xiě)入{}\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" ])
)

執(zhí)行打包

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("***********************************************************************")
# 構(gòu)建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("***********************************************************************")
# 執(zhí)行打包
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() # 構(gòu)建pyd文件
 renamePyd() # 重命名pyd文件
 pyinstaller(uuid.uuid4()[0:16], "1.ico") # 執(zhí)行打包
 clearPyd() # 清理pyd文件
 clearBuildAndSpec() # 刪除bulid和spec文件

總結(jié)

到此這篇關(guān)于Pyinstaller加密打包應(yīng)用的文章就介紹到這了,更多相關(guān)Pyinstaller加密打包內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python語(yǔ)法概念基礎(chǔ)詳解

    Python語(yǔ)法概念基礎(chǔ)詳解

    這篇文章主要為大家介紹了Python語(yǔ)法概念基礎(chǔ),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2022-01-01
  • 詳解Django框架中用戶的登錄和退出的實(shí)現(xiàn)

    詳解Django框架中用戶的登錄和退出的實(shí)現(xiàn)

    這篇文章主要介紹了詳解Django框架中用戶的登錄和退出的實(shí)現(xiàn),Django是重多Python人氣框架中最為知名的一個(gè),需要的朋友可以參考下
    2015-07-07
  • spyder 在控制臺(tái)(console)執(zhí)行python文件,debug python程序方式

    spyder 在控制臺(tái)(console)執(zhí)行python文件,debug python程序方式

    這篇文章主要介紹了spyder 在控制臺(tái)(console)執(zhí)行python文件,debug python程序方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-04-04
  • python進(jìn)階教程之文本文件的讀取和寫(xiě)入

    python進(jìn)階教程之文本文件的讀取和寫(xiě)入

    這篇文章主要介紹了python進(jìn)階教程之文本文件的讀取和寫(xiě)入,本文講解的是最基本的文件讀取和寫(xiě)入功能,需要的朋友可以參考下
    2014-08-08
  • Python?操作?Excel?之?openpyxl?模塊

    Python?操作?Excel?之?openpyxl?模塊

    這篇文章主要介紹了Python?操作?Excel?之?openpyxl?模塊,文章基于python的相關(guān)資料展開(kāi)對(duì)?openpyxl?模塊的詳細(xì)介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-05-05
  • 最新評(píng)論