tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

wrap.sh (1613B)


      1 #!/system/bin/sh
      2 # shellcheck shell=ksh
      3 
      4 # call getprop before setting LD_PRELOAD
      5 os_version=$(getprop ro.build.version.sdk)
      6 
      7 # These options mirror those in build/sanitizers/AsanOptions.cpp
      8 # except for fast_unwind_* which are only needed on Android
      9 options=(
     10  alloc_dealloc_mismatch=0
     11  allocator_may_return_null=1
     12  allow_user_segv_handler=1
     13  detect_leaks=0
     14  fast_unwind_on_check=1
     15  fast_unwind_on_fatal=1
     16  free_fill_byte=229
     17  handle_abort=1
     18  handle_sigill=1
     19  handle_sigtrap=1
     20  intercept_tls_get_addr=0
     21  malloc_fill_byte=228
     22  max_free_fill_size=268435456
     23  max_malloc_fill_size=268435456
     24 )
     25 if [ -e "/data/local/tmp/asan.options.gecko" ]; then
     26  options+=("$(tr -d '\n' < /data/local/tmp/asan.options.gecko)")
     27 fi
     28 
     29 # : is the usual separator for ASAN options
     30 # save and reset IFS so it doesn't interfere with later commands
     31 old_ifs="$IFS"
     32 IFS=:
     33 ASAN_OPTIONS="${options[*]}"
     34 export ASAN_OPTIONS
     35 IFS="$old_ifs"
     36 
     37 LIB_PATH="$(cd "$(dirname "$0")" && pwd)"
     38 LD_PRELOAD="$(ls "$LIB_PATH"/libclang_rt.asan-*-android.so)"
     39 export LD_PRELOAD
     40 
     41 cmd="$1"
     42 shift
     43 
     44 # enable debugging
     45 # https://developer.android.com/ndk/guides/wrap-script#debugging_when_using_wrapsh
     46 # note that wrap.sh is not supported before android 8.1 (API 27)
     47 if [ "$os_version" -eq "27" ]; then
     48  args=("-Xrunjdwp:transport=dt_android_adb,suspend=n,server=y" -Xcompiler-option --debuggable)
     49 elif [ "$os_version" -eq "28" ]; then
     50  args=(-XjdwpProvider:adbconnection "-XjdwpOptions:suspend=n,server=y" -Xcompiler-option --debuggable)
     51 else
     52  args=(-XjdwpProvider:adbconnection "-XjdwpOptions:suspend=n,server=y")
     53 fi
     54 
     55 exec "$cmd" "${args[@]}" "$@"