Using dd to dump Android partitions via adb
Unfortunately there are some pitfalls, e.g. \n is converted to \n\r which is rather annoying in binary data.
Works as expected
1
| $ adb exec-out 'dd if=/dev/block/mmcblk0p1 2>/dev/null' > mmcblk0p1.bin
|
Also works as expected, but once resulted in a dump missing 2 bytes (could not be reproduced)
1
| $ adb shell 'dd if=/dev/block/mmcblk0p1 2>/dev/null' | sed 's/\r$//' > mmcblk0p1.img
|
This results in the said conversion (DON’T USE THIS)
1
| $ adb shell 'dd if=/dev/block/mmcblk0p1 2>/dev/null' > test.img
|
Broken images can be fixed with
1
| $ sed 's/\r$//' < test.img > test.bin
|
or
1
| $ cat test.img | sed 's/\r$//' > test.bin
|
This also doesn’t work as expected
1
| $ adb shell 'stty raw && dd if=/dev/block/mmcblk0p1 2>/dev/null' > mmcblk0p1.img
|
Restoring a partition is straightforward though
1
| $ adb push mmcblk0p1.bin /dev/block/mmcblk0p1
|
Also helpful https://android.stackexchange.com/questions/69434/is-it-possible-to-cat-a-file-to-an-android-phone-and-dd-to-dev-xxx-on-the-fly-w