From 71e544e0fcda061aab5c2f65f73f2a1b93c74fef Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 15 Feb 2016 18:52:11 +0300 Subject: [PATCH] added user tag for reports, fixed couple of compile warnings in gcc --- Telegram/SourceFiles/facades.cpp | 28 +++++++++++++++++-- Telegram/SourceFiles/facades.h | 2 ++ Telegram/SourceFiles/history.cpp | 1 + Telegram/SourceFiles/logs.cpp | 1 + .../SourceFiles/mtproto/mtpConnection.cpp | 2 +- Telegram/SourceFiles/types.h | 11 ++++++++ Telegram/SourceFiles/window.cpp | 2 +- 7 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Telegram/SourceFiles/facades.cpp b/Telegram/SourceFiles/facades.cpp index 1750f0250..69d1584cd 100644 --- a/Telegram/SourceFiles/facades.cpp +++ b/Telegram/SourceFiles/facades.cpp @@ -215,6 +215,7 @@ struct SandboxDataStruct { ConnectionProxy PreLaunchProxy; }; SandboxDataStruct *SandboxData = 0; +uint64 SandboxUserTag = 0; namespace Sandbox { @@ -276,6 +277,27 @@ namespace Sandbox { f.write("1"); } } + + srand((int32)time(NULL)); + + SandboxUserTag = 0; + QFile usertag(cWorkingDir() + qsl("tdata/usertag")); + if (usertag.open(QIODevice::ReadOnly)) { + if (usertag.read(reinterpret_cast(&SandboxUserTag), sizeof(uint64)) != sizeof(uint64)) { + SandboxUserTag = 0; + } + usertag.close(); + } + if (!SandboxUserTag) { + do { + memsetrnd_bad(SandboxUserTag); + } while (!SandboxUserTag); + + if (usertag.open(QIODevice::WriteOnly)) { + usertag.write(reinterpret_cast(&SandboxUserTag), sizeof(uint64)); + usertag.close(); + } + } } void start() { @@ -290,8 +312,6 @@ namespace Sandbox { break; } } - - srand((int32)time(NULL)); } void finish() { @@ -299,6 +319,10 @@ namespace Sandbox { SandboxData = 0; } + uint64 UserTag() { + return SandboxUserTag; + } + DefineReadOnlyVar(Sandbox, QString, LangSystemISO); DefineReadOnlyVar(Sandbox, int32, LangSystem); DefineVar(Sandbox, QByteArray, LastCrashDump); diff --git a/Telegram/SourceFiles/facades.h b/Telegram/SourceFiles/facades.h index 43da4a026..0e3272193 100644 --- a/Telegram/SourceFiles/facades.h +++ b/Telegram/SourceFiles/facades.h @@ -112,6 +112,8 @@ namespace Sandbox { void start(); void finish(); + uint64 UserTag(); + DeclareReadOnlyVar(QString, LangSystemISO); DeclareReadOnlyVar(int32, LangSystem); DeclareVar(QByteArray, LastCrashDump); diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index b27b6aac0..fc0cbceb4 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -3803,6 +3803,7 @@ HistoryDocument::HistoryDocument(DocumentData *document, const QString &caption, } HistoryDocument::HistoryDocument(const HistoryDocument &other) : HistoryFileMedia() +, Interfaces() , _parent(0) , _data(other._data) { const HistoryDocumentCaptioned *captioned = other.Get(); diff --git a/Telegram/SourceFiles/logs.cpp b/Telegram/SourceFiles/logs.cpp index 502644d7a..4a90c14aa 100644 --- a/Telegram/SourceFiles/logs.cpp +++ b/Telegram/SourceFiles/logs.cpp @@ -868,6 +868,7 @@ namespace SignalHandlers { ProcessAnnotations["Version"] = (cBetaVersion() ? qsl("%1 beta").arg(cBetaVersion()) : (cDevVersion() ? qsl("%1 dev") : qsl("%1")).arg(AppVersion)).toUtf8().constData(); ProcessAnnotations["Launched"] = QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss").toUtf8().constData(); ProcessAnnotations["Platform"] = cPlatformString().toUtf8().constData(); + ProcessAnnotations["UserTag"] = QString::number(Sandbox::UserTag(), 16).toUtf8().constData(); QString dumpspath = cWorkingDir() + qsl("tdata/dumps"); QDir().mkpath(dumpspath); diff --git a/Telegram/SourceFiles/mtproto/mtpConnection.cpp b/Telegram/SourceFiles/mtproto/mtpConnection.cpp index e9c8502db..0410baf26 100644 --- a/Telegram/SourceFiles/mtproto/mtpConnection.cpp +++ b/Telegram/SourceFiles/mtproto/mtpConnection.cpp @@ -426,7 +426,7 @@ namespace { size = (((uint32(bytes[3]) << 8) | uint32(bytes[2])) << 8) | uint32(bytes[1]); len -= 3; } - if (size * sizeof(mtpPrime) != len) { + if (size * int32(sizeof(mtpPrime)) != len) { LOG(("TCP Error: bad packet header")); TCP_LOG(("TCP Error: bad packet header, packet: %1").arg(Logs::mb(packet, length).str())); return mtpBuffer(1, -500); diff --git a/Telegram/SourceFiles/types.h b/Telegram/SourceFiles/types.h index a87d0fa67..b93bf822d 100644 --- a/Telegram/SourceFiles/types.h +++ b/Telegram/SourceFiles/types.h @@ -222,6 +222,17 @@ inline void memsetrnd(T &value) { memset_rand(&value, sizeof(value)); } +inline void memset_rand_bad(void *data, uint32 len) { + for (uchar *i = reinterpret_cast(data), *e = i + len; i != e; ++i) { + *i = uchar(rand() & 0xFF); + } +} + +template +inline void memsetrnd_bad(T &value) { + memset_rand_bad(&value, sizeof(value)); +} + class ReadLockerAttempt { public: diff --git a/Telegram/SourceFiles/window.cpp b/Telegram/SourceFiles/window.cpp index 9c6b19c64..87022c4d9 100644 --- a/Telegram/SourceFiles/window.cpp +++ b/Telegram/SourceFiles/window.cpp @@ -2118,7 +2118,7 @@ LastCrashedWindow::LastCrashedWindow() #endif _pleaseSendReport.setText(qsl("Please send us a crash report.")); - _yourReportName.setText(qsl("Your crash report tag: %1").arg(_minidumpName)); + _yourReportName.setText(qsl("Your Report Tag: %1\nYour User Tag: %2").arg(QString(_minidumpName).replace(".dmp", "")).arg(Sandbox::UserTag(), 0, 16)); _yourReportName.setCursor(style::cur_text); _yourReportName.setTextInteractionFlags(Qt::TextSelectableByMouse);