Skip to content

Commit 89e590b

Browse files
committed
Move the "unknown constructor found" logging logic
1 parent 975ff21 commit 89e590b

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

pyrogram/crypto/mtproto.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,16 @@ def unpack(b: BytesIO, session_id: bytes, auth_key: bytes, auth_key_id: bytes) -
6060
# https://core.telegram.org/mtproto/security_guidelines#checking-session-id
6161
assert data.read(8) == session_id
6262

63-
message = Message.read(data)
63+
try:
64+
message = Message.read(data)
65+
except KeyError as e:
66+
left = data.read().hex()
67+
68+
left = [left[i:i + 64] for i in range(0, len(left), 64)]
69+
left = [[left[i:i + 8] for i in range(0, len(left), 8)] for left in left]
70+
left = "\n".join(" ".join(x for x in left) for left in left)
71+
72+
raise ValueError(f"Unknown constructor found: {hex(e.args[0])}\n{left}")
6473

6574
# https://core.telegram.org/mtproto/security_guidelines#checking-sha256-hash-value-of-msg-key
6675
# https://core.telegram.org/mtproto/security_guidelines#checking-message-length

pyrogram/raw/core/tl_object.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,7 @@ class TLObject:
3030

3131
@classmethod
3232
def read(cls, data: BytesIO, *args: Any) -> Any:
33-
try:
34-
return cast(TLObject, objects[int.from_bytes(data.read(4), "little")]).read(data, *args)
35-
except KeyError as e:
36-
left = data.read().hex()
37-
38-
left = [left[i:i + 64] for i in range(0, len(left), 64)]
39-
left = [[left[i:i + 8] for i in range(0, len(left), 8)] for left in left]
40-
left = "\n".join(" ".join(x for x in left) for left in left)
41-
42-
raise ValueError(f"Unknown constructor found: {hex(e.args[0])}\n{left}")
33+
return cast(TLObject, objects[int.from_bytes(data.read(4), "little")]).read(data, *args)
4334

4435
def write(self, *args: Any) -> bytes:
4536
pass

0 commit comments

Comments
 (0)