android-interact.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash -e
  2. # File: android-interact.sh
  3. # Date: Sun Feb 01 17:26:48 2015 +0800
  4. # Author: Yuxin Wu <[email protected]>
  5. source compatibility.sh
  6. PROG_NAME=`$REALPATH "$0"`
  7. PROG_DIR=`dirname "$PROG_NAME"`
  8. cd "$PROG_DIR"
  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. 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. echo "Failed to get imei. You can try other methods, or report a bug."
  27. exit 1
  28. }
  29. echo "Got imei: $imei"
  30. elif [[ $1 == "db" || $1 == "res" ]]; then
  31. echo "Looking for user dir name..."
  32. sleep 1 # sometimes adb complains: device not found
  33. userList=$(adb ls $RES_DIR | cut -f 4 -d ' ' \
  34. | awk '{if (length() == 32) print}')
  35. numUser=$(echo $userList | wc -l)
  36. # choose the first user.
  37. chooseUser=$(echo $userList | head -n1)
  38. [[ -n $chooseUser ]] || {
  39. echo "Could not find user. Please check whether your resource dir is $RES_DIR"
  40. exit 1
  41. }
  42. echo "Found $numUser user(s). User chosen: $chooseUser"
  43. if [[ $1 == "res" ]]; then
  44. echo "Pulling resources... this might take a long time..."
  45. mkdir -p resource; cd resource
  46. for d in image2 voice2 emoji avatar video; do
  47. mkdir -p $d; cd $d
  48. adb pull $RES_DIR/$chooseUser/$d
  49. cd ..
  50. [[ -d $d ]] || {
  51. echo "Failed to download resource directory: $RES_DIR/$chooseUser/$d"
  52. exit 1
  53. }
  54. done
  55. cd ..
  56. echo "Resource pulled at ./resource"
  57. echo "Total size: $(du -sh resource | cut -f1)"
  58. else
  59. echo "Pulling database file..."
  60. adb pull $MM_DIR/MicroMsg/$chooseUser/EnMicroMsg.db
  61. [[ -f EnMicroMsg.db ]] && \
  62. echo "File successfully downloaded to EnMicroMsg.db" || {
  63. echo "Failed to pull database from adb"
  64. exit 1
  65. }
  66. fi
  67. elif [[ $1 == "db_decrypt" ]]; then
  68. echo "Getting uin..."
  69. $0 uin | tail -n1 | grep -o '[0-9]*' | tee /tmp/uin
  70. echo "Getting imei..."
  71. $0 imei | tail -n1 | grep -o '[0-9]*' | tee /tmp/imei
  72. echo "Getting db..."
  73. $0 db
  74. echo "Decrypting db..."
  75. ./decrypt_db.sh EnMicroMsg.db $(</tmp/imei) $(</tmp/uin)
  76. rm /tmp/{uin,imei}
  77. echo "Done. See decoded.db"
  78. else
  79. echo "Usage: $0 <res|db_decrypt>"
  80. exit 1
  81. fi