Skip to content

Commit

Permalink
Fix setup on termux (#367)
Browse files Browse the repository at this point in the history
* Fix installation on termux
* remove binutils & build-essential
  * They should already be present if the user has installed R2.
* remove un-necessary install
  • Loading branch information
AbhiTheModder authored Oct 21, 2024
1 parent 3d2fa79 commit 54ff412
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
71 changes: 69 additions & 2 deletions r2angr/angr
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOL >$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
Expand Down
4 changes: 2 additions & 2 deletions r2angr/r2angr
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

0 comments on commit 54ff412

Please sign in to comment.