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

Use Recipient instead of Address (Signal v4.48.0 breaking change) #64

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func ExtractAttachments(bf *types.BackupFile) error {

ps := f.GetStatement().GetParameters()
if len(ps) == 25 { // Contains blob information
aEncs[*ps[19].IntegerParameter] = *ps[3].StringParamter
aEncs[*ps[19].IntegerParameter] = *ps[3].StringParameter
log.Printf("found attachment metadata %v: `%v`\n", *ps[19].IntegerParameter, ps)
}

Expand Down
58 changes: 57 additions & 1 deletion cmd/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"log"
"os"
"runtime/debug"
"strconv"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -92,9 +93,18 @@ func JSON(bf *types.BackupFile, out io.Writer) error {
// CSV dumps the raw backup data into a comma-separated value format.
func CSV(bf *types.BackupFile, message string, out io.Writer) error {
ss := make([][]string, 0)
recipients := map[uint64]types.Recipient{}

fns := types.ConsumeFuncs{
StatementFunc: func(s *signal.SqlStatement) error {
if strings.HasPrefix(*s.Statement, "INSERT INTO recipient") {
id, recipient, err := types.NewRecipientFromStatement(s)
if err != nil {
return errors.Wrap(err, "recipîent statement couldn't be generated")
}
recipients[id] = *recipient
}

if (*s.Statement)[:15] == "INSERT INTO "+message {
ss = append(ss, types.StatementToStringArray(s))
}
Expand All @@ -106,6 +116,28 @@ func CSV(bf *types.BackupFile, message string, out io.Writer) error {
return err
}

SMSFieldsCount := len(types.SMSCSVHeaders)
MMSFieldsCount := len(types.MMSCSVHeaders)

for id, line := range ss {
var addressFieldIndex int
if len(line) == SMSFieldsCount {
addressFieldIndex = 2
} else if len(line) == MMSFieldsCount {
addressFieldIndex = 13
} else {
continue
}

recipientID, err := strconv.ParseUint(line[addressFieldIndex], 10, 64)
if err != nil {
panic(err)
}
phone := recipients[recipientID].Phone

ss[id][addressFieldIndex] = phone
}

w := csv.NewWriter(out)
var headers []string
if message == "mms" {
Expand Down Expand Up @@ -141,6 +173,7 @@ func XML(bf *types.BackupFile, out io.Writer) error {
var attachmentBuffer bytes.Buffer
attachmentEncoder := base64.NewEncoder(base64.StdEncoding, &attachmentBuffer)
attachments := map[uint64]attachmentDetails{}
recipients := map[uint64]types.Recipient{}
smses := &types.SMSes{}
mmses := map[uint64]types.MMS{}
mmsParts := map[uint64][]types.MMSPart{}
Expand Down Expand Up @@ -171,7 +204,15 @@ func XML(bf *types.BackupFile, out io.Writer) error {
}
}()

// Only use SMS/MMS statements
// Only use SMS/MMS/recipient statements
if strings.HasPrefix(*s.Statement, "INSERT INTO recipient") {
id, recipient, err := types.NewRecipientFromStatement(s)
if err != nil {
return errors.Wrap(err, "recipîent statement couldn't be generated")
}
recipients[id] = *recipient
}

if strings.HasPrefix(*s.Statement, "INSERT INTO sms") {
sms, err := types.NewSMSFromStatement(s)
if err != nil {
Expand Down Expand Up @@ -251,6 +292,21 @@ func XML(bf *types.BackupFile, out io.Writer) error {
smses.MMS = append(smses.MMS, mms)
}

for id, sms := range smses.SMS {
recipientID, err := strconv.ParseUint(sms.RecipientID, 10, 64)
if err != nil {
panic(err)
}
smses.SMS[id].Address = recipients[recipientID].Phone
}
for id, mms := range smses.MMS {
recipientID, err := strconv.ParseUint(mms.RecipientID, 10, 64)
if err != nil {
panic(err)
}
smses.MMS[id].Address = recipients[recipientID].Phone
}

smses.Count = len(smses.SMS)
x, err := xml.MarshalIndent(smses, "", " ")
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions signal/Backups.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion signal/Backups.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ option java_outer_classname = "BackupProtos";

message SqlStatement {
message SqlParameter {
optional string stringParamter = 1;
optional string stringParameter = 1;
optional uint64 integerParameter = 2;
optional double doubleParameter = 3;
optional bytes blobParameter = 4;
Expand Down
Loading