android-interact.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/bash
  2. # File: android-interact.sh
  3. # Date: Wed Nov 29 02:19:00 2017 -0800
  4. # Author: Yuxin Wu <[email protected]>
  5. PROG_NAME=`python -c "import os, sys; print(os.path.realpath(sys.argv[1]))" "$0"`
  6. PROG_DIR=`dirname "$PROG_NAME"`
  7. cd "$PROG_DIR"
  8. source compatibility.sh
  9. # Please check that your path is the same, since this might be different among devices
  10. RES_DIR="/mnt/sdcard/tencent/MicroMsg"
  11. MM_DIR="/data/data/com.tencent.mm"
  12. echo "Starting rooted adb server..."
  13. adb root
  14. if [[ $1 == "uin" ]]; then
  15. adb pull $MM_DIR/shared_prefs/system_config_prefs.xml 2>/dev/null
  16. uin=$($GREP 'default_uin' system_config_prefs.xml | $GREP -o 'value=\"\-?[0-9]*' | cut -c 8-)
  17. [[ -n $uin ]] || {
  18. >&2 echo "Failed to get wechat uin. You can try other methods, or report a bug."
  19. exit 1
  20. }
  21. rm system_config_prefs.xml
  22. echo "Got wechat uin: $uin"
  23. elif [[ $1 == "imei" ]]; then
  24. imei=$(adb shell dumpsys iphonesubinfo | $GREP 'Device ID' | $GREP -o '[0-9]+')
  25. [[ -n $imei ]] || {
  26. imei=$(adb shell service call iphonesubinfo 1 | awk -F "'" '{print $2}' | sed 's/[^0-9A-F]*//g' | tr -d '\n')
  27. }
  28. [[ -n $imei ]] || {
  29. >&2 echo "Failed to get imei. You can try other methods mentioned in README, or report a bug."
  30. exit 1
  31. }
  32. echo "Got imei: $imei"
  33. elif [[ $1 == "db" || $1 == "res" ]]; then
  34. echo "Looking for user dir name..."
  35. sleep 1 # sometimes adb complains: device not found
  36. # look for dirname which looks like md5 (32 alpha-numeric chars)
  37. userList=$(adb ls $RES_DIR | cut -f 4 -d ' ' | sed 's/[^0-9a-z]//g' \
  38. | awk '{if (length() == 32) print}')
  39. numUser=$(echo "$userList" | wc -l)
  40. # choose the first user.
  41. chooseUser=$(echo "$userList" | head -n1)
  42. [[ -n $chooseUser ]] || {
  43. >&2 echo "Could not find user. Please check whether your resource dir is $RES_DIR"
  44. exit 1
  45. }
  46. echo "Found $numUser user(s). User chosen: $chooseUser"
  47. if [[ $1 == "res" ]]; then
  48. mkdir -p resource; cd resource
  49. echo "Pulling resources... "
  50. for d in avatar image2 voice2 emoji video sfs; do
  51. adb shell "cd $RES_DIR/$chooseUser &&
  52. busybox tar czf - $d 2>/dev/null | busybox base64" |
  53. base64 -di | tar xzf -
  54. # Old Slow Way:
  55. # mkdir -p $d; cd $d
  56. # adb pull "$RES_DIR/$chooseUser/$d"
  57. # cd ..
  58. [[ -d $d ]] || {
  59. >&2 echo "Failed to download resource directory: $RES_DIR/$chooseUser/$d"
  60. exit 1
  61. }
  62. done
  63. cd ..
  64. echo "Resource pulled at ./resource"
  65. echo "Total size: $(du -sh resource | cut -f1)"
  66. else
  67. echo "Pulling database and avatar index file..."
  68. adb pull $MM_DIR/MicroMsg/$chooseUser/EnMicroMsg.db
  69. [[ -f EnMicroMsg.db ]] && \
  70. echo "Database successfully downloaded to EnMicroMsg.db" || {
  71. >&2 echo "Failed to pull database by adb"
  72. exit 1
  73. }
  74. adb pull $MM_DIR/MicroMsg/$chooseUser/sfs/avatar.index
  75. [[ -f avatar.index ]] && \
  76. echo "Avatar index successfully downloaded to avatar.index" || {
  77. >&2 echo "Failed to pull avatar index by adb, are you using latest version of wechat?"
  78. exit 1
  79. }
  80. fi
  81. elif [[ $1 == "db-decrypt" ]]; then
  82. set -e
  83. echo "Getting uin..."
  84. $0 uin | tail -n1 | $GREP -o '\-?[0-9]*' | tee /tmp/uin
  85. echo "Getting imei..."
  86. $0 imei | tail -n1 | $GREP -o '[0-9]*' | tee /tmp/imei
  87. echo "Getting db..."
  88. $0 db
  89. echo "Decrypting db..."
  90. imei=$(cat /tmp/imei)
  91. uin=$(cat /tmp/uin)
  92. if [[ -z $imei || -z $uin ]]; then
  93. >&2 echo "Failed to get imei or uin. See README for manual methods."
  94. exit 1
  95. fi
  96. ./decrypt-db.py EnMicroMsg.db $imei $uin
  97. rm /tmp/{uin,imei}
  98. echo "Done. See decoded.db"
  99. else
  100. echo "Usage: $0 <res|db-decrypt>"
  101. exit 1
  102. fi