понеделник, 5 декември 2016 г.

How to root Xperia X8 trough Linux and export mmssms.db

To backup the sms from my old phone, it turned out I have to first root it. Which I never did for unknown reasons. Anyway, because my ex-phone is with some ridiculously old Android (not even Gingerbread), I had to root it in the konsole adb way. I found this great tutorial how to do it.
1. Download SuperOneClickv2.3.3-ShortFuse.zip and extract it to a folder
2. Cd into SuperOneClickv2.3.3-ShortFuse/
3. Turn on USB Debugging mode (Settings --> Applications --> Development --> USB Debugging)
4. Unmount the SD Card (Settings --> SD Card --> Unmount SD Card)
5. Connect your phone to the computer using the USB lead, when the phone asks chose "Charge Phone".
6. Go to your konsole (BASH):
Execute the following commands:
$adb push Exploits/psneuter /data/local/tmp/psneuter
$adb push Root/su-v2 /data/local/tmp/su                      
$adb push Root/Superuser.apk /data/local/tmp/superuser.apk
$adb shell
$cd /data/local/tmp
$chmod 755 psneuter
.$/psneuter

$adb shell
$cd /data/local/tmp
$mount -o remount,rw -t yaffs2 /dev/block/mtdblock0 /system
$cat su > /system/bin/su
$cat superuser.apk > /system/app/superuser.apk
$chmod 06777 /system/bin/su
$chmod 777 /system/app/superuser.apk
$reboot

Then you should have "su" on your phone. You can test this by typing:
$adb shell
$su
If you don't get an error, you're good to go. If you get an error, get to the link above and see possible solutions.

Then on to copying your text messages.
You need the following file: /data/data/com.android.providers.telephony/databases/mmssms.db
 I tried pulling it as it is, but I got permission error.
So what I did is the following:
$adb shell
$su
$chmod 777 /data/data/com.android.providers.telephony/databases/mmssms.db
$exit
$cd ~/Downloads
$adb pull /data/data/com.android.providers.telephony/databases/mmssms.db
And the file was in ~/Downloads.
To import this file to your new phone, you need to do:
$adb push mmssms.db /data/data/com.android.providers.telephony/databases/
Obviously, your new phone will have to be rooted, which is somewhat inconvenient if your phone is brand new. But in principle you can.
This is a database file. You can play with it using sqlite. For example: 
$sqlite3 -header mmssms.db 'select address from sms' | sort -n | uniq -c | sort -n
will tell you who is the person you communicated with the most.
$sqlite3 mmssms.db
$ SELECT * FROM sms WHERE read=1;
will show you all the read messages and read=0 will show you the unread messages.
The same funtion without entering sqlite
$ echo 'select address,body from sms;' | sqlite3 -csv mmssms.db
If you want to, you can export them to a file (db.txt) with:
$echo 'select address,body from sms;' | sqlite3 -csv mmssms.db >> dx.txt
Then you can replace all the phones with names and happily read your sms.