Skip to content

Instantly share code, notes, and snippets.

@rufoa
Last active Aug 3, 2022
Embed
What would you like to do?
sublime merge 2 build 2068 linux
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
target="${1:-/opt/sublime_merge/sublime_merge}"
check_sha() {
local sha_valid
sha_valid=("$@")
local hash
hash="$(sha256sum "$target" | cut -d' ' -f1)"
for s in "${sha_valid[@]}"; do
if [ "$hash" = "$s" ]; then
return 0
fi
done
return 1
}
patch_offset() {
printf "$3" | dd of="$target" bs=1 seek=$(($1)) count="$2" conv=notrunc status=none
}
if [ ! -w "$target" ]; then
echo "$target does not exist or is not writable. Ensure the path is correct and that you have write permission." >&2
exit 1
fi
if check_sha "17cfde363bbb4ed7ad412b29db51d6433571a1397ea5215738233117a0875b3f" "f271c550f5bd3307880db30bf85d9c6ccd08c3b739e9307c907b01e16b6a9ec8"; then
echo "Checksum matches" >&2
else
echo "Checksum does not match. Ensure $target is the correct, unmodified version of Sublime Merge." >&2
exit 1
fi
backup="$target.bak"
cp "$target" "$backup"
revert() {
err=$?
trap - TERM INT EXIT
mv "$backup" "$target"
echo "Reverted modifications to $target" >&2
exit $err
}
trap revert TERM INT EXIT
echo "Patching $target" >&2
# Swap public key
patch_offset 0x59BC0 160 '\x30\x81\x9d\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01\x05\x00\x03\x81\x8b\x00\x30\x81\x87\x02\x81\x81\x00\xc9\xda\x03\xe0\xc6\x33\xce\x4e\x55\xf5\xbf\x60\xf9\xb1\xb0\xda\xd6\x64\xc0\x5d\x03\xca\x7e\x21\xa6\x57\xd2\x17\xa9\x58\x9d\x51\x73\x30\x0d\xb5\x34\x13\x08\xab\x55\x5c\x22\x26\x6c\x03\x0d\xbe\x3c\x80\xb4\x59\xe9\xee\xad\x45\x8f\xa1\x38\x37\x69\xcd\x51\xa2\x19\xa4\x41\x4b\x8c\x0a\x1e\x51\x7f\x58\xc8\x33\xa5\x3c\x15\xc8\x24\xcd\xcc\x94\xb8\x5a\xfe\x44\x12\xa0\x18\x34\x63\x87\x72\x11\x11\x0b\x0c\x12\x44\x76\xec\x60\x13\xc0\x0d\x7e\xf1\x48\xbf\x8a\xce\x10\x02\x79\x45\x31\xf5\x3a\x34\xf2\x56\x6e\x71\xc7\xf4\x45\x02\x01\x11'
# Swap xor key
patch_offset 0x3C6A72 1 '\x00'
# Fix sha-2 check
patch_offset 0x3C72ED 4 '\x44\x89\xf5\x90'
# Disable online licence check
patch_offset 0x3C7E85 1 '\xc3'
# Disable phone home
patch_offset 0x3C6788 1 '\xc3'
if check_sha "dca8a5dbf858d7c27412cde351ba26ca41e02f70d97acd0b76c8dbe695184fc8" "e4664019965cae0391a7e4382bb1e27aba6424a173c4d3ac09aa091ccb349ee7"; then
echo "Patch applied successfully" >&2
else
echo "Patch appears unsuccessful" >&2
exit 1
fi
trap - TERM INT EXIT
----- BEGIN LICENSE -----
TEAM RUFIO
Unlimited User License
E52D-666666
487EE6F0309908F702DDD52AFCD99A6A
6EE14CF8A2D42271B4FC0991BBF93ADC
FAA9075C436B3796669194A2F36CAAEF
B251155329EC2E434FD28B4A21BE68CC
955D306EE9ED843C5E98B1577D02DEAA
1F4E872AE6495CD5E3B1DA55D5ACD2B2
2EA4110FB800F21AA3EC2E3902589BCF
7281A19C2DFF0CEE4AEA5DDD1E6DF893
----- END LICENSE -----
@tukusejssirs
Copy link

tukusejssirs commented May 21, 2021

@rufoa, you definitely did not incorpporate my script, you reworked and improved it! 😉 I still think though that the licence should be inserted via command (echo "$licence" > "$HOME/.config/sublime-merge/Local/License.sublime_license"). If needed, we could place it under a command-line option (getopt; also see also this comment of mine. It might a good idea to backup the previous licence.

Also I think that INFO | WARN | ERROR prefixes are nice to have; they provide some additional information to the user what is the log level of a particular message.

Also I think that the exit codes could be different for every different error type. We should then list them in the help message.


Do tell me what you think about a repo with patching script for both ST and SM. 😉

@MrSunny-M
Copy link

MrSunny-M commented Jun 6, 2021

how to use this on windows

@bitsper2nd
Copy link

bitsper2nd commented Jun 7, 2021

how to use this on windows

I think you would need to use bash. If you have git for windows installed, then you could run the script with a slight modification.

@ardyfeb
Copy link

ardyfeb commented Aug 27, 2021

Any update for 2059 ?

@rufoa
Copy link
Author

rufoa commented Aug 27, 2021

@ardyfeb updated for build 2059

@ahmubashshir
Copy link

ahmubashshir commented Aug 28, 2021

Checksum of 2059 is 3d36ad7cf10e87b83e2443070366e69093c32b16dad820bffe4a46f66245ab70 on my machine, installed from AUR.

@rufoa
Copy link
Author

rufoa commented Aug 28, 2021

@ahmubashshir I can't reproduce that. Please confirm my steps:

This also works correctly with the official repo https://www.sublimemerge.com/docs/linux_repositories#pacman

@ahmubashshir
Copy link

ahmubashshir commented Aug 28, 2021

@zheltikov
Copy link

zheltikov commented Oct 29, 2021

Any update for 2063?

@Stygmatik
Copy link

Stygmatik commented Nov 6, 2021

@zheltikov @rufoa

For build 2063, you can try to modify this gist script with the following:

origin sha256: 92108171247654639a5565f5acd709b354bed94dec7de8fa2effdb20e282e9bd
patched sha256: 18067f36d268e8b5d15e54ae3d6b0d66f7b9d593ddaff3def779aec92f3241b9

Swap public key

same patch, but now at 0x59210

Swap xor key

same patch, but now at 0x3B3B98

Fix sha-2 check

simpler patch, at 0x3B43FB inject these 3 bytes: '\x8B\xEE\x90'

Disable online licence check

same patch, but now at 0x3B4F8D

Disable phone home

same patch, but now at 0x3B38AE

Enjoy ;)

@tukusejssirs
Copy link

tukusejssirs commented Nov 7, 2021

@Stygmatik, in my case, SM 2063 installed on Fedora 34 has the following original hash: e615f12165cbc16546632215590c89103179ddfd17936cba7302c5f7e79090af (/opt/sublime_merge/sublime_merge). Obviously, the patch as is does not work for me.

@Stygmatik
Copy link

Stygmatik commented Nov 7, 2021

I guess Fedora mainteners did mess with the binary (they strip it maybe).
You should be able to swap the Fedora binary with the one coming directly from Sublime guys (https://download.sublimetext.com/sublime_merge_build_2063_x64.tar.xz).
And then apply the patch ;-)

edit: After I did lose few hours to "reverse" (at least I learned a little to use Ghidra) and adapt the patches from previous versions, I found this other gist which have updated offsets for latest Sublime Text 4 and Sublime Merge 2 builds (multi-platform) ^^. Not exactly same offsets, but should also do the trick.

@tukusejssirs
Copy link

tukusejssirs commented Nov 8, 2021

You should be able to swap the Fedora binary with the one coming directly from Sublime guys

@Stygmatik, I doubt that, as I installed it from the offical SM repo.

I guess Fedora mainteners did mess with the binary (they strip it maybe).

It would strange, as until now all @rufoa’s patches worked as expected and he shared same checksums as files installed on my system.

What OS do you use for testing?

I found this other gist

Thanks for sharing. 😉 I’ll try that out too.

@Stygmatik
Copy link

Stygmatik commented Nov 8, 2021

Yes you can swap the binary.

I'm using ArchLinux. And when I'm using AUR to install this sublime merge build, I also got a different checksum than the one coming from https://download.sublimetext.com/sublime_merge_build_2063_x64.tar.xz

But at least, in my case I know why. The PKGBUILD is stripping the downloaded binary before moving it to /opt/.

That's why I said it may be the same with dnf packages.

As you can see in @rufoa patch, it checks for different hashes for the same file.

I only took the hash of the "pure" binary, not the ones coming from AUR, dnf, or apt.

You could try to add your "original" hash to the script. Or take the "pure" binary.

Regards

@rufoa
Copy link
Author

rufoa commented Nov 8, 2021

I'll update this soon, I've been a bit busy

Thanks for the info @Stygmatik, I will investigate your simpler method for the sha-2 check

The official rpm version differs from the other official linux versions for some reason. Both are stripped. But the very end of the file is different (and a couple of bytes in the elf header). Luckily the patches still apply at the same offsets for both

@kimocoder
Copy link

kimocoder commented Dec 14, 2021

@Voldemaar84
Copy link

Voldemaar84 commented Dec 21, 2021

Any update for 2068?

@rufoa
Copy link
Author

rufoa commented Dec 28, 2021

Updated for build 2068

@alexdrm98
Copy link

alexdrm98 commented Apr 8, 2022

not working for build 2068 from AUR.
Checksum does not match. Ensure /opt/sublime_merge/sublime_merge is the correct, unmodified version of Sublime Merge.
>> sha256sum /opt/sublime_merge/sublime_merge
16a5c27826c7b53d29c29de34c7d4f4301ad10fe06cf33397857077ad8618f94 /opt/sublime_merge/sublime_merge

@rufoa
Copy link
Author

rufoa commented Apr 8, 2022

@alexdrm98 download the tar.xz from the SM website and use the unmodified sublime_merge binary inside as the input to this patcher

@alexdrm98
Copy link

alexdrm98 commented Apr 8, 2022

@alexdrm98 download the tar.xz from the SM website and use the unmodified sublime_merge binary inside as the input to this patcher

Thanks man! it worked :)
btw, i've sublime 4131 build. it shows "license upgrade required". Does that mean if i upgrade i have to patch/buy license?

@alexdrm98
Copy link

alexdrm98 commented Apr 8, 2022

@alexdrm98 download the tar.xz from the SM website and use the unmodified sublime_merge binary inside as the input to this patcher

Thanks man! it worked :)
btw, i've sublime 4131 build. it shows "license upgrade required". Does that mean if i upgrade i have to patch/buy license?

@rufoa
Copy link
Author

rufoa commented Apr 8, 2022

@alexdrm98 yes, I believe that means your 3 year licence has expired, so to use versions newer than (your licence purchase date + 3 years) you'll need a new licence or patch

@ask6483
Copy link

ask6483 commented Apr 25, 2022

There is new build 2071, any chances to make the patch work?

@zheltikov
Copy link

zheltikov commented Apr 25, 2022

Any update for the latest 2071 build?

@rufoa
Copy link
Author

rufoa commented Apr 25, 2022

Yes I'm aware of the new version and hope to update the patch soon

@rafaelribeiroo
Copy link

rafaelribeiroo commented May 2, 2022

Yes I'm aware of the new version and hope to update the patch soon

Any update?

@kimhongsu
Copy link

kimhongsu commented Jun 15, 2022

Any update?

@ask6483
Copy link

ask6483 commented Jun 15, 2022

Thx @theol0403 works great on linux!

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