Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode encoding for sms #14

Open
FilLupin opened this issue Sep 26, 2014 · 12 comments
Open

Unicode encoding for sms #14

FilLupin opened this issue Sep 26, 2014 · 12 comments
Assignees
Labels

Comments

@FilLupin
Copy link

Hi,
thank you first for your script, a script like this one should be very helpfull to me.

Trying to convert my ios6 sms.db to android, I get this output when I launch "./bin/smstools --type android sms.db mmssms.db" :

Traceback (most recent call last):
File "./bin/smstools", line 59, in
print " " + term.blue(smstools.truncate(new_texts[-1].body))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 42: ordinal not in range(128)

Some sms contains french characters like accents.

@t413 t413 self-assigned this Sep 26, 2014
@t413 t413 added the bug label Sep 26, 2014
@FilLupin
Copy link
Author

Because it is some unicode issue, some .encode("utf-8") should solve this.
After looking into the code, it seems, in addition to changing line 59 of ./bin/smstools into

print " " + term.blue(smstools.truncate(new_texts[-1].body.encode("utf-8")))
texts.extend(new_texts)

we should change line 25 of ./smstools/android.py into

txt = core.Text(num=row[0],date=long(row[1]),incoming=(row[2]==2),body=row[3].encode("utf-8")).
I make some tries but I do not know very well the android database format so I am not sure how to interpret my results...

@t413
Copy link
Owner

t413 commented Sep 26, 2014

It looks like from your error that the problem is actually with the debug printing to the terminal. Try taking out File "./bin/smstools", line 59 all together and running it again.

@FilLupin
Copy link
Author

Yes, this is another solution, but I think the first part of my solution will keep the informations of your script which is interesting because it allows to check that the script tooks into account the last sms.
I am not sure about the whole script is ok with this only modification because I did not succed to push my sms into my replicant encrypted phone, I am now looking for the exact way to do this.
Thanks anyway for your answer and your script.

@FilLupin
Copy link
Author

Up because I noted that my messages have been hidden before by github.

@FilLupin
Copy link
Author

Perhaps is it due to mmssms.db-journal which is included into the basic android (without any sms) and not generated by the script...

@FilLupin
Copy link
Author

FilLupin commented Dec 4, 2014

I think I understand (one of) the issue(s) : a date_sent field should exist in tables sms and pdu (it exists in empty mmssms.db files but not into the files generated by the smstools script).

@t413
Copy link
Owner

t413 commented Dec 4, 2014

Can you test to see if including that column in the database will make the phone happy? I don't have any working android phones at the moment.

@FilLupin
Copy link
Author

FilLupin commented Dec 5, 2014

Yes, I tried to understand where SQL request on pdu and sms tables have to be modified.
I have done some modifications (creation/insertion/update of same content into fields date and date_sent) but they does not seem to actually succeed, generated pdu and sms tables do not include date_sent fields, probably because I am not sufficiently expert in python language.

@FilLupin FilLupin closed this as completed Dec 5, 2014
@FilLupin
Copy link
Author

FilLupin commented Dec 6, 2014

mmssms.db does not seems to be accepted by android, even by adding date_sent fields to sms and pdu tables. Generated structure seems to be consistent with initial db given with my phone (it seems to depends on the phone http://az4n6.blogspot.de/2013/02/finding-and-reverse-engineering-deleted_1865.html).

Perhaps is it because only some tables (android_metadata, sms,threads, and canonical_addresses) are populated...
Do you have any doc of the android and ios db structure ?

@FilLupin FilLupin reopened this Dec 6, 2014
@FilLupin
Copy link
Author

FilLupin commented Dec 9, 2014

I can push my modifications if you want, but they do not allow the mmssms.db generated to be recognized, just let me know...

@fyears
Copy link

fyears commented Jan 25, 2015

Maybe I have similar issue. I have some international text, a.k.a non ascii characters in my messages.

After I try smstools --type json ios-sms.db output.json, I got something like:

[
    {
        "body": "\u041b",
        "chatroom": null, 
        "date": 12345, 
        "incoming": true, 
        "members": null, 
        "num": "+11234567890"
    }
]

which is python-specific (and incorrect).

I suggest saving all the non ascii characters as UTF-8, like this:

[
    {
        "body": "Л",
        "chatroom": null, 
        "date": 12345, 
        "incoming": true, 
        "members": null, 
        "num": "+11234567890"
    }
]

@varunpalekar
Copy link

Just add below lines in starting of smstools main file basically at /usr/local/bin/smstools:

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants