Pyinstaller 逆向时报 bad marshal data

前言

对使用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

uncompyle6decomplie3都是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即可正常反编译。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值