Skip to content

Instantly share code, notes, and snippets.

@erfanoabdi
Created August 6, 2017 04:34
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save erfanoabdi/7ff14d614f4919fee5159fccd7885370 to your computer and use it in GitHub Desktop.
Save erfanoabdi/7ff14d614f4919fee5159fccd7885370 to your computer and use it in GitHub Desktop.
sparseChunks to image Convertor for motorola images
#!/bin/sh
#SparseChunks to image Convertor for motorola images by Erfan Abdi
#special thanks to superR for header removal script
#make sure you have only one image with sparse chunks (system or oem)
echo "Converting all SparseChunks to Raw Image"
./simg2img *chunk* system.img.raw
echo "Removing Moto Header"
offset=$(LANG=C grep -aobP -m1 '\x53\xEF' system.img.raw | head -1 | gawk '{print $1 - 1080}')
dd if=system.img.raw of=system_moto.img ibs=$offset skip=1 2>&1
echo "Removing Raw Image"
rm -rf system.img.raw
echo "Removing Moto Footer"
head -c $(( 4*1024*-1 )) system_moto.img > system.img
echo "Removing moto Image"
rm -rf system_moto.img
echo "system.img is ready"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment