Frida 安装及 ERROR: Failed building wheel for frida 错误解决

如果你只是简单的使用 Frida 去 Hook Android 中的方法,请移步:一文带你轻松入门Frida框架,编写Hook脚本
如果是想使用 Frida 的进阶用法,请移步:Frida Hook Android App 进阶用法之 Java 运行时

Frida 安装

Windows / Linux 安装 Frida 有多种方法,可以对源码进行编译,也可以使用 pip 直接安装。最简便的当然是使用 python 安装。

# 方法一:
pip3 install frida-tools -i https://pypi.mirrors.ustc.edu.cn/simple/ 
# 方法二:
pip3 install frida -i https://pypi.mirrors.ustc.edu.cn/simple/ 
注意:Windows 的 Frida 目前只支持 python2.7 和 python3.7,如果非要用 python2.7 来安装,经测试后,frida的版本最高只能到11.0.13,高于这个版本安装后不会在 Scripts 目录生成 exe 文件。
注意:Linux 的 Frida,如果使用 python3,安装,当其版本是 3.7,会出现问题,具体情况如下。

Frida 支持 python2 和 python 3,如果你使用的是较新版本的 Linux 发行版(例如 Ubuntu 18.0.4 / Kali 2019),由于自带 python 版本较高,可能会出现以下情况 ERROR: Failed building wheel for frida

ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ritve202/frida/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ritve202/frida/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-44k2wbq5/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.7/frida
         cwd: /tmp/pip-install-ritve202/frida/
    Complete output (13 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.7
    creating build/lib.linux-x86_64-3.7/frida
    copying frida/__init__.py -> build/lib.linux-x86_64-3.7/frida
    copying frida/core.py -> build/lib.linux-x86_64-3.7/frida
    running build_ext
    looking for prebuilt extension in home directory, i.e. /root/frida-12.8.15-py3.7-linux-x86_64.egg
    prebuilt extension not found in home directory, will try downloading it
    querying pypi for available prebuilds
    error: <urlopen error [Errno 101] Network is unreachable>

关键错误代码:i.e. /root/frida-12.8.15-py3.7-linux-x86_64.egg,也就是说,极有可能是因为缺少相关文件。打开 Python 官方 Frida 包,我们发现
在这里插入图片描述

解决方案

Frida 在 Linux 环境下(Windows 也可能出现类似问题),只有 python3.6 的安装包,如果你的 python 版本是 3.7,则会去寻找 frida-12.8.15-py3.7-linux-x86_64.egg,当然是找不到了。解决方法有二

下载完成之后,使用 easy_install 安装

python3 /usr/lib/python3/dist-packages/easy_install.py frida-12.8.16-py3.6-linux-x86_64.egg

当运行到下图界面,直接 Ctrl+C 中断,因为国内访问国外的 Frida 网速很慢

root@kali:~/Documents# python3 /usr/lib/python3/dist-packages/easy_install.py frida-12.8.16-py3.6-linux-x86_64.egg
Processing frida-12.8.16-py3.6-linux-x86_64.egg
Copying frida-12.8.16-py3.6-linux-x86_64.egg to /usr/local/lib/python3.7/dist-packages
Adding frida 12.8.16 to easy-install.pth file

Installed /usr/local/lib/python3.7/dist-packages/frida-12.8.16-py3.6-linux-x86_64.egg
Processing dependencies for frida==12.8.16
Searching for frida==12.8.16
Reading https://pypi.org/simple/frida/
^Cinterrupted

此时,再次运行

pip3 install frida -i https://pypi.mirrors.ustc.edu.cn/simple/ 

安装成功
在这里插入图片描述

一直卡在 Building wheel for frida (setup.py) …

即使使用了源,使用pip安装的时候,仍然可能出现问题

Collecting frida
  Downloading https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/dd/b4/eca8047218220ec1468824a0149b1f04299913a5668bc6ede8263c0c8dea/frida-14.0.8.tar.gz (7.4 kB)
Building wheels for collected packages: frida
  Building wheel for frida (setup.py) ... \

这是因为设置 pypi 源镜像只对 pip 本身有用,但是 frida 的 setup.py 自己会去 pypi 下载一个包,这时候就无视你的镜像设置。因此最好的方法是科学上网

Frida Server 安装

Releases 版本地址:https://github.com/frida/frida/releases,将相应的版本下载下来,复制到手机

注意一点:frida-server版本要和frida版本一致。

Frida 具体使用方法可参考:一文带你轻松入门Frida框架,编写Hook脚本

总结

如果你使用的是 Windows,建议使用 python2.7 或者 python 3.7;如果你使用的是 Linux,python 2 版本不限,但是对于 python3,要么使用 3.6 版本及以下,要么在 python 3.7 中手动安装。经过笔者实践,无论是 Windows 还是 Linux,使用 python3 都有可能遇到本文中的 ERROR: Failed building wheel for frida,解决方案就是手动安装。

版本 python2 python3
Windows python 2.7 python 3.7
Linux 不限 python 3~3.6,3.7 版本必须手动安装

猜你喜欢

转载自blog.csdn.net/song_lee/article/details/105102108