Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Dr Gareth Owen, University of Greenwich
- # PNG Image parser and inspector for stenographic content
- import sys
- import zlib
- import struct
- import collections
- #import file
- idat = ''
- width = 0
- height = 0
- Header = collections.namedtuple('Header', 'width height bpp coltype comptype filtype intype')
- hdr = ''
- def readChunk(f):
- global idat, hdr
- (len,) = struct.unpack('>L', f.read(4))
- type = f.read(4)
- print "Len %d Type %s" % (len, type)
- data = f.read(len)
- if type == "IHDR":
- hdr = Header._make(struct.unpack('>LLBBBBB', data))
- print hdr
- elif type == "iTXt":
- print data
- elif type == "tIME":
- Tm = collections.namedtuple('Tm', 'year month day hour minute second')
- print Tm._make(struct.unpack('>HBBBBB', data))
- elif type == "IDAT":
- idat += data
- crc = f.read(4)
- return type
- inf = open('cyber.png', 'r')
- sig = inf.read(8)
- while readChunk(inf) != 'IEND':
- pass
- unpacked = zlib.decompress(idat)
- print "Decom len %d " % (len(unpacked))
- # has extra byte at beginning of each scan line indicating encoding type
- o = open('cyber.raw', 'w')
- o.write(unpacked)
- o.close()
- # check Least significant bits for stenographic content
- #for y in range(0, hdr.height):
- # for x in range(1, hdr.width):
- # print ord(unpacked[y*hdr.width + x]) & 0x01,
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement