Created
August 2, 2021 09:54
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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