V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
wangsongyan
V2EX  ›  Python

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

  •  
  •   wangsongyan · 2023-02-26 15:36:13 +08:00 · 2510 次点击
    这是一个创建于 424 天前的主题,其中的信息可能已经有所发展或是发生改变。

    手头有一个 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 条回复    2023-02-26 20:44:34 +08:00
    Tanix2
        1
    Tanix2  
       2023-02-26 17:52:16 +08:00   ❤️ 1
    f1ush
        2
    f1ush  
       2023-02-26 20:35:28 +08:00
    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  
       2023-02-26 20:40:13 +08:00   ❤️ 1
    https://zhuanlan.zhihu.com/p/145811103 这篇文章里面有介绍直接从 pyc 文件读取里面 PyCodeObject 的过程,3.11 里面 PyCodeObject 的偏移估计又不一样,需要自己猜一下了(或者直接看下 cpython 的源码)
    wangsongyan
        4
    wangsongyan  
    OP
       2023-02-26 20:44:34 +08:00
    @Tanix2 #1 我试了下,pydumpck 底层也是 pycdch 和 uncompyle6 ,解不出来

    @f1ush #2 感谢,看起来只能这样了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5373 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 08:50 · PVG 16:50 · LAX 01:50 · JFK 04:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.