Created
April 28, 2019 07:34
-
-
Save shuax/76923d20d55359a5191be63339341a16 to your computer and use it in GitHub Desktop.
qq拼音皮肤格式
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install olefile | |
# pip install pywin32 | |
import os | |
import zlib | |
import struct | |
import binascii | |
import olefile | |
import pythoncom | |
from win32com import storagecon | |
def unpack_stg(folder, data): | |
print(folder) | |
ole = olefile.OleFileIO(data) | |
for name in ole.listdir(): | |
name = name[0] | |
path = os.path.join(folder, name) | |
print(path) | |
os.makedirs(folder, exist_ok=True) | |
with open(path, 'wb') as f: | |
f.write(ole.openstream(name).read()) | |
def unpack(name): | |
with open(name, 'rb') as f: | |
data = f.read() | |
data = zlib.decompress(data[12:]) | |
# with open('test.bin', 'wb') as f: | |
# f.write(data) | |
data = data[276:] | |
name = os.path.splitext(name)[0] | |
unpack_stg(name, data) | |
def repack(folder): | |
istorage = pythoncom.StgCreateDocfile('temp.bin', storagecon.STGM_CREATE | storagecon.STGM_DIRECT| storagecon.STGM_READWRITE | storagecon.STGM_SHARE_EXCLUSIVE) | |
for parent, dirnames, filenames in os.walk(folder): | |
for filename in filenames: | |
pathfile = os.path.join(parent, filename) | |
stg = istorage.CreateStream(filename, storagecon.STGM_DIRECT| storagecon.STGM_READWRITE | storagecon.STGM_SHARE_EXCLUSIVE) | |
stg.Write(open(pathfile,'rb').read()) | |
# stg = None | |
istorage = None | |
with open('temp.bin', 'rb') as f: | |
data = f.read() | |
os.remove('temp.bin') | |
buf = B'FSPQ' | |
buf += struct.pack('I', 1) | |
buf += struct.pack('I', 0) | |
buf += struct.pack('I', len(data)) | |
buf += B'\0' * 260 | |
buf += data | |
size = len(buf) | |
data = zlib.compress(buf) | |
buf = B'SYPQ' | |
buf += struct.pack('I', binascii.crc32(data)) | |
buf += struct.pack('I', size) | |
buf += data | |
with open('test.qpys', 'wb') as f: | |
f.write(buf) | |
unpack('4293196787.qpys') | |
repack('4293196787') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment