From d55283c69987f6b494b0989c8e612bd72a03ca12 Mon Sep 17 00:00:00 2001 From: Abhi Date: Fri, 18 Oct 2024 01:03:34 +0530 Subject: [PATCH 1/6] Fix installation on termux --- r2angr/angr | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 2 deletions(-) diff --git a/r2angr/angr b/r2angr/angr index 0f43e857f..6c7c30bf1 100755 --- a/r2angr/angr +++ b/r2angr/angr @@ -3,11 +3,87 @@ CWD=$(dirname $0) OLD=$PWD cd $CWD if [ ! -d venv ]; then - python -m venv venv + if ! command -v termux-setup-storage; then + python3 -m venv venv + else + echo -e "\033[1;33mTermux environment detected. Installing necessary packages...\033[0m" + + pkg update && pkg upgrade -y + pkg install -y cmake ninja clang binutils build-essential python-numpy + pkg install -y unicorn # Required for unicorn during angr installation + python3 -m venv --system-site-packages venv # For packages like numpy + fi fi . venv/bin/activate if [ ! -x venv/bin/angr ]; then - pip install angr + if command -v termux-setup-storage; then + pip install git+https://github.com/angr/archinfo.git + pip install git+https://github.com/angr/cle.git + pip install git+https://github.com/angr/ailment.git + 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 + echo -e "\033[1;33m Starting z3 build, it may take a while...\033[0m" + python scripts/mk_make.py --python + cd build + cpu_count=$(nproc) + make -j$cpu_count + 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 + pip install git+https://github.com/angr/claripy.git + # Re-Check if z3-solver is installed or not + if [ -z "$(pip show z3-solver)" ]; then + echo -e "\033[0;33mSeems like an error occured during installation!" + echo "Please try to install it manually" + echo -e "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 + pip install setuptools + git clone https://github.com/angr/pyvex.git --recursive && cd $CWD/pyvex && pip install . && cd ../ && rm -rf pyvex + pip install -v angr --no-build-isolation + else + pip install -v angr + fi pip install capstone==5.0.3 fi cd $OLD From 96dba4572f89174a62c655ebae63b8d2ccaf9d56 Mon Sep 17 00:00:00 2001 From: Abhi Date: Fri, 18 Oct 2024 01:10:39 +0530 Subject: [PATCH 2/6] remove binutils & build-essential They should already be present if the user has installed R2. --- r2angr/angr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/r2angr/angr b/r2angr/angr index 6c7c30bf1..88cf99dda 100755 --- a/r2angr/angr +++ b/r2angr/angr @@ -9,7 +9,7 @@ if [ ! -d venv ]; then echo -e "\033[1;33mTermux environment detected. Installing necessary packages...\033[0m" pkg update && pkg upgrade -y - pkg install -y cmake ninja clang binutils build-essential python-numpy + pkg install -y cmake ninja clang python-numpy pkg install -y unicorn # Required for unicorn during angr installation python3 -m venv --system-site-packages venv # For packages like numpy fi From fc82ac906a22298428b0cca1663e4dedc0503766 Mon Sep 17 00:00:00 2001 From: Abhi Date: Fri, 18 Oct 2024 19:37:41 +0530 Subject: [PATCH 3/6] remove un-necessary install --- r2angr/angr | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/r2angr/angr b/r2angr/angr index 88cf99dda..9abb17673 100755 --- a/r2angr/angr +++ b/r2angr/angr @@ -17,9 +17,7 @@ fi . venv/bin/activate if [ ! -x venv/bin/angr ]; then if command -v termux-setup-storage; then - pip install git+https://github.com/angr/archinfo.git - pip install git+https://github.com/angr/cle.git - pip install git+https://github.com/angr/ailment.git + 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 @@ -32,8 +30,7 @@ if [ ! -x venv/bin/angr ]; then echo -e "\033[1;33m Starting z3 build, it may take a while...\033[0m" python scripts/mk_make.py --python cd build - cpu_count=$(nproc) - make -j$cpu_count + make make install cd ../../ @@ -69,7 +66,6 @@ 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 - pip install git+https://github.com/angr/claripy.git # Re-Check if z3-solver is installed or not if [ -z "$(pip show z3-solver)" ]; then echo -e "\033[0;33mSeems like an error occured during installation!" @@ -78,12 +74,8 @@ EOL echo "You can find the venv folder in $HOME/.local/share/radare2/prefix/bin" exit 1 fi - pip install setuptools - git clone https://github.com/angr/pyvex.git --recursive && cd $CWD/pyvex && pip install . && cd ../ && rm -rf pyvex - pip install -v angr --no-build-isolation - else - pip install -v angr fi + pip install -v angr pip install capstone==5.0.3 fi cd $OLD From e5fd31e2614e61db4b540dc6b9854eec5a6ebcc9 Mon Sep 17 00:00:00 2001 From: Abhi Date: Fri, 18 Oct 2024 19:38:44 +0530 Subject: [PATCH 4/6] short --- r2angr/angr | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/r2angr/angr b/r2angr/angr index 9abb17673..dffb0e872 100755 --- a/r2angr/angr +++ b/r2angr/angr @@ -9,9 +9,8 @@ if [ ! -d venv ]; then echo -e "\033[1;33mTermux environment detected. Installing necessary packages...\033[0m" pkg update && pkg upgrade -y - pkg install -y cmake ninja clang python-numpy - pkg install -y unicorn # Required for unicorn during angr installation - python3 -m venv --system-site-packages venv # For packages like numpy + 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 fi fi . venv/bin/activate From 8a58683fcc9783eb61e0986c9fdbc8c7581247ab Mon Sep 17 00:00:00 2001 From: Abhi Date: Fri, 18 Oct 2024 19:56:18 +0530 Subject: [PATCH 5/6] fix: unexpected operator --- r2angr/r2angr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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" From 42f90e438cc089af3f432e8e8c6d272caf0ae936 Mon Sep 17 00:00:00 2001 From: Abhi Date: Mon, 21 Oct 2024 19:00:14 +0530 Subject: [PATCH 6/6] use printf & reverse condition --- r2angr/angr | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/r2angr/angr b/r2angr/angr index dffb0e872..1f440807e 100755 --- a/r2angr/angr +++ b/r2angr/angr @@ -3,14 +3,14 @@ CWD=$(dirname $0) OLD=$PWD cd $CWD if [ ! -d venv ]; then - if ! command -v termux-setup-storage; then - python3 -m venv venv - else - echo -e "\033[1;33mTermux environment detected. Installing necessary packages...\033[0m" + 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 @@ -26,7 +26,7 @@ if [ ! -x venv/bin/angr ]; then # So I'm just going to install z3 from source :) git clone https://github.com/Z3Prover/z3.git --depth 1 cd $CWD/z3 - echo -e "\033[1;33m Starting z3 build, it may take a while...\033[0m" + printf "\033[1;33m Starting z3 build, it may take a while...\033[0m" python scripts/mk_make.py --python cd build make @@ -67,9 +67,9 @@ In the event of technical difficulties related to configuration, compilation, or EOL # Re-Check if z3-solver is installed or not if [ -z "$(pip show z3-solver)" ]; then - echo -e "\033[0;33mSeems like an error occured during installation!" + printf "\033[0;33mSeems like an error occured during installation!" echo "Please try to install it manually" - echo -e "Without z3-solver, we can't install angr on Termux!\033[0m" + 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