From e48d0801c1e5b14c9194d398a93a8f194c6e2c70 Mon Sep 17 00:00:00 2001 From: Abhi <85984486+AbhiTheModder@users.noreply.github.com> Date: Fri, 3 Oct 2025 01:08:02 +0530 Subject: [PATCH] add support for ollvm ndk --- dcc.cfg | 4 ++ dcc.py | 34 +++++++++++++--- termux_install.sh | 102 +++++++++++++++++++++++++++++++--------------- 3 files changed, 102 insertions(+), 38 deletions(-) diff --git a/dcc.cfg b/dcc.cfg index a040e00..5251a60 100644 --- a/dcc.cfg +++ b/dcc.cfg @@ -9,5 +9,9 @@ "v1_enabled": true, "v2_enabled": true, "v3_enabled": true + }, + "ollvm": { + "enable": false, + "flags": "-fvisibility=hidden -mllvm -fla -mllvm -split -mllvm -split_num=5 -mllvm -sub -mllvm -sub_loop=5 -mllvm -sobf -mllvm -bcf_loop=5 -mllvm -bcf_prob=100" } } diff --git a/dcc.py b/dcc.py index fb15a08..b43ddf7 100644 --- a/dcc.py +++ b/dcc.py @@ -857,15 +857,13 @@ def dcc_main( source_archive="project-source.zip", dynamic_register=False, disable_signing=False, + enable_ollvm=False, + ollvm_flags="", ): if not path.exists(apkfile): Logger.error("Input apk file %s does not exist", apkfile) return - if not outapk: - Logger.error("\033[31mOutput file name required\n\033[0m") - return - if custom_loader.rfind(".") == -1: Logger.error( "\n[ERROR] Custom Loader must have at least one package, such as \033[31mDemo.%s\033[0m\n", @@ -873,6 +871,22 @@ def dcc_main( ) return + # If OLLVM is enabled, add ollvm CFLAGS + if enable_ollvm: + Logger.warning("You've enabled ollvm flag, make sure your NDK supports it!") + ollvm_cflags = f"LOCAL_CFLAGS := {ollvm_flags}\n" + ollvm_cppflags = f"LOCAL_CPPFLAGS := {ollvm_flags}\n" + + with open("project/jni/Android.mk", "r+") as file: + lines = file.readlines() + for index, line in enumerate(lines): + if "LOCAL_LDLIBS := -llog" in line: + lines.insert(index + 1, ollvm_cflags) + lines.insert(index + 2, ollvm_cppflags) + break + file.seek(0) + file.writelines(lines) + # Modify the dex2c file to use the custom loader path for integrity check with open("project/jni/nc/Dex2C.cpp", "r") as file: dex2c_file_data = file.read() @@ -1104,8 +1118,8 @@ def dcc_main( if __name__ == "__main__": parser = argparse.ArgumentParser() - parser.add_argument("-a", "--input", nargs="?", help="Input apk file path") - parser.add_argument("-o", "--out", nargs="?", help="Output apk file path") + parser.add_argument("-a", "--input", help="Input apk file path", required=True) + parser.add_argument("-o", "--out", help="Output apk file path", required=True) parser.add_argument( "-p", "--obfuscate", @@ -1171,6 +1185,8 @@ def dcc_main( source_archive = args["project_archive"] dynamic_register = args["dynamic_register"] disable_signing = args["disable_signing"] + enable_ollvm = False + ollvm_flags = "" if args["source_dir"]: project_dir = args["source_dir"] @@ -1195,6 +1211,10 @@ def dcc_main( if "apktool" in dcc_cfg and path.exists(dcc_cfg["apktool"]): APKTOOL = dcc_cfg["apktool"] + if "ollvm" in dcc_cfg and dcc_cfg["ollvm"]["enable"]: + enable_ollvm = True + ollvm_flags = dcc_cfg["ollvm"]["flags"] + show_logging(level=INFO) # n @@ -1216,6 +1236,8 @@ def dcc_main( source_archive, dynamic_register, disable_signing, + enable_ollvm, + ollvm_flags, ) except Exception as e: Logger.error("Compile %s failed!" % input_apk, exc_info=True) diff --git a/termux_install.sh b/termux_install.sh index acf84ca..2f7aefb 100755 --- a/termux_install.sh +++ b/termux_install.sh @@ -7,7 +7,7 @@ fi termux-setup-storage -cd $HOME +cd "$HOME" || exit pkg update pkg upgrade -y @@ -19,6 +19,7 @@ red="$(tput setaf 1)" blue="$(tput setaf 32)" yellow="$(tput setaf 3)" note="$(tput setaf 6)" +ollvm_enable=false echo "${green}━━━ Basic Requirements Setup ━━━${nocolor}" @@ -38,31 +39,64 @@ if [ -d "android-sdk" ]; then elif [ -d "androidide-tools" ]; then rm -rf androidide-tools git clone https://github.com/AndroidIDEOfficial/androidide-tools - cd androidide-tools/scripts + cd androidide-tools/scripts || exit ./idesetup -c else git clone https://github.com/AndroidIDEOfficial/androidide-tools - cd androidide-tools/scripts + cd androidide-tools/scripts || exit ./idesetup -c fi echo "${yellow}ANDROID SDK TOOLS Successfully Installed!${nocolor}" -cd $HOME -echo +cd "$HOME" || exit echo "${green}━━━ Starting NDK installation ━━━${nocolor}" -echo "Now You'll be asked about which version of NDK to isntall" -echo "${note}If your Android Version is 9 or above then choose ${red}'9'${nocolor}" -echo "${note}If your Android Version is below 9 or if you faced issues with '9' (A9 and above users) then choose ${red}'8'${nocolor}" -echo "${red} If you're choosing other options then you're on your own and experiment yourself ¯⁠\⁠_⁠ಠ⁠_⁠ಠ⁠_⁠/⁠¯${nocolor}" -if [ -f "ndk-install.sh" ]; then - chmod +x ndk-install.sh && bash ndk-install.sh +echo "Would you like to enable support for OLLVM ?" +echo "Please note that ollvm support requires heavy resources and might not work/hang your device if enabled on low-end devices." +read -r -p "(Y/n) > " enable_ollvm +if [[ $enable_ollvm == "y" || $enable_ollvm == "Y" ]]; then + ollvm_enable=true + ndk_ver="" + ndk_ver_name="" + echo "${yellow}Select with NDK version you need install?${nocolor}" + select item in r25c r28c; do + case $item in + "r25c") + ndk_ver="25.2.9519653" + ndk_ver_name="r25c-ollvm-aarch64" + break + ;; + "r28c") + ndk_ver="28.2.13676358" + ndk_ver_name="r28c" + break + ;; + *) + echo "${red}No NDK version selected, terminating...${nocolor}" + exit 1 + ;; + esac + done + echo "Selected this version $ndk_ver_name ($ndk_ver) to install" + echo "${yellow}Warning! This NDK only for aarch64${nocolor}" + wget https://github.com/codehasan/dex2c/releases/download/ollvm-termux/android-ndk-$ndk_ver_name.tar.xz --no-verbose --show-progress -N + mkdir -p "$HOME"/android-sdk/ndk + tar -xvf android-ndk-$ndk_ver_name.tar.xz -C "$HOME"/android-sdk/ndk + rm android-ndk-$ndk_ver_name.tar.xz else - cd && echo -ne "Prepering, please wait..." && pkg upgrade &> /dev/null && pkg install wget &> /dev/null && wget -q https://github.com/MrIkso/AndroidIDE-NDK/raw/main/ndk-install.sh -N && echo -ne "\r \r" && chmod +x ndk-install.sh && bash ndk-install.sh -fi + echo "Now You'll be asked about which version of NDK to isntall" + echo "${note}If your Android Version is 9 or above then choose ${red}'9'${nocolor}" + echo "${note}If your Android Version is below 9 or if you faced issues with '9' (A9 and above users) then choose ${red}'8'${nocolor}" + echo "${red} If you're choosing other options then you're on your own and experiment yourself ¯⁠\⁠_⁠ಠ⁠_⁠ಠ⁠_⁠/⁠¯${nocolor}" + if [ -f "ndk-install.sh" ]; then + chmod +x ndk-install.sh && bash ndk-install.sh + else + cd && echo -ne "Prepering, please wait..." && pkg upgrade &>/dev/null && pkg install wget &>/dev/null && wget -q https://github.com/MrIkso/AndroidIDE-NDK/raw/main/ndk-install.sh -N && echo -ne "\r \r" && chmod +x ndk-install.sh && bash ndk-install.sh + fi -if [ -f "ndk-install.sh" ]; then - rm ndk-install.sh + if [ -f "ndk-install.sh" ]; then + rm ndk-install.sh + fi fi ndk_versions=("17.2.4988734" "18.1.5063045" "19.2.5345600" "20.1.5948944" "21.4.7075529" "22.1.7171670" "23.2.8568313" "24.0.8215888" "26.1.10909125" "27.1.12297006" "27.2.12479018" "28.1.13356709" "29.0.13113456" "27.3.13750724" "26.3.11579264" "28.2.13676358" "29.0.14033849-beta4" "23.1.7779620" "25.2.9519653") @@ -81,7 +115,7 @@ if [ -z "$ndk_version" ]; then fi echo "${yellow}ANDROID NDK Successfully Installed!${nocolor}" -cd $HOME +cd "$HOME" || exit echo echo "${green}━━━ Setting up apktool ━━━${nocolor}" if [ -f "$PREFIX/bin/apktool.jar" ]; then @@ -89,14 +123,14 @@ if [ -f "$PREFIX/bin/apktool.jar" ]; then else sh -c 'wget https://bitbucket.org/iBotPeaches/apktool/downloads/apktool_2.10.0.jar -O $PREFIX/bin/apktool.jar' - chmod +r $PREFIX/bin/apktool.jar + chmod +r "$PREFIX"/bin/apktool.jar - sh -c 'wget https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/linux/apktool -O $PREFIX/bin/apktool' && chmod +x $PREFIX/bin/apktool || exit 2 + sh -c 'wget https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/linux/apktool -O $PREFIX/bin/apktool' && chmod +x "$PREFIX"/bin/apktool || exit 2 fi -cd $HOME +cd "$HOME" || exit if [ -d "dex2c" ]; then - cd dex2c + cd dex2c || exit elif [ -f "dcc.py" ] && [ -d "tools" ]; then : else @@ -105,13 +139,13 @@ else fi if [ -f "$HOME/dex2c/tools/apktool.jar" ]; then - rm $HOME/dex2c/tools/apktool.jar - cp $PREFIX/bin/apktool.jar $HOME/dex2c/tools/apktool.jar + rm "$HOME"/dex2c/tools/apktool.jar + cp "$PREFIX"/bin/apktool.jar "$HOME"/dex2c/tools/apktool.jar else sh -c 'wget https://bitbucket.org/iBotPeaches/apktool/downloads/apktool_2.10.0.jar -O $HOME/dex2c/tools/apktool.jar' fi -cd ~/dex2c +cd ~/dex2c || exit python3 -m pip install -r requirements.txt || exit 2 update_rc() { @@ -123,18 +157,18 @@ update_rc() { sed -i '/export PATH=.*\/android-sdk\/ndk\/.*/d' "$file" sed -i '/export ANDROID_NDK_ROOT=/d' "$file" - echo -e "export ANDROID_HOME=$HOME/android-sdk\nexport PATH=\$PATH:$HOME/android-sdk/cmdline-tools/latest/bin\nexport PATH=\$PATH:$HOME/android-sdk/platform-tools\nexport PATH=\$PATH:$HOME/android-sdk/build-tools/34.0.4\nexport PATH=\$PATH:$HOME/android-sdk/ndk/$ndk_version\nexport ANDROID_NDK_ROOT=$HOME/android-sdk/ndk/$ndk_version" >> "$file" + echo -e "export ANDROID_HOME=$HOME/android-sdk\nexport PATH=\$PATH:$HOME/android-sdk/cmdline-tools/latest/bin\nexport PATH=\$PATH:$HOME/android-sdk/platform-tools\nexport PATH=\$PATH:$HOME/android-sdk/build-tools/34.0.4\nexport PATH=\$PATH:$HOME/android-sdk/ndk/$ndk_version\nexport ANDROID_NDK_ROOT=$HOME/android-sdk/ndk/$ndk_version" >>"$file" } update_xonsh_rc() { local file="$1" - sed -i '/\$ANDROID_HOME =/d' "$file" - sed -i '/\$PATH.*\/android-sdk\/cmdline-tools\/latest\/bin/d' "$file" - sed -i '/\$PATH.*\/android-sdk\/platform-tools/d' "$file" - sed -i '/\$PATH.*\/android-sdk\/build-tools\/34.0.4/d' "$file" - sed -i '/\$PATH.*\/android-sdk\/ndk\/.*/d' "$file" - sed -i '/\$ANDROID_NDK_ROOT =/d' "$file" - cat <> "$file" + sed -i "/\$ANDROID_HOME =/d" "$file" + sed -i "/\$PATH.*\/android-sdk\/cmdline-tools\/latest\/bin/d" "$file" + sed -i "/\$PATH.*\/android-sdk\/platform-tools/d" "$file" + sed -i "/\$PATH.*\/android-sdk\/build-tools\/34.0.4/d" "$file" + sed -i "/\$PATH.*\/android-sdk\/ndk\/.*/d" "$file" + sed -i "/\$ANDROID_NDK_ROOT =/d" "$file" + cat <>"$file" \$ANDROID_HOME = "${HOME}/android-sdk" \$PATH.append('${HOME}/android-sdk/cmdline-tools/latest/bin') \$PATH.append('${HOME}/android-sdk/platform-tools') @@ -157,7 +191,7 @@ if [ -f "$PREFIX/etc/bash.bashrc" ]; then update_rc "$PREFIX/etc/bash.bashrc" fi -cat > $HOME/dex2c/dcc.cfg << EOL +cat >"$HOME"/dex2c/dcc.cfg < $HOME/dex2c/dcc.cfg << EOL "v2_enabled": true, "v3_enabled": true } + "ollvm": { + "enable": $ollvm_enable, + "flags": "-fvisibility=hidden -mllvm -fla -mllvm -split -mllvm -split_num=5 -mllvm -sub -mllvm -sub_loop=5 -mllvm -sobf -mllvm -bcf_loop=5 -mllvm -bcf_prob=100" + } } EOL