Android device data recovery note

@vrqq  December 10, 2020

1. Dump partition from remote phone

  • Power your mobile phone into FastBoot Mode
  • We assume have already unlocked bootloader now. (you may unlock first but may unwarranted or all-data-clear, please be PATIENT)
  • If you have the 3rd recovery, using volume-up/down to select Recovery then enter it.
  • If not, you can use fastboot boot twrp-recovery.img to enter the temporary location
  • Then use adb pull /dev/mmcblk0 ./mhdd.img to dump disk image.

2. Build ext4magic

In my RHEL 8

We do not have file-devel in RHEL but I have an idea

  • Using dnf info file-libs to ensure the version of file-libs (FILE5_33 in my system)
  • Then download from https://github.com/file/file/releases/tag/FILE5_33 and copy all .h file from file-FILE5_33/src into ext4magic-0.3.2/src folder
  • Remove codes like AC_SEARCH_LIBS([magic_getpath], [magic], [], [fail=1]) in ext4magic-0.3.2/configure.ac (about L31-34) and run autoconf to regenerate configure script
  • Check the library name of libmagic.so by ldconfig -p | grep libmagic (ref: https://stackoverflow.com/a/37286031/12529885)
  • There's libmagic.so.1 in my system so I have to create a link cd src; ln -s /lib64/libmagic.so.1 libmagic.so
  • Then modify makefile by searching -lmagic then add -L., to specify the location of our library link.

Then you may see these error

inode.c: In function ‘dump_inode’:
inode.c:407:82: error: ‘struct ext2_inode’ has no member named ‘i_dir_acl’; did you mean ‘i_file_acl’?
                         inode->i_file_acl, LINUX_S_ISDIR(inode->i_mode) ? inode->i_dir_acl : 0,
                                                                                  ^~~~~~~~~
                                                                                  i_file_acl
inode.c:414:63: error: ‘struct ext2_inode’ has no member named ‘i_dir_acl’; did you mean ‘i_file_acl’?
                         LINUX_S_ISDIR(inode->i_mode) ? inode->i_dir_acl : 0);
                                                               ^~~~~~~~~
                                                               i_file_acl

And These error

ext4magic-0.3.2/src/recover.c:478: undefined reference to `makedev'
  • Add #include <sys/sysmacros.h> in src\recover.c by error undefined reference to `makedev'

Finally
make and successful

3. Mount mhdd.img

Since I use hyper-V to run linux, I need to push mhdd.img into linux. I try to qemu-img and some ISO creator and hope to mount by Hyper-V manager directly but failure to convert it into .vhdx and .iso, so I had to scp mhdd.img rhel:~/ finally.
In linux we reload loop module since the dozens number of partition in mhdd.img
(Thanks for https://unix.stackexchange.com/a/270183/275728 )

# modprobe -r loop
# modprobe loop max_part=30
# mount /dev/loop0p28 /mnt/mdata -oro

4. Scan it by ext4magic

./ext4magic /dev/loop0p28 -f /data

添加新评论