0

我想编译一个加密的 exe(以防止“随意”反编译)。

当我不使用加密时,我可以使用规范文件在一个 exe 文件中使用 Pyinstaller v2.1 进行编译。

但是,当我将以下行添加到 .spec 文件以引入加密(pycryptodome)时:

block_cipher = pyi_crypto.PyiBlockCipher(key='1234567812345678')

我最终得到这个错误: File "c:\users\username\test-env\lib\site-packages\Crypto\Util\_raw_api.py", line 151, in c_uint8_ptr raise TypeError("Object type %s cannot be passed to C code" % type(data)) TypeError: Object type <class 'str'> cannot be passed to C code

导致错误的日志是: 90328 INFO: Appending 'datas' from .spec 90371 INFO: checking PYZ 90372 INFO: Building PYZ because out00-PYZ.toc is non existent 90373 INFO: Building PYZ (ZlibArchive) C:\Users\choom.000\Documents\masstools_clean\obf\build\graphms\out00-PYZ.pyz Traceback (most recent call last): File "C:\Users\choom.000\test-env\Scripts\pyinstaller-script.py", line 11, in <module> load_entry_point('PyInstaller==3.3.1', 'console_scripts', 'pyinstaller')() File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\__main__.py", line 94, in run run_build(pyi_config, spec_file, **vars(args)) File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\__main__.py", line 46, in run_build PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs) File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\building\build_main.py", line 791, in main build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build')) File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\building\build_main.py", line 737, in build exec(text, spec_namespace) File "<string>", line 20, in <module> File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\building\api.py", line 98, in __init__ self.__postinit__() File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\building\datastruct.py", line 161, in __postinit__ self.assemble() File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\building\api.py", line 133, in assemble pyz = ZlibArchiveWriter(self.name, toc, code_dict=self.code_dict, cipher=self.cipher) File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\archive\writers.py", line 184, in __init__ super(ZlibArchiveWriter, self).__init__(archive_path, logical_toc) File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\archive\writers.py", line 59, in __init__ self._add_from_table_of_contents(logical_toc) File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\archive\writers.py", line 84, in _add_from_table_of_contents self.add(toc_entry) # The guts of the archive. File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\archive\writers.py", line 213, in add obj = self.cipher.encrypt(obj) File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\archive\pyz_crypto.py", line 58, in encrypt return iv + self.__create_cipher(iv).encrypt(data) File "c:\users\choom.000\test-env\lib\site-packages\PyInstaller\archive\pyz_crypto.py", line 64, in __create_cipher return self._aesmod.new(self.key, self._aesmod.MODE_CFB, iv) File "c:\users\choom.000\test-env\lib\site-packages\Crypto\Cipher\AES.py", line 200, in new return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs) File "c:\users\choom.000\test-env\lib\site-packages\Crypto\Cipher\__init__.py", line 55, in _create_cipher return modes[mode](factory, **kwargs) File "c:\users\choom.000\test-env\lib\site-packages\Crypto\Cipher\_mode_cfb.py", line 230, in _create_cfb_cipher cipher_state = factory._create_base_cipher(kwargs) File "c:\users\choom.000\test-env\lib\site-packages\Crypto\Cipher\AES.py", line 100, in _create_base_cipher result = start_operation(c_uint8_ptr(key), File "c:\users\choom.000\test-env\lib\site-packages\Crypto\Util\_raw_api.py", line 151, in c_uint8_ptr raise TypeError("Object type %s cannot be passed to C code" % type(data)) TypeError: Object type <class 'str'> cannot be passed to C code

似乎这是“str”类的“key”的问题。我试图在 .spec 文件中更改 key = 'a123456712345678' 或 u'1234567812345678' 但仍然有问题。

4

0 回答 0