關於求swf寬和高的,又查了些資料,應該這樣寫
from struct import *
import zlib
import cStringIO
def parse_rect(rd_type, s):
d ={
0x50: (0, 0, 4, 0, 5, 4 ),
0x58: (1, 1, 4, 0, 6, 4 ),
0x60: (0, 1, 4, 0, 7, 4 ),
0x68: (1, 2, 4, 0, 9, 4 ),
0x70: (0, 2, 4, 0, 9, 4 ),
0x78: (1, 3, 4, 0, 10, 4 ),
0x80: (0, 3, 4, 0, 11, 4 ),
0x88: (1, 2, 5, 0, 12, 4 ),
}
st = []
for b in s:
st.append(b >> 4)
st.append(b & 0xf)
c1, w, ws, c2, h, hs = d[rd_type]
xw = 0
for b in st[w: w + ws]:
xw <<= 4
xw += b
if c1: xw /= 40
else: xw /= 10
xh = 0
for b in st[h: h + hs]:
xh <<= 4
xh += b
if c2: xh /= 40
else: xh /= 10
return xw, xh
def main(swffilename):
swffile = open(swffilename, 'rb')
header = swffile.read(8)
sig, v, file_length = unpack('<3sBl', header)
if sig == 'CWS':
content = cStringIO.StringIO(zlib.decompress(swffile.read()))
else:
content = cStringIO.StringIO(swffile.read())
swffile.close()
content.seek(0)
(rd_type, ) = unpack('<B', content.read(1))
s = unpack('<8B', content.read(8))
w, h = parse_rect(rd_type, s)
print w, h
if __name__ == '__main__':
main('test.swf')