Created
September 21, 2019 03:06
-
-
Save GeoffWilliams/708e31ee847d21b43e23440430d0c331 to your computer and use it in GitHub Desktop.
Compare disk images block-by-block, print out index of sectors with changes and save the different blocks to file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
afile = "sdcard.img" | |
bfile = "sdcard.img.manualworks" | |
afilediff = "sdcard.img.diff" | |
bfilediff = "sdcard.img.manualworks.diff" | |
afile_size = os.path.getsize(afile) | |
bfile_size = os.path.getsize(bfile) | |
if afile_size != bfile_size: | |
raise "different sizes!" | |
incident = 0 | |
with open(afile, 'rb') as af: | |
with open(bfile, 'rb') as bf: | |
pos = 0 | |
while(pos < afile_size): | |
pos = af.tell() | |
a_sect = af.read(512) | |
b_sect = bf.read(512) | |
if (a_sect != b_sect): | |
print(f"different data at byte {pos} (sector {pos/512})") | |
print("a_file") | |
print(str(a_sect)) | |
print("b_file") | |
print(str(b_sect)) | |
print() | |
with open(f"afilediff-{incident}", 'wb') as afd: | |
afd.write(a_sect) | |
with open(f"bfilediff-{incident}", 'wb') as bfd: | |
bfd.write(b_sect) | |
incident += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment