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

Exported messages don't have phone numbers? #67

Open
TotalBan opened this issue Nov 12, 2019 · 18 comments
Open

Exported messages don't have phone numbers? #67

TotalBan opened this issue Nov 12, 2019 · 18 comments

Comments

@TotalBan
Copy link

  • Operating system: Windows 10
  • Build version (signal-back --version): signal-back v0.1.7-alpha.2, proto commit: d6610f0

Detailed description

The exported messages have obfuscated IDs (i.e. "address="44" instead of "address="+5555555555") is this intentional? I can edit the XML file myself, but it's tough to sell that much effort to someone else.

@rumzie
Copy link

rumzie commented Nov 14, 2019

I am experiencing the same issue. All formats of export result in the phone numbers being a few characters long, even when restored through SMS Backup and Restore.

I remember this not happening in the past, as I've successfully restored messages before. Currently, I am unable to restore messages with the correct phone numbers.

@pallu
Copy link

pallu commented Nov 15, 2019

Same issue

@AlexHarn
Copy link

I am pretty sure this is not an issue for this repository. I have a feeling Signal does this on purpose to make the message import into other apps harder and I am very upset about it. The 3 digit numbers are Signals internal ID for the contacts, it internally links them to your phone contacts and as far as I know there is no way of accessing that mapping table.

So to get around this you have to manually match all your contacts to the IDs and replace them in the converted backup before importing it into the SMS backup app, which is incredibly tedious but I don't see a way around it. The best way to do this is simply to create some text file where you map numbers with IDs and then just run a Python script over the converted backup xml to to the replaceing.

@AlexHarn
Copy link

AlexHarn commented Nov 16, 2019

Okay I just finished doing this for myself, so for anyone who wants to do this as well: Just create a text file named "contact_map.txt" that has the following format for each line:

signal_id,name,phone_number

The name isn't really necessary, I just used it for my own book keeping while figuring out which signal ID corresponds to which of my contacts.

Then use the following python script to update all the numbers:

import numpy as np

contacts = np.loadtxt('contact_map.txt', delimiter=',', dtype='str')

with open('raw_backup.xml', 'r') as file:
    filedata = file.read()

for contact in contacts:
    filedata = filedata.replace('address="{}"'.format(contact[0]),
                                'address="{}"'.format(contact[2]))

with open('converted_backup.xml', 'w') as file:
    file.write(filedata)

@pallu
Copy link

pallu commented Nov 16, 2019

Wow! Thanks a ton.

@bmlong1956
Copy link

Could you explain what program you're using in order to accomplish the task above. I understand creating the .txt file but what would be used for the xml file and running the script.

@AlexHarn
Copy link

AlexHarn commented Dec 2, 2019

Could you explain what program you're using in order to accomplish the task above. I understand creating the .txt file but what would be used for the xml file and running the script.

What I call the 'raw_backup.xml' in my script is the original converted xml output of the Signal app after decryption which contains the IDs instead of phone numbers (that's the corrupt one, if you import that one into the SMS app it shows the IDs instead of phone numbers). So in that XML file each message has a tag called 'address' which contains the ID and you want to replace each of those with the phone number instead so Android's Messages app can link it to your contacts after importing.

You could use really any text replace tool, I just use Python because it's super simple. So you need to have a Python installation on your system, then just make sure the xml and .txt file are in the same directory you're executing your script from and it should create the file 'converted_backup.xml' in the same directory. That file has the same content as the 'raw_backup.xml' except that all address fields have now the correct phone number in them and not the internal Signal IDs.

@Kingwad
Copy link

Kingwad commented Dec 19, 2019

The internal database of signal (and as a result, the backup of that database) is under active development, while signal-back has not been modified in over a year. These compatibility drifts are inevitable.

Check out the fork at https://github.com/maximeborges/signal-back for a possible fix

@ghost
Copy link

ghost commented Jan 6, 2020

Okay I just finished doing this for myself, so for anyone who wants to do this as well: Just create a text file named "contact_map.txt" that has the following format for each line:

signal_id,name,phone_number

The name isn't really necessary, I just used it for my own book keeping while figuring out which signal ID corresponds to which of my contacts.

Then use the following python script to update all the numbers:

import numpy as np

contacts = np.loadtxt('contact_map.txt', delimiter=',', dtype='str')

with open('raw_backup.xml', 'r') as file:
    filedata = file.read()

for contact in contacts:
    filedata = filedata.replace('address="{}"'.format(contact[0]),
                                'address="{}"'.format(contact[2]))

with open('converted_backup.xml', 'w') as file:
    file.write(filedata)

Traceback (most recent call last):
File "D:\Koofr\My desktop sync\signalback\pythonscript.py", line 6, in
filedata = file.read()
File "C:\Program Files\Python38\lib\encodings\cp1250.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 3538: character maps to

Using 64-bit Python 3.8.1.

@ghost
Copy link

ghost commented Jan 6, 2020

Okay I just finished doing this for myself, so for anyone who wants to do this as well: Just create a text file named "contact_map.txt" that has the following format for each line:

signal_id,name,phone_number

I don't understand this part.
How do you mean "for each line"? Can you show a parto of text/code?

@ghost
Copy link

ghost commented Jan 6, 2020

UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 3538: character maps to

Using 64-bit Python 3.8.1.

Later I added:

encoding = "UTF-8"
errors = "ignore"

But it doesn't solve the problem, just makes it "prettier"...

@AlexHarn
Copy link

AlexHarn commented Jan 6, 2020

The issue doesn't lie in the code, it is most likely your text file. I just made it a blank text file and I don't even know which encoding but I'd guess my vim used UTF-8, it shouldn't really matter. Since you are using Windows things might be weird. Just try Microsoft's Notepad as an editor to create the file. As an example, the file content should look something like this:

123,John,1112223333
456,Emily,4445556666
and so on, one line for each contact.

But like I said (and as you can see in the code I posted) the name is totally irrelevant, I just added it in my file so I know which line belongs to which contact since I have a very bad memory. Only the signal ID (first column) and phone number (third column) are actually used by the script.

All the script does is replace each occurrence of the signal ID in the address fields of the XML file with the phone number, you could also just use a text editor or regular expressions or whatever to do the search and replace, for me the python script was just the lowest effort solution.

@ghost
Copy link

ghost commented Jan 6, 2020

Hi,

thanks for the answer. :-)

Sure, I could just ignore the Python-based solution, but it was (is) a good excuse/reason to start playing with Python again. ;-)

I didn't even use my .txt file yet. (It was made with Notepad and saved with UTF-8 coding support.)

Br. c",)

@AlexHarn
Copy link

AlexHarn commented Jan 7, 2020

You're welcome :)

Ah I see. I don't know enough about Windows but I do know that there can be issues with encoding of scripts and the python runtime. It seems to me like your python runtime environment doesn't like the encoding of the script. Try to create a fresh txt file and raw paste the script in there (or even type it) and make sure it's consistent with spaces instead of tabs etc. I think Linux and Windows also use different new line characters and I pasted the script from Linux. Don't know what actually ends up in your file after copy & pasting it from GitHub but obviously some character is in there that your runtime doesn't like.

@ajayyy
Copy link

ajayyy commented Jan 13, 2020

@Kingwad The fork made an XML with zero messages sadly.

@CingularIT
Copy link

For those who found their way here - I'd suggest checking out the following: https://github.com/johanw666/Signal-Android - Allowed me to quickly export my messages and re-import them to my stock messages app using SMS Backup and Restore with contact info intact.

-Uninstall Signal
-Install an APK from Above
-Launch the Signal replacement and restore your encrypted backup when prompted
-From the Signal replacement menu --> Export plaintext backup
-Restore the data from the above export using SMS Backup and Restore.

@ajayyy
Copy link

ajayyy commented Feb 12, 2020

@CingularIT Thank you so much for this link. I was planning on doing this myself (make a fork) but never got the time. I didn't realize it had already been done.

@troennes
Copy link

I used another tool to get phone numbers. With https://github.com/pajowu/signal-backup-decode you can get the whole, decrypted Sqlite database. Messages and contacts are in different tables, but can be listed together with a join between the sms/mms and recipient table.

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

No branches or pull requests

9 participants