推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
wa8n
V2EX  ›  Python

有办法提取 python3.11 pyc 文件源码吗?

  •  
  •   wa8n · Feb 26, 2023 · 3801 views
    This topic created in 1316 days ago, the information mentioned may be changed or developed.

    手头有一个 Python3.11 编写打包的 exe 文件,通过 pyinstxtractor/python-exe-unpacker 提取到了关键的入口app.pyc文件。我做了以下尝试:

    • 尝试使用 Uncompyle6 提取,提示Unknown magic number 3495 in app.pyc,查阅资料说 Uncompyle6 仅支持到 3.8
    • 接着看到了pycdc项目,能提取出 import 部分的代码,再往后就报 Unsupported opcode 。尝试通过修改源代码跳过报错的 opcode ,接着又会出来其他不支持的 opcode

    想请问下各位大佬,还有其他招式吗?

    4 replies  •  2023-02-26 20:44:34 +08:00
    Tanix2
        1
    Tanix2  
       Feb 26, 2023   ❤️ 1
    f1ush
        2
    f1ush  
       Feb 26, 2023
    python3.11 有点难了,现成的工具估计都还没有更新到支持 3.11 的,3.11 好像做了很多优化,更新得 opcode 还蛮多的;可以考虑直接看 Python 的 opcode ,可以用 dis.dis 把 pyc 形式的文件转换成 稍微可读一点的 opcode 列表(类似于汇编至于 C 语言),然后对着 [https://docs.python.org/3/library/dis.html?highlight=opcode#opcode-collections]( https://docs.python.org/3/library/dis.html?highlight=opcode#opcode-collections) 自己手动逆向了
    f1ush
        3
    f1ush  
       Feb 26, 2023   ❤️ 1
    https://zhuanlan.zhihu.com/p/145811103 这篇文章里面有介绍直接从 pyc 文件读取里面 PyCodeObject 的过程,3.11 里面 PyCodeObject 的偏移估计又不一样,需要自己猜一下了(或者直接看下 cpython 的源码)
    wa8n
        4
    wa8n  
    OP
       Feb 26, 2023
    @Tanix2 #1 我试了下,pydumpck 底层也是 pycdch 和 uncompyle6 ,解不出来

    @f1ush #2 感谢,看起来只能这样了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2244 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 10:18 · PVG 18:18 · LAX 03:18 · JFK 06:18
    ♥ Do have faith in what you're doing.