41 lines
1.6 KiB
Executable file

if [[ $# -lt 2 ]]; then
echo "usage: $0 <mbank_apk> <your desired name(s)>"
exit 0
apk=$(realpath $1)
mkdir mbank
cd mbank
[[ ! -f "apktool.jar" ]] && wget -O apktool.jar
[[ ! -f "signapk.jar" ]] && wget -O signapk.jar
[[ ! -f "zipalign.jar" ]] && wget -O zipalign.jar
java -jar apktool.jar d $apk -o base
strings_file_en=$(grep -Rl "Hello, %s" base/res/*)
strings_file_pl=$(grep -Rl "Witaj, %s" base/res/*)
sed -i "s/Hello, \%s/Hello, $2/" $strings_file_en
sed -i "s/Witaj, \%s/Witaj, $2/" $strings_file_pl
if [[ ! -f "crypto.crt" || ! -f "key.pk8" ]]; then
openssl genrsa -out crypto.key 1024
openssl req -new -key crypto.key -out crypto.csr -subj "/C=PL/ST=Warsaw/L=Warsaw/O=Paweł Tanajno Rigcz Hawajska+ hacker collective"
openssl x509 -req -days 9999 -in crypto.csr -signkey crypto.key -out crypto.crt
cat crypto.key crypto.crt > certificate.pem
openssl pkcs8 -topk8 -outform DER -in certificate.pem -inform PEM -out key.pk8 -nocrypt
rm crypto.key crypto.csr certificate.pem
java -jar apktool.jar --use-aapt2 b base -o out.apk
java -jar zipalign.jar out.apk out_aligned.apk # we don't know if this is strictly needed, but it might as well be
java -jar signapk.jar crypto.crt key.pk8 out_aligned.apk out_signed.apk
rm -R base
cp out_signed.apk ..
echo "IMPORTANT NOTE: please store crypto.crt and key.pk8 in a safe place - you'll need them to sign the app after any updates."
echo "OUTPUT FILE: out_signed.apk"