好吧 frida build@linux 参照frida.re编译指示 只需要:
#https://frida.re/docs/building/#gnulinux
#docker ubuntu:22.04 中执行以下命令:(即构建frida)
$ git clone --recurse-submodules https://github.com/frida/frida.git
$ cd frida
$ make #列出目标
$ make core-linux-x86_64-thin
$ make tools-linux-x86_64-thin
pip install colorama prompt_toolkit pygments
./build/frida-linux-x86_64/bin/frida
fedora-36所用git版本为git 2.39.1, 该版本git clone过程的后阶段携带了git index-pack动作,这样的行为导致了git-replace无法正常工作,从而造成凡是github的仓库clone都很慢无法解决,于是只好放弃fedora-36,转向ubuntu:22.04
sudo mkdir /frida-home/;
sudo chown z.z /frida-home
cd /frida-home/
git clone [email protected]:fridaz/frida.git
cd frida; git submodule update --init --checkout --recursive --depth 1
#git status:zmaster(基于官方frida 16.0.7)
sudo mkdir /pubx/
sudo chown z.z /pubx
cd /pubx/
git clone [email protected]:pubx/git-replace.git
cp -rv ~/.ssh /frida-home/ #宿主机中的 私钥 ~/.ssh/* 是被 gitcode信任的
cd /frida-home/
wget https://mirrors.bfsu.edu.cn/anaconda/miniconda/Miniconda3-py310_22.11.1-1-Linux-x86_64.sh
0.拉取docker镜像
#基本上各个docker镜像不好用,这里在宿主机中搭建 claash for linux, 搭建claash for linux参考
su - root
proxyychainss4 docker pull ubuntu:22.04
exit #退出su - root
sudo docker pull ubuntu:22.04 #网络卡慢的话 ,参照上方
sudo docker run -itd -v /frida-home/:/frida-home -v /pubx/:/pubx/ ubuntu:22.04
sudo docker exec -it 9bc6bcec7bb9 bash
以下小段脚本 只是记录docker启动bash常见命令,不直接作为此处业务过程
#本小段脚本只是记录docker启动bash常见命令,不直接作为此处业务过程
#一步到bash, 但退出bash即关闭容器
sudo docker run -it -v /frida-home:/frida-home/ -v /pubx/:/pubx/ ubuntu:22.04 bash
#一步到bash, 启动的是自己commit过的tag ubuntu_22.04_frida_build_env
sudo docker run -it -v /frida-home/:/frida-home -v /pubx/:/pubx/ ubuntu_22.04_frida_build_env bash
#先以daemon样式启动容器,再运行该容器中的bash。这样退出bash不会导致容器退出,方便多次进出bash。
sudo docker run -itd -v /frida-home/:/frida-home -v /pubx/:/pubx/ fedora_36_frida_build_env
sudo docker exec -it 9bc6bcec7bb9 bash
参考: ubuntu清华源
注意不要用https,否则会出现ca证书不信任问题
sed -i "s@http://.*archive.ubuntu.com@http://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
sed -i "s@http://.*security.ubuntu.com@http://mirrors.tuna.tsinghua.edu.cn@g" /etc/apt/sources.list
进docker执行:
### in docker bash:
export PS1="\[\`if [[ \$? = "0" ]]; then echo '\e[32m\h\e[0m'; else echo '\e[31m\h\e[0m' ; fi\`:\$PWD\n\$ "
#export PS1='\[`[ $? = 0 ] && X=2 || X=1; tput setaf $X`\]\h\[`tput sgr0`\]:$PWD\n\$ '
#yum whatprovides *bin/which #原fedora的
#which-2.21-32.fc36.x86_64 #原fedora的
#yum install which #原fedora的
apt install git -y
#替换git命令, 以将:
# 1. clone的很慢的github仓库地址替换为预置国内仓库地址、
# 2. clone后若发现子模块.gitmodules , 则替换.gitmodules中的github仓库地址为预置的国内仓库地址
cd /pubx/git-replace; sh -x install.sh ; cd -
ssh-keygen #一路回车, 只为了生成正确权限的的~/.ssh目录
cp -rv /frida-home/.ssh/* ~/.ssh #从宿主机 复制 gitcode信任的 私钥
sh /frida-home/Miniconda3-py39_22.11.1-1-Linux-x86_64.sh #install to /miniconda3/
source /miniconda3/bin/activate
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip install meson ninja
#yum install gcc gcc-c++ #原fedora的
apt show gcc g++
apt install gcc g++
gcc --version #gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
g++ --version #g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
#yum install libffi libffi-devel -y#原fedora的
#注意 不安装libffi的话, meson会选择编译subprojects/libffi/,
#但这样总是在link时报找不到 ffi_set_mem_callbacks . 实际上 subprojects/libffi/src/libffi.so.8.1.2 已经有 ffi_set_mem_callbacks了
#meson通过pkg-config找到系统自带的libffi库的, 因此需要先安装pkg-config
apt install pkg-config
#让meson找到系统自带的libffi,而不是去编译/frida-home/frida/frida-gum/subprojects/libffi/
apt install libffi8 libffi-dev -y #libffi 3.4.2-4
#由于这里使得 frida-gum默认编译gumjs,因此需要安装nodejs环境
#[安装nodejs环境](https://blog.csdn.net/hfcaoguilin/article/details/124598084)
apt install curl
#curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
curl https://gitcode.net/pubx/nvm/-/raw/master/install.sh | bash
echo """export NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node/
export NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node/""" >> ~/.bashrc
source ~/.bashrc
#再用nvm安装nodejs
nvm ls-remote
nvm install v18.13.0
nvm use v18.13.0
which node #/root/.nvm/versions/node/v14.17.1/bin/node
which npm #/root/.nvm/versions/node/v14.17.1/bin/npm
npm config -g set registry https://registry.npm.taobao.org
##nodejs环境安装完毕
#yum install glib2 glibc-devel glib2-static -y
cd /frida-home/frida/frida-gum/
meson build; #这一步结束处可看到 glib 2.75.0
cd build;
ninja; #编译
ninja install #安装, 以使得 后续的 frida-core 的 meson build 能找到刚编译的frida-gum
#查看 刚 ninja install 的glib2.0的版本, 从以下可见是 glib2 2.75
#ls -lh /usr/local/lib64/libglib-2.0.so*
#lrwxrwxrwx 1 root root 16 Jan 26 13:34 /usr/local/lib64/libglib-2.0.so -> libglib-2.0.so.0
#lrwxrwxrwx 1 root root 23 Jan 26 13:34 /usr/local/lib64/libglib-2.0.so.0 -> libglib-2.0.so.0.7500.0
#-rwxr-xr-x 1 root root 2.7M Jan 26 13:27 /usr/local/lib64/libglib-2.0.so.0.7500.0
#设置pkg-config search path, 以使得pkg-config能知道刚刚 ninja install 安装的这些 .so
echo 'export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib64/pkgconfig/' >> ~/.bashrc
source ~/.bashrc
#在 ninja install打印的输出 搜索 .pc 可获得目录: /usr/local/lib64/pkgconfig/
真机ubuntu 22.10(kinetic)下, frida-gum 在ninja install后的 pkg-config search path举例
#真机ubuntu 22.10(kinetic)下, frida-gum 在ninja install后的 pkg-config search path举例
echo 'export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/x86_64-linux-gnu/' >> ~/.bashrc
source ~/.bashrc
frida-gum编译结果
#frida-gum编译结果
cd /frida-home/frida/frida-gum/build/
#...
#ninja 编译后 看下有哪些so:
find . -name *.so
#...
#./gum/libfrida-gum-1.0.so
#./bindings/gumjs/libfrida-gumjs-1.0.so
#...
#...
#ninja install后看下系统中有哪些so:
pkg-config --list-all
#libcrypt libffi libnsl libtirpc libxcrypt shared-mime-info
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib64/pkgconfig/
pkg-config --list-all
#blkid capstone frida-gum-1.0 frida-gum-heap-1.0 frida-gum-prof-1.0 frida-gumjs-1.0
#frida-gumjs-inspector-1.0 gee-0.8 gio-2.0 gio-unix-2.0 glib-2.0 gmodule-2.0 gmodule-export-2.0
#gmodule-no-export-2.0 gobject-2.0 gthread-2.0 json-glib-1.0 libcrypt libdwarf libelf libffi liblzma
#libnghttp2 libnsl libpcre libpcre16 libpcre2-16 libpcre2-32 libpcre2-8 libpcre2-posix libpcre32 libpcrecpp
#libpcreposix libpsl libselinux libsepol libsoup-3.0 libtcc libtirpc libunwind
#libxcrypt mount quickjs shared-mime-info sqlite3 uuid vapigen vapigen-0.56 zlib
ls /usr/local/lib64/libfrida-gum*
#/usr/local/lib64/libfrida-gum-1.0.so
#/usr/local/lib64/libfrida-gum-prof-1.0.so
#/usr/local/lib64/libfrida-gumjs-inspector-1.0.so
#/usr/local/lib64/libfrida-gum-heap-1.0.so
#/usr/local/lib64/libfrida-gumjs-1.0.so
安装 miniconda3时报错 如下 ,可忽略,不影响miniconda3使用
sh /frida-home/Miniconda3-py39_22.11.1-1-Linux-x86_64.sh #install to /miniconda3/
#报错如下: ,以下报错可忽略,不影响miniconda3使用
"""/frida-home/Miniconda3-py39_22.11.1-1-Linux-x86_64.sh: 438: [[: not found
Installing * environment...
/frida-home/Miniconda3-py39_22.11.1-1-Linux-x86_64.sh: 444: [[: not found
CondaFileIOError: '/miniconda3/pkgs/envs/*/env.txt'. [Errno 2] No such file or directory: '/miniconda3/pkgs/envs/*/env.txt'
"""
#ubuntu 22.04 中 build frida-core执行的命令:
apt install valac -y
apt install libgee-0.8-2 libgee-0.8-dev -y
#apt install libglib2.0-dev libjson-glib-dev libpurple-dev -y
apt install libjson-glib-dev -y
apt install libbrotli-dev libbrotli1 -y #libbrotlienc
#确保glib2版本高于2.32, 否则 则编译frida-core时可能导致 错误 Thread.garbage_collect not found
apt remove libglib2.0-0 libglib2.0-dev #此步骤可能会卸载pkg-config
apt install pkg-config #因此需要再次安装pkg-config
#使用系统自带的glib2 若其版本低于2.32 则编译frida-core时可能导致 错误 Thread.garbage_collect not found
#https://valadoc.org/glib-2.0/GLib.Thread.Thread.html #注意这里的 Version ( since = "2.32" )
cd /frida-home/frida/frida-core/
meson build;
cd build;
ninja -v #或者 meson compile -v
问题
// https://github.com/frida/frida-core/blob/main/lib/agent/agent.vala
#if !WINDOWS
GumJS.prepare_to_fork ();
Gum.prepare_to_fork ();
GIOFork.prepare_to_fork ();
GLibFork.prepare_to_fork ();
cd /frida-home/frida/frida-core/build/
valac -v -C --debug --debug --define=HAVE_EMBEDDED_ASSETS --vapidir=/frida-home/frida/frida-core/vapi --pkg config --define=LINUX --define=X86_64 --pkg json-glib-1.0 --pkg frida-gumjs-1.0 --pkg frida-gum-1.0 --pkg gee-0.8 --pkg gio-2.0 --color=always --directory lib/agent/libfrida-agent.so.p --basedir ../lib/agent --library frida-agent --header lib/agent/frida-agent.h --vapi ../frida-agent.vapi --pkg=posix ../lib/agent/agent.vala lib/base/frida-base-1.0.vapi lib/pipe/frida-pipe.vapi lib/payload/frida-payload-1.0.vapi
#报错:
"""../lib/agent/agent.vala:444.4-444.10: error: The name `GIOFork' does not exist in the context of `Frida.Agent.Runner.suspend_subsystems'
444 | GIOFork.prepare_to_fork ();
"""
#TODO: 估计是 wsl2 下 在 "#if !WINDOWS"被当成是微软windows了 但是在其他地方当成不是微软windows了
#所以要知道 vala 宏 "#if !WINDOWS" 怎么能看到?
#真机ubuntu 22.10(kinetic)安装valac出现"Segmentation fault (core dumped)",原因不详,是否必先不详
sudo apt install valac -y
#Segmentation fault (core dumped)
ninja -v 参考自这里
ninja -v #报错
#[44/142] /frida-home/frida/frida-core/src/embed-helper.sh '' '' /frida-home/frida/frida-core/build/src linux /frida-home/frida/frida-core/build/tools/frida-resource-compiler ../src/helper.resources ''
#FAILED: src/frida-data-helper-process.vapi src/frida-data-helper-process.h src/frida-data-helper-process.c src/frida-data-helper-process-blob.S
#Segmentation fault (core dumped)
#手工执行:
sh -x /frida-home/frida/frida-core/src/embed-helper.sh '' '' /frida-home/frida/frida-core/build/src linux /frida-home/frida/frida-core/build/tools/frida-resource-compiler ../src/helper.resources ''
# 最终发现失败处:
#/frida-home/frida/frida-core/build/tools/frida-resource-compiler --toolchain=gnu -c ../src/helper.resources -o /frida-home/frida/frida-core/build/src/frida-data-helper-process /frida-home/frida/frida-core/build/src/frida-helper@emb/frida-helper-64 /frida-home/frida/frida-core/build/src/frida-helper@emb/frida-helper-32
#Segmentation fault (core dumped)
sudo docker run -it -v /frida-home:/frida-home ubuntu:22.04 bash
#容器bash中执行: ....miniconda3, meson, ninja, gcc, .... 等安装(见以下编译过程)
#可以在这之后 将容器a982d01d2752保存为镜像:
sudo docker commit a982d01d2752 ubuntu_22.04_frida_build_env
#下次再从镜像 创建容器:
sudo docker run -it -v /frida-home:/frida-home ubuntu_22.04_frida_build_env bash
#容器的中已经有以上安装过的部件了,无需再次安装了
sudo docker run -it -v /frida-home:/frida-home ubuntu:22.04 bash
#容器bash中执行: ....miniconda3, meson, ninja, gcc, .... 等安装(见以下编译过程)
#可以在这之后 将容器a982d01d2752保存为镜像:
sudo docker save --output ubuntu_22.04_frida_build_env.tar a982d01d2752
#下次再从镜像 创建容器:
sudo docker load --input ubuntu_22.04_frida_build_env.tar
#容器的中已经有以上安装过的部件了,无需再次安装了
docker desktop win10 ,using wsl2 ; 编译 gum时报错 python\r not found
#docker desktop win10 ,using wsl2
/frida-home/frida/frida-gum/
meson build; cd build;
ninja #此时报错 python/r not found
#解决办法:
apt install dos2unix
find /frida-home/frida/frida-gum/ -name *.py | xargs -I% dos2unix %
#再次编译
ninja #再次编译正常了
类似的 frida-core下也有此问题
find /frida-home/frida/frida-core/ -name *.py | xargs -I% dos2unix %
find /frida-home/frida/frida-core/ -name *.sh | xargs -I% dos2unix %
meson决定自己编译ffi,但却并没有处理好,
导致即使meson从源码(/frida-home/frida/frida-gum/subprojects/libffi/)编译了libffi,却没有带上libffi中的函数ffi_deinit,所以链接时报错。
#meson通过pkg-config找到系统自带的libffi库的, 因此需要先安装pkg-config
apt install pkg-config
apt install libffi-dev libffi8 # libffi 3.4.2-4
FAILED: gum/libfrida-gum-1.0.so
cc -o gum/libfrida-gum-1.0.so gum/libfrida-gum-1.0.so.p/meson-generated_.._gumenumtypes.c.o gum/libfrida-gum-1.0.so.p/zHook.c.o gum/libfrida-gum-1.0.so.p/gum.c.o gum/libfrida-gum-1.0.so.p/gumapiresolver.c.o gum/libfrida-gum-1.0.so.p/gumbacktracer.c.o gum/libfrida-gum-1.0.so.p/gumcloak.c.o gum/libfrida-gum-1.0.so.p/gumcodeallocator.c.o gum/libfrida-gum-1.0.so.p/gumcodesegment.c.o gum/libfrida-gum-1.0.so.p/gumdarwingrafter.c.o gum/libfrida-gum-1.0.so.p/gumdarwinmodule.c.o gum/libfrida-gum-1.0.so.p/gumexceptor.c.o gum/libfrida-gum-1.0.so.p/gumeventsink.c.o gum/libfrida-gum-1.0.so.p/gumheapapi.c.o gum/libfrida-gum-1.0.so.p/guminterceptor.c.o gum/libfrida-gum-1.0.so.p/guminvocationcontext.c.o gum/libfrida-gum-1.0.so.p/guminvocationlistener.c.o gum/libfrida-gum-1.0.so.p/gumkernel.c.o gum/libfrida-gum-1.0.so.p/gumleb.c.o gum/libfrida-gum-1.0.so.p/gumlibc.c.o gum/libfrida-gum-1.0.so.p/gummemory.c.o gum/libfrida-gum-1.0.so.p/gummemorymap.c.o gum/libfrida-gum-1.0.so.p/gummetalarray.c.o gum/libfrida-gum-1.0.so.p/gummetalhash.c.o gum/libfrida-gum-1.0.so.p/gummoduleapiresolver.c.o gum/libfrida-gum-1.0.so.p/gummodulemap.c.o gum/libfrida-gum-1.0.so.p/gumprintf.c.o gum/libfrida-gum-1.0.so.p/gumprocess.c.o gum/libfrida-gum-1.0.so.p/gumreturnaddress.c.o gum/libfrida-gum-1.0.so.p/gumstalker.c.o gum/libfrida-gum-1.0.so.p/arch-x86_gumx86writer.c.o gum/libfrida-gum-1.0.so.p/arch-x86_gumx86relocator.c.o gum/libfrida-gum-1.0.so.p/arch-x86_gumx86reader.c.o gum/libfrida-gum-1.0.so.p/arch-arm_gumarmwriter.c.o gum/libfrida-gum-1.0.so.p/arch-arm_gumarmrelocator.c.o gum/libfrida-gum-1.0.so.p/arch-arm_gumthumbwriter.c.o gum/libfrida-gum-1.0.so.p/arch-arm_gumthumbrelocator.c.o gum/libfrida-gum-1.0.so.p/arch-arm_gumarmreg.c.o gum/libfrida-gum-1.0.so.p/arch-arm64_gumarm64writer.c.o gum/libfrida-gum-1.0.so.p/arch-arm64_gumarm64relocator.c.o gum/libfrida-gum-1.0.so.p/arch-mips_gummipswriter.c.o gum/libfrida-gum-1.0.so.p/arch-mips_gummipsrelocator.c.o gum/libfrida-gum-1.0.so.p/backend-posix_gummemoryaccessmonitor-posix.c.o gum/libfrida-gum-1.0.so.p/backend-linux_gummemory-linux.c.o gum/libfrida-gum-1.0.so.p/backend-posix_gummemory-posix.c.o gum/libfrida-gum-1.0.so.p/backend-linux_gumprocess-linux.c.o gum/libfrida-gum-1.0.so.p/backend-posix_gumtls-posix.c.o gum/libfrida-gum-1.0.so.p/backend-posix_gumexceptor-posix.c.o gum/libfrida-gum-1.0.so.p/backend-elf_gumprocess-elf.c.o gum/libfrida-gum-1.0.so.p/backend-elf_gumelfmodule.c.o gum/libfrida-gum-1.0.so.p/arch-x86_gumx86backtracer.c.o gum/libfrida-gum-1.0.so.p/backend-x86_gumcpucontext-x86.c.o gum/libfrida-gum-1.0.so.p/backend-x86_guminterceptor-x86.c.o gum/libfrida-gum-1.0.so.p/backend-x86_gumstalker-x86.c.o gum/libfrida-gum-1.0.so.p/backend-x86_gumspinlock-x86.c.o gum/libfrida-gum-1.0.so.p/backend-x86_gumstalker-x86-glue.S.o gum/libfrida-gum-1.0.so.p/backend-libunwind_gumunwbacktracer.c.o gum/libfrida-gum-1.0.so.p/backend-libdwarf_gumsymbolutil-libdwarf.c.o -Wl,--as-needed -Wl,--no-undefined -shared -fPIC -Wl,--start-group -Wl,-soname,libfrida-gum-1.0.so '-Wl,-rpath,$ORIGIN/../subprojects/glib/glib:$ORIGIN/../subprojects/pcre2:$ORIGIN/../subprojects/capstone:$ORIGIN/../subprojects/glib/gobject:$ORIGIN/../subprojects/libffi/src:$ORIGIN/../subprojects/libunwind/src:$ORIGIN/../subprojects/xz/src/liblzma:$ORIGIN/../subprojects/zlib:$ORIGIN/../subprojects/elfutils/libelf:$ORIGIN/../subprojects/libdwarf/libdwarf' -Wl,-rpath-link,/frida-home/frida/frida-gum/build/subprojects/glib/glib -Wl,-rpath-link,/frida-home/frida/frida-gum/build/subprojects/pcre2 -Wl,-rpath-link,/frida-home/frida/frida-gum/build/subprojects/capstone -Wl,-rpath-link,/frida-home/frida/frida-gum/build/subprojects/glib/gobject -Wl,-rpath-link,/frida-home/frida/frida-gum/build/subprojects/libffi/src -Wl,-rpath-link,/frida-home/frida/frida-gum/build/subprojects/libunwind/src -Wl,-rpath-link,/frida-home/frida/frida-gum/build/subprojects/xz/src/liblzma -Wl,-rpath-link,/frida-home/frida/frida-gum/build/subprojects/zlib -Wl,-rpath-link,/frida-home/frida/frida-gum/build/subprojects/elfutils/libelf -Wl,-rpath-link,/frida-home/frida/frida-gum/build/subprojects/libdwarf/libdwarf subprojects/glib/glib/libglib-2.0.so.0.7500.0 subprojects/capstone/libcapstone.so subprojects/glib/gobject/libgobject-2.0.so.0.7500.0 subprojects/libffi/src/libffi.so.8.1.2 subprojects/libunwind/src/libunwind.so.8.0.1 subprojects/elfutils/libelf/libelf.so.0.186 subprojects/libdwarf/libdwarf/libdwarf.so.1.0.0 -ldl -Wl,--end-group -pthread
/usr/bin/ld: gum/libfrida-gum-1.0.so.p/gum.c.o: in function `gum_init_embedded':
/frida-home/frida/frida-gum/build/../gum/gum.c:282: undefined reference to `ffi_set_mem_callbacks'
/usr/bin/ld: gum/libfrida-gum-1.0.so.p/gum.c.o: in function `gum_deinit_embedded':
/frida-home/frida/frida-gum/build/../gum/gum.c:334: undefined reference to `ffi_deinit'
------------------------原fedora36中的命令------------------------------------------------------
#原fedora36中 build frida-core 执行的命令:
yum install vala -y
yum install libgee-devel -y
yum install json-glib json-glib-devel -y
yum install libsoup3 libsoup3-devel -y
-------------------------------------------以下是原先内容,现已经废弃---------------------
install git-args-replacer
cd /pubx/; git clone https://gitcode.net/pubx/git-replace.git
sudo apt reinstall git ;cd /pubx/git-replace/; sh -x install.sh;
build frida-gum
cd /mnt/d/frida-home/frida/frida-gum/
meson build
cd build; ninja
meson build 中 所用到的github仓库都被映射到 git-replace/repo_map.py
编译结果
# ~/d/frida-home/frida/frida-gum/build$
find . -name *.so | xargs -I@ ls -lh @
# -rwxrwxrwx 1 z z 1.9M Jan 11 11:13 ./gum/libfrida-gum-1.0.so
#...
sudo apt install valac -y
sudo apt install libgee-0.8-2 libgee-0.8-dev
sudo apt install libglib2.0-dev libjson-glib-dev libpurple-dev
#Dependency "libsoup-3.0" not found