Last active
December 28, 2022 18:13
-
-
Save abjdiat/6398666 to your computer and use it in GitHub Desktop.
Python Script to check SVF files integrity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
##this script was written by [email protected] , feel free to modify it but mention the author, thank you | |
import zlib,sys,os.path | |
##this function calculates CRC of a fileName | |
file_to_check=sys.argv[1] | |
file_path=os.path.dirname(file_to_check) | |
def crc(fileName): | |
prev=0 | |
global file_path | |
##for the script to work on any sfv file no matter where it's located , we have to parse the absolute path of each file within sfv | |
##so, we will add the file path to each file name , pretty neat huh ? | |
fileName=os.path.join(file_path,fileName) | |
#print fileName | |
if os.path.exists(fileName): | |
store=open(fileName, "rb") | |
for eachLine in store: | |
prev = zlib.crc32(eachLine, prev) | |
return "%x"%(prev & 0xFFFFFFFF) | |
store.close() | |
else: | |
print"crc of this file can't be verified since it doesn't exists " | |
##=============## | |
if os.path.exists(file_to_check)==True: | |
if file_to_check[-3:]=="sfv": | |
s=open(file_to_check) | |
names_list=[] | |
sfv_list=[] | |
##loop thru all lines of sfv, removes all unnecessary /r /n chars, split each line to two values,creates two distinct arrays | |
for line in s.readlines(): | |
m=line.rstrip('\r\n') | |
m=m.split(' ') | |
names_list.append(m[0]) | |
sfv_list.append(m[1]) | |
#print line | |
i=0 | |
no_errors=False | |
while(len(names_list)>i): | |
print names_list[i] | |
calc_sfv_value=crc(names_list[i]) | |
print calc_sfv_value | |
print sfv_list[i] | |
#sfv_match= re.sub("^0+","",sfv_list[i]) | |
if sfv_list[i].lstrip('0')==calc_sfv_value: | |
print "MATCH"; | |
no_errors=True | |
else: | |
print "this was a problem with file" | |
no_errors=False | |
i=i+1 | |
if (no_errors): | |
print "Great, sfv verification went well without any errors,you can extract files safely" | |
else: | |
print " not SFV file" | |
else: | |
print "this file doesn't exist" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment