@@ -2554,7 +2554,7 @@ def initCommonOutputs():
2554
2554
if line not in kb .commonOutputs [key ]:
2555
2555
kb .commonOutputs [key ].add (line )
2556
2556
2557
- def getFileItems (filename , commentPrefix = '#' , unicoded = True , lowercase = False , unique = False ):
2557
+ def getFileItems (filename , commentPrefix = '#' , unicoded = True , lowercase = False , unique = False , raiseOnError = True ):
2558
2558
"""
2559
2559
Returns newline delimited items contained inside file
2560
2560
@@ -2567,7 +2567,7 @@ def getFileItems(filename, commentPrefix='#', unicoded=True, lowercase=False, un
2567
2567
if filename :
2568
2568
filename = filename .strip ('"\' ' )
2569
2569
2570
- checkFile (filename )
2570
+ checkFile (filename , raiseOnError = raiseOnError )
2571
2571
2572
2572
try :
2573
2573
with openFile (filename , 'r' , errors = "ignore" ) if unicoded else open (filename , 'r' ) as f :
@@ -5599,18 +5599,45 @@ def checkSums():
5599
5599
5600
5600
retVal = True
5601
5601
5602
- if paths .get ("DIGEST_FILE" ):
5603
- for entry in getFileItems (paths .DIGEST_FILE ):
5604
- match = re .search (r"([0-9a-f]+)\s+([^\s]+)" , entry )
5605
- if match :
5606
- expected , filename = match .groups ()
5607
- filepath = os .path .join (paths .SQLMAP_ROOT_PATH , filename ).replace ('/' , os .path .sep )
5608
- if not checkFile (filepath , False ):
5609
- continue
5610
- with open (filepath , "rb" ) as f :
5611
- content = f .read ()
5612
- if not hashlib .sha256 (content ).hexdigest () == expected :
5613
- retVal &= False
5614
- break
5602
+ for entry in getFileItems (paths .DIGEST_FILE , raiseOnError = False ):
5603
+ try :
5604
+ (file_hash , file_name ) = entry .split ()
5605
+ except ValueError :
5606
+ retVal &= False
5607
+ break
5608
+ if len (file_hash ) == 64 :
5609
+ if not hashlib .sha256 (
5610
+ openFile (
5611
+ os .path .join (
5612
+ paths .SQLMAP_ROOT_PATH , file_name .encode ('utf-8' ).decode ('utf-8' )
5613
+ ).replace ('/' , os .path .sep ),
5614
+ 'rb' , None ).read ()).hexdigest () == file_hash :
5615
+ retVal &= False
5616
+ break
5615
5617
5616
5618
return retVal
5619
+
5620
+
5621
+ def updateSums ():
5622
+ # Read existing entries to maintain file order
5623
+ entries = ""
5624
+ for entry in getFileItems (paths .DIGEST_FILE , raiseOnError = False ):
5625
+ try :
5626
+ (file_hash , file_name ) = entry .split ()
5627
+ except ValueError :
5628
+ break
5629
+ if len (file_hash ) == 64 :
5630
+ entries += "%s %s\n " % (
5631
+ hashlib .sha256 (
5632
+ openFile (
5633
+ os .path .join (
5634
+ paths .SQLMAP_ROOT_PATH , file_name .encode ('utf-8' ).decode ('utf-8' )
5635
+ ).replace ('/' , os .path .sep ), 'rb' , None ).read ()
5636
+ ).hexdigest (),
5637
+ file_name .encode ('utf-8' ).decode ('utf-8' ),
5638
+ )
5639
+ with open (paths .DIGEST_FILE , "w" ) as f :
5640
+ f .write (entries )
5641
+ else :
5642
+ pass
5643
+
0 commit comments