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
- n = 123456789 # <- EDIT THIS!
- offset = 314159 # <- EDIT THIS!
- partitionName = "/dev/sda3" # <- EDIT THIS!
- numIncrementSectors = 1 # <- Possibly edit this...
- bytesPerSector = 512 # <- Only edit this if you know what you're doing
- m=n+offset
- partition=open(partitionName,'rb') # Open partition
- #Read data at sector n
- partition.seek(n*bytesPerSector,0)
- nData=partition.read(1*bytesPerSector)
- print("Initial sector data:\n\n" + nData + "\n")
- #Read data at sector m
- partition.seek(m*bytesPerSector,0)
- mData=partition.read(1*bytesPerSector)
- if (nData != mData):
- partition.close()
- sys.exit("Initial sectors don't match, are you sure your numbers are correct?")
- print("Starting at sector offset " + str(m-numIncrementSectors))
- while (nData == mData):
- n += numIncrementSectors # Increment sector pointer
- partition.seek(n*bytesPerSector) # Seek to pointer position
- nData=partition.read(bytesPerSector) # Read data at that position
- m += numIncrementSectors # Same as above
- partition.seek(m*bytesPerSector)
- mData=partition.read(bytesPerSector)
- if (( m % (1024*1024*1024/512)) == 0): # Check how far we've got
- print("Offset: " + str(m/(1024*1024*1024/512)) + " GiB, current sector offset: " + str(m-numIncrementSectors))
- print("Last matching original/copied sector has absolute offset: " + str(m-numIncrementSectors))
- print("Last matching copied/original sector has absolute offset: " + str(n-numIncrementSectors))
- partition.close() # Close partition
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement