Advertisement
metalx1000

Android ADB Print last 25 sms messages formatted

Jan 17th, 2025
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.69 KB | None | 0 0
  1. #!/system/bin/sh
  2. #####################################################################
  3. #Copyright (C) 2025  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation version 3 of the License.
  9.  
  10. #This program is distributed in the hope that it will be useful,
  11. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #GNU General Public License for more details.
  14.  
  15. #You should have received a copy of the GNU General Public License
  16. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17. ######################################################################
  18.  
  19. # This script will print your last 25 sms messages
  20. # although the number can be changed on the "head" line
  21. # it does need to look through all your messages
  22. # so the output might take a little while
  23. # also see https://pastebin.com/uYFB929z
  24.  
  25. echo "Loading Messages..."
  26.  
  27. projection="address:date_sent:body"
  28.  
  29. content query --uri content://sms/ --projection ${projection}|\
  30. tr "\n" "|"|\
  31. sed 's/|Row: [0-9]/\n/g'|\
  32. head -n 25|\
  33. tac|\
  34. sed 's/ address=/\nnumber=/g;s/, date_sent=/\ndate=/g;s/, body=/\n/g'|\
  35. tr "|" "\n"|while read line;do
  36.   if [[ $line == "date="* ]]; then
  37.     # Format Date
  38.     d=(${line//=/ })
  39.     date -d @${d[1]}
  40.   elif [[ $line == "number="* ]]; then
  41.     # Format Phone Number
  42.     number=(${line//+/ })
  43.     echo "${number[1]:1}" |sed "s/\([0-9]\{3\}\)\([0-9]\{3\}\)\([0-9]*\)/(\1)\2-\3/"
  44.   else
  45.     #Print Message
  46.     echo "$line"
  47.   fi
  48. done|sed 's/^Row: 0//' # clean up
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement