Skip to content

Instantly share code, notes, and snippets.

@wavedevgit
Last active February 3, 2026 15:55
Show Gist options
  • Select an option

  • Save wavedevgit/e78717b0cf8942f20abc05cdb7b8ae18 to your computer and use it in GitHub Desktop.

Select an option

Save wavedevgit/e78717b0cf8942f20abc05cdb7b8ae18 to your computer and use it in GitHub Desktop.
patch discord's apks utility
#!/bin/bash
# utility script made by @wavedevgit
# patch apk to own api
# this works with all clients
# make sure you put correct config here
API_URL="http://localhost:3001" # this is for api + ws, do not add version, only base url
CDN_URL="http://localhost:3001"
API_HOST="localhost:3001" # Used for ws
### colors ###
YELLOW='\033[1;33m'
GREEN='\033[1;32m'
RESET='\033[0m'
echo -e using ${GREEN}api url${RESET}=${YELLOW}$API_URL, ${GREEN}cdn url${RESET}=${YELLOW}$CDN_URL
check_tool() {
local tool=$1
if command -v "$tool" >/dev/null; then
echo "$tool exists"
else
echo "ERROR: $tool missing, please download it!"
exit 1
fi
}
check_required_tools() {
echo -e "${YELLOW}----tools----${RESET}"
check_tool "apktool"
check_tool "zipalign"
check_tool "apksigner"
echo -e "${YELLOW}-------------${RESET}"
}
generate_key() {
keytool -genkeypair \
-keystore debug.keystore \
-alias whatever \
-keyalg RSA \
-keysize 2048 \
-validity 10000 \
-storepass password \
-keypass password \
-dname "CN=Android,O=Android,C=US"
}
## check tools before doing anything
check_required_tools
if [ ! -f "$1" ]; then
echo "file: \"$1\" doesn't exist."
exit 1
fi
echo -e ${YELLOW}decompiling apk using apktool${RESET}
apktool d $1 -f -o "$1"_decompiled
cd "$1"_decompiled
### MODIFY CDN URL ###
find . -type f -name "*.smali" -exec sed -i "s|https://cdn.discordapp.com|$CDN_URL|g" {} +
### MODIFY API URL ###
find . -type f -name "*.smali" -exec sed -i "s|https://discordapp.com|$API_URL|g" {} +
find . -type f -name "*.smali" -exec sed -i "s|https://discord.com|$API_URL|g" {} +
find . -type f -name "*.smali" -exec sed -i "s|discord.com|$API_HOST|g" {} +
find . -type f -name "*.smali" -exec sed -i "s|discordapp.com|$API_HOST|g" {} +
echo -e ${GREEN}Patched smali files, building and signing${RESET}
apktool b
cd dist
### ALIGN ZIP ###
echo -e ${YELLOW}ZIPAligning apk${RESET}
zipalign -p 4 *.apk app-aligned.apk
### GENERATE KEY ###
generate_key
echo -e ${GREEN}generated debug key at debug.keystore${RESET}
### SIGN APK ###
echo -e ${YELLOW}signing apk${RESET}
apksigner sign \
--ks debug.keystore \
--ks-key-alias whatever \
--ks-pass pass:password \
--key-pass pass:password \
--out patched-signed.apk \
app-aligned.apk
apksigner verify --verbose patched-signed.apk
cp ./patched-signed.apk ../../patched-signed.apk
echo -e ${YELLOW}Done patching, apk is saved to patched-signed.apk
echo -e HAVE FUN!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment