#!/bin/bash
# 检查参数数量
if [ "$#" -ne 2 ]; then
echo "错误:参数数量不正确!"
echo "使用方法:$0 [新包名] [APK文件路径]"
exit 1
fi
# 提取输入参数
new_package_name="$1"
apk_file_path="$2"
# 定义字母集合
letters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
new_package_name=""
# 生成包含8位随机字母的字符串
# random_string=""
for i in {1..10}; do
random_char="${letters:RANDOM%${#letters}:1}"
new_package_name+="$random_char"
done
timestamp=$(date +%s)
new_package_name="com.$new_package_name"
# 将时间戳拼接到 new_package_name 变量后面
new_package_name="${new_package_name}${timestamp}"
# 检查APK文件是否存在
if [ ! -f "$apk_file_path" ]; then
echo "错误:指定的APK文件不存在!"
exit 1
fi
# 备份原始APK文件
cp "$apk_file_path" "$apk_file_path.bak"
# 使用apktool反编译APK
java -jar /root/sdk/apktool.jar d -f "$apk_file_path" -o tmp
# 替换包名
old_package_name=$(grep -oP '(?<=package=")[^"]+' tmp/AndroidManifest.xml)
sed -i "s/$old_package_name/$new_package_name/g" tmp/AndroidManifest.xml
# 使用apktool重新编译APK
java -jar /root/sdk/apktool.jar b tmp -o "$apk_file_path"
# 清理临时文件
rm -rf tmp
echo "APK包名已修改为:$new_package_name"
echo "修改后的APK文件已保存并覆盖原始APK文件:$apk_file_path"
发表回复