Skip to content

Instantly share code, notes, and snippets.

@bodqhrohro
Last active February 10, 2024 19:59
Show Gist options
  • Save bodqhrohro/b9f23ac680661eb0a8b572b49b754263 to your computer and use it in GitHub Desktop.
Save bodqhrohro/b9f23ac680661eb0a8b572b49b754263 to your computer and use it in GitHub Desktop.
Read data from legacy telegram-purple auth files
#!/usr/bin/python3
import os, struct
DIR = os.path.join(os.environ['HOME'], ".purple/telegram-purple")
def cprint(color, s):
print("\x1b[" + str(color) + "m" + s + "\x1b[0m", end="")
def pkeyvalue(key, value):
cprint(33, key)
print(": " + str(value))
def read_int(f):
return struct.unpack("<I", f.read(4))[0]
for root, dirs, files in os.walk(DIR):
for file in files:
if file == "auth":
cprint(32, "%s in %s:\n" % (file, root))
with open(os.path.join(root, file), 'rb') as f:
pkeyvalue("DC_SERIALIZED_MAGIC", read_int(f))
max_dc_num = read_int(f)
pkeyvalue("max_dc_num", max_dc_num)
pkeyvalue("dc_working_num", read_int(f))
for i in range(max_dc_num+1):
is_dc = read_int(f)
if is_dc == 1:
cprint(36, "DC%s:\n" % i)
pkeyvalue("port", read_int(f))
ip_len = read_int(f)
pkeyvalue("IP", struct.unpack(str(ip_len) + "s", f.read(ip_len))[0].decode('utf-8'))
pkeyvalue("auth_key_id", f.read(8).hex())
pkeyvalue("auth_key", f.read(256).hex())
pkeyvalue("our_id", read_int(f))
#!/usr/bin/python3
import os, struct
DIR = os.path.join(os.environ['HOME'], ".purple/telegram-purple")
def cprint(color, s):
print("\x1b[" + str(color) + "m" + s + "\x1b[0m", end="")
def pkeyvalue(key, value):
cprint(33, key)
print(": " + str(value))
def read_int(f):
return struct.unpack("<I", f.read(4))[0]
for root, dirs, files in os.walk(DIR):
for file in files:
if file == "secret":
cprint(32, "%s in %s:\n" % (file, root))
with open(os.path.join(root, file), 'rb') as f:
pkeyvalue("SECRET_CHAT_FILE_MAGIC", read_int(f))
pkeyvalue("version", read_int(f))
num = read_int(f)
pkeyvalue("num", num)
for i in range(num):
cprint(36, "chat %s:\n" % i)
pkeyvalue("peer_id", read_int(f))
name_len = read_int(f)
pkeyvalue("name", struct.unpack(str(name_len) + "s", f.read(name_len))[0].decode('utf-8'))
pkeyvalue("user_id", read_int(f))
pkeyvalue("admin_id", read_int(f))
pkeyvalue("date", read_int(f))
pkeyvalue("ttl", read_int(f))
pkeyvalue("layer", read_int(f))
pkeyvalue("access_hash", f.read(8).hex())
pkeyvalue("state", read_int(f))
pkeyvalue("key_fingerprint", f.read(8).hex())
pkeyvalue("key", f.read(256).hex())
pkeyvalue("first_key_sha", f.read(20).hex())
pkeyvalue("in_seq_no", read_int(f))
pkeyvalue("last_in_seq_no", read_int(f))
pkeyvalue("out_seq_no", read_int(f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment