dotfiles: leviathan: arch-openbox-20231010
This commit is contained in:
36
.local/bin/img2ext4
Executable file
36
.local/bin/img2ext4
Executable file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python2
|
||||
|
||||
import sys
|
||||
import mmap
|
||||
|
||||
ext4Magic = '\x53\xEF'
|
||||
ext4MagicOffset = 1080
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print("No I/O supplied")
|
||||
exit(1)
|
||||
|
||||
def copyExt4Image(origin, offset, size, dest):
|
||||
with open(origin, 'r') as input:
|
||||
with open(dest, 'w') as output:
|
||||
input.seek(offset - ext4MagicOffset)
|
||||
output.write(input.read(size + ext4MagicOffset))
|
||||
|
||||
def findMagics(input):
|
||||
magics = [0]
|
||||
with open(input, 'r+b') as f:
|
||||
mm = mmap.mmap(f.fileno(), 0)
|
||||
while magics[-1] != -1:
|
||||
magics.append(mm.find(ext4Magic, magics[-1] + ext4MagicOffset))
|
||||
return magics
|
||||
|
||||
systemimg = sys.argv[1]
|
||||
offsets = findMagics(systemimg)
|
||||
if len(offsets[1:]) != 0:
|
||||
for num, offset in enumerate(offsets[1:], start=1):
|
||||
print('ext4 magic number found at byte %d' % offset)
|
||||
name = "{}_part{}.img".format(systemimg, num)
|
||||
print('Creating {}...'.format(name))
|
||||
copyExt4Image(systemimg, offset, offsets[num + 1] - offset, name)
|
||||
else:
|
||||
print("Not ext4 images found")
|
Reference in New Issue
Block a user