最近碰到的问题,记录一下
C:\Users\zzzz>uncompyle6 xxxx.pyc
Traceback (most recent call last):
File "C:\python3\Lib\site-packages\xdis\load.py", line 143, in load_module_from_file_object
float_version = float(magics.versions[magic][:3])
KeyError: b'\xe3\x00\x00\x00'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\python3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "c:\python3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\python3\Scripts\uncompyle6.exe\__main__.py", line 7, in <module>
File "C:\python3\Lib\site-packages\uncompyle6\bin\uncompile.py", line 194, in main_bin
**options)
File "C:\python3\Lib\site-packages\uncompyle6\main.py", line 322, in main
do_fragments,
File "C:\python3\Lib\site-packages\uncompyle6\main.py", line 182, in decompile_file
filename, code_objects
File "C:\python3\Lib\site-packages\xdis\load.py", line 116, in load_module
get_code=get_code,
File "C:\python3\Lib\site-packages\xdis\load.py", line 152, in load_module_from_file_object
% (ord(magic[0:1]) + 256 * ord(magic[1:2]), filename)
ImportError: Unknown magic number 227 in xxxx.pyc
原因是文件头magic number没有对上
magic number(前4个字节)可以在struct里面找到,直接把到E3前面的二进制都复制过去就可以了
不同文件的magic number不一定一样,需要注意
用 winhex 在pyc文件最前面加上
33 0D 0D 0A 00 00 00 00 00 00 00 00
参考文章:https://zondatw.github.io/2019/pyinstaller_decompile/