Skip to content

Commit

Permalink
Merge pull request #119 from serveroid/main
Browse files Browse the repository at this point in the history
work with new tdata
  • Loading branch information
thedemons authored Jul 15, 2024
2 parents a56c036 + db002b5 commit 1a6f081
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
56 changes: 54 additions & 2 deletions src/td/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def __init__(self, basePath: str) -> None:
self._favedStickersKey = FileKey(0)
self._archivedStickersKey = FileKey(0)
self._archivedMasksKey = FileKey(0)
self._installedCustomEmojiKey = FileKey(0)
self._featuredCustomEmojiKey = FileKey(0)
self._archivedCustomEmojiKey = FileKey(0)
self._searchSuggestionsKey = FileKey(0)
self._webviewStorageTokenBots = FileKey(0)
self._webviewStorageTokenOther = FileKey(0)
self._savedGifsKey = FileKey(0)
self._recentStickersKeyOld = FileKey(0)
self._legacyBackgroundKeyDay = FileKey(0)
Expand Down Expand Up @@ -109,14 +115,22 @@ def read(self, localKey: td.AuthKey, legacyPasscode: QByteArray) -> None:
installedMasksKey = 0
recentMasksKey = 0
archivedMasksKey = 0
installedCustomEmojiKey = 0
featuredCustomEmojiKey = 0
archivedCustomEmojiKey = 0
searchSuggestionsKey = 0
webviewStorageTokenBots = 0
webviewStorageTokenOther = 0
savedGifsKey = 0
legacyBackgroundKeyDay = 0
legacyBackgroundKeyNight = 0
userSettingsKey = 0
recentHashtagsAndBotsKey = 0
exportSettingsKey = 0

while not map.stream.atEnd():
is_finished = False

while not is_finished and not map.stream.atEnd():
keyType = map.stream.readUInt32()

if keyType == lskType.lskDraft:
Expand Down Expand Up @@ -210,6 +224,17 @@ def read(self, localKey: td.AuthKey, legacyPasscode: QByteArray) -> None:
recentMasksKey = map.stream.readUInt64()
archivedMasksKey = map.stream.readUInt64()

elif keyType == lskType.lskCustomEmojiKeys:
installedCustomEmojiKey = map.stream.readUInt64()
featuredCustomEmojiKey = map.stream.readUInt64()
archivedCustomEmojiKey = map.stream.readUInt64()

elif keyType == lskType.lskSearchSuggestions:
searchSuggestionsKey = map.stream.readUInt64()

elif keyType == lskType.lskWebviewTokens:
is_finished = True

else:
logging.warning(f"Unknown key type in encrypted map: {keyType}")

Expand All @@ -233,6 +258,12 @@ def read(self, localKey: td.AuthKey, legacyPasscode: QByteArray) -> None:
self._installedMasksKey = installedMasksKey
self._recentMasksKey = recentMasksKey
self._archivedMasksKey = archivedMasksKey
self._installedCustomEmojiKey = installedCustomEmojiKey
self._featuredCustomEmojiKey = featuredCustomEmojiKey
self._archivedCustomEmojiKey = archivedCustomEmojiKey
self._searchSuggestionsKey = searchSuggestionsKey
self._webviewStorageTokenBots = webviewStorageTokenBots
self._webviewStorageTokenOther = webviewStorageTokenOther
self._legacyBackgroundKeyDay = legacyBackgroundKeyDay
self._legacyBackgroundKeyNight = legacyBackgroundKeyNight
self._settingsKey = userSettingsKey
Expand Down Expand Up @@ -279,6 +310,12 @@ def prepareToWrite(self) -> td.Storage.EncryptedDescriptor:
mapSize += sizeof(uint32) + sizeof(uint64)
if self._installedMasksKey or self._recentMasksKey or self._archivedMasksKey:
mapSize += sizeof(uint32) + 3 * sizeof(uint64)
if self._installedCustomEmojiKey or self._featuredCustomEmojiKey or self._archivedCustomEmojiKey:
mapSize += sizeof(uint32) + 3 * sizeof(uint64)
if self._searchSuggestionsKey:
mapSize += sizeof(uint32) + sizeof(uint64)
if self._webviewStorageTokenBots or self._webviewStorageTokenOther:
mapSize += sizeof(uint32) + 2 * sizeof(uint64)

mapData = td.Storage.EncryptedDescriptor(mapSize)
stream = mapData.stream
Expand Down Expand Up @@ -347,6 +384,21 @@ def prepareToWrite(self) -> td.Storage.EncryptedDescriptor:
stream.writeUInt64(self._recentMasksKey)
stream.writeUInt64(self._archivedMasksKey)

if self._installedCustomEmojiKey or self._featuredCustomEmojiKey or self._archivedCustomEmojiKey:
stream.writeUInt32(lskType.lskCustomEmojiKeys)
stream.writeUInt64(self._installedCustomEmojiKey)
stream.writeUInt64(self._featuredCustomEmojiKey)
stream.writeUInt64(self._archivedCustomEmojiKey)

if self._searchSuggestionsKey:
stream.writeUInt32(lskType.lskSearchSuggestions)
stream.writeUInt64(self._searchSuggestionsKey)

if self._webviewStorageTokenBots or self._webviewStorageTokenOther:
stream.writeUInt32(lskType.lskWebviewTokens)
stream.writeUInt64(self._webviewStorageTokenBots)
stream.writeUInt64(self._webviewStorageTokenOther)

return mapData


Expand Down Expand Up @@ -656,7 +708,7 @@ def __init__(

self.__mtpKeys: typing.List[td.AuthKey] = []
self.__mtpKeysToDestroy: typing.List[td.AuthKey] = []
self.api = api.copy()
self.api = api

self._local = StorageAccount(
self, self.basePath, td.Storage.ComposeDataString(self.__keyFile, index)
Expand Down
3 changes: 3 additions & 0 deletions src/td/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ class lskType(int): # nocov
lskBackgroundOld = 0x14 # no data
lskSelfSerialized = 0x15 # serialized self
lskMasksKeys = 0x16 # no data
lskCustomEmojiKeys = 0x17 # no data
lskSearchSuggestions = 0x18 # no data
lskWebviewTokens = 0x19 # data: QByteArray bots, QByteArray other


class BotTrustFlag(int): # nocov
Expand Down

0 comments on commit 1a6f081

Please sign in to comment.