Skip to content

Instantly share code, notes, and snippets.

@kjsolo
Last active January 14, 2025 07:43
Show Gist options
  • Save kjsolo/83baf5be19449c336894f49ef653410e to your computer and use it in GitHub Desktop.
Save kjsolo/83baf5be19449c336894f49ef653410e to your computer and use it in GitHub Desktop.
#!/bin/bash
jiagu() {
local input_apk="$1"
local tool_dir="/Users/$USER/YiDunPackTool"
local jar_file="$tool_dir/NHPProtect.jar"
# Check if tool_dir exists
if [ ! -d "$tool_dir" ]; then
echo "未找到加固工具: $tool_dir. 请先下载和配置: https://coolapk.feishu.cn/docx/B4JYdAfzUowkvMxRFjYcdcyonhg#share-IIjJdPgnLok6saxVmsRcCancnFh"
return 1
fi
if [ -z "$input_apk" ]; then
read -p "请输入apk文件路径: " input_apk
if [ -z "$input_apk" ]; then
echo "Error: APK file path not provided"
return 1
fi
fi
if [ ! -f "$input_apk" ]; then
echo "Error: APK file not found: $input_apk"
return 1
fi
if [ ! -f "$jar_file" ]; then
echo "Error: NHPProtect.jar not found in: $tool_dir"
return 1
fi
java -jar "$jar_file" -yunconfig -fullapk -apksign -zipalign -input "$input_apk"
# Extract the filename without extension
local file_name=$(basename "$input_apk" .apk)
# Construct the expected output file name
local output_file="${file_name}_encrypted_align_sign.apk"
local renamed_file="${file_name}-sign.apk"
# Construct the full path for the output file
local output_full_path=$(dirname "$input_apk")/"$output_file"
local renamed_full_path=$(dirname "$input_apk")/"$renamed_file"
# Check if the output file exists, and rename it
if [ -f "$output_full_path" ]; then
mv "$output_full_path" "$renamed_full_path"
echo "Renamed output file to: $renamed_full_path"
else
echo "Error: Output file not found: $output_full_path"
return 1
fi
}
jiagu "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment