android-interact.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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"
  9. MM_DIR="/data/data/com.tencent.mm"
  10. echo "Starting rooted adb server..."
  11. adb root
  12. if [[ $1 == "db" || $1 == "res" ]]; then
  13. echo "Looking for user dir name..."
  14. sleep 1 # sometimes adb complains: device not found
  15. # look for dirname which looks like md5 (32 alpha-numeric chars)
  16. userList=$(adb ls $RES_DIR | cut -f 4 -d ' ' | sed 's/[^0-9a-z]//g' \
  17. | awk '{if (length() == 32) print}')
  18. numUser=$(echo "$userList" | wc -l)
  19. # choose the first user.
  20. chooseUser=$(echo "$userList" | head -n1)
  21. [[ -n $chooseUser ]] || {
  22. >&2 echo "Could not find user. Please check whether your resource dir is $RES_DIR"
  23. exit 1
  24. }
  25. echo "Found $numUser user(s). User chosen: $chooseUser"
  26. if [[ $1 == "res" ]]; then
  27. mkdir -p resource
  28. (
  29. cd resource || exit
  30. echo "Pulling resources... "
  31. for d in avatar image2 voice2 emoji video sfs; do
  32. echo "Trying to download $RES_DIR/$chooseUser/$d with busybox ..."
  33. adb shell "cd $RES_DIR/$chooseUser &&
  34. busybox tar czf - $d 2>/dev/null | busybox base64" |
  35. base64 -di | tar xzf -
  36. [[ -d $d ]] && continue
  37. echo "Trying to download $RES_DIR/$chooseUser/$d with tar & base64 ..."
  38. adb shell "cd $RES_DIR/$chooseUser &&
  39. tar czf - $d 2>/dev/null | base64" | base64 -di | tar xzf -
  40. [[ -d $d ]] && continue
  41. echo "Trying to download $RES_DIR/$chooseUser/$d with adb pull (slow) ..."
  42. mkdir -p $d
  43. (
  44. cd $d || exit
  45. adb pull "$RES_DIR/$chooseUser/$d"
  46. )
  47. [[ -d $d ]] || {
  48. echo "Failed to download $RES_DIR/$chooseUser/$d"
  49. }
  50. done
  51. echo "Resource pulled at ./resource"
  52. echo "Total size: $(du -sh | cut -f1)"
  53. )
  54. else
  55. echo "Pulling database and avatar index file..."
  56. adb pull $MM_DIR/MicroMsg/$chooseUser/EnMicroMsg.db
  57. [[ -f EnMicroMsg.db ]] && \
  58. echo "Database successfully downloaded to EnMicroMsg.db" || {
  59. >&2 echo "Failed to pull database by adb!"
  60. exit 1
  61. }
  62. adb pull $MM_DIR/MicroMsg/$chooseUser/sfs/avatar.index
  63. [[ -f avatar.index ]] && echo "Avatar index successfully downloaded to avatar.index"
  64. fi
  65. else
  66. echo "Usage: $0 <res|db>"
  67. exit 1
  68. fi