From b1bfe44bde874be8f88a9c2c93cf7ebcf33850d9 Mon Sep 17 00:00:00 2001 From: tanson Date: Thu, 17 Oct 2019 21:41:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=9B=BE=E7=89=87=E9=AB=98=E5=AE=BD?= =?UTF-8?q?=E5=BA=A6=E4=BF=AE=E5=A4=8D=EF=BC=8C=E9=87=87=E7=94=A8=E5=8E=9F?= =?UTF-8?q?crc=E5=80=BC=EF=BC=8C=E9=81=8D=E5=8E=86=E9=AB=98=E5=AE=BD?= =?UTF-8?q?=E5=BA=A6=E7=88=86=E7=A0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PCRT.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/PCRT.py b/PCRT.py index 386f8f4..0315714 100644 --- a/PCRT.py +++ b/PCRT.py @@ -522,7 +522,21 @@ 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] @@ -530,7 +544,7 @@ def CheckIHDR(self,data): 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] From 1ebf488a85c3b9ca1f8dc420d25d912d749b1e68 Mon Sep 17 00:00:00 2001 From: tanson Date: Thu, 17 Oct 2019 21:57:06 +0800 Subject: [PATCH 2/2] fix --- PCRT.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/PCRT.py b/PCRT.py index 0315714..8224945 100644 --- a/PCRT.py +++ b/PCRT.py @@ -544,14 +544,15 @@ def CheckIHDR(self,data): IHDR=IHDR[:8]+chunk_ihdr+calc_crc print '[Finished] Successfully fix crc' break - else if fix==0: + 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)