Skip to content

Instantly share code, notes, and snippets.

@aholmes
Created August 4, 2014 22:17
Show Gist options
  • Save aholmes/1c3e5b494ebebc977e07 to your computer and use it in GitHub Desktop.
Save aholmes/1c3e5b494ebebc977e07 to your computer and use it in GitHub Desktop.
Get the height and width of an uncompressed SWF.
#!/usr/bin/python
import array
f = open('uncompressed_test_adx30.swf', 'r')
input = f.read(8)
chars = [ord(ch) for ch in input]
nbits = chars[0] >> 3
rect = array.array('H', chars)
rect[0] = (rect[0] & 0x07)
address,length = rect.buffer_info()
converted = ""
for i in xrange(0,length):
for j in xrange(0,8):
converted += "1" if (rect[i] & 0x80) > 0 else "0"
rect[i] = rect[i] << 1
bits = converted[5:]
dims = array.array('L', [0,0,0,0]);
for x in xrange(0,4):
trimlen = nbits if len(bits) > nbits else len(bits)
dest = bits[:trimlen]
# pad the rightside of the number with 0-bits for each bit missing.
# this makes the byte contain 16 bits instead of len(bits)
if trimlen != nbits:
dest += '0' * (nbits - len(bits))
bits = bits[trimlen:]
conv = 0;
for y in xrange(0, len(dest)):
conv = (conv << 1) + (1 if dest[y] == '1' else 0)
dims[x] = conv / (20 if x < 3 else 19)
print "0 0 %d %d" % (dims[1] - dims[0], dims[3] - dims[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment