Skip to main content

Deserializes/serializes Telegram tgnet.dat format. Can be used to extract/replace authKey and dcId.

Project description

tgnet

Deserializes/serializes Telegram tgnet.dat format. Can be used to extract/replace authKey and dcId.

This is fork of batreller/telegram_android_session_converter with support of serialization and zero dependencies.

To convert the session all you need is just tgnet.dat file from the root directory of your telegram app on the phone, it's located at /data/data/org.telegram.messenger.web (or another package name, if you're using an unofficial client), it can be extracted using ADB (Android Debug Bridge).

Usage

>>> from tgnet import TGAndroidSession, NativeByteBuffer
>>> with open("tgnet.dat", "rb") as f:
...     buf = NativeByteBuffer(f)
...     tgdata = TGAndroidSession.deserialize(buf)
...
>>> currentDcId = tgdata.headers.currentDatacenterId
>>> currentDc = tgdata.datacenters[currentDcId - 1]  # or tgdata.currentDc()
>>> print(currentDc.auth.authKeyPerm.hex())
'72a9808fb4a9e51e6ca57259714c14fa83546fc9d56fcb9d7de77c59fa13b6d6...'

Running tests

pytest -s -x --disable-warnings --cov=tgnet/ test.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tgnet-0.1.1.tar.gz (10.3 kB view hashes)

Uploaded Source

Built Distribution

tgnet-0.1.1-py3-none-any.whl (8.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page