SHOW:
|
|
- or go back to the newest paste.
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! |
15 | + | n = 123456789 # <- EDIT THIS! |
16 | - | offset=843812864 # <- EDIT THIS! |
16 | + | offset = 314159 # <- EDIT THIS! |
17 | - | n=1685403600 # <- EDIT THIS! |
17 | + | partitionName = "/dev/sda3" # <- EDIT THIS! |
18 | numIncrementSectors = 1 # <- Possibly edit this... | |
19 | bytesPerSector = 512 # <- Only edit this if you know what you're doing | |
20 | - | bytesPerSector = 512 |
20 | + | |
21 | - | numSectorsToIncrement = 1 |
21 | + | |
22 | ||
23 | - | ntfspartition=open(partition,'rb') # Open partition |
23 | + | partition=open(partitionName,'rb') # Open partition |
24 | ||
25 | #Read data at sector n | |
26 | - | ntfspartition.seek(n*bytesPerSector,0) |
26 | + | partition.seek(n*bytesPerSector,0) |
27 | - | nData=ntfspartition.read(1*bytesPerSector) |
27 | + | nData=partition.read(1*bytesPerSector) |
28 | - | print(nData) |
28 | + | print("Initial sector data:\n\n" + nData + "\n") |
29 | ||
30 | #Read data at sector m | |
31 | - | ntfspartition.seek(m*BytesPerSector,0) |
31 | + | partition.seek(m*bytesPerSector,0) |
32 | - | mData=ntfspartition.read(1*BytesPerSector) |
32 | + | mData=partition.read(1*bytesPerSector) |
33 | ||
34 | if (nData != mData): | |
35 | - | ntfspartition.close() |
35 | + | partition.close() |
36 | sys.exit("Initial sectors don't match, are you sure your numbers are correct?") | |
37 | ||
38 | - | print("Starting at sector " + str(m)) |
38 | + | print("Starting at sector offset " + str(m-numIncrementSectors)) |
39 | ||
40 | while (nData == mData): | |
41 | - | n=n+numSectorsToIncrement |
41 | + | n += numIncrementSectors # Increment sector pointer |
42 | - | ntfspartition.seek(n*BytesPerSector) |
42 | + | partition.seek(n*bytesPerSector) # Seek to pointer position |
43 | - | nData=ntfspartition.read(BytesPerSector) |
43 | + | nData=partition.read(bytesPerSector) # Read data at that position |
44 | ||
45 | - | m=m+numSectorsToIncrement |
45 | + | m += numIncrementSectors # Same as above |
46 | - | ntfspartition.seek(m*BytesPerSector) |
46 | + | partition.seek(m*bytesPerSector) |
47 | - | mData=ntfspartition.read(BytesPerSector) |
47 | + | mData=partition.read(bytesPerSector) |
48 | - | if (( m % (1024*1024*1024/512)) == 0): |
48 | + | |
49 | - | print("Offset: " + str(m/(1024*1024*1024/512)) + " GiB, current sector: " + str(m)) |
49 | + | if (( m % (1024*1024*1024/512)) == 0): # Check how far we've got |
50 | print("Offset: " + str(m/(1024*1024*1024/512)) + " GiB, current sector offset: " + str(m-numIncrementSectors)) | |
51 | - | print("Last matching original sector is " + str(m-numSectorsToIncrement)) |
51 | + | |
52 | - | print("Last matching copied sector is " + str(n-numSectorsToIncrement)) |
52 | + | print("Last matching original/copied sector has absolute offset: " + str(m-numIncrementSectors)) |
53 | print("Last matching copied/original sector has absolute offset: " + str(n-numIncrementSectors)) | |
54 | - | ntfspartition.close() # Close partition |
54 | + | |
55 | partition.close() # Close partition |