-
Notifications
You must be signed in to change notification settings - Fork 0
/
android-sms
executable file
·77 lines (60 loc) · 1.32 KB
/
android-sms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
_usage() {
echo "
Usage:
android-sms [-a]
Options:
-a Show read messages.
-l Show only last message.
"
}
_main() {
arg_all=false
arg_last=false
while getopts al ARG; do
case "$ARG" in
a)
arg_all=true
;;
l)
arg_last=true
;;
\?)
_usage
exit 0
;;
esac
done
_list $arg_all $arg_last
}
_list() {
local arg_all=$1
local arg_last=$2
local FILE=/data/data/com.android.providers.telephony/databases/mmssms.db
local QUERY="
select
'{BEGIN}', address, '{|}', body, '{END}'
from sms
"
if ! $arg_all; then
QUERY="$QUERY"$'\n'"WHERE read=0"
fi
if $arg_last; then
QUERY="$QUERY"$'\n'"ORDER BY date DESC LIMIT 1"
fi
local CMDLINE=
read -r -d '' CMDLINE <<CMDLINE
echo "$QUERY;" | su root sqlite3 -csv "$FILE"
CMDLINE
local SMS=$(
adb -d shell "$CMDLINE" \
| sed 's/{BEGIN},/{"address": "/g' \
| sed 's/,{|},/", "body": /g' \
| sed 's/,{END}/},/g' \
| tr -d '\r' \
| tr '\n' ' ' \
| sed 's/, $//' # prevent expecting another array element
)
echo "[$SMS]"
}
_main $@