diff options
Diffstat (limited to '')
-rwxr-xr-x | tests/gpt-header-move | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/gpt-header-move b/tests/gpt-header-move new file mode 100755 index 0000000..18f58d0 --- /dev/null +++ b/tests/gpt-header-move @@ -0,0 +1,42 @@ +#!/usr/bin/python3 + +# open img file, subtract 33 from altlba address, and move the last 33 sectors +# back by 33 sectors + +from struct import unpack_from, pack_into +from zipfile import crc32 +import array +import sys + +file = open(sys.argv[1],'rb+') +file.seek(512) +gptheader = file.read(512) +altlba = unpack_from('<q', gptheader, offset=32)[0] +gptheader = array.array('B', gptheader) +pack_into('<Q', gptheader, 32, altlba-33) +#zero header crc +pack_into('<L', gptheader, 16, 0) +#compute new crc +newcrc = ((crc32(gptheader[:92])) & 0xFFFFFFFF) +pack_into('<L', gptheader, 16, newcrc) +file.seek(512) +file.write(gptheader) +file.seek(512*altlba) +gptheader = file.read(512) +file.seek(512*(altlba-32)) +backup = file.read(512*32) +altlba -= 33 +gptheader = array.array('B',gptheader) +#update mylba +pack_into('<Q', gptheader, 24, altlba) +#update table lba +pack_into('<Q', gptheader, 72, altlba-32) +#zero header crc +pack_into('<L', gptheader, 16, 0) +#compute new crc +newcrc = ((crc32(gptheader[:92])) & 0xFFFFFFFF) +pack_into('<L', gptheader, 16, newcrc) +file.seek(512*(altlba-32)) +file.write(backup) +file.write(gptheader) +file.write(b"\0" * (512 * 33)) |