Skip to content

Instantly share code, notes, and snippets.

@WebberHuang
Created May 11, 2014 15:58
Show Gist options
  • Save WebberHuang/4ed6e828f4da26d9dc43 to your computer and use it in GitHub Desktop.
Save WebberHuang/4ed6e828f4da26d9dc43 to your computer and use it in GitHub Desktop.
Repair files that corrupted by desktop virus
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