Compare commits
No commits in common. "08d78941a348b319b05f5c3c6b3575144b45f84a" and "c92fa1b8d4722303a631b64a7f1ba3d409c716e9" have entirely different histories.
08d78941a3
...
c92fa1b8d4
12 changed files with 684 additions and 0 deletions
32
discord-electron-openasar/.SRCINFO
Normal file
32
discord-electron-openasar/.SRCINFO
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
pkgbase = discord-electron-openasar
|
||||||
|
pkgdesc = Discord packaged with OpenAsar using system provided electron (v39) for increased security and performance
|
||||||
|
pkgver = 0.0.121+847
|
||||||
|
pkgrel = 1
|
||||||
|
url = https://discord.com
|
||||||
|
install = discord-electron-openasar.install
|
||||||
|
arch = x86_64
|
||||||
|
license = custom
|
||||||
|
makedepends = git
|
||||||
|
makedepends = asar
|
||||||
|
makedepends = nodejs
|
||||||
|
makedepends = curl
|
||||||
|
depends = electron39
|
||||||
|
depends = libxss
|
||||||
|
depends = unzip
|
||||||
|
optdepends = libpulse: Pulseaudio support
|
||||||
|
optdepends = xdg-utils: Open files
|
||||||
|
optdepends = python-pyelftools: Required for Krisp patcher
|
||||||
|
optdepends = python-capstone: Required for Krisp patcher
|
||||||
|
provides = discord
|
||||||
|
conflicts = discord
|
||||||
|
options = !strip
|
||||||
|
source = https://dl.discordapp.net/apps/linux/0.0.121/discord-0.0.121.tar.gz
|
||||||
|
source = discord-launcher.sh
|
||||||
|
source = krisp-patcher.py
|
||||||
|
source = git+https://github.com/goosemod/openasar.git#commit=5b259e4efaf9eee69aeca7b2ef153e5bfedc35d0
|
||||||
|
sha512sums = 5e5b5f9c45004174353a10db9625234521f373d737f0f0dcc3f45d9cdf02439ad549fef7e46d09abb37c9748e8411403eeaa53ac316c89380edb929b01746c66
|
||||||
|
sha512sums = 618c89fdd90d6826dd44c3d5973428fb68b1836f1198a356e936da0b78c18b748d522ff7ecee15752d590dcd137ef16c4370ac6325c5b5f0aced4b5cce36b825
|
||||||
|
sha512sums = 42cef68c1f7d574b4fbe859a4dc616e8994c7d16f62bcae3ff1f88e1edc58ac37b39c238d7defa9c97ceda417fcd6224cf0a0fd2608b8d18d0877e3c1befa59c
|
||||||
|
sha512sums = 86e296524f831b450620e4c0abb576f5b370982f70951beafdc821bcbce7db4b7b000bb2a7ce29516c209c2590fb428e8fed9450387ec37918dd79fc0a0a85e4
|
||||||
|
|
||||||
|
pkgname = discord-electron-openasar
|
||||||
92
discord-electron-openasar/PKGBUILD
Normal file
92
discord-electron-openasar/PKGBUILD
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
# Maintainer: Manuel Hüsers <aur@huesers.de>
|
||||||
|
|
||||||
|
pkgname=discord-electron-openasar
|
||||||
|
_pkgname=discord
|
||||||
|
pkgver=0.0.121+847
|
||||||
|
_pkgver=${pkgver%%+*}
|
||||||
|
pkgrel=1
|
||||||
|
_electronver=39
|
||||||
|
_electronname="electron${_electronver}"
|
||||||
|
pkgdesc="Discord packaged with OpenAsar using system provided electron (v${_electronver}) for increased security and performance"
|
||||||
|
arch=('x86_64')
|
||||||
|
provides=("${_pkgname}")
|
||||||
|
conflicts=("${_pkgname}")
|
||||||
|
url='https://discord.com'
|
||||||
|
license=('custom')
|
||||||
|
options=('!strip')
|
||||||
|
install="$pkgname.install"
|
||||||
|
depends=("${_electronname}" 'libxss' 'unzip')
|
||||||
|
makedepends=('git' 'asar' 'nodejs' 'curl')
|
||||||
|
optdepends=(
|
||||||
|
'libpulse: Pulseaudio support'
|
||||||
|
'xdg-utils: Open files'
|
||||||
|
'python-pyelftools: Required for Krisp patcher'
|
||||||
|
'python-capstone: Required for Krisp patcher'
|
||||||
|
)
|
||||||
|
source=("https://dl.discordapp.net/apps/linux/${_pkgver}/${_pkgname}-${_pkgver}.tar.gz"
|
||||||
|
'discord-launcher.sh'
|
||||||
|
'krisp-patcher.py' # original: https://github.com/sersorrel/sys/blob/main/hm/discord/krisp-patcher.py
|
||||||
|
"git+https://github.com/goosemod/openasar.git#commit=5b259e4efaf9eee69aeca7b2ef153e5bfedc35d0")
|
||||||
|
sha512sums=('5e5b5f9c45004174353a10db9625234521f373d737f0f0dcc3f45d9cdf02439ad549fef7e46d09abb37c9748e8411403eeaa53ac316c89380edb929b01746c66'
|
||||||
|
'618c89fdd90d6826dd44c3d5973428fb68b1836f1198a356e936da0b78c18b748d522ff7ecee15752d590dcd137ef16c4370ac6325c5b5f0aced4b5cce36b825'
|
||||||
|
'42cef68c1f7d574b4fbe859a4dc616e8994c7d16f62bcae3ff1f88e1edc58ac37b39c238d7defa9c97ceda417fcd6224cf0a0fd2608b8d18d0877e3c1befa59c'
|
||||||
|
'86e296524f831b450620e4c0abb576f5b370982f70951beafdc821bcbce7db4b7b000bb2a7ce29516c209c2590fb428e8fed9450387ec37918dd79fc0a0a85e4')
|
||||||
|
|
||||||
|
# just in case I get the version wrong
|
||||||
|
pkgver() {
|
||||||
|
cd "${srcdir}/openasar"
|
||||||
|
printf "%s+%s" "$_pkgver" "$(git rev-list --count HEAD)"
|
||||||
|
}
|
||||||
|
|
||||||
|
prepare() {
|
||||||
|
# prepare launcher script
|
||||||
|
sed -i -e "s|@PKGNAME@|${_pkgname}|g" \
|
||||||
|
-e "s|@PKGVER@|${_pkgver}|g" \
|
||||||
|
-e "s|@ELECTRON@|${_electronname}|g" \
|
||||||
|
discord-launcher.sh
|
||||||
|
|
||||||
|
# fix the .desktop file
|
||||||
|
sed -i -e "s|Exec=.*|Exec=/usr/bin/${_pkgname}|" ${_pkgname^}/$_pkgname.desktop
|
||||||
|
|
||||||
|
# create the license files
|
||||||
|
curl -o LICENSE.html https://discord.com/terms
|
||||||
|
curl -o OSS-LICENSES.html https://discord.com/licenses
|
||||||
|
}
|
||||||
|
|
||||||
|
build() {
|
||||||
|
cd "${srcdir}"/openasar
|
||||||
|
|
||||||
|
# pack openasar
|
||||||
|
sed -i -e "s|nightly|nightly-$(git rev-parse HEAD | cut -c 1-7)|" src/index.js
|
||||||
|
sed -i -e "/config.setup = true/a\ config.autoupdate = false;" src/config/index.js
|
||||||
|
sed -i -e "s|process.resourcesPath|'/usr/lib/${_pkgname}/resources'|" src/utils/buildInfo.js
|
||||||
|
sed -i -e "s|^Exec=\${exec}$|Exec=/usr/bin/${_pkgname}|" \
|
||||||
|
-e "s|^Name=\${basename(exec)}$|Name=${_pkgname^}|" src/autoStart.js
|
||||||
|
node scripts/strip.js
|
||||||
|
asar p src app.asar
|
||||||
|
}
|
||||||
|
|
||||||
|
package() {
|
||||||
|
# create necessary directories
|
||||||
|
install -d "${pkgdir}"/usr/lib/$_pkgname
|
||||||
|
|
||||||
|
# copy relevant data
|
||||||
|
cp -r ${_pkgname^}/resources "${pkgdir}"/usr/lib/$_pkgname/
|
||||||
|
|
||||||
|
# intall icon and desktop file
|
||||||
|
install -Dm 644 ${_pkgname^}/$_pkgname.png "${pkgdir}"/usr/share/pixmaps/$_pkgname.png
|
||||||
|
install -Dm 644 ${_pkgname^}/$_pkgname.desktop "${pkgdir}"/usr/share/applications/$_pkgname.desktop
|
||||||
|
|
||||||
|
# overwrite Discord asar
|
||||||
|
install -Dm 644 openasar/app.asar "${pkgdir}"/usr/lib/$_pkgname/resources/
|
||||||
|
|
||||||
|
# install the launch script
|
||||||
|
install -Dm 755 discord-launcher.sh "${pkgdir}"/usr/bin/$_pkgname
|
||||||
|
|
||||||
|
# install krisp patcher
|
||||||
|
install -Dm 644 krisp-patcher.py "${pkgdir}"/usr/lib/$_pkgname/
|
||||||
|
|
||||||
|
# install licenses
|
||||||
|
install -Dm 644 LICENSE.html "${pkgdir}"/usr/share/licenses/$_pkgname/LICENSE.html
|
||||||
|
install -Dm 644 OSS-LICENSES.html "${pkgdir}"/usr/share/licenses/$_pkgname/OSS-LICENSES.html
|
||||||
|
}
|
||||||
43
discord-electron-openasar/discord-electron-openasar.install
Normal file
43
discord-electron-openasar/discord-electron-openasar.install
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
post_upgrade() {
|
||||||
|
# return if old package version is greater than or equal to 0.0.55+827-1...
|
||||||
|
(( $(vercmp $2 '0.0.55+827-1') >= 0 )) && return
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
==> Instead of using 'rizin' to patch Krisp support a patcher written in Python
|
||||||
|
is now used. Consider installing the necessary optional dependencies to use
|
||||||
|
this feature.
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# return if old package version is greater than or equal to 0.0.39+824-2...
|
||||||
|
(( $(vercmp $2 '0.0.39+824-2') >= 0 )) && return
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
==> In order to patch Krisp noise suppression support set 'PATCH_KRISP=true'
|
||||||
|
in '~/.config/discord.conf' in addition to having 'rizin' installed.
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# return if old package version is greater than or equal to 0.0.27+809-5...
|
||||||
|
(( $(vercmp $2 '0.0.27+809-5') >= 0 )) && return
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
==> The launch script will now patch Krisp noise suppression support
|
||||||
|
if 'rizin' is installed. Restart your Discord client after update
|
||||||
|
to apply the patch.
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# return if old package version is greater than or equal to 0.0.27+809-2...
|
||||||
|
(( $(vercmp $2 '0.0.27+809-2') >= 0 )) && return
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
==> You can now set additional Electron flags in '~/.config/discord-flags.conf'.
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
post_install() {
|
||||||
|
cat <<EOF
|
||||||
|
==> For Krisp noise suppression support consider installing the necessary optional
|
||||||
|
dependencies and setting 'PATCH_KRISP=true' in '~/.config/discord.conf'.
|
||||||
|
Restart your Discord client afterwards to apply the patch.
|
||||||
|
==> Additional Electron flags can be set in '~/.config/discord-flags.conf'.
|
||||||
|
EOF
|
||||||
|
}
|
||||||
40
discord-electron-openasar/discord-launcher.sh
Normal file
40
discord-electron-openasar/discord-launcher.sh
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
declare -a flags
|
||||||
|
declare -l PATCH_KRISP
|
||||||
|
|
||||||
|
[[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/@PKGNAME@.conf" ]] && source "${XDG_CONFIG_HOME:-$HOME/.config}/@PKGNAME@.conf"
|
||||||
|
|
||||||
|
flags_file="${XDG_CONFIG_HOME:-$HOME/.config}/@PKGNAME@-flags.conf"
|
||||||
|
krisp_bin="${DISCORD_USER_DATA_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/@PKGNAME@}/@PKGVER@/modules/@PKGNAME@_krisp/@PKGNAME@_krisp.node"
|
||||||
|
|
||||||
|
if [[ "${PATCH_KRISP:-}" == true ]] && [[ -w "${krisp_bin}" ]]; then
|
||||||
|
if hash python &> /dev/null && python -c 'import capstone; import elftools' &> /dev/null; then
|
||||||
|
# Patch Krisp binary to ignore signature check
|
||||||
|
echo -n 'Running Krisp patcher... '
|
||||||
|
python /usr/lib/@PKGNAME@/krisp-patcher.py "${krisp_bin}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -r "${flags_file}" ]]; then
|
||||||
|
# Replacing because old flag does not work
|
||||||
|
if [[ -w "${flags_file}" ]] && grep -q '\--ignore-gpu-blacklist' "${flags_file}"; then
|
||||||
|
sed -i 's|--ignore-gpu-blacklist|--ignore-gpu-blocklist|' "${flags_file}"
|
||||||
|
fi
|
||||||
|
mapfile -t < "${flags_file}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
for line in "${MAPFILE[@]}"; do
|
||||||
|
if [[ ! "${line}" =~ ^[[:space:]]*#.* ]] && [[ -n "${line}" ]]; then
|
||||||
|
flags+=("${line}")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
unset flags_file krisp_bin
|
||||||
|
|
||||||
|
|
||||||
|
exec /usr/lib/@ELECTRON@/electron \
|
||||||
|
/usr/lib/@PKGNAME@/resources/app.asar \
|
||||||
|
"${flags[@]}" "$@"
|
||||||
85
discord-electron-openasar/krisp-patcher.py
Normal file
85
discord-electron-openasar/krisp-patcher.py
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
import sys
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
from elftools.elf.elffile import ELFFile
|
||||||
|
from capstone import *
|
||||||
|
from capstone.x86 import *
|
||||||
|
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print(f"Usage: {sys.argv[0]} [path to discord_krisp.node]")
|
||||||
|
# "Unix programs generally use 2 for command line syntax errors and 1 for all other kind of errors."
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
executable = sys.argv[1]
|
||||||
|
|
||||||
|
elf = ELFFile(open(executable, "rb"))
|
||||||
|
symtab = elf.get_section_by_name('.symtab')
|
||||||
|
|
||||||
|
krisp_initialize_address = symtab.get_symbol_by_name("_ZN7discordL17DoKrispInitializeEv")[0].entry.st_value
|
||||||
|
isSignedByDiscord_address = symtab.get_symbol_by_name("_ZN7discord4util17IsSignedByDiscordERKNSt4__Cr12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE")[0].entry.st_value
|
||||||
|
|
||||||
|
text = elf.get_section_by_name('.text')
|
||||||
|
text_start = text['sh_addr']
|
||||||
|
text_start_file = text['sh_offset']
|
||||||
|
# This seems to always be zero (.text starts at the right offset in the file). Do it just in case?
|
||||||
|
address_to_file = text_start_file - text_start
|
||||||
|
|
||||||
|
# Done with the ELF now.
|
||||||
|
# elf.close()
|
||||||
|
|
||||||
|
krisp_initialize_offset = krisp_initialize_address - address_to_file
|
||||||
|
isSignedByDiscord_offset = krisp_initialize_address - address_to_file
|
||||||
|
|
||||||
|
f = open(executable, "rb")
|
||||||
|
f.seek(krisp_initialize_offset)
|
||||||
|
krisp_initialize = f.read(96)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
# States
|
||||||
|
found_issigned_by_discord_call = False
|
||||||
|
found_issigned_by_discord_test = False
|
||||||
|
found_issigned_by_discord_je = False
|
||||||
|
found_already_patched = False
|
||||||
|
je_location = None
|
||||||
|
je_size = 0
|
||||||
|
|
||||||
|
# We are looking for a call to IsSignedByDiscord, followed by a test, followed by a je.
|
||||||
|
# Then we replace the je with nops.
|
||||||
|
|
||||||
|
md = Cs(CS_ARCH_X86, CS_MODE_64)
|
||||||
|
md.detail = True
|
||||||
|
for i in md.disasm(krisp_initialize, krisp_initialize_address):
|
||||||
|
if i.id == X86_INS_CALL:
|
||||||
|
if i.operands[0].type == X86_OP_IMM:
|
||||||
|
if i.operands[0].imm == isSignedByDiscord_address:
|
||||||
|
found_issigned_by_discord_call = True
|
||||||
|
|
||||||
|
if i.id == X86_INS_TEST:
|
||||||
|
if found_issigned_by_discord_call:
|
||||||
|
found_issigned_by_discord_test = True
|
||||||
|
|
||||||
|
if i.id == X86_INS_JE:
|
||||||
|
if found_issigned_by_discord_test:
|
||||||
|
found_issigned_by_discord_je = True
|
||||||
|
je_location = i.address
|
||||||
|
je_size = len(i.bytes)
|
||||||
|
break
|
||||||
|
|
||||||
|
if i.id == X86_INS_NOP:
|
||||||
|
if found_issigned_by_discord_test:
|
||||||
|
found_already_patched = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if je_location:
|
||||||
|
print(f"Found patch location: 0x{je_location:x}")
|
||||||
|
|
||||||
|
shutil.copyfile(executable, executable + ".orig")
|
||||||
|
f = open(executable, 'rb+')
|
||||||
|
f.seek(je_location - address_to_file)
|
||||||
|
f.write(b'\x90' * je_size) # je can be larger than 2 bytes given a large enough displacement :(
|
||||||
|
f.close()
|
||||||
|
else:
|
||||||
|
if found_already_patched:
|
||||||
|
print("Couldn't find patch location - already patched.")
|
||||||
|
else:
|
||||||
|
print("Couldn't find patch location - review manually. Sorry.")
|
||||||
57
discord-electron-openasar/update-package.sh
Executable file
57
discord-electron-openasar/update-package.sh
Executable file
|
|
@ -0,0 +1,57 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
readonly all_off="$(tput sgr0)"
|
||||||
|
readonly bold="${all_off}$(tput bold)"
|
||||||
|
readonly white="${bold}$(tput setaf 7)"
|
||||||
|
readonly blue="${bold}$(tput setaf 4)"
|
||||||
|
readonly red="${bold}$(tput setaf 1)"
|
||||||
|
|
||||||
|
msg() {
|
||||||
|
printf "${blue}::${white} $1${all_off}\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
printf "${red}::${white} $1${all_off}\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
msgbegin() {
|
||||||
|
printf "${blue}::${white} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
msgend() {
|
||||||
|
printf "$1${all_off}\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
readonly krisp_zip='discord_krisp-1.zip'
|
||||||
|
readonly krisp_bin='discord_krisp.node'
|
||||||
|
|
||||||
|
# head to directory of this script
|
||||||
|
cd $(dirname "$0")
|
||||||
|
|
||||||
|
# update package to version used in PKGBUILD
|
||||||
|
source PKGBUILD
|
||||||
|
|
||||||
|
msg "Running updpkgsums (Updating checksums)"
|
||||||
|
updpkgsums
|
||||||
|
|
||||||
|
msg "Running mksrcinfo (Updating SRCINFO file)"
|
||||||
|
makepkg --printsrcinfo > .SRCINFO
|
||||||
|
|
||||||
|
msg "Getting Krisp module"
|
||||||
|
curl -O "https://dl.discordapp.net/apps/linux/${_pkgver:-${pkgver}}/modules/${krisp_zip}"
|
||||||
|
unzip "${krisp_zip}" "${krisp_bin}"
|
||||||
|
|
||||||
|
msg "Checking if Krisp module is patchable (watch output)"
|
||||||
|
python krisp-patcher.py "${krisp_bin}"
|
||||||
|
|
||||||
|
#msg "Updating Krisp module checksum"
|
||||||
|
#readonly chcksm=$(b2sum "${krisp_bin}.orig" | head -c 128)
|
||||||
|
#sed -i "s/^_krisp_b2sum='.*'$/_krisp_b2sum='${chcksm}'/" PKGBUILD
|
||||||
|
|
||||||
|
msgbegin "Cleaning up... "
|
||||||
|
rm -f "${krisp_zip}" "${krisp_bin}" "${krisp_bin}.orig"
|
||||||
|
|
||||||
|
msgend "Done"
|
||||||
27
discord-electron/.SRCINFO
Normal file
27
discord-electron/.SRCINFO
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
pkgbase = discord-electron
|
||||||
|
pkgdesc = Discord using system provided electron (v39) for increased security and performance
|
||||||
|
pkgver = 0.0.121
|
||||||
|
pkgrel = 1
|
||||||
|
url = https://discord.com
|
||||||
|
install = discord-electron.install
|
||||||
|
arch = x86_64
|
||||||
|
license = custom
|
||||||
|
makedepends = asar
|
||||||
|
makedepends = curl
|
||||||
|
depends = electron39
|
||||||
|
depends = libxss
|
||||||
|
optdepends = libpulse: Pulseaudio support
|
||||||
|
optdepends = xdg-utils: Open files
|
||||||
|
optdepends = python-pyelftools: Required for Krisp patcher
|
||||||
|
optdepends = python-capstone: Required for Krisp patcher
|
||||||
|
provides = discord
|
||||||
|
conflicts = discord
|
||||||
|
options = !strip
|
||||||
|
source = https://dl.discordapp.net/apps/linux/0.0.121/discord-0.0.121.tar.gz
|
||||||
|
source = discord-launcher.sh
|
||||||
|
source = krisp-patcher.py
|
||||||
|
sha512sums = 5e5b5f9c45004174353a10db9625234521f373d737f0f0dcc3f45d9cdf02439ad549fef7e46d09abb37c9748e8411403eeaa53ac316c89380edb929b01746c66
|
||||||
|
sha512sums = 618c89fdd90d6826dd44c3d5973428fb68b1836f1198a356e936da0b78c18b748d522ff7ecee15752d590dcd137ef16c4370ac6325c5b5f0aced4b5cce36b825
|
||||||
|
sha512sums = 42cef68c1f7d574b4fbe859a4dc616e8994c7d16f62bcae3ff1f88e1edc58ac37b39c238d7defa9c97ceda417fcd6224cf0a0fd2608b8d18d0877e3c1befa59c
|
||||||
|
|
||||||
|
pkgname = discord-electron
|
||||||
82
discord-electron/PKGBUILD
Normal file
82
discord-electron/PKGBUILD
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
pkgname=discord-electron
|
||||||
|
_pkgname=discord
|
||||||
|
pkgver=0.0.121
|
||||||
|
pkgrel=1
|
||||||
|
_electronver=39
|
||||||
|
_electronname="electron${_electronver}"
|
||||||
|
pkgdesc="Discord using system provided electron (v${_electronver}) for increased security and performance"
|
||||||
|
arch=('x86_64')
|
||||||
|
provides=("${_pkgname}")
|
||||||
|
conflicts=("${_pkgname}")
|
||||||
|
url='https://discord.com'
|
||||||
|
license=('custom')
|
||||||
|
options=('!strip')
|
||||||
|
install="$pkgname.install"
|
||||||
|
depends=("${_electronname}" 'libxss')
|
||||||
|
makedepends=('asar' 'curl')
|
||||||
|
optdepends=(
|
||||||
|
'libpulse: Pulseaudio support'
|
||||||
|
'xdg-utils: Open files'
|
||||||
|
'python-pyelftools: Required for Krisp patcher'
|
||||||
|
'python-capstone: Required for Krisp patcher'
|
||||||
|
)
|
||||||
|
source=("https://dl.discordapp.net/apps/linux/${pkgver}/${_pkgname}-${pkgver}.tar.gz"
|
||||||
|
'discord-launcher.sh'
|
||||||
|
'krisp-patcher.py') # original: https://github.com/sersorrel/sys/blob/main/hm/discord/krisp-patcher.py
|
||||||
|
sha512sums=('5e5b5f9c45004174353a10db9625234521f373d737f0f0dcc3f45d9cdf02439ad549fef7e46d09abb37c9748e8411403eeaa53ac316c89380edb929b01746c66'
|
||||||
|
'618c89fdd90d6826dd44c3d5973428fb68b1836f1198a356e936da0b78c18b748d522ff7ecee15752d590dcd137ef16c4370ac6325c5b5f0aced4b5cce36b825'
|
||||||
|
'42cef68c1f7d574b4fbe859a4dc616e8994c7d16f62bcae3ff1f88e1edc58ac37b39c238d7defa9c97ceda417fcd6224cf0a0fd2608b8d18d0877e3c1befa59c')
|
||||||
|
|
||||||
|
prepare() {
|
||||||
|
# prepare launcher script
|
||||||
|
sed -i -e "s|@PKGNAME@|${_pkgname}|g" \
|
||||||
|
-e "s|@PKGVER@|${pkgver}|g" \
|
||||||
|
-e "s|@ELECTRON@|${_electronname}|g" \
|
||||||
|
discord-launcher.sh
|
||||||
|
|
||||||
|
# fix the .desktop file
|
||||||
|
sed -i -e "s|Exec=.*|Exec=/usr/bin/${_pkgname}|" ${_pkgname^}/$_pkgname.desktop
|
||||||
|
|
||||||
|
# create the license files
|
||||||
|
curl -o LICENSE.html https://discord.com/terms
|
||||||
|
curl -o OSS-LICENSES.html https://discord.com/licenses
|
||||||
|
}
|
||||||
|
|
||||||
|
build() {
|
||||||
|
cd "${srcdir}"/${_pkgname^}
|
||||||
|
|
||||||
|
# use system electron
|
||||||
|
asar e resources/app.asar resources/app
|
||||||
|
rm resources/app.asar
|
||||||
|
sed -i -e "/resourcesPath = .*;$/d" -e "s|return resourcesPath|return '/usr/lib/${_pkgname}/resources'|" resources/app/common/paths.js
|
||||||
|
sed -i -e "s|process.resourcesPath|'/usr/lib/${_pkgname}/resources'|" resources/app/app_bootstrap/buildInfo.js
|
||||||
|
sed -i -e "/^const appName/d" -e "/^const exePath/d" -e "/^const exeDir/d" -e "/^const iconPath/d" \
|
||||||
|
-e "s|^Exec=\${exePath}$|Exec=/usr/bin/${_pkgname}|" \
|
||||||
|
-e "s|^Name=\${appName}$|Name=${_pkgname^}|" \
|
||||||
|
-e "s|^Icon=\${iconPath}$|Icon=/usr/share/pixmaps/${_pkgname}.png|" \
|
||||||
|
resources/app/app_bootstrap/autoStart/linux.js
|
||||||
|
asar p resources/app resources/app.asar
|
||||||
|
rm -rf resources/app
|
||||||
|
}
|
||||||
|
|
||||||
|
package() {
|
||||||
|
# create necessary directories
|
||||||
|
install -d "${pkgdir}"/usr/lib/$_pkgname
|
||||||
|
|
||||||
|
# copy relevant data
|
||||||
|
cp -r ${_pkgname^}/resources "${pkgdir}"/usr/lib/$_pkgname/
|
||||||
|
|
||||||
|
# intall icon and desktop file
|
||||||
|
install -Dm 644 ${_pkgname^}/$_pkgname.png "${pkgdir}"/usr/share/pixmaps/$_pkgname.png
|
||||||
|
install -Dm 644 ${_pkgname^}/$_pkgname.desktop "${pkgdir}"/usr/share/applications/$_pkgname.desktop
|
||||||
|
|
||||||
|
# install the launch script
|
||||||
|
install -Dm 755 discord-launcher.sh "${pkgdir}"/usr/bin/$_pkgname
|
||||||
|
|
||||||
|
# install krisp patcher
|
||||||
|
install -Dm 644 krisp-patcher.py "${pkgdir}"/usr/lib/$_pkgname/
|
||||||
|
|
||||||
|
# install licenses
|
||||||
|
install -Dm 644 LICENSE.html "${pkgdir}"/usr/share/licenses/$_pkgname/LICENSE.html
|
||||||
|
install -Dm 644 OSS-LICENSES.html "${pkgdir}"/usr/share/licenses/$_pkgname/OSS-LICENSES.html
|
||||||
|
}
|
||||||
44
discord-electron/discord-electron.install
Normal file
44
discord-electron/discord-electron.install
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
post_upgrade() {
|
||||||
|
# return if old package version is greater than or equal to 0.0.55-1...
|
||||||
|
(( $(vercmp $2 '0.0.55-1') >= 0 )) && return
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
==> Instead of using 'rizin' to patch Krisp support a patcher written in Python
|
||||||
|
is now used. Consider installing the necessary optional dependencies to use
|
||||||
|
this feature.
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# return if old package version is greater than or equal to 0.0.39-2...
|
||||||
|
(( $(vercmp $2 '0.0.39-2') >= 0 )) && return
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
==> In order to patch Krisp noise suppression support set 'PATCH_KRISP=true'
|
||||||
|
in '~/.config/discord.conf' in addition to having 'rizin' installed.
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# return if old package version is greater than or equal to 0.0.27-5...
|
||||||
|
(( $(vercmp $2 '0.0.27-5') >= 0 )) && return
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
==> The launch script will now patch Krisp noise suppression support
|
||||||
|
if 'rizin' is installed. Restart your Discord client after update
|
||||||
|
to apply the patch.
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# return if old package version is greater than or equal to 0.0.27-2...
|
||||||
|
(( $(vercmp $2 '0.0.27-2') >= 0 )) && return
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
==> You can now set additional Electron flags in '~/.config/discord-flags.conf'.
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
post_install() {
|
||||||
|
cat <<EOF
|
||||||
|
==> For Krisp noise suppression support consider installing the necessary optional
|
||||||
|
dependencies and setting 'PATCH_KRISP=true' in '~/.config/discord.conf'.
|
||||||
|
Restart your Discord client afterwards to apply the patch.
|
||||||
|
==> In case of performance problems consider setting additional flags
|
||||||
|
in '~/.config/discord-flags.conf'.
|
||||||
|
EOF
|
||||||
|
}
|
||||||
40
discord-electron/discord-launcher.sh
Normal file
40
discord-electron/discord-launcher.sh
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
declare -a flags
|
||||||
|
declare -l PATCH_KRISP
|
||||||
|
|
||||||
|
[[ -r "${XDG_CONFIG_HOME:-$HOME/.config}/@PKGNAME@.conf" ]] && source "${XDG_CONFIG_HOME:-$HOME/.config}/@PKGNAME@.conf"
|
||||||
|
|
||||||
|
flags_file="${XDG_CONFIG_HOME:-$HOME/.config}/@PKGNAME@-flags.conf"
|
||||||
|
krisp_bin="${DISCORD_USER_DATA_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/@PKGNAME@}/@PKGVER@/modules/@PKGNAME@_krisp/@PKGNAME@_krisp.node"
|
||||||
|
|
||||||
|
if [[ "${PATCH_KRISP:-}" == true ]] && [[ -w "${krisp_bin}" ]]; then
|
||||||
|
if hash python &> /dev/null && python -c 'import capstone; import elftools' &> /dev/null; then
|
||||||
|
# Patch Krisp binary to ignore signature check
|
||||||
|
echo -n 'Running Krisp patcher... '
|
||||||
|
python /usr/lib/@PKGNAME@/krisp-patcher.py "${krisp_bin}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -r "${flags_file}" ]]; then
|
||||||
|
# Replacing because old flag does not work
|
||||||
|
if [[ -w "${flags_file}" ]] && grep -q '\--ignore-gpu-blacklist' "${flags_file}"; then
|
||||||
|
sed -i 's|--ignore-gpu-blacklist|--ignore-gpu-blocklist|' "${flags_file}"
|
||||||
|
fi
|
||||||
|
mapfile -t < "${flags_file}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
for line in "${MAPFILE[@]}"; do
|
||||||
|
if [[ ! "${line}" =~ ^[[:space:]]*#.* ]] && [[ -n "${line}" ]]; then
|
||||||
|
flags+=("${line}")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
unset flags_file krisp_bin
|
||||||
|
|
||||||
|
|
||||||
|
exec /usr/lib/@ELECTRON@/electron \
|
||||||
|
/usr/lib/@PKGNAME@/resources/app.asar \
|
||||||
|
"${flags[@]}" "$@"
|
||||||
85
discord-electron/krisp-patcher.py
Normal file
85
discord-electron/krisp-patcher.py
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
import sys
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
from elftools.elf.elffile import ELFFile
|
||||||
|
from capstone import *
|
||||||
|
from capstone.x86 import *
|
||||||
|
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print(f"Usage: {sys.argv[0]} [path to discord_krisp.node]")
|
||||||
|
# "Unix programs generally use 2 for command line syntax errors and 1 for all other kind of errors."
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
executable = sys.argv[1]
|
||||||
|
|
||||||
|
elf = ELFFile(open(executable, "rb"))
|
||||||
|
symtab = elf.get_section_by_name('.symtab')
|
||||||
|
|
||||||
|
krisp_initialize_address = symtab.get_symbol_by_name("_ZN7discordL17DoKrispInitializeEv")[0].entry.st_value
|
||||||
|
isSignedByDiscord_address = symtab.get_symbol_by_name("_ZN7discord4util17IsSignedByDiscordERKNSt4__Cr12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE")[0].entry.st_value
|
||||||
|
|
||||||
|
text = elf.get_section_by_name('.text')
|
||||||
|
text_start = text['sh_addr']
|
||||||
|
text_start_file = text['sh_offset']
|
||||||
|
# This seems to always be zero (.text starts at the right offset in the file). Do it just in case?
|
||||||
|
address_to_file = text_start_file - text_start
|
||||||
|
|
||||||
|
# Done with the ELF now.
|
||||||
|
# elf.close()
|
||||||
|
|
||||||
|
krisp_initialize_offset = krisp_initialize_address - address_to_file
|
||||||
|
isSignedByDiscord_offset = krisp_initialize_address - address_to_file
|
||||||
|
|
||||||
|
f = open(executable, "rb")
|
||||||
|
f.seek(krisp_initialize_offset)
|
||||||
|
krisp_initialize = f.read(96)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
# States
|
||||||
|
found_issigned_by_discord_call = False
|
||||||
|
found_issigned_by_discord_test = False
|
||||||
|
found_issigned_by_discord_je = False
|
||||||
|
found_already_patched = False
|
||||||
|
je_location = None
|
||||||
|
je_size = 0
|
||||||
|
|
||||||
|
# We are looking for a call to IsSignedByDiscord, followed by a test, followed by a je.
|
||||||
|
# Then we replace the je with nops.
|
||||||
|
|
||||||
|
md = Cs(CS_ARCH_X86, CS_MODE_64)
|
||||||
|
md.detail = True
|
||||||
|
for i in md.disasm(krisp_initialize, krisp_initialize_address):
|
||||||
|
if i.id == X86_INS_CALL:
|
||||||
|
if i.operands[0].type == X86_OP_IMM:
|
||||||
|
if i.operands[0].imm == isSignedByDiscord_address:
|
||||||
|
found_issigned_by_discord_call = True
|
||||||
|
|
||||||
|
if i.id == X86_INS_TEST:
|
||||||
|
if found_issigned_by_discord_call:
|
||||||
|
found_issigned_by_discord_test = True
|
||||||
|
|
||||||
|
if i.id == X86_INS_JE:
|
||||||
|
if found_issigned_by_discord_test:
|
||||||
|
found_issigned_by_discord_je = True
|
||||||
|
je_location = i.address
|
||||||
|
je_size = len(i.bytes)
|
||||||
|
break
|
||||||
|
|
||||||
|
if i.id == X86_INS_NOP:
|
||||||
|
if found_issigned_by_discord_test:
|
||||||
|
found_already_patched = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if je_location:
|
||||||
|
print(f"Found patch location: 0x{je_location:x}")
|
||||||
|
|
||||||
|
shutil.copyfile(executable, executable + ".orig")
|
||||||
|
f = open(executable, 'rb+')
|
||||||
|
f.seek(je_location - address_to_file)
|
||||||
|
f.write(b'\x90' * je_size) # je can be larger than 2 bytes given a large enough displacement :(
|
||||||
|
f.close()
|
||||||
|
else:
|
||||||
|
if found_already_patched:
|
||||||
|
print("Couldn't find patch location - already patched.")
|
||||||
|
else:
|
||||||
|
print("Couldn't find patch location - review manually. Sorry.")
|
||||||
57
discord-electron/update-package.sh
Executable file
57
discord-electron/update-package.sh
Executable file
|
|
@ -0,0 +1,57 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
readonly all_off="$(tput sgr0)"
|
||||||
|
readonly bold="${all_off}$(tput bold)"
|
||||||
|
readonly white="${bold}$(tput setaf 7)"
|
||||||
|
readonly blue="${bold}$(tput setaf 4)"
|
||||||
|
readonly red="${bold}$(tput setaf 1)"
|
||||||
|
|
||||||
|
msg() {
|
||||||
|
printf "${blue}::${white} $1${all_off}\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
printf "${red}::${white} $1${all_off}\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
msgbegin() {
|
||||||
|
printf "${blue}::${white} $1"
|
||||||
|
}
|
||||||
|
|
||||||
|
msgend() {
|
||||||
|
printf "$1${all_off}\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
readonly krisp_zip='discord_krisp-1.zip'
|
||||||
|
readonly krisp_bin='discord_krisp.node'
|
||||||
|
|
||||||
|
# head to directory of this script
|
||||||
|
cd $(dirname "$0")
|
||||||
|
|
||||||
|
# update package to version used in PKGBUILD
|
||||||
|
source PKGBUILD
|
||||||
|
|
||||||
|
msg "Running updpkgsums (Updating checksums)"
|
||||||
|
updpkgsums
|
||||||
|
|
||||||
|
msg "Running mksrcinfo (Updating SRCINFO file)"
|
||||||
|
makepkg --printsrcinfo > .SRCINFO
|
||||||
|
|
||||||
|
msg "Getting Krisp module"
|
||||||
|
curl -O "https://dl.discordapp.net/apps/linux/${_pkgver:-${pkgver}}/modules/${krisp_zip}"
|
||||||
|
unzip "${krisp_zip}" "${krisp_bin}"
|
||||||
|
|
||||||
|
msg "Checking if Krisp module is patchable (watch output)"
|
||||||
|
python krisp-patcher.py "${krisp_bin}"
|
||||||
|
|
||||||
|
#msg "Updating Krisp module checksum"
|
||||||
|
#readonly chcksm=$(b2sum "${krisp_bin}.orig" | head -c 128)
|
||||||
|
#sed -i "s/^_krisp_b2sum='.*'$/_krisp_b2sum='${chcksm}'/" PKGBUILD
|
||||||
|
|
||||||
|
msgbegin "Cleaning up... "
|
||||||
|
rm -f "${krisp_zip}" "${krisp_bin}" "${krisp_bin}.orig"
|
||||||
|
|
||||||
|
msgend "Done"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue