1
0

decrypt-db.sh 805 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash -e
  2. # File: decrypt-db.sh
  3. # Date: Tue Jun 16 22:23:13 2015 +0800
  4. source compatibility.sh
  5. MSGDB=$1
  6. imei=$2
  7. uin=$3
  8. output=decrypted.db
  9. if [[ -z "$1" || -z "$2" || -z "$3" ]]; then
  10. echo "Usage: $0 <path to EnMicroMsg.db> <imei> <uin>"
  11. exit 1
  12. fi
  13. if [[ -f $output ]]; then
  14. echo -n "$output already exists. removed? (y/n)"
  15. read r
  16. [[ $r == "y" ]] && rm -v $output || exit 1
  17. fi
  18. KEY=$(echo -n "$imei$uin" | $MD5SUM | cut -b 1-7)
  19. echo "KEY: $KEY"
  20. echo "Dump decrypted database... "
  21. # https://github.com/sqlcipher/sqlcipher/commit/e4b66d6cc8a2b7547a32ff2c3ac52f148eba3516
  22. sqlcipher "$MSGDB" << EOF
  23. PRAGMA key='$KEY';
  24. PRAGMA cipher_compatibility = 1;
  25. ATTACH DATABASE "$output" AS db KEY "";
  26. SELECT sqlcipher_export("db");
  27. DETACH DATABASE db;
  28. EOF
  29. echo "Database successfully dumped to $output"