Skip to content

Instantly share code, notes, and snippets.

@MrMetric
Forked from gpadd/fix_telegram.md
Last active January 12, 2017 04:54
Show Gist options
  • Save MrMetric/93a4e0735a794b02353184cfef712e8a to your computer and use it in GitHub Desktop.
Save MrMetric/93a4e0735a794b02353184cfef712e8a to your computer and use it in GitHub Desktop.
How to fix the really really round telegram bubbles and avatars and << >> -- stuff

Credits goes to several people:

MrMetric - telegramdesktop/tdesktop#2235 (comment)

Afogal - https://gist.github.com/afogal/5ec200f46856b1b776a9a91601c00b87

SijmenSchoon - https://gist.github.com/SijmenSchoon/a24b453f001549bb14562de5078ae1bc

Streetwalrus - https://gist.github.com/Streetwalrus/bb2091bc5761a71e3b7c85d4e4a1ad99

Here is a bash/GDB script to patch Telegram Desktop 1.0 (tested on GNU/Linux only):

#/bin/bash

cp Telegram Telegram_backup

gdb --write ./Telegram << EOF

tbreak _ZN3App9initMediaEv
set {char}_ZN3App9msgRadiusEv=0xB8
set {int}(_ZN3App9msgRadiusEv+1)=3
set {char}(_ZN3App9msgRadiusEv+5)=0xC3

set {char}_Z25replaceStringWithEntitiesRK13QLatin1String5QCharR7QStringP5QListI12EntityInTextEb=0xC3

set {char}(_ZNK5Image10pixCircledEii+208)=1
EOF

If you want to run Telegram Desktop without modifying it, use this instead:

tbreak _ZN3App9initMediaEv
commands
	set {char}_ZN3App9msgRadiusEv=0xB8
	set {int}(_ZN3App9msgRadiusEv+1)=0
	set {char}(_ZN3App9msgRadiusEv+5)=0xC3

	set {char}_Z25replaceStringWithEntitiesRK13QLatin1String5QCharR7QStringP5QListI12EntityInTextEb=0xC3

	set {char}(_ZNK5Image10pixCircledEii+208)=1
end
run
detach
quit

Assuming you saved it to fix_telegram.gdb and Telegram Desktop is /usr/bin/telegram-desktop, run it like this:

gdb -x fix_telegram.gdb /usr/bin/telegram-desktop

This replaces the start of App::msgRadius with

mov $0x3, %eax
retq

In C++, that is return 3;

Explanation: 0xB8 means mov a number to %eax, 3 is the border radius, and 0xC3 is retq.

The start of void replaceStringWithEntities is replaced with retq, which disables these substitutions:

-- → — (em dash)
<< → «
>> → »

In Image::pixCircled, this line:

auto options = Images::Option::Smooth | Images::Option::Circled;

Is changed to:

auto options = Images::Option::Smooth;

Explanation: Smooth is 1, Circled is 4. That combination is 5. The byte is replaced with 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment