【问题标题】:How to run a python script from a password protected zip如何从受密码保护的 zip 运行 python 脚本
【发布时间】:2015-07-13 23:45:06
【问题描述】:

我知道 python 模块/脚本可以在 zip 存档中运行,如下所述: https://www.python.org/dev/peps/pep-0441/https://blogs.gnome.org/jamesh/2012/05/21/python-zip-files/

但我的问题是:

是否可以使用密码保护此存档或 .pyz 文件并使用另一个小型 python 脚本运行它,该脚本将发送密码然后运行 ​​__main__.py

谢谢!

【问题讨论】:

    标签: python zip obfuscation password-protection pyz


    【解决方案1】:

    管理导入的代码位于zipimport 模块中。 读取存档在函数getdata 中完成 它假定通过解压缩文件未加密(参见here)。

    所以不,不幸的是,直接从命令行使用加密文件似乎是不可能的。但是你可以想象一个包装器通过使用importlibexample)来做到这一点。

    【讨论】:

      【解决方案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
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-09
        • 1970-01-01
        • 1970-01-01
        • 2012-05-22
        相关资源
        最近更新 更多