前言
对使用Pyinstaller打包的exe进行逆向时,报错ValueError: bad marshal data (unknown type code) python
1. 逆向步骤
1.1使用pyinstxtractor
首先使用pyinstxtractor,将exe解包成pyc文件,用法: $ python pyinstxtractor.py xxx.exe
1.2 使用uncompyle6或decompile3
uncompyle6和decomplie3都是pyc文件反编译为py文件的工具。正如作者rocky提到的:For Python 3.7 and 3.8, the code in decompyle3 is generally better。所以这里选用decompile3。
用法:decompyle3 -o . xxx.pyc # decompile to ./foo.pyc_dis and ./bar.pyc_dis当中的.是代表当前文件夹,表示将xxx.pyc反编译为当前目录下的xxx.py
2.遇到错误 bad marshal data
在使用命令decompyle3 -o . xxx.pyc 报错
decompyle3 -o . xxx.pyc
Traceback (most recent call last):
File "d:\python\lib\site-packages\xdis\load.py", line 300, in load_module_from_file_object
co = marshal.loads(bytecode)
ValueError: bad marshal data (unknown type code)
Ill-formed bytecode file stockx_goat_du_all.pyc
<class 'ValueError'>; bad marshal data (unknown type code)
3. 解决方法,使用winhex
这是由于pyc首部数据时错的,只要替换正确的首部即可。在当前文件夹下有一个struct.pyc,该文件是可以正确反编译的,所以复制其首部即可。

如上图,将不能正常反编译的pyc文件的首8位替换为struct.pyc的首8位即可。再次使用decompile3即可正常反编译。
2132

被折叠的 条评论
为什么被折叠?



