android-interact.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/bash
  2. # File: android-interact.sh
  3. # Date: Fri Jun 26 10:38:07 2015 +0800
  4. # Author: Yuxin Wu <ppwwyyxxc@gmail.com>
  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, 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. userList=$(adb ls $RES_DIR | cut -f 4 -d ' ' \
  37. | awk '{if (length() == 32) print}')
  38. numUser=$(echo $userList | wc -l)
  39. # choose the first user.
  40. chooseUser=$(echo $userList | head -n1)
  41. [[ -n $chooseUser ]] || {
  42. >&2 echo "Could not find user. Please check whether your resource dir is $RES_DIR"
  43. exit 1
  44. }
  45. echo "Found $numUser user(s). User chosen: $chooseUser"
  46. if [[ $1 == "res" ]]; then
  47. echo "Pulling resources... this might take a long time, because adb sucks..."
  48. mkdir -p resource; cd resource
  49. for d in image2 voice2 emoji video sfs; do
  50. mkdir -p $d; cd $d
  51. adb pull $RES_DIR/$chooseUser/$d
  52. cd ..
  53. [[ -d $d ]] || {
  54. >&2 echo "Failed to download resource directory: $RES_DIR/$chooseUser/$d"
  55. exit 1
  56. }
  57. done
  58. cd ..
  59. echo "Resource pulled at ./resource"
  60. echo "Total size: $(du -sh resource | cut -f1)"
  61. else
  62. echo "Pulling database and avatar index file..."
  63. adb pull $MM_DIR/MicroMsg/$chooseUser/EnMicroMsg.db
  64. [[ -f EnMicroMsg.db ]] && \
  65. echo "Database successfully downloaded to EnMicroMsg.db" || {
  66. >&2 echo "Failed to pull database by adb"
  67. exit 1
  68. }
  69. adb pull $MM_DIR/MicroMsg/$chooseUser/sfs/avatar.index
  70. [[ -f avatar.index ]] && \
  71. echo "Avatar index successfully downloaded to avatar.index" || {
  72. >&2 echo "Failed to pull avatar index by adb, are you using latest version of wechat?"
  73. exit 1
  74. }
  75. fi
  76. elif [[ $1 == "db-decrypt" ]]; then
  77. echo "Getting uin..."
  78. $0 uin | tail -n1 | $GREP -o '\-?[0-9]*' | tee /tmp/uin
  79. echo "Getting imei..."
  80. $0 imei | tail -n1 | $GREP -o '[0-9]*' | tee /tmp/imei
  81. echo "Getting db..."
  82. $0 db
  83. echo "Decrypting db..."
  84. imei=$(cat /tmp/imei)
  85. uin=$(cat /tmp/uin)
  86. if [[ -z $imei || -z $uin ]]; then
  87. >&2 echo "Failed to get imei or uin. See README for manual methods."
  88. exit 1
  89. fi
  90. ./decrypt-db.py EnMicroMsg.db $imei $uin
  91. rm /tmp/{uin,imei}
  92. echo "Done. See decrypted.db"
  93. else
  94. echo "Usage: $0 <res|db-decrypt>"
  95. exit 1
  96. fi