From 54ff4129761d7dddd8f72758f28133ea2c9a17ed Mon Sep 17 00:00:00 2001 From: Abhi <85984486+AbhiTheModder@users.noreply.github.com> Date: Mon, 21 Oct 2024 21:19:49 +0530 Subject: [PATCH] Fix setup on termux (#367) * Fix installation on termux * remove binutils & build-essential * They should already be present if the user has installed R2. * remove un-necessary install --- r2angr/angr | 71 +++++++++++++++++++++++++++++++++++++++++++++++++-- r2angr/r2angr | 4 +-- 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/r2angr/angr b/r2angr/angr index 0f43e857f..1f440807e 100755 --- a/r2angr/angr +++ b/r2angr/angr @@ -3,11 +3,78 @@ CWD=$(dirname $0) OLD=$PWD cd $CWD if [ ! -d venv ]; then - python -m venv venv + if command -v termux-setup-storage; then + printf "\033[1;33mTermux environment detected. Installing necessary packages...\033[0m" + + pkg update && pkg upgrade -y + pkg install -y cmake ninja clang python-numpy unicorn # uncorn Required for unicorn during angr installation + python3 -m venv --system-site-packages venv # For packages like numpy + else + python3 -m venv venv + fi fi . venv/bin/activate if [ ! -x venv/bin/angr ]; then - pip install angr + if command -v termux-setup-storage; then + pip install setuptools + pip install unicorn==2.0.1.post1 + # Because z3-solver from pip tries to force install custom cmake + # which breaks installation of z3-solver, check https://github.com/Z3Prover/z3/issues/7424 + # Yes I know we could use solution(s) mentioned from this issue https://github.com/termux/termux-packages/issues/10065 but + # Because that's a bit lengthy and I don't want to (I'm lazy :P) + # And in that too we need to install cmake from source + # So I'm just going to install z3 from source :) + git clone https://github.com/Z3Prover/z3.git --depth 1 + cd $CWD/z3 + printf "\033[1;33m Starting z3 build, it may take a while...\033[0m" + python scripts/mk_make.py --python + cd build + make + make install + cd ../../ + + # Now we don't need z3 source anymore + if [ -d $CWD/z3 ]; then + rm -rf $CWD/z3 + fi + + # Create dist-info folder and METADATA file + DIST_INFO_PATH="$CWD/venv/lib/python3.12/site-packages/z3_solver-4.13.0.0.dist-info" + mkdir -p $DIST_INFO_PATH + touch $DIST_INFO_PATH/RECORD + echo "z3" >$DIST_INFO_PATH/top_level.txt + echo "z3_solver" >$DIST_INFO_PATH/WHEEL + echo "pip" >$DIST_INFO_PATH/INSTALLER + + cat <$DIST_INFO_PATH/METADATA +Metadata-Version: 2.1 +Name: z3-solver +Version: 4.13.0.0 +Summary: An efficient SMT solver library +Home-page: https://github.com/Z3Prover/z3 +Author: The Z3 Theorem Prover Project +Maintainer: Audrey Dutcher and Nikolaj Bjorner +Maintainer-email: audrey@rhelmot.io +License: MIT License +Keywords: z3,smt,sat,prover,theorem +Requires-Dist: importlib-resources ; python_version < "3.9" + +Z3 is a theorem prover from Microsoft Research with support for bitvectors, booleans, arrays, floating point numbers, strings, and other data types. + +For documentation, please read http://z3prover.github.io/api/html/z3.html + +In the event of technical difficulties related to configuration, compilation, or installation, please submit issues to https://github.com/z3prover/z3.git +EOL + # Re-Check if z3-solver is installed or not + if [ -z "$(pip show z3-solver)" ]; then + printf "\033[0;33mSeems like an error occured during installation!" + echo "Please try to install it manually" + printf "Without z3-solver, we can't install angr on Termux!\033[0m" + echo "You can find the venv folder in $HOME/.local/share/radare2/prefix/bin" + exit 1 + fi + fi + pip install -v angr pip install capstone==5.0.3 fi cd $OLD diff --git a/r2angr/r2angr b/r2angr/r2angr index 180ad10fc..c4d1d5b66 100755 --- a/r2angr/r2angr +++ b/r2angr/r2angr @@ -3,7 +3,7 @@ if [ -z "$R2_FILE" ]; then echo "Run this script from radare2. with !r2angr ([sailr,phenox,dream])" exit 1 fi -if [ "$R2_BADDR" == 0 ]; then +if [ "$R2_BADDR" = 0 ]; then echo "If the function is not found use r2 -B 0x400000" elif [ "$R2_OFFSET" -lt 10000 ]; then echo "If the function is not found use r2 -B 0x400000" @@ -12,5 +12,5 @@ ARG="" [ -n "$1" ] && ARG="--structurer $1" [ -z "$TMPDIR" ] && TMPDIR=/tmp angr decompile $ARG --functions=${R2_XOFFSET} \ - ${R2_FILE} 2> "${TMPDIR}/.r2angr.txt" || \ + ${R2_FILE} 2>"${TMPDIR}/.r2angr.txt" || echo "r2pm -ci angr, Check ${TMPDIR}/.r2angr.txt for details"