Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions PCRT.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,22 +522,37 @@ def CheckIHDR(self,data):
msg = Termcolor('Notice','Try fixing it? (y or n) [default:y] ')
choice = raw_input(msg)
if choice == 'y' or choice=='':
if width > height:
fix=0
for h in range(0, 65535):
for w in range(0, 65535):
chunk_ihdr=struct.pack('!I',w)+struct.pack('!I',h)+IHDR[16:8+length]
if self.Checkcrc(chunk_type,chunk_ihdr,crc) == None:
IHDR=IHDR[:8]+chunk_ihdr+crc
fix=1
calc_crc=crc
print '[Finished] Successfully fix crc'
print h
print w
break
if fix==1:
break
if width > height and fix==0:
# fix height
for h in xrange(height,width):
chunk_ihdr=IHDR[8:12]+struct.pack('!I',h)+IHDR[16:8+length]
if self.Checkcrc(chunk_type,chunk_ihdr,calc_crc) == None:
IHDR=IHDR[:8]+chunk_ihdr+calc_crc
print '[Finished] Successfully fix crc'
break
else:
else :
if fix==0:
# fix width
for w in xrange(width,height):
chunk_ihdr=struct.pack('!I',w)+IHDR[12:8+length]
if self.Checkcrc(chunk_type,chunk_ihdr,calc_crc) == None:
IHDR=IHDR[:8]+chunk_ihdr+calc_crc
print '[Finished] Successfully fix crc'
break
for w in xrange(width,height):
chunk_ihdr=struct.pack('!I',w)+IHDR[12:8+length]
if self.Checkcrc(chunk_type,chunk_ihdr,calc_crc) == None:
IHDR=IHDR[:8]+chunk_ihdr+calc_crc
print '[Finished] Successfully fix crc'
break
else:
print '[Finished] Correct IHDR CRC (offset: %s): %s'% (int2hex(pos+4+length),str2hex(crc))
self.file.write(IHDR)
Expand Down