Advertisement
Guest User

findCopyInterruptLocation.py

a guest
Aug 3rd, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. # This script finds the last sector copied by GParted given an initial sector
  2. # and an offset to the location of its copy.
  3. #
  4. # This is done simply by comparing sector number n to sector number
  5. # n+<offset_of_copy>. If these match it increments n and continues.
  6. #
  7. #        *** WARNING: In its current form, this script is very slow! ***
  8. #
  9. # You may prefer to increment n by a much larger number to save time (simply
  10. # modify numSectorsToIncrement), but this won't find the exact last copied
  11. # sector, just one within your increment size.
  12.  
  13. import sys
  14.  
  15. partition="/dev/sda3"# <- EDIT THIS!
  16. offset=843812864 #     <- EDIT THIS!
  17. n=1685403600 #         <- EDIT THIS!
  18. m=n+offset
  19.  
  20. bytesPerSector = 512
  21. numSectorsToIncrement = 1
  22.  
  23. ntfspartition=open(partition,'rb') # Open partition
  24.  
  25. #Read data at sector n
  26. ntfspartition.seek(n*bytesPerSector,0)
  27. nData=ntfspartition.read(1*bytesPerSector)
  28. print(nData)
  29.  
  30. #Read data at sector m
  31. ntfspartition.seek(m*BytesPerSector,0)
  32. mData=ntfspartition.read(1*BytesPerSector)
  33.  
  34. if (nData != mData):
  35.     ntfspartition.close()
  36.     sys.exit("Initial sectors don't match, are you sure your numbers are correct?")
  37.  
  38. print("Starting at sector " + str(m))
  39.  
  40. while (nData == mData):
  41.     n=n+numSectorsToIncrement
  42.     ntfspartition.seek(n*BytesPerSector)
  43.     nData=ntfspartition.read(BytesPerSector)
  44.    
  45.     m=m+numSectorsToIncrement
  46.     ntfspartition.seek(m*BytesPerSector)
  47.     mData=ntfspartition.read(BytesPerSector)
  48.     if (( m % (1024*1024*1024/512)) == 0):
  49.         print("Offset: " + str(m/(1024*1024*1024/512)) + " GiB, current sector: " + str(m))
  50.        
  51. print("Last matching original sector is " + str(m-numSectorsToIncrement))
  52. print("Last matching copied sector is   " + str(n-numSectorsToIncrement))
  53.  
  54. ntfspartition.close() # Close partition
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement