tdesktop

package
v0.116.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 21 Imported by: 16

Documentation

Overview

Package tdesktop contains Telegram Desktop session decoder.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyInfoDecrypt is returned when key data decrypt fails.
	// It can happen if passed passcode is wrong.
	ErrKeyInfoDecrypt = errors.New("key data decrypt")
	// ErrNoAccounts reports that decoded tdata does not contain any accounts info.
	ErrNoAccounts = errors.New("tdesktop data does not contain accounts")
)

Functions

This section is empty.

Types

type Account

type Account struct {
	// IDx is an internal Telegram Desktop account ID.
	IDx uint32
	// Authorization contains Telegram user and MTProto sessions.
	Authorization MTPAuthorization
	// Config contains Telegram config.
	Config MTPConfig
}

Account is a Telegram user account representation in Telegram Desktop storage.

func Read

func Read(root string, passcode []byte) ([]Account, error)

Read reads accounts info from given Telegram Desktop tdata root. Shorthand for:

ReadFS(os.DirFS(root), passcode)
Example
package main

import (
	"fmt"
	"os"
	"path/filepath"

	"github.com/gotd/td/session/tdesktop"
)

func main() {
	home, err := os.UserHomeDir()
	if err != nil {
		panic(err)
	}

	root := filepath.Join(home, "Downloads", "Telegram", "tdata")
	accounts, err := tdesktop.Read(root, nil)
	if err != nil {
		panic(err)
	}

	for _, account := range accounts {
		auth := account.Authorization
		cfg := account.Config
		fmt.Println(auth.UserID, auth.MainDC, cfg.Environment)
	}
}
Output:

func ReadFS

func ReadFS(root fs.FS, passcode []byte) ([]Account, error)

ReadFS reads Telegram Desktop accounts info from given FS root.

type MTPAuthorization

type MTPAuthorization struct {
	// UserID is a Telegram user ID.
	UserID uint64
	// MainDC is a main DC ID of this user.
	MainDC int
	// Key is a map of keys per DC ID.
	Keys map[int]crypto.Key // DC ID -> Key
}

MTPAuthorization is a Telegram Desktop storage structure which stores MTProto session info.

See https://github.com/telegramdesktop/tdesktop/blob/dev/Telegram/SourceFiles/main/main_account.cpp#L359.

type MTPConfig added in v0.52.0

type MTPConfig struct {
	Environment              MTPConfigEnvironment
	DCOptions                MTPDCOptions
	ChatSizeMax              int32  // default: 200
	MegagroupSizeMax         int32  // default: 10000
	ForwardedCountMax        int32  // default: 100
	OnlineUpdatePeriod       int32  // default: 120000
	OfflineBlurTimeout       int32  // default: 5000
	OfflineIdleTimeout       int32  // default: 30000
	OnlineFocusTimeout       int32  // default: 1000
	OnlineCloudTimeout       int32  // default: 300000
	NotifyCloudDelay         int32  // default: 30000
	NotifyDefaultDelay       int32  // default: 1500
	SavedGifsLimit           int32  // default: 200
	EditTimeLimit            int32  // default: 172800
	RevokeTimeLimit          int32  // default: 172800
	RevokePrivateTimeLimit   int32  // default: 172800
	RevokePrivateInbox       bool   // default: false
	StickersRecentLimit      int32  // default: 30
	StickersFavedLimit       int32  // default: 5
	PinnedDialogsCountMax    int32  // default: 5
	PinnedDialogsInFolderMax int32  // default: 100
	InternalLinksDomain      string // default: "https://t.me/"
	ChannelsReadMediaPeriod  int32  // default: 86400 * 7
	CallReceiveTimeoutMs     int32  // default: 20000
	CallRingTimeoutMs        int32  // default: 90000
	CallConnectTimeoutMs     int32  // default: 30000
	CallPacketTimeoutMs      int32  // default: 10000
	WebFileDCID              int32  // default: 4
	TxtDomainString          string // default: ""
	PhoneCallsEnabled        bool   // default: true
	BlockedMode              bool   // default: false
	CaptionLengthMax         int32  // default: 1024
}

MTPConfig is a Telegram Desktop storage structure which stores MTProto config info.

See https://github.com/telegramdesktop/tdesktop/blob/v2.9.8/Telegram/SourceFiles/mtproto/mtproto_config.h.

type MTPConfigEnvironment added in v0.52.0

type MTPConfigEnvironment int32

MTPConfigEnvironment is enum of config environment.

func (MTPConfigEnvironment) String added in v0.52.0

func (e MTPConfigEnvironment) String() string

String implements fmt.Stringer.

func (MTPConfigEnvironment) Test added in v0.52.0

func (e MTPConfigEnvironment) Test() bool

Test denotes that environment is test.

type MTPDCOption added in v0.52.0

type MTPDCOption struct {
	ID     int32
	Flags  bin.Fields
	Port   int32
	IP     string
	Secret []byte
}

MTPDCOption is a Telegram Desktop storage structure which stores DC info.

See https://github.com/telegramdesktop/tdesktop/blob/v2.9.8/Telegram/SourceFiles/mtproto/mtproto_dc_options.h.

func (MTPDCOption) CDN added in v0.52.0

func (m MTPDCOption) CDN() bool

CDN denotes that this is a CDN DC.

func (MTPDCOption) IPv6 added in v0.52.0

func (m MTPDCOption) IPv6() bool

IPv6 denotes that the specified IP is an IPv6 address.

func (MTPDCOption) MediaOnly added in v0.52.0

func (m MTPDCOption) MediaOnly() bool

MediaOnly denotes that this DC should only be used to download or upload files.

func (MTPDCOption) Static added in v0.52.0

func (m MTPDCOption) Static() bool

Static denotes that this IP should be used when connecting through a proxy.

func (MTPDCOption) TCPOOnly added in v0.52.0

func (m MTPDCOption) TCPOOnly() bool

TCPOOnly denotes that this DC only supports connection with transport obfuscation.

type MTPDCOptions added in v0.52.0

type MTPDCOptions struct {
	Options []MTPDCOption
}

MTPDCOptions is a Telegram Desktop storage structure which stores DCs info.

See https://github.com/telegramdesktop/tdesktop/blob/v2.9.8/Telegram/SourceFiles/mtproto/mtproto_dc_options.cpp#L479.

type WrongMagicError

type WrongMagicError struct {
	Magic [4]byte
}

WrongMagicError is returned when tdesktop data file has wrong magic header.

func (*WrongMagicError) Error

func (w *WrongMagicError) Error() string

Error implements error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL