Move the "unknown constructor found" logging logic

This commit is contained in:
Dan 2021-03-17 15:03:18 +01:00
parent 975ff219f2
commit 89e590b968
2 changed files with 11 additions and 11 deletions

View File

@ -60,7 +60,16 @@ def unpack(b: BytesIO, session_id: bytes, auth_key: bytes, auth_key_id: bytes) -
# https://core.telegram.org/mtproto/security_guidelines#checking-session-id
assert data.read(8) == session_id
message = Message.read(data)
try:
message = Message.read(data)
except KeyError as e:
left = data.read().hex()
left = [left[i:i + 64] for i in range(0, len(left), 64)]
left = [[left[i:i + 8] for i in range(0, len(left), 8)] for left in left]
left = "\n".join(" ".join(x for x in left) for left in left)
raise ValueError(f"Unknown constructor found: {hex(e.args[0])}\n{left}")
# https://core.telegram.org/mtproto/security_guidelines#checking-sha256-hash-value-of-msg-key
# https://core.telegram.org/mtproto/security_guidelines#checking-message-length

View File

@ -30,16 +30,7 @@ class TLObject:
@classmethod
def read(cls, data: BytesIO, *args: Any) -> Any:
try:
return cast(TLObject, objects[int.from_bytes(data.read(4), "little")]).read(data, *args)
except KeyError as e:
left = data.read().hex()
left = [left[i:i + 64] for i in range(0, len(left), 64)]
left = [[left[i:i + 8] for i in range(0, len(left), 8)] for left in left]
left = "\n".join(" ".join(x for x in left) for left in left)
raise ValueError(f"Unknown constructor found: {hex(e.args[0])}\n{left}")
return cast(TLObject, objects[int.from_bytes(data.read(4), "little")]).read(data, *args)
def write(self, *args: Any) -> bytes:
pass