From 6b29201cc43b927dd4ffd54b04b1955cb3f35fa7 Mon Sep 17 00:00:00 2001 From: f1ynng8 Date: Sun, 21 Jun 2026 14:26:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0setup=5Ffrida=5Fand=5Fbuild.s?= =?UTF-8?q?h=E8=84=9A=E6=9C=AC=E7=94=A8=E4=BA=8E=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=B9=B6=E4=B8=8B=E8=BD=BDfrida-devkit?= =?UTF-8?q?=E5=BA=93,=E7=84=B6=E5=90=8E=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 -- setup_frida_and_build.sh | 51 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100755 setup_frida_and_build.sh diff --git a/.gitignore b/.gitignore index d1a9bce..911cc9a 100644 --- a/.gitignore +++ b/.gitignore @@ -21,8 +21,6 @@ codex.md install_frida_gadget_automated.sh note.md requirements.md -setup_frida_and_build.sh .gocache/ .gomodcache/ -local_build.sh frida-devkit/ \ No newline at end of file diff --git a/setup_frida_and_build.sh b/setup_frida_and_build.sh new file mode 100755 index 0000000..5be0b8f --- /dev/null +++ b/setup_frida_and_build.sh @@ -0,0 +1,51 @@ +#!/bin/bash +set -e + +# Frida devkit must match the frida-go API used by go.mod. +FRIDA_VERSION="${FRIDA_VERSION:-17.8.0}" +OS="macos" +ARCH="arm64" +DEVKIT_NAME="frida-core-devkit-${FRIDA_VERSION}-${OS}-${ARCH}" +DOWNLOAD_URL="https://github.com/frida/frida/releases/download/${FRIDA_VERSION}/${DEVKIT_NAME}.tar.xz" +DEVKIT_DIR="$(pwd)/frida-devkit" + +echo "🔧 配置 Frida 开发环境 (Version: $FRIDA_VERSION, Arch: $ARCH)..." + +# 检查是否已存在且版本/API匹配 +if [ -f "$DEVKIT_DIR/libfrida-core.a" ] && [ -f "$DEVKIT_DIR/frida-core.h" ] && grep -q "FridaPackageManager" "$DEVKIT_DIR/frida-core.h"; then + echo "✅ 发现已存在且兼容的 Frida Devkit,跳过下载。" +else + # 如果版本不匹配,清理旧的 + if [ -d "$DEVKIT_DIR" ]; then + echo "⚠️ 清理旧的或不兼容的 Devkit 目录..." + rm -rf "$DEVKIT_DIR" + fi + + mkdir -p "$DEVKIT_DIR" + echo "⬇️ 正在下载 ${DEVKIT_NAME}..." + curl -L -o "$DEVKIT_DIR/devkit.tar.xz" "$DOWNLOAD_URL" + + echo "📦 正在解压..." + tar -xf "$DEVKIT_DIR/devkit.tar.xz" -C "$DEVKIT_DIR" + rm "$DEVKIT_DIR/devkit.tar.xz" + echo "✅ 解压完成" +fi + + +# 2. 编译 +echo "🚀 开始编译 OneBot..." +cd onebot + +# 强制设置 GOARCH 为 arm64,因为我们下载的是 arm64 的库 +export GOARCH=arm64 +export CGO_ENABLED=1 +export CGO_CFLAGS="-I$DEVKIT_DIR" +export CGO_LDFLAGS="-L$DEVKIT_DIR -lfrida-core" + +echo "⚙️ GOARCH=$GOARCH" +echo "⚙️ CGO_CFLAGS=$CGO_CFLAGS" +echo "⚙️ CGO_LDFLAGS=$CGO_LDFLAGS" + +go build -v -o onebot . + +echo "🎉 编译成功!二进制文件位置: $(pwd)/onebot/onebot"