Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def extract_chunk(input, output)
- lenword = input.read(4)
- length = lenword.unpack('N')[0]
- type = input.read(4)
- data = length>0 ? input.read(length) : ""
- crc = input.read(4)
- return nil if length<0 || !(('A'..'z')===type[0,1])
- #return nil if validate_crc(type+data, crc)
- output.write lenword
- output.write type
- output.write data
- output.write crc
- return type
- end
- def extract_png(input, output)
- hdr = input.read(8)
- raise "Not a PNG File" if hdr[0,4]!= "\211PNG"
- raise "file not in binary mode" if hdr[4,4]!="\r\n\032\n"
- output.write(hdr)
- loop do
- chunk_type = extract_chunk(input,output)
- p chunk_type
- break if chunk_type.nil? || chunk_type == 'IEND'
- end
- end
- i=0
- fp = File.new("has_embedded_png.dat","rb")
- begin
- m= /\211PNG/.match(fp.read)
- raise "no PNG" if !m
- fp.seek(m.begin(0))
- #fp.seek 22946097
- ofp = File.new("out#{i}.png","wb")
- extract_png(fp,ofp)
- end while m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement