# hermes-tdata 🚀
**Pure Rust parser for Telegram Desktop's `tdata` storage.**
[](https://crates.io/crates/hermes-tdata)
[](https://docs.rs/hermes-tdata)
[](LICENSE)
Extract sessions and authentication keys from Telegram Desktop's local storage (`tdata`) **without** launching the official client, using `Qt`, or relying on `Python`.
## ⚡️ Features
- **Pure Rust**: No dependencies on Qt, C++, or Python. Statically linked and blazing fast.
- **Cross-Platform**: Works on Linux, Windows, and macOS tdata folders.
- **Cryptography**: Full implementation of TDesktop's custom encryption scheme:
- PBKDF2-SHA512 key derivation with custom parameters.
- AES-256-IGE encryption implementation.
- Custom MD5/SHA1 file integrity verification.
- **MTP Parsing**:
- Parses `key_data` (local keys).
- Parses `map` files (account data).
- Extracts `AuthKey`, `UserId`, and `DcId`.
- Supports new (64-bit ID) and legacy tdata formats.
- **Interoperability**:
- Generates session strings compatible with `grammers` (Rust).
- Easily adaptable for `telethon` or `pyrogram`.
- **Multi-Account**: Automatically detects and extracts all active accounts.
## 📦 Installation
Add this to your `Cargo.toml`:
```toml
[dependencies]
hermes-tdata = "0.1"
```
## 🚀 Quick Start
### Convert tdata to Session String
```rust
use hermes_tdata::tdesktop::TDesktop;
use std::path::PathBuf;
fn main() -> anyhow::Result<()> {
// 1. Path to tdata (Linux example)
let tdata_path = PathBuf::from(std::env::var("HOME")?)
.join(".local/share/TelegramDesktop/tdata");
// 2. Load TDesktop storage
let tdata = TDesktop::from_path(&tdata_path)?;
println!("Found {} accounts!", tdata.accounts().len());
// 3. Iterate accounts
for account in tdata.accounts() {
println!("User ID: {}", account.user_id());
// 4. Generate session string for Grammers
let session = account.session_string()?;
println!("Session: {}", session);
// 5. Or get raw auth key
let auth_key = account.auth_key();
println!("Auth Key: {}", hex::encode(auth_key));
}
Ok(())
}
```
## 🛠 CLI Utility
This crate includes a ready-to-use CLI tool to inspect tdata and extract sessions.
```bash
# Run directly from source
cargo run --example cli
# Or specify a custom path
cargo run --example cli -- /path/to/tdata
# With passcode
cargo run --example cli -- --passcode "secret123"
```
**Output example:**
```text
📂 Reading tdata from: "/home/user/.local/share/TelegramDesktop/tdata"
✅ Successfully loaded TDesktop storage!
App Version: 6004001
Passcode: NO
Accounts: 2
👤 Account #1 (Index 0)
User ID: 123456789
DC ID: 2
Session: 1/33p1... (ready for grammers)
👤 Account #2 (Index 1)
User ID: 987654321
DC ID: 2
Session: 1/5a2b...
```
## 🔒 Security Note
This library deals with **sensitive authentication keys**.
- Never share your `tdata` folder or the output of this tool.
- Anyone with the `AuthKey` can access your Telegram account without 2FA.
- This tool runs locally on your machine and does not transmit keys anywhere.
## 🤝 Acknowledgements
- **[opentele](https://github.com/thedemons/opentele)** (Python) - Protocol reference.
- **[tdesktop](https://github.com/telegramdesktop/tdesktop)** (C++) - The source of truth.
## 📜 License
MIT or Apache-2.0