Skip to content

Instantly share code, notes, and snippets.

@LockBlock-dev
Created August 2, 2021 09:54
Show Gist options
  • Save LockBlock-dev/32949a7c8e425b2f61bb348d68e23b90 to your computer and use it in GitHub Desktop.
Save LockBlock-dev/32949a7c8e425b2f61bb348d68e23b90 to your computer and use it in GitHub Desktop.
Tiny code to decode Discord WS Zlib ETF messages (doesn't always work)
import zlib
import base64
import earl
ZLIB_SUFFIX = b'\x00\x00\xff\xff'
buffer = bytearray()
def uncompress(str):
str = base64.decodebytes(str)
buffer.extend(str)
if len(str) >= 4 or str[-4:] == ZLIB_SUFFIX:
str = zlib.decompressobj().decompress(buffer)
return str
def decode(str):
str = base64.decodebytes(str)
str = earl.unpack(str)
return str
def main (obj):
if (obj["type"] == "received"):
return decode(uncompress(obj["text"]))
elif (obj["type"] == "sent"):
return decode(obj["text"])
msg = {
"text": ""
#,"type": "sent"
#,"type": "received"
#uncomment the type, sent by the client or received by the client
}
msg["text"] = msg["text"].encode("ascii")
print(main(msg))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment