2
0

android-interact.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/bash
  2. # File: android-interact.sh
  3. PROG_NAME=`python -c "import os, sys; print(os.path.realpath(sys.argv[1]))" "$0"`
  4. PROG_DIR=`dirname "$PROG_NAME"`
  5. cd "$PROG_DIR"
  6. # Please check that your path is the same, since this might be different among devices
  7. # RES_DIR="/mnt/sdcard/tencent/MicroMsg" # old version of wechat use this path.
  8. RES_DIR="/data/data/com.tencent.mm/MicroMsg"
  9. if [[ $1 == "db" || $1 == "res" ]]; then
  10. echo "Looking for user dir name..."
  11. # look for dirname which looks like md5 (32 alpha-numeric chars)
  12. userList=$(adb shell su -c "ls $RES_DIR" | awk '{if (length() == 32) print}')
  13. numUser=$(echo "$userList" | wc -l)
  14. # choose the first user.
  15. chooseUser=$(echo "$userList" | head -n1)
  16. [[ -n $chooseUser ]] || {
  17. >&2 echo "Could not find user. Please check whether your resource dir is $RES_DIR"
  18. exit 1
  19. }
  20. echo "Found $numUser user(s). User chosen: $chooseUser"
  21. if [[ $1 == "res" ]]; then
  22. mkdir -p resource
  23. (
  24. cd resource || exit
  25. echo "Pulling resources... "
  26. for d in avatar image2 voice2 emoji video sfs; do
  27. echo "Trying to download $RES_DIR/$chooseUser/$d with busybox ..."
  28. adb shell su -c "busybox tar czf - $RES_DIR/$chooseUser/$d 2>/dev/null |
  29. busybox base64" | base64 -di | tar xzf - --strip-components 5
  30. [[ -d $d ]] && continue
  31. echo "Trying to download $RES_DIR/$chooseUser/$d with tar & base64 ..."
  32. adb shell su -c "tar czf - $RES_DIR/$chooseUser/$d 2>/dev/null | base64" |
  33. base64 -di | tar xzf - --strip-components 5
  34. [[ -d $d ]] && continue
  35. echo "Trying to download $RES_DIR/$chooseUser/$d with adb pull (slow) ..."
  36. mkdir -p $d
  37. (
  38. cd $d || exit
  39. adb root
  40. sleep 1 # sometimes adb complains: device not found
  41. adb pull "$RES_DIR/$chooseUser/$d"
  42. )
  43. [[ -d $d ]] || {
  44. echo "Failed to download $RES_DIR/$chooseUser/$d"
  45. }
  46. done
  47. echo "Resource pulled at ./resource"
  48. echo "Total size: $(du -sh | cut -f1)"
  49. )
  50. else
  51. for f in EnMicroMsg.db sfs/avatar.index; do
  52. echo "Trying to download $RES_DIR/$chooseUser/$f with busybox ..."
  53. adb shell su -c "busybox tar czf - $RES_DIR/$chooseUser/$f 2>/dev/null |
  54. busybox base64" | base64 -di | tar xzf - --strip-components 5
  55. [[ -f $f ]] && continue
  56. echo "Trying to download $RES_DIR/$chooseUser/$f with tar & base64 ..."
  57. adb shell su -c "tar czf - $RES_DIR/$chooseUser/$f 2>/dev/null | base64" |
  58. base64 -di | tar xzf - --strip-components 5
  59. [[ -f $f ]] && continue
  60. echo "Trying to download $RES_DIR/$chooseUser/$f with adb pull..."
  61. adb root
  62. sleep 1
  63. adb pull $RES_DIR/$chooseUser/$f
  64. [[ -f $f ]] || {
  65. echo "Failed to download $RES_DIR/$chooseUser/$f"
  66. }
  67. done
  68. echo "Database and avatar index file successfully downloaded"
  69. fi
  70. else
  71. echo "Usage: $0 <res|db>"
  72. exit 1
  73. fi