Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This script finds the last sector copied by GParted given an initial sector
- # and an offset to the location of its copy.
- #
- # This is done simply by comparing sector number n to sector number
- # n+<offset_of_copy>. If these match it increments n and continues.
- #
- # *** WARNING: In its current form, this script is very slow! ***
- #
- # You may prefer to increment n by a much larger number to save time (simply
- # modify numSectorsToIncrement), but this won't find the exact last copied
- # sector, just one within your increment size.
- import sys
- partition="/dev/sda3"# <- EDIT THIS!
- offset=843812864 # <- EDIT THIS!
- n=1685403600 # <- EDIT THIS!
- m=n+offset
- bytesPerSector = 512
- numSectorsToIncrement = 1
- ntfspartition=open(partition,'rb') # Open partition
- #Read data at sector n
- ntfspartition.seek(n*bytesPerSector,0)
- nData=ntfspartition.read(1*bytesPerSector)
- print(nData)
- #Read data at sector m
- ntfspartition.seek(m*BytesPerSector,0)
- mData=ntfspartition.read(1*BytesPerSector)
- if (nData != mData):
- ntfspartition.close()
- sys.exit("Initial sectors don't match, are you sure your numbers are correct?")
- print("Starting at sector " + str(m))
- while (nData == mData):
- n=n+numSectorsToIncrement
- ntfspartition.seek(n*BytesPerSector)
- nData=ntfspartition.read(BytesPerSector)
- m=m+numSectorsToIncrement
- ntfspartition.seek(m*BytesPerSector)
- mData=ntfspartition.read(BytesPerSector)
- if (( m % (1024*1024*1024/512)) == 0):
- print("Offset: " + str(m/(1024*1024*1024/512)) + " GiB, current sector: " + str(m))
- print("Last matching original sector is " + str(m-numSectorsToIncrement))
- print("Last matching copied sector is " + str(n-numSectorsToIncrement))
- ntfspartition.close() # Close partition
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement