我有一个.exe安装程序,它可以很容易地用7zip打开;它的内容可以在不安装的情况下提取出来。
我使用预编译的7z.exe和python的subprocess来提取它。
import os, subprocess
subprocess.call(r'"7z.exe" x ' + "Installer.exe" + ' -o' + os.getcwd())然而,现在我正在寻找一种方法,它将是纯代码,并且不依赖任何外部可执行来提取打包的exe的内容。
我尝试过像tarfile, PyLZMA, py7zlib这样的库,但是它们无法提取exe,或者会抱怨文件格式无效等等。
发布于 2017-03-02 09:43:28
自解压缩存档只是一个带有7zip存档的可执行文件。您可以查找存档的所有可能启动,并尝试从那里开始解压缩文件句柄:
HEADER = b'7z\xBC\xAF\x27\x1C'
def try_decompressing_archive(filename):
with open(filename, 'rb') as handle:
start = 0
# Try decompressing the archive at all the possible header locations
while True:
handle.seek(start)
try:
return decompress_archive(handle)
except SomeDecompressionException:
# We find the next instance of HEADER, skipping the current one
start += handle.read().index(HEADER, 1)https://stackoverflow.com/questions/42551098
复制相似问题