Created
May 11, 2014 15:58
-
-
Save WebberHuang/4ed6e828f4da26d9dc43 to your computer and use it in GitHub Desktop.
Repair files that corrupted by desktop virus
This file contains 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
blockSize = 100 | |
fileList = ["filepath1", "filepath2", "filepath3"] | |
def invert(x): | |
return ~x & 0xFF | |
def repair(filePath, blockSize): | |
try: | |
with open(filePath,"rb+") as f: | |
block = f.read(blockSize) | |
newStr = '' | |
for ch in block: | |
uc = ord(ch) | |
inv = invert(uc) | |
newStr += chr(inv) | |
f.seek(0) | |
f.write(newStr) | |
f.close() | |
except Exception, e: | |
raise e | |
print "Successful!" | |
for f in fileList: | |
try: | |
repair(f, blockSize) | |
except Exception, e: | |
print e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment