由于之前写的文件找不到源码了,到网上找反编译教程已过时,踩了许多坑。
注意:
1pyinstxtractor.py适用于由pyinstaller打包python形成的exe的反编译,反编译后形成pyc文件
2需要WIN10
3需要安装了python3
4包imp在python3.4后已不再使用,pyinstxtractor在2017后不再更新。
5这是下载pyinstxtractor.py原地址:https://nchc.dl.sourceforge.net/project/pyinstallerextractor/dist/pyinstxtractor.py
由4可知其所需包imp在python3.4后已不再使用,此附于2022可用的pyinstxtractor修改后的代码
from __future__ import print_function
import os
import struct
import marshal
import zlib
import sys
from importlib import reload as imp
import types
from uuid import uuid4 as uniquename
class CTOCEntry:
def __init__(self, position, cmprsdDataSize, uncmprsdDataSize, cmprsFlag, typeCmprsData, name):
self.position = position
self.cmprsdDataSize = cmprsdDataSize
self.uncmprsdDataSize = uncmprsdDataSize
self.cmprsFlag = cmprsFlag
self.typeCmprsData = typeCmprsData
self.name = name
class PyInstArchive:
PYINST20_COOKIE_SIZE = 24 # For pyinstaller 2.0
PYINST21_COOKIE_SIZE = 24 + 64 # For pyinstaller 2.1+
MAGIC = b'MEI\014\013\012\013\016' # Magic number which identifies pyinstaller
def __init__(self, path):
self.filePath = path
def open(self):
try:
self.fPtr = open(self.filePath, 'rb')
self.fileSize = os.stat(self.filePath).st_size
except:
print('[*] Error: Could not open {0}'.format(self.filePath))
return False
return True
def close(self):
try:
self.fPtr.close()
except:
pass
def checkFile(self):
print('[*] Processing {0}'.format(self.filePath))
# Check if it is a 2.0 archive
self.fPtr.seek(self.fileSize - self.PYINST20_COOKIE_SIZE