├── LICENSE └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Ant-tree 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ObfuscatorNDK 2 | Android Obfuscator NDK 23 for Windows 3 | 4 | > Fully tested 5 | 6 | * Origin NDK : 23c (23.2.8568313) 7 | * Clang : 12.0.9 8 | * LLVM : 12.0.9 9 | 10 | ## 1. Usage 11 | 12 | Add CMAKE_C_FLAGS in CmakeLists.txt file 13 | 14 | This will apply the obfuscation, module by module. 15 | 16 | ```shell 17 | set(CMAKE_C_FLAGS "-mllvm -fla -mllvm -bcf -mllvm -sub -mllvm -sobf") 18 | ``` 19 | 20 | Or, in case of using ```Android.mk``` : 21 | 22 | ```bash 23 | LOCAL_CFLAGS := -Wall -D__MODULE__=\"$(LOCAL_MODULE)\" -fcommon -mllvm -fla -mllvm -bcf -mllvm -sub -mllvm -sobf 24 | ``` 25 | 26 | 27 | 28 | Currently available options 29 | 30 | | Option | Description | 31 | | ---------------- | ------------ | 32 | | **-mllvm -sub** | substitution | 33 | | **-mllvm -fla** | flattening | 34 | | **-mllvm -bcf** | bogus | 35 | | **-mllvm -sobf** | string obf | 36 | 37 | ## 2. How to build this NDK? 38 | 39 | | Env | Desc | 40 | | -------- | ----------------- | 41 | | Built on | Ubuntu 16.04 (VM) | 42 | | Host | windows | 43 | 44 | Avoid using ubuntu 20.04 -> might have sym-link problem 45 | 46 | 47 | 48 | 1. Check for exact NDK version and branch 49 | 50 | > Check AndroidVersion.txt from```{NDK_PATH}}\toolchains\llvm\prebuilt\windows-x86_64``` 51 | 52 | ``` 53 | 12.0.9 54 | based on r416183c2 55 | ``` 56 | 57 | 2. Download repo bin for clone from google source repository 58 | 59 | ```shell 60 | curl https://storage.googleapis.com/git-repo-downloads/repo > /usr/bin/repo 61 | chmod a+x /usr/bin/repo 62 | ``` 63 | 64 | Upgrade to python 3.9 if lower 65 | 66 | > ```shell 67 | > ##### Download required packages 68 | > sudo apt-get install build-essential checkinstall 69 | > sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev \ 70 | > libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev 71 | > 72 | > ##### Download 73 | > cd /opt 74 | > sudo wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz 75 | > sudo tar xzf Python-3.9.1.tgz 76 | > cd Python-3.9.1 77 | > sudo ./configure --enable-optimizations 78 | > sudo make altinstall 79 | > sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.9 1 80 | > ``` 81 | 82 | 3. Download essential packages to build ndk toolchain 83 | 84 | ```shell 85 | ##### CMAKE and bison for toolchain build 86 | apt install cmake bison 87 | ``` 88 | 89 | 4. Check for manifest file in original ndk 90 | 91 | ```shell 92 | ##### Search for "manifest" in original ndk directory 93 | -> Result : manifest_8481493.xml 94 | ``` 95 | 96 | 5. Clone the repo 97 | 98 | ```shell 99 | mkdir llvm-toolchain && cd llvm-toolchain 100 | repo init -u https://android.googlesource.com/platform/manifest -b llvm-toolchain 101 | 102 | ## >>> [COPY {NDK_PATH}/~~/manifest_8181493.xml to llvm-toolchain/.repo/manifests] 103 | 104 | repo init -m manifest_8481493.xml 105 | repo sync -c 106 | ``` 107 | 108 | 6. Build with ```--no-build linux``` option 109 | 110 | ```shell 111 | python toolchain/llvm_android/build.py --no-build linux 112 | ``` 113 | 114 | 7. Cherry pick the source from ollvm 12.x 115 | 116 | ```shell 117 | # Changing Targets : 118 | cp -r {TARGET}/llvm/lib/Transforms/Obfuscation {SOURCE}/llvm/lib/Transforms/Obfuscation 119 | cp -r {TARGET}/llvm/include/Transforms/Obfuscation {SOURCE}/llvm/include/Transforms/Obfuscation 120 | 121 | # add Obfuscation to 122 | -> lib/Transforms/IPO/CMakeList.txt 123 | -> lib/Transforms/CMakeList.txt 124 | 125 | #Cherry pick the sources from lib/Transforms/IPO/PassManagerBuilder.cpp 126 | ``` 127 | 128 | 8. Build again 129 | 130 | ```shell 131 | python toolchain/llvm_android/build.py --no-build linux 132 | ``` 133 | 134 | 135 | 136 | ## 3. Handle the built output 137 | 138 | ```out/install/windows-x86/clang-dev``` from result corresponds to ```toolchains/llvm/prebuilt/windows-x86-64``` 139 | 140 | so, copy and paste the output(clang-dev) to original ndk directory 141 | 142 | don't forget to manually substitute symbolic-linked binaries in ```bin/``` 143 | 144 | (usually 1KB files in output are symbolic linked, except lldb.cmd) 145 | 146 | 147 | 148 | ## 4. Known issues when apply 149 | 150 | NONE 151 | 152 | 153 | 154 | --- 155 | 156 | 157 | 158 | Android NDK 159 | =========== 160 | 161 | Documentation 162 | ------------- 163 | 164 | NDK documentation, guides, and API reference are available on 165 | [our website](https://developer.android.com/ndk/index.html). 166 | 167 | NDK code samples are available on 168 | [GitHub](https://github.com/googlesamples/android-ndk). 169 | 170 | Information about Android Studio can be found on [the Android Studio 171 | website](https://developer.android.com/studio/index.html). 172 | 173 | Filing Bugs 174 | ----------- 175 | 176 | NDK bugs should be filed on 177 | [GitHub](https://github.com/android-ndk/ndk/issues/new). 178 | 179 | Android Studio and Gradle bugs should be filed in the [Android Studio Bug 180 | Tracker](http://b.android.com). For the fastest response, make sure you follow 181 | their guide on [Filing Bugs](http://tools.android.com/filing-bugs). 182 | --------------------------------------------------------------------------------