Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import binascii, sys
- def crc2hex(calcular):
- crc32 = binascii.crc32(calcular)
- final=''
- for i in range(4):
- tmp=crc32 & 0xFF
- crc32 >>= 8
- final='%02X%s' % (tmp, final)
- return final
- png = open(sys.argv[1],"rb").read()
- print str(png.count("IDAT"))+" IDAT encontrados:\n"
- nIDAT = 0
- errores = 0
- for i in range(0,len(png),1):
- if(png[i:i+4]=="\x49\x44\x41\x54"):
- nIDAT += 1
- lenchunk = png[i-4:i]
- longitud = int(lenchunk.encode("hex"),16)
- offsetCRC = (i+4)+longitud
- crc32sum = crc2hex(png[i:offsetCRC])
- chunkcrc32 = png[offsetCRC:offsetCRC+4]
- chunkcrc32 = str(chunkcrc32.encode("hex")).upper()
- if(crc32sum != chunkcrc32):
- errores += 1
- print "\nError en el chunk IDAT #"+str(nIDAT)+" en la posicion "+str(int(i))+str(" (offset ")+str("%X" % i)+str(")")
- print "\n\t.-Longitud = "+str(longitud)+" bytes"
- print "\t.-CRC32 = "+chunkcrc32+"\tDeberia ser = "+crc32sum+"\n"
- if(errores == 0):
- print "No se encontraron errores =)"
- elif(errores == 1):
- print "\n\t\t<< 1 error encontrado >>"
- else:
- print "\n\t\t<< "+str(errores)+" errores encontrados >>"
Advertisement
Add Comment
Please, Sign In to add comment