From a0ed096b8b443afda3bc6262bae4d2d8065abd29 Mon Sep 17 00:00:00 2001 From: XXXRef Date: Fri, 27 Dec 2019 16:04:03 -0800 Subject: [PATCH] Updated to correctly process data of new Telegram client version --- .../TelegramDesktop/BlockIDs/DataBlockID.cs | 29 +++++---- .../BlockIDs/LocalStorageKey.cs | 11 ++-- .../InternalTypes/Enums/ConnectionType.cs | 3 +- .../TelegramDesktop/LocalStorage.cs | 4 ++ .../TelegramDesktop/Map.cs | 15 +++-- .../TelegramDesktop/Settings.cs | 59 +++++++++++++++---- 6 files changed, 88 insertions(+), 33 deletions(-) diff --git a/src/TelegramStorageParser/TelegramDesktop/BlockIDs/DataBlockID.cs b/src/TelegramStorageParser/TelegramDesktop/BlockIDs/DataBlockID.cs index 57fc66c..836b5ed 100644 --- a/src/TelegramStorageParser/TelegramDesktop/BlockIDs/DataBlockID.cs +++ b/src/TelegramStorageParser/TelegramDesktop/BlockIDs/DataBlockID.cs @@ -7,7 +7,7 @@ internal enum DataBlockID dbiDcOptionOldOld = 0x02, dbiChatSizeMax = 0x03, dbiMutePeer = 0x04, - dbiSendKey = 0x05, + dbiSendKeyOld = 0x05, dbiAutoStart = 0x06, dbiStartMinimized = 0x07, dbiSoundNotify = 0x08, @@ -21,10 +21,10 @@ internal enum DataBlockID // 0x10 reserved dbiDefaultAttach = 0x11, dbiCatsAndDogs = 0x12, - dbiReplaceEmoji = 0x13, + dbiReplaceEmojiOld = 0x13, dbiAskDownloadPath = 0x14, dbiDownloadPathOld = 0x15, - dbiScale = 0x16, + dbiScaleOld = 0x16, dbiEmojiTabOld = 0x17, dbiRecentEmojiOldOld = 0x18, dbiLoggedPhoneNumber = 0x19, @@ -45,13 +45,13 @@ internal enum DataBlockID dbiTryIPv6 = 0x28, dbiSongVolume = 0x29, dbiWindowsNotificationsOld = 0x30, - dbiIncludeMuted = 0x31, + dbiIncludeMutedOld = 0x31, dbiMegagroupSizeMax = 0x32, dbiDownloadPath = 0x33, - dbiAutoDownload = 0x34, + dbiAutoDownloadOld = 0x34, dbiSavedGifsLimit = 0x35, dbiShowingSavedGifsOld = 0x36, - dbiAutoPlay = 0x37, + dbiAutoPlayOld = 0x37, dbiAdaptiveForWide = 0x38, dbiHiddenPinnedMessages = 0x39, dbiRecentEmoji = 0x3a, @@ -69,15 +69,24 @@ internal enum DataBlockID dbiDcOptions = 0x4a, dbiMtpAuthorization = 0x4b, dbiLastSeenWarningSeenOld = 0x4c, - dbiAuthSessionSettings = 0x4d, + dbiSessionSettings = 0x4d, dbiLangPackKey = 0x4e, dbiConnectionType = 0x4f, dbiStickersFavedLimit = 0x50, - dbiSuggestStickersByEmoji = 0x51, - dbiSuggestEmoji = 0x52, - dbiTxtDomainString = 0x53, + dbiSuggestStickersByEmojiOld = 0x51, + dbiSuggestEmojiOld = 0x52, + dbiTxtDomainStringOld = 0x53, dbiThemeKey = 0x54, dbiTileBackground = 0x55, + dbiCacheSettingsOld = 0x56, + dbiAnimationsDisabled = 0x57, + dbiScalePercent = 0x58, + dbiPlaybackSpeed = 0x59, + dbiLanguagesKey = 0x5a, + dbiCallSettings = 0x5b, + dbiCacheSettings = 0x5c, + dbiTxtDomainString = 0x5d, + dbiApplicationSettings = 0x5e, dbiEncryptedWithSalt = 333, dbiEncrypted = 444, diff --git a/src/TelegramStorageParser/TelegramDesktop/BlockIDs/LocalStorageKey.cs b/src/TelegramStorageParser/TelegramDesktop/BlockIDs/LocalStorageKey.cs index b4537bb..5722b67 100644 --- a/src/TelegramStorageParser/TelegramDesktop/BlockIDs/LocalStorageKey.cs +++ b/src/TelegramStorageParser/TelegramDesktop/BlockIDs/LocalStorageKey.cs @@ -5,17 +5,17 @@ internal enum LocalStorageKey lskUserMap = 0x00, lskDraft = 0x01, // data: PeerId peer lskDraftPosition = 0x02, // data: PeerId peer - lskImages = 0x03, // data: StorageKey location + lskLegacyImages = 0x03, // data: StorageKey location lskLocations = 0x04, // no data - lskStickerImages = 0x05, // data: StorageKey location - lskAudios = 0x06, // data: StorageKey location + lskLegacyStickerImages = 0x05, // data: StorageKey location + lskLegacyAudios = 0x06, // data: StorageKey location lskRecentStickersOld = 0x07, // no data lskBackgroundOld = 0x08, // no data lskUserSettings = 0x09, // no data lskRecentHashtagsAndBots = 0x0a, // no data lskStickersOld = 0x0b, // no data - lskSavedPeers = 0x0c, // no data - lskReportSpamStatuses = 0x0d, // no data + lskSavedPeersOld = 0x0c, // no data + lskReportSpamStatusesOld = 0x0d, // no data lskSavedGifsOld = 0x0e, // no data lskSavedGifs = 0x0f, // no data lskStickersKeys = 0x10, // no data @@ -23,5 +23,6 @@ internal enum LocalStorageKey lskFavedStickers = 0x12, // no data lskExportSettings = 0x13, // no data lskBackground = 0x14, // no data + lskSelfSerialized = 0x15 // serialized self } } diff --git a/src/TelegramStorageParser/TelegramDesktop/InternalTypes/Enums/ConnectionType.cs b/src/TelegramStorageParser/TelegramDesktop/InternalTypes/Enums/ConnectionType.cs index 74f8b43..a041c56 100644 --- a/src/TelegramStorageParser/TelegramDesktop/InternalTypes/Enums/ConnectionType.cs +++ b/src/TelegramStorageParser/TelegramDesktop/InternalTypes/Enums/ConnectionType.cs @@ -9,6 +9,7 @@ internal enum ConnectionType HttpAuto = 1, HttpProxy = 2, TcpProxy = 3, - ProxiesList = 4, + ProxiesListOld = 4, + ProxiesList = 5, } } diff --git a/src/TelegramStorageParser/TelegramDesktop/LocalStorage.cs b/src/TelegramStorageParser/TelegramDesktop/LocalStorage.cs index 9615b32..352f9dc 100644 --- a/src/TelegramStorageParser/TelegramDesktop/LocalStorage.cs +++ b/src/TelegramStorageParser/TelegramDesktop/LocalStorage.cs @@ -417,6 +417,10 @@ internal void TryParse_ExportSettings(FileKey fileKey) DataStream stream = file.DataStream; + } + internal void TryParse_SelfSerialized(byte[] array) + { + } internal void TryParse_ThemeLegacy(FileKey fileKey) { diff --git a/src/TelegramStorageParser/TelegramDesktop/Map.cs b/src/TelegramStorageParser/TelegramDesktop/Map.cs index 9927591..33b8f4c 100644 --- a/src/TelegramStorageParser/TelegramDesktop/Map.cs +++ b/src/TelegramStorageParser/TelegramDesktop/Map.cs @@ -55,19 +55,23 @@ private static bool ReadKey(LocalStorageKey storageKey, DataStream stream, Local storage._draftsMap = stream.ReadDraftsMap(); return true; + case LocalStorageKey.lskSelfSerialized: + storage.TryParse_SelfSerialized(stream.ReadByteArray()); + return true; + case LocalStorageKey.lskDraftPosition: storage._draftCursorsMap = stream.ReadDraftsMap(); return true; - case LocalStorageKey.lskImages: + case LocalStorageKey.lskLegacyImages: storage._imagesMap = stream.ReadStorageMap(); return true; - case LocalStorageKey.lskStickerImages: + case LocalStorageKey.lskLegacyStickerImages: storage._stickersMap = stream.ReadStorageMap(); return true; - case LocalStorageKey.lskAudios: + case LocalStorageKey.lskLegacyAudios: storage._audiosMap = stream.ReadStorageMap(); return true; @@ -75,7 +79,7 @@ private static bool ReadKey(LocalStorageKey storageKey, DataStream stream, Local storage.TryParse_Locations(stream.ReadUInt64()); return true; - case LocalStorageKey.lskReportSpamStatuses: + case LocalStorageKey.lskReportSpamStatusesOld: storage.TryParse_ReportSpamStatuses(stream.ReadUInt64()); return true; @@ -127,7 +131,7 @@ private static bool ReadKey(LocalStorageKey storageKey, DataStream stream, Local storage.TryParse_SavedGifs(stream.ReadUInt64()); return true; - case LocalStorageKey.lskSavedPeers: + case LocalStorageKey.lskSavedPeersOld: storage.TryParse_SavedPeers(stream.ReadUInt64()); return true; @@ -135,7 +139,6 @@ private static bool ReadKey(LocalStorageKey storageKey, DataStream stream, Local storage.TryParse_ExportSettings(stream.ReadUInt64()); return true; - default: return false; } diff --git a/src/TelegramStorageParser/TelegramDesktop/Settings.cs b/src/TelegramStorageParser/TelegramDesktop/Settings.cs index f280a24..86666a9 100644 --- a/src/TelegramStorageParser/TelegramDesktop/Settings.cs +++ b/src/TelegramStorageParser/TelegramDesktop/Settings.cs @@ -115,13 +115,13 @@ private static bool TryReadSetting(DataBlockID blockId, DataStream stream, Local storage.SoundNotify = stream.ReadBool(); return true; - case DataBlockID.dbiAutoDownload: + case DataBlockID.dbiAutoDownloadOld: storage.AutoDownloadPhoto = stream.ReadBool(); storage.AutoDownloadAudio = stream.ReadBool(); storage.AutoDownloadGif = stream.ReadBool(); return true; - case DataBlockID.dbiAutoPlay: + case DataBlockID.dbiAutoPlayOld: storage.AutoPlayGif = stream.ReadBool(); return true; @@ -135,7 +135,7 @@ private static bool TryReadSetting(DataBlockID blockId, DataStream stream, Local storage.ModerateModeEnabled = stream.ReadBool(); return true; - case DataBlockID.dbiIncludeMuted: + case DataBlockID.dbiIncludeMutedOld: storage.IncludeMuted = stream.ReadBool(); return true; @@ -165,7 +165,7 @@ private static bool TryReadSetting(DataBlockID blockId, DataStream stream, Local storage.LastSeenWarningSeen = stream.ReadBool(); return true; - case DataBlockID.dbiAuthSessionSettings: + case DataBlockID.dbiSessionSettings: storage.TryDeserialize_AuthSessionSettings(stream.ReadByteArray()); return true; @@ -177,6 +177,10 @@ private static bool TryReadSetting(DataBlockID blockId, DataStream stream, Local storage.TxtDomainString = stream.ReadString(); return true; + case DataBlockID.dbiTxtDomainStringOld: + stream.ReadString(); + return true; + case DataBlockID.dbiConnectionTypeOld: ConnectionType connectionTypeOld = (ConnectionType)stream.ReadInt32(); if (connectionTypeOld == ConnectionType.HttpProxy || connectionTypeOld == ConnectionType.TcpProxy) @@ -190,7 +194,7 @@ private static bool TryReadSetting(DataBlockID blockId, DataStream stream, Local case DataBlockID.dbiConnectionType: ConnectionType connectionType = (ConnectionType)stream.ReadInt32(); - if (connectionType == ConnectionType.ProxiesList) + if (connectionType == ConnectionType.ProxiesListOld || connectionType == ConnectionType.ProxiesList) { int proxyCount = stream.ReadInt32(); int proxyIndex = stream.ReadInt32(); @@ -269,7 +273,7 @@ private static bool TryReadSetting(DataBlockID blockId, DataStream stream, Local storage.LoggedPhoneNumber = stream.ReadString().Replace(" ", ""); return true; - case DataBlockID.dbiSendKey: + case DataBlockID.dbiSendKeyOld: storage.SendKey = (SendKey)stream.ReadInt32(); return true; @@ -286,15 +290,15 @@ private static bool TryReadSetting(DataBlockID blockId, DataStream stream, Local storage.AutoLockSeconds = stream.ReadInt32(); return true; - case DataBlockID.dbiReplaceEmoji: + case DataBlockID.dbiReplaceEmojiOld: storage.ReplaceEmoji = stream.ReadBool(); return true; - case DataBlockID.dbiSuggestEmoji: + case DataBlockID.dbiSuggestEmojiOld: storage.SuggestEmoji = stream.ReadBool(); return true; - case DataBlockID.dbiSuggestStickersByEmoji: + case DataBlockID.dbiSuggestStickersByEmojiOld: storage.SuggestStickersByEmoji = stream.ReadBool(); return true; @@ -338,10 +342,10 @@ private static bool TryReadSetting(DataBlockID blockId, DataStream stream, Local storage.VideoVolume = (stream.ReadInt32() / 1e6f).Snap(0f, 1f); return true; - // Discard - either discarded by the client or just not useful for anything - case DataBlockID.dbiScale: + case DataBlockID.dbiScaleOld: + case DataBlockID.dbiScalePercent: case DataBlockID.dbiEmojiTabOld: case DataBlockID.dbiDefaultAttach: case DataBlockID.dbiShowingSavedGifsOld: @@ -403,6 +407,39 @@ private static bool TryReadSetting(DataBlockID blockId, DataStream stream, Local stream.SeekForward(4); return true; + case DataBlockID.dbiCacheSettingsOld: + stream.SeekForward(8); //size + stream.SeekForward(4); //time + return true; + + case DataBlockID.dbiCacheSettings: + stream.SeekForward(8); //size + stream.SeekForward(4); //time + stream.SeekForward(8); //sizeBig + stream.SeekForward(4); //timeBig + return true; + + case DataBlockID.dbiLanguagesKey: + stream.SeekForward(8); //languagesKey + return true; + + case DataBlockID.dbiPlaybackSpeed: + stream.SeekForward(4); //v + return true; + + case DataBlockID.dbiCallSettings: + stream.ReadByteArray(); //callSettings + return true; + + + case DataBlockID.dbiApplicationSettings: + stream.ReadByteArray(); //serialized + return true; + + case DataBlockID.dbiAnimationsDisabled: + stream.SeekForward(4); //disabled + return true; + default: return false;