props.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. package http
  2. import (
  3. "encoding/base64"
  4. "encoding/json"
  5. "github.com/diamondburned/arikawa/v3/discord"
  6. "github.com/diamondburned/arikawa/v3/gateway"
  7. "github.com/google/uuid"
  8. )
  9. const (
  10. OS = "Windows"
  11. OSVersion = "10"
  12. Browser = "Chrome"
  13. BrowserVersion = "143.0.0.0"
  14. BrowserUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " + Browser + "/" + BrowserVersion + " Safari/537.36"
  15. ClientBuildNumber = 482285
  16. Locale = discord.EnglishUS
  17. )
  18. func IdentifyProperties() gateway.IdentifyProperties {
  19. return gateway.IdentifyProperties{
  20. gateway.IdentifyDevice: "",
  21. gateway.IdentifyOS: OS,
  22. "os_version": OSVersion,
  23. gateway.IdentifyBrowser: Browser,
  24. "browser_version": BrowserVersion,
  25. "browser_user_agent": BrowserUserAgent,
  26. "client_build_number": ClientBuildNumber,
  27. "client_event_source": nil,
  28. "client_app_state": "focused",
  29. "client_launch_id": uuid.NewString(),
  30. "client_heartbeat_session_id": uuid.NewString(),
  31. "launch_signature": generateLaunchSignature(),
  32. "system_locale": Locale,
  33. "release_channel": "stable",
  34. "has_client_mods": false,
  35. "referrer": "",
  36. "referrer_current": "",
  37. "referring_domain": "",
  38. "referring_domain_current": "",
  39. // These properties are only sent when identifying with the gateway and are not included in the X-Super-Properties header.
  40. "is_fast_connect": false,
  41. "gateway_connect_reasons": "AppSkeleton",
  42. }
  43. }
  44. func getSuperProps() (string, error) {
  45. props := IdentifyProperties()
  46. delete(props, "is_fast_connect")
  47. delete(props, "gateway_connect_reasons")
  48. raw, err := json.Marshal(props)
  49. if err != nil {
  50. return "", err
  51. }
  52. return base64.StdEncoding.EncodeToString(raw), nil
  53. }
  54. func generateLaunchSignature() string {
  55. // Discord uses specific UUID bits to detect client modifications.
  56. // This mask clears detection bits to avoid identification.
  57. // Reference: https://docs.discord.food/reference#launch-signature
  58. //
  59. // Required version and variant bits for UUIDv4 validity are set by google/uuid.
  60. // Reference: https://github.com/google/uuid/blob/master/version4.go#L54
  61. mask := [16]byte{
  62. 0b11111111, 0b01111111, 0b11101111, 0b11101111,
  63. 0b11110111, 0b11101111, 0b11110111, 0b11111111,
  64. 0b11011111, 0b01111110, 0b11111111, 0b10111111,
  65. 0b11111110, 0b11111111, 0b11110111, 0b11111111,
  66. }
  67. id := uuid.New()
  68. for i := range mask {
  69. id[i] &= mask[i]
  70. }
  71. return id.String()
  72. }