idea java 逆向脚本

逆向脚本

target_app="/Users/voidm/Applications/GoLand.app"
rewrite_file="$(pwd)/../out/production/java_dev/com/jetbrains/ls/responses/License.class"
rewrite_file2="$(pwd)/../out/production/java_dev/com/jetbrains/ls/responses/License\$1.class"

echo "Changing directory to ${target_app}/Contents/lib"
cd "${target_app}/Contents/lib"

# 查找包含目标 Class 的 jar 包
check_jar_for_class() {
    local directory="$1"
    local class_file="$2"
    local found=false

    for jar_file in "$directory"/*.jar; do
        if jar tf "$jar_file" | grep -q "$class_file"; then
            # 返回包含指定类文件的jar包名称
            echo "$(basename "$jar_file")"
            found=true
            return
        fi
    done

    # 如果未找到指定文件,则输出日志并退出
    if ! $found; then
        echo "target class_file not found" >&2
        exit 1
    fi
}

jar_name=$(check_jar_for_class "${target_app}/Contents/lib" "com/jetbrains/ls/responses/License.class")
echo "target_jar is : $jar_name"

jar_file="${target_app}/Contents/lib/${jar_name}"
jar_file_back="${jar_file}_Backup"

# 备份文件
if [ ! -f "$jar_file_back" ]; 
then
    echo "Backing up $jar_file to $jar_file_back"
    cp "$jar_file" "$jar_file_back"
fi

# 解压缩 Jar
echo "Extracting ${jar_name}"
jar -xvf ${jar_name} com/jetbrains/ls/responses/License.class

# 替换文件
cp -f ${rewrite_file} "./com/jetbrains/ls/responses/License.class"
cp -f ${rewrite_file2} "./com/jetbrains/ls/responses/License\$1.class"

# 重新打包
echo "Compressing ${jar_name}"
jar -uvf ${jar_name} "com/jetbrains/ls/responses/License.class"
jar -uvf ${jar_name} "com/jetbrains/ls/responses/License\$1.class"
# 清理临时文件
rm -rf ./com
posted @ 2024-08-02 10:02  vx_guanchaoguo0  阅读(7)  评论(0编辑  收藏  举报