【问题标题】:How to run a python script from a password protected zip如何从受密码保护的 zip 运行 python 脚本
【发布时间】:2015-07-13 23:45:06
【问题描述】:
【问题讨论】:
标签:
python
zip
obfuscation
password-protection
pyz
【解决方案1】:
管理导入的代码位于zipimport 模块中。
读取存档在函数getdata 中完成
它假定通过解压缩文件未加密(参见here)。
所以不,不幸的是,直接从命令行使用加密文件似乎是不可能的。但是你可以想象一个包装器通过使用importlib(example)来做到这一点。
【解决方案2】:
我自己也需要这样的东西,所以我做到了。您需要在这里找到的模块:https://github.com/Dakkaron/ArchiveImporter
那么你可以像这样使用它:
python ArchiveImporter.py [zipfile] [-p=password] [args...]
适用于 Python2 和 Python3。
模块也可以从代码中使用:
# First import the ArchiveImporter module
import ArchiveImporter
# Then add the password encrypted file you want to import from using addZip(zippath, password)
ArchiveImporter.addZip("test.pyz", "password")
# Now import modules from the archive as usual
import testmod