Skip to content

Commit

Permalink
Allow compiling with older gcc versions + update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
bepaald committed Jul 31, 2020
1 parent 1e32842 commit fbea5b1
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 20 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ Tool to work with backup files generated by the Signal android application (http
### Requirements

Current stable released versions of
- a c++ compiler (tested with [GCC](https://gcc.gnu.org) 9.2.0 and [Clang](https://clang.llvm.org) 9.0.0)
- [OpenSSL](https://www.openssl.org/) (tested with 1.1.1d) _or_ [Crypto++](https://www.cryptopp.com/) (tested with 8.2.0, known to not compile with 5.6.4, which is currently in Ubuntu). The default is openssl, see below to compile with crypto++ instead.
- [SQLite3](https://www.sqlite.org/) (tested with 3.31.1)
- a c++ compiler (tested with [GCC](https://gcc.gnu.org) 10.1.0 and [Clang](https://clang.llvm.org) 10.0.1, also tested and working with GCC 9.3.0 and 8.4.0)
- [OpenSSL](https://www.openssl.org/) (tested with 1.1.1g) _or_ [Crypto++](https://www.cryptopp.com/) (tested with 8.2.0, known to not compile with 5.6.4, which is currently in Ubuntu). The default is openssl, see below to compile with crypto++ instead.
- [SQLite3](https://www.sqlite.org/) (tested with 3.32.3)

### Obtaining

**<span id="compiling">Compiling</span>**

A script is provided that will compile the binary on Arch and Fedora (and possibly many other distro's). In general just running `g++ -std=c++2a */*.cc *.cc -lcrypto -lsqlite3` should do the trick. If you have difficulty compling under your OS, I recommend downloading a Fedora Live image, booting of of that and running the following commands in a terminal (in the project directory):
A script is provided that will compile the binary on Arch and Fedora (and possibly many other distro's). In general just running `g++ -std=c++2a */*.cc *.cc -lcrypto -lsqlite3` should do the trick. When compiling with gcc 8.x, also add the `-stdc++fs` flag. If you have difficulty compling under your OS, I recommend downloading a Fedora Live image, booting of of that and running the following commands in a terminal (in the project directory):

```
$ sudo dnf install gcc-g++ openssl-devel sqlite-devel which
Expand All @@ -37,6 +37,8 @@ Alternatively, a Dockerfile has been kindly provided by David J. Meier, and is a

If for any reason you need to compile against cryptopp instead of openssl, run `sh BUILDSCRIPT --config cryptopp`, or manually `g++ -std=c++2a -DUSE_CRYPTOPP */*.cc *.cc -lcryptopp -lsqlite3`.

It should be possible to compile and run the program under MacOS as well, for more info see [here](https://github.com/bepaald/signalbackup-tools/issues/9).

**<span id="windows">Windows binary</span>**

For the most recent Windows executable, check [the releases page](https://github.com/bepaald/signalbackup-tools/releases). This executable is a static build, cross compiled from my Arch linux install. It is only minimally tested.
Expand Down
2 changes: 1 addition & 1 deletion autoversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
#ifndef VERSION_H_
#define VERSION_H_

#define VERSIONDATE "20200731.163140"
#define VERSIONDATE "20200731.170058"

#endif
7 changes: 6 additions & 1 deletion common_be.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@

#define STRLEN( STR ) (std::integral_constant<int, bepaald::strlitLength(STR)>::value)

#if __GNUC__ < 9
#define STRING_STARTS_WITH( STR, SUB ) ( STR.substr(0, STRLEN(SUB)) == SUB )
#else
#define STRING_STARTS_WITH( STR, SUB ) ( STR.starts_with(SUB) )
#endif

typedef unsigned int uint;

namespace bepaald
Expand Down Expand Up @@ -117,7 +123,6 @@ T bepaald::toNumber(std::string const &str)

inline std::string bepaald::bytesToHexString(std::pair<std::shared_ptr<unsigned char []>, unsigned int> const &data, bool unformatted)
{
std::cout << "THIS IS THE WEIRD CALL!!!" << std::endl;
return bytesToHexString(data.first.get(), data.second, unformatted);
}

Expand Down
15 changes: 15 additions & 0 deletions signalbackup/exporttodir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ bool SignalBackup::exportBackupToDir(std::string const &directory, bool overwrit

// export avatars
std::cout << "Writing Avatars..." << std::endl;
#if __GNUC__ < 9
int count = 1;
for (auto const &aframe : d_avatars)
#else
for (int count = 1 ; auto const &aframe : d_avatars)
#endif
{
AvatarFrame *a = aframe.second.get();
std::string avatar_basefilename = directory + "/Avatar_" +
Expand All @@ -100,13 +105,23 @@ bool SignalBackup::exportBackupToDir(std::string const &directory, bool overwrit

// export sharedpreferences
std::cout << "Writing SharedPrefFrame(s)..." << std::endl;
#if __GNUC__ < 9
count = 1;
for (auto const &spframe : d_sharedpreferenceframes)
#else
for (int count = 1; auto const &spframe : d_sharedpreferenceframes)
#endif
if (!writeRawFrameDataToFile(directory + "/SharedPreference_" + bepaald::toString(count++) + ".sbf", spframe))
return false;

// export stickers
std::cout << "Writing StickerFrames..." << std::endl;
#if __GNUC__ < 9
count = 1;
for (auto const &sframe : d_stickers)
#else
for (int count = 1; auto const &sframe : d_stickers)
#endif
{
StickerFrame *s = sframe.second.get();
std::string sticker_basefilename = directory + "/Sticker_" + bepaald::toString(count++) + "_" + bepaald::toString(s->rowId());
Expand Down
10 changes: 5 additions & 5 deletions signalbackup/exporttofile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ bool SignalBackup::exportBackupToFile(std::string const &filename, std::string c
{
if (results.valueHasType<std::string>(i, 1) &&
(results.getValueAs<std::string>(i, 1) != "sms_fts" &&
results.getValueAs<std::string>(i, 1).starts_with("sms_fts")))
STRING_STARTS_WITH(results.getValueAs<std::string>(i, 1), "sms_fts")))
;//std::cout << "Skipping " << results[i][1].second << " because it is smsftssecrettable" << std::endl;
else if (results.valueHasType<std::string>(i, 1) &&
(results.getValueAs<std::string>(i, 1) != "mms_fts" &&
results.getValueAs<std::string>(i, 1).starts_with("mms_fts")))
STRING_STARTS_WITH(results.getValueAs<std::string>(i, 1), "mms_fts")))
;//std::cout << "Skipping " << results[i][1].second << " because it is smsftssecrettable" << std::endl;
else
{
Expand All @@ -115,12 +115,12 @@ bool SignalBackup::exportBackupToFile(std::string const &filename, std::string c
if (table == "signed_prekeys" ||
table == "one_time_prekeys" ||
table == "sessions" ||
table.starts_with("sms_fts") ||
table.starts_with("mms_fts") ||
STRING_STARTS_WITH(table, "sms_fts") ||
STRING_STARTS_WITH(table, "mms_fts") ||
//table == "job_spec" || // this is in the official export. But it makes testing more difficult.
//table == "constraint_spec" || // it should be ok to export these (if present in source), since we are
//table == "dependency_spec" || // only dealing with exported backups (not from live installations) and the
table.starts_with("sqlite_")) // official import should be able to deal with them
STRING_STARTS_WITH(table, "sqlite_")) // official import should be able to deal with them
continue;

d_database.exec("SELECT * FROM " + table, &results);
Expand Down
6 changes: 3 additions & 3 deletions signalbackup/importthread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ void SignalBackup::importThread(SignalBackup *source, long long int thread)
if (table == "signed_prekeys" ||
table == "one_time_prekeys" ||
table == "sessions" ||
table.starts_with("sms_fts") ||
table.starts_with("mms_fts") ||
table.starts_with("sqlite_"))
STRING_STARTS_WITH(table, "sms_fts") ||
STRING_STARTS_WITH(table, "mms_fts") ||
STRING_STARTS_WITH(table, "sqlite_"))
continue;
std::cout << "Importing statements from source table '" << table << "'...";
source->d_database.exec("SELECT * FROM " + table, &results);
Expand Down
9 changes: 7 additions & 2 deletions signalbackup/initfromdir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,17 @@ void SignalBackup::initFromDir(std::string const &inputdir)
return;
}
for (auto const &avatar : dirit) // put all Avatar_[...].sbf files in vector:
if (avatar.path().extension() == ".sbf" && avatar.path().filename().string().starts_with("Avatar_"))
if (avatar.path().extension() == ".sbf" && STRING_STARTS_WITH(avatar.path().filename().string(), "Avatar_"))
avatarfiles.push_back(avatar.path().string());

std::sort(avatarfiles.begin(), avatarfiles.end());

#if __GNUC__ < 9
unsigned int i = 0;
for (auto const &file : avatarfiles)
#else
for (unsigned int i = 0; auto const &file : avatarfiles)
#endif
{
if (d_showprogress)
{
Expand Down Expand Up @@ -115,7 +120,7 @@ void SignalBackup::initFromDir(std::string const &inputdir)
}
for (auto const &att : dirit)
{
if (att.path().extension() != ".sbf" || !att.path().filename().string().starts_with("Attachment_"))
if (att.path().extension() != ".sbf" || !STRING_STARTS_WITH(att.path().filename().string(), "Attachment_"))
continue;

std::filesystem::path attframe = att.path();
Expand Down
8 changes: 4 additions & 4 deletions signalbackup/updatethreadsentries.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,22 @@ void SignalBackup::updateThreadsEntries(long long int thread)
//std::cout << "FILE TYPE: " << t << std::endl;

std::string snippet;
if (t.starts_with("image/gif"))
if (STRING_STARTS_WITH(t, "image/gif"))
{
snippet = "\xF0\x9F\x8E\xA1 "; // ferris wheel emoji for some reason
snippet += (newsnippet.empty()) ? "GIF" : newsnippet;
}
else if (t.starts_with("image"))
else if (STRING_STARTS_WITH(t, "image"))
{
snippet = "\xF0\x9F\x93\xB7 "; // (still) camera emoji
snippet += (newsnippet.empty()) ? "Photo" : newsnippet;
}
else if (t.starts_with("audio"))
else if (STRING_STARTS_WITH(t, "audio"))
{
snippet = "\xF0\x9F\x8E\xA4 "; // microphone emoji
snippet += (newsnippet.empty()) ? "Voice message" : newsnippet;
}
else if (t.starts_with("video"))
else if (STRING_STARTS_WITH(t, "video"))
{
snippet = "\xF0\x9F\x8E\xA5 "; // (movie) camera emoji
snippet += (newsnippet.empty()) ? "Video" : newsnippet;
Expand Down

0 comments on commit fbea5b1

Please sign in to comment.