android-interact.sh 2.4 KB

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