Skip to content

Instantly share code, notes, and snippets.

@V3ntus
Created February 4, 2022 04:07
Show Gist options
  • Save V3ntus/1c96a95cc7e5ea37289e80f1f5239544 to your computer and use it in GitHub Desktop.
Save V3ntus/1c96a95cc7e5ea37289e80f1f5239544 to your computer and use it in GitHub Desktop.
My notes on how Discord Rich Presence works on a low level

How to intercept Unix socket messages

If on Linux/Mac OS Discord

# example commands
sudo mv $XDG_RUNTIME_DIR/discord-ipc-0 ./discord-ipc-0 # backup original socket
sudo socat -t100 -x -v UNIX-LISTEN:$XDG_RUNTIME_DIR/discord-ipc-0,mode=777,reuseaddr,fork UNIX-CONNECT:$(pwd)/discord-ipc-0

socat opens a bidirectional tunnel that will forward message to and from these two sockets. -v will print debug message to stdout, allowing you to read the raw hex data traffic

Notes:

Process:

  1. The application sends an init message:
'\x00\x00\x00\x00(\x00\x00\x00{"v":1,"client_id":"504587825122456329"}'
  • 8 byte header for padding?
  • Sends the client ID
  1. Discord client RPC sends a response:
....F...{"cmd":"DISPATCH",
"data":{"v":1,"config":{"cdn_host":"cdn.discordapp.com","api_endpoint":"//discord.com/api","environment":"production"},
"user":{"id":"[USER ID]","username":"[USERNAME]","discriminator":"[USER DISCRIMINATOR]","avatar":"[AVATAR HASH]","bot":false,"flags":xxx,"premium_type":x
 }},"evt":"READY","nonce":null}
  • again with an 8 byte header
  1. Application sends rich presence payloads:
........{"cmd":"SET_ACTIVITY",
"args": {"pid":22371, "activity": {
"state": "Test",
"details": "Test details",
"instance":true}}, "nonce":"1643825703.14191587033350390625"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment