python程序打包加密防反编译【教程及bug汇总】----多的是 你不知道的事

采用2个手段,小模块生成pyd,主程序打包时加密

一、python程序打包成pyd

step1:创建新文件test.py

#coding:utf-8
def speak():
    print("hello world")

step2:再创建文件setup.py

from distutils.core import setup
from Cython.Build import cythonize

setup(name = 'HW',ext_modules = cythonize("test.py"))

step3:执行指令运行setup文件

python setup.py build_ext --inplace

此时生成文件

build

test.c

test.XXXX-XXX.pyd

step4:将test.XXXX-XXX.pyd重命名为test.pyd(注,一定要与python文件同名)

step5:测试

import test
if __name__=="__main__":
    test.speak()

输出:

hello world

2 pyinstaller打包时  

pyinstaller -key 密码 -Fmain.py

 

错误1:ModuleNotFoundError: No module named 'Crypto.Cipher'

解决:

pip uninstall crypto pycryptodome

pip install pycryptodome

错误2:AttributeError: module 'Crypto' has no attribute '__version__'

解决:找到此处,改源码

 File "...\lib\site-packages\PyInstaller\building\makespec.py", line 333, in main
    is_version_acceptable = LooseVersion(Crypto.__version__) >= LooseVersion('2.4')

is_version_acceptable = True

错误3:TypeError: Object type cannot be passed to C code

解决:找到此处,改源码

  File "........lib\site-packages\PyInstaller\archive\pyz_crypto.py", line 65, in __create_cipher
    return self._aesmod.new(self.key, self._aesmod.MODE_CFB, iv)

... ...
TypeError: Object type cannot be passed to C code

 def __create_cipher(self, iv):
        # The 'BlockAlgo' class is stateful, this factory method is used to
        # re-initialize the block cipher class with each call to encrypt() and
        # decrypt().
        print("xws---",type(self.key),self.key)
        return self._aesmod.new(self.key.encode("utf-8"), self._aesmod.MODE_CFB, iv)

输出

xws--- 000byfwsxnsvrdxs

说明真的是字符串,将self.key按utf-8编码即可解决问题

你可能感兴趣的:(pyqt)