L'ensemble des outils de ce scripts sont des outils GNU. Ils peuvent être installé sur n'importe quel système Unix/Linux, ce script opensource (WTF licence) est donc facilement adaptable pour votre environnement. Il utilise sqlite3 pour extraire les SMS sauvegardés lors d'une synchronisation avec iTunes.
0x01. PRESENTATION
Usage: sms.iphone [-p phonenumber|-n 'firstname lastname'|-n 'firstname'|-n 'lastname'] Script will read in iTunes backup for messages.
0x02. LE SCRIPT
Petite astuce pour les couleurs, définissons des variables avec le nom de chaque couleur.
#!/bin/zsh APPNAME="$(basename $0)" APPDIR="$(echo $0|sed "s/\\/$APPNAME$//1")" APPRS="$APPDIR/../Resources" INFOPLIST="$APPDIR/../Info.plist" #log=/tmp/$APPNAME.log log=/dev/null # do not make log echo $RANDOM" - "$(date) > $log echo >> $log ls "$APPDIR/$APPNAME" >> $log ls -d "$APPDIR" >> $log ls -d "$APPRS" >> $log ls "$INFOPLIST" >> $log echo >> $log env >> $log echo >> $log # open APP.app --args -arg1 -arg2 val1 echo $* >> $log echo >> $log ## ## TODO: write your code here ## msgbox() { if [ $# -eq 3 ]; then cat << EOD |osascript tell application "Finder" display dialog "$1" buttons {"$2","$3"} end tell EOD fi if [ $# -eq 2 ]; then cat << EOD |osascript tell application "Finder" display dialog "$1" buttons {"$2"} end tell EOD fi if [ $# -eq 1 ]; then cat << EOD |osascript tell application "Finder" display dialog "$1" end tell EOD fi } s=0 FOLDBKP="$HOME/Library/Application Support/MobileSync/Backup/" cd "$FOLDBKP" LASTBKP=$(find . -maxdepth 1|egrep -v "^\\.$|\\-"|sed 's/^\\.\\///1') cd $OLDPWD SMS_DBFILE="$FOLDBKP/$LASTBKP/3d0d7e5fb2ce288813306e4d4636395e047a3d28" ADR_DBFILE="$FOLDBKP/$LASTBKP/31bb7ba8914766d4ba40d6dfb6113c8b614be442" SMS_CSVFILE="/tmp/sms.csv" ADR_CSVFILE="/tmp/adr.csv" SMS_EXPORT="$HOME/Desktop/SMS.$(date +"%d-%m-%y_@_%H:%M").txt" MAXWIDTH="100" if [ ! -f "$SMS_DBFILE" ] then msgbox "Fichier de SMS non trouvé : '$SMS_DBFILE'" "Terminer." echo ls "$SMS_DBFILE" exit 1 fi if [ ! -f "$ADR_DBFILE" ] then msgbox "Fichier de carnet d'adresse non trouvé : '$ADR_DBFILE'" "Terminer." echo ls "$ADR_DBFILE" exit 1 fi echo "select c.chat_identifier,datetime(date+978307200,'unixepoch','localtime'),m.date_read ,replace(m.text,\\"\\n\\",\\" \\") from message m,chat_message_join cmj,chat c WHERE m.ROWID = cmj.message_id AND cmj.chat_id = c.ROWID ORDER BY m.date;"|\\ sqlite3 "$SMS_DBFILE" > "$SMS_CSVFILE" echo "SELECT b.first,b.last,b.organization,d.value FROM ABMultiValue d, ABPerson b WHERE b.ROWID = d.record_id AND d.property LIKE '3' AND ( d.value LIKE '06%' OR d.value LIKE '+%') ORDER BY d.record_id;" \\ |sqlite3 -batch "$ADR_DBFILE" \\ |sed -E 's/\\|/;/g;s/([0-9]) /\\1/g;s/06/+336/1' > "$ADR_CSVFILE" while read contact; do firstname=$(echo "$contact"|cut -d';' -f1); lastname=$(echo "$contact"|cut -d';' -f2|tr "a-z" "A-Z") organization=$(echo "$contact"|cut -d';' -f3) [ ! -z "$organization" ] && organization="/ "$organization telnumber=$(echo "$contact"|cut -d';' -f4) title="$firstname $lastname $organization : $telnumber" msg=$(grep "$telnumber" "$SMS_CSVFILE"|cut -d'|' -f2,3,4|sed -E 's/\\|0\\|/ > /g;s/(.$)/\\1/1;s/\\|.........\\|/ < /1') ok=0 if [ $# -eq 2 ]; then if [ "$1" = "-n" ]; then echo "$2"|grep -i "$firstname $lastname" >/dev/null 2>&1 ; e=$? [ $e -ne 0 ] && echo "$2"|grep -i "$lastname" >/dev/null 2>&1 ; e=$? [ $e -ne 0 ] && echo "$2"|grep -i "$firstname" >/dev/null 2>&1 ; e=$? if [ $e -ne 0 ] ; then continue else ok=1 fi fi if [ "$1" = "-p" ]; then if [ "$2" != "$telnumber" ]; then continue else ok=1 fi fi fi if [ ! -z "$msg" ]; then echo echo "$title" for i in $(seq 1 ${#title}); do printf "�" ; done printf "\\n\\n" printf "$msg\\n" for i in $(seq 1 $MAXWIDTH); do printf "=" ; done printf "\\n\\n\\n" [ "$ok" = "1" ] && exit fi done < "$ADR_CSVFILE" > "$SMS_EXPORT" open "$SMS_EXPORT" rm -fv "$ADR_CSVFILE" rm -fv "$SMS_CSVFILE"
=> Écrit par : Nicolas, le 21 juillet 2015