Guest User

findDuplicateSector.py

a guest
Aug 3rd, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.68 KB | None | 0 0
  1. # This script reads a reference sector from the partition, and then starting at
  2. # startSector looks for an identical sector. If one isn't found by the time it
  3. # gets to lastSector it will give up.
  4. #
  5. # This script is really slow (though gets close to my HDD's maximum transfer
  6. # rate, so at least it's efficient), if you have any idea where the copied
  7. # sector might be, use that information and save yourself some time!
  8.  
  9. refSector   = 1685403600 # <- Reference sector           EDIT THIS!
  10. startSector = 1685403601 # <- Sector to start comparison EDIT THIS!
  11. endSector   = 2000000000 # <- Sector to end comparison   EDIT THIS!
  12.  
  13. compareSector = startSector
  14.  
  15. bytesPerSector = 512
  16.  
  17. # Open the partition in binary, read only mode
  18. ntfspartition=open("/dev/sda3",'rb')
  19.  
  20. # Read data in refSector
  21. ntfspartition.seek(refSector*bytesPerSector,0)
  22. refData=ntfspartition.read(1*bytesPerSector)
  23. print("Data in reference sector is:\n\n" + nData + "\n\n")
  24.  
  25. # Read data at startSector
  26. ntfspartition.seek(startSector*512,0)
  27. compareData=ntfspartition.read(1*bytesPerSector)
  28.  
  29. print("Starting comparison with sector " + str(startSector))
  30.  
  31. # Loop through until we find an identical sector or we get to endSector
  32. while ((refData != compareData) and (compareSector <= endSector)):
  33.     compareSector += 1
  34.     compareData = ntfspartition.read(512)
  35.     if (( compareSector % 2097152) == 0):
  36.         print("Offset: " + str(m/2097152) + " GiB, current sector: " + str(m))
  37.  
  38. # Close the 'file'
  39. ntfspartition.close()
  40.  
  41. # Tell the user the outcome...
  42. if (compareSector == (endSector+1)):
  43.     print("Couldn't find any sector matching reference sector :(.")
  44. else:
  45.     print("Sector " + compareSector + " matches the reference sector! Yay!")
Advertisement
Add Comment
Please, Sign In to add comment