('YCBCRCOEFFICIENTS', 529), ('YCBCRPOSITIONING', 531), ('YCBCRSUBSAMPLING', 530), ('YCLIPPATHUNITS', 345), ('YPOSITION', 287), ('YRESOLUTION', 283), ('ZIPQUALITY', 65557), ] TAGS = dict([(i[1], i[0]) for i in tags_types] + tags_types) for i,j in TAGS.iteritems(): TAGS[j] = i _file = open(sys.argv[1], "rb") s = struc.struc(_file) #TODO # * extract information from valoff # * go to next directory import struct def ReadEndianness(v): global _C Little = {"II":True, "MM":False}[struct.pack("H", v)] _C = {True:"<", False:">"}[Little] def Check42(v): if v != 42: print v
with open("dec.bin", "wb") as fw: fw.write(decfile) return d SIGS = {"FWS":None,"CWS": cws} with open(sys.argv[1], "rb") as f: d = struc.data(f.read()) sig = d.read(3) if sig not in SIGS: raise(BaseException("Wrong Signature")) version = d.read(1) if version not in (chr(i) for i in xrange(10)): raise(BaseException("Wrong Version")) do = SIGS[sig] if do is not None: d = do(d, version) s = struc.struc(d) # weird, must be wrong s.handles([ ["<I,SizeTag", None], ["<I,FrameSize", None], ["<H,FrameRate", None], ["<I,FrameCount", None], ])
# tiny png parser # Ange Albertini, BSD Licence, 2011 import struc import sys _file = open(sys.argv[1], "rb") s = struc.struc(_file) ############################################ # PNG import binascii import struct # todo: add support for ascii buffer.... s.handle(["8B,header", None]) #sig = _file.read(8) #if sig != "\x89PNG\x0d\x0a\x1a\x0a": # raise(BaseException("Wrong Header")) while (True): #EOF() ? # should be printed only once the structure is confirmed correct # print "%04X: %s%s:" % (_file.tell(), " " * _level, "Chunk") # should be handled at class level s.levelup() try: size = s.handle([">I,Size", None]) except struct.error: break
fw.write(decfile) return d SIGS = {"FWS": None, "CWS": cws} with open(sys.argv[1], "rb") as f: d = struc.data(f.read()) sig = d.read(3) if sig not in SIGS: raise (BaseException("Wrong Signature")) version = d.read(1) if version not in (chr(i) for i in xrange(10)): raise (BaseException("Wrong Version")) do = SIGS[sig] if do is not None: d = do(d, version) s = struc.struc(d) # weird, must be wrong s.handles([ ["<I,SizeTag", None], ["<I,FrameSize", None], ["<H,FrameRate", None], ["<I,FrameCount", None], ])