Giter VIP home page Giter VIP logo

obfuscator's Introduction

LLVM14 and Later

NDK LLVM: https://android.googlesource.com/toolchain/llvm-project

Apple LLVM: https://github.com/apple/llvm-project

Normal LLVM: https://github.com/llvm/llvm-project

LegacyPass

wget https://heroims.github.io/obfuscator/LegacyPass/ollvm14.patch
git clone -b release/14.x [email protected]:llvm/llvm-project.git
cd llvm-project
git apply ../ollvm14.patch

NewPass

wget https://heroims.github.io/obfuscator/NewPass/ollvm14.patch
git clone -b release/14.x [email protected]:llvm/llvm-project.git
cd llvm-project
git apply ../ollvm14.patch

Resolve Conflict

git apply --reject --ignore-whitespace ../ollvm14.patch

And then follow the .rej prompts to modify

Please have a look at the wiki!

You can cite Obfuscator-LLVM using the following Bibtex entry:

@INPROCEEDINGS{ieeespro2015-JunodRWM,
  author={Pascal Junod and Julien Rinaldini and Johan Wehrli and Julie Michielin},
  booktitle={Proceedings of the {IEEE/ACM} 1st International Workshop on Software Protection, {SPRO'15}, Firenze, Italy, May 19th, 2015},
  editor = {Brecht Wyseur},
  publisher = {IEEE},
  title={Obfuscator-{LLVM} -- Software Protection for the Masses},
  year={2015},
  pages={3--9},
  doi={10.1109/SPRO.2015.10},
}

obfuscator's People

Contributors

cryptopathe avatar heroims avatar obfuscator-llvm avatar r1kk3r avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

obfuscator's Issues

Can't patch NDK source with Ollvm 14

Describe the bug
I want to try to patch Ollvm 14 on NDK source instead LLVM source, but it fails

git apply ../ollvm14.patch -v

../ollvm14.patch:2558: trailing whitespace.
    
../ollvm14.patch:2741: trailing whitespace.
Copyright (c) 2014 Haute Ecole d'Ingénierie et de Gestion du Canton de Vaud (HEIG-VD). All rights reserved. 
../ollvm14.patch:2748: trailing whitespace.
    of the University of Applied Sciences and Arts Western Switzerland (HES-SO) 
../ollvm14.patch:2766: trailing whitespace.
    * Neither the names of the Obfuscator-LLVM Team, the Haute Ecole d'Ingénierie 
../ollvm14.patch:2767: trailing whitespace.
      et de Gestion du Canton de Vaud (HEIG-VD), the University of Applied Sciences 
Checking patch llvm/CMakeLists.txt...
Hunk #1 succeeded at 241 (offset -5 lines).
Checking patch llvm/CODE_OWNERS.TXT...
Checking patch llvm/include/llvm/InitializePasses.h...
Checking patch llvm/include/llvm/Transforms/Obfuscation/BogusControlFlow.h...
Checking patch llvm/include/llvm/Transforms/Obfuscation/CryptoUtils.h...
Checking patch llvm/include/llvm/Transforms/Obfuscation/Flattening.h...
Checking patch llvm/include/llvm/Transforms/Obfuscation/Split.h...
Checking patch llvm/include/llvm/Transforms/Obfuscation/StringObfuscation.h...
Checking patch llvm/include/llvm/Transforms/Obfuscation/Substitution.h...
Checking patch llvm/include/llvm/Transforms/Obfuscation/Utils.h...
Checking patch llvm/lib/Transforms/CMakeLists.txt...
Checking patch llvm/lib/Transforms/IPO/CMakeLists.txt...
Checking patch llvm/lib/Transforms/IPO/PassManagerBuilder.cpp...
Hunk #4 succeeded at 719 (offset -18 lines).
Hunk #5 succeeded at 755 (offset -18 lines).
error: while searching for:
  // flattening of blocks.
  MPM.add(createDivRemPairsPass());

  // LoopSink (and other loop passes since the last simplifyCFG) might have
  // resulted in single-entry-single-exit or empty blocks. Clean up the CFG.
  MPM.add(createCFGSimplificationPass(

error: patch failed: llvm/lib/Transforms/IPO/PassManagerBuilder.cpp:991
error: llvm/lib/Transforms/IPO/PassManagerBuilder.cpp: patch does not apply
Checking patch llvm/lib/Transforms/Obfuscation/BogusControlFlow.cpp...
Checking patch llvm/lib/Transforms/Obfuscation/CMakeLists.txt...
Checking patch llvm/lib/Transforms/Obfuscation/CryptoUtils.cpp...
Checking patch llvm/lib/Transforms/Obfuscation/Flattening.cpp...
Checking patch llvm/lib/Transforms/Obfuscation/LICENSE-OBFUSCATOR.TXT...
Checking patch llvm/lib/Transforms/Obfuscation/LLVMBuild.txt...
Checking patch llvm/lib/Transforms/Obfuscation/SplitBasicBlocks.cpp...
Checking patch llvm/lib/Transforms/Obfuscation/StringObfuscation.cpp...
Checking patch llvm/lib/Transforms/Obfuscation/Substitution.cpp...
Checking patch llvm/lib/Transforms/Obfuscation/Utils.cpp...
void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
  // Load sample profile before running the LTO optimization pipeline.
  if (!PGOSampleUse.empty()) {
    PM.add(createPruneEHPass()); //This is line 991
    PM.add(createSampleProfileLoaderPass(PGOSampleUse));
  }

To Reproduce
I followed this tutorial how to clone NDK source https://bbs.kanxue.com/thread-271271.htm but I used NDK 25.2 source manifest_9352603.xml

Screenshots
N/A

Desktop (please complete the following information):

  • OS: Linux Mint
  • Version: 21.1

字符串混淆无效

在vs2022工程中的cpp属性 c/c++ ->Command Line->添加
-mllvm -sub -mllvm -bcf -mllvm -fla -mllvm -sobf -mllvm -seed=D3CB62378971722C0ED2AD9729CD7D72

然后重新生成工程以后,字符串未混混淆

does not appear to contain CMakeLists.txt

llvm 13 dont have CMakeLists.txt so can not cmake project.

cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_CREATE_XCODE_TOOLCHAIN=ON -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi" ../obfuscator

CMake Warning:
Ignoring extra path from command line:

"../obfuscator"

CMake Error: The source directory "/Users/QuangVu/Desktop/TestWorking/obfuscator" does not appear to contain CMakeLists.txt.

Why is libunwind required?

I have been using ollvm 9.0.1 (https://github.com/o2e/OLLVM-9.0.1 with clear instruction how to install ollvm on NDK) for Android NDK 21 and it's working great so far on Windows 10, no issues at all. The minor problem is it doesn't support c++20 flag so I needed to use newer NDK 23 with llvm 12
Now i'm having some issues with ollvm 12, it needs libunwind, it's looking for lib/linux/arm/libunwind.a even though i'm on Windows. I'm not sure why it's required

C:\Users\Administrator\Documents\GitHub\Android-Mod-Menu\app\src\main>C:\Users\Administrator\AppData\Local\Android\Sdk\ndk\23.0.7599858\ndk-build
fcntl(): Bad file descriptor
Android NDK: APP_PLATFORM not set. Defaulting to minimum supported version android-16.
Android NDK: WARNING: APP_PLATFORM android-16 is higher than android:minSdkVersion 1 in ./AndroidManifest.xml. NDK binaries will *not* be compatible with devices older than android-16. See https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md for more information.
Android NDK: ERROR:C:/Users/Administrator/AppData/Local/Android/Sdk/ndk/23.0.7599858/build//../sources/cxx-stl/llvm-libc++abi/Android.mk:unwind: LOCAL_SRC_FILES points to a missing file
Android NDK: Check that C:\Users\Administrator\AppData\Local\Android\Sdk\ndk\23.0.7599858\toolchains\llvm\prebuilt\windows-x86_64\lib\clang\12.0.0/lib/linux/arm/libunwind.a exists  or that its path is correct
C:/Users/Administrator/AppData/Local/Android/Sdk/ndk/23.0.7599858/build//../build/core/prebuilt-library.mk:45: *** Android NDK: Aborting    .  Stop.
PS C:\Users\Administrator\Documents\GitHub\Android-Mod-Menu\app\src\main>

So I added libunwind in -DLLVM_ENABLE_PROJECTS flag

My way to compile:

cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release  -DLLVM_ENABLE_PROJECTS="clang;libunwind" ../llvm
mingw32-make -j4

But getting compile error about declaring at 3%.

Why is libunwind required? and if it's required, what should I do to fix it without having to use linux? i'm not well familar with llvm

Note: I removed warnings to keep output log clearer

Log output:
                 from C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\libunwind.cpp:22:
[  3%] Built target obj.clang-tblgen
In file included from C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\UnwindCursor.hpp:73 In member function ',
                 from bool libunwind::RWMutex::lock_shared()[  3%] C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\libunwind.cpp:22':
Building CXX object projects/libunwind/src/CMakeFiles/unwind_shared.dir/Unwind-EHABI.cpp.obj:

                                                                                  C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:  In member function '                                             '':
AcquireSRWLockShared                                                                                  ' was not declared in this scope
                                 (&_lock);
     '                                        In file included from
' was not declared in this scope
     C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\UnwindCursor.hpp:73[  3%] AcquireSRWLockShared,
                 from Building C object projects/libunwind/src/CMakeFiles/unwind_static.dir/UnwindLevel1.c.obj(&_lock);

C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\Unwind-seh.cpp:29^~~~~~~~~~~~~~~~~~~~C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:42:5::

 C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:note:  In member function 'suggested alternative: 'C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:42:5:bool libunwind::RWMutex::lock_shared()RpcSsContextLockShared':
 '
     C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:42:5:                           suggested alternative: '(&_lock);
     error:                                           ''
     cc1.exe: warning: command line option '-nostdinc++' is valid for C++/ObjC++ but not for C
cc1.exe: warning: command line option '-Wno-suggest-override' is valid for C++/ObjC++ but not for C
cc1.exe: warning: command line option '-fno-rtti' is valid for C++/ObjC++ but not for C

     AcquireSRWLockShared                                          ' was not declared in this scope
     (&_lock);

AcquireSRWLockShared^~~~~~~~~~~~~~~~~~~~C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:
     (&_lock);
                          RpcSsContextLockShared^~~~~~~~~~~~~~~~~~~~bool libunwind::RWMutex::unlock_shared()

':
                                                                             C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:46:5:C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:42:5:                                                                            ':
 suggested alternative: 'C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:46:5:ReleaseSRWLockShared                       ' was not declared in this scope
     '
     error:                                         '(&_lock);
     (&_lock);
     ReleaseSRWLockShared                                        ' was not declared in this scope


     [  3%] Built target libclang_exports
ReleaseSRWLockShared                      C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:46:5:(&_lock);

                            C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:      Building CXX object projects/libunwind/src/CMakeFiles/unwind_shared.dir/Unwind-seh.cpp.obj
 In member function 'suggested alternative: '
bool libunwind::RWMutex::unlock_shared()ReleaseSemaphore':
'
     C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:46:5:C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:46:5:ReleaseSRWLockShared  (&_lock);
                  ^~~~~~~~~~~~~~~~~~~~                        '
     ReleaseSemaphoreReleaseSRWLockSharedReleaseSemaphore'
     ' was not declared in this scope

ReleaseSRWLockSharedReleaseSRWLockShared(&_lock);
     C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:(&_lock);
     ^~~~~~~~~~~~~~~~~~~~ In member function '^~~~~~~~~~~~~~~~~~~~
     bool libunwind::RWMutex::lock()
ReleaseSemaphore':

C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:50:5:C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:46:5:C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:                       note: error:                                                        '':
                AcquireSRWLockExclusiveC:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:50:5:'
     ' was not declared in this scope
                          AcquireSRWLockExclusive       (&_lock);
     (&_lock);
     '                    ^~~~~~~~~~~~~~~~~~~~~~~

' was not declared in this scope

C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:50:5:(&_lock);
                                                                                  In file included from  ^~~~~~~~~~~~~~~~~~~~~~~                     C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\UnwindCursor.hpp:73
                               ,
                 from suggested alternative: '':
C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\Unwind-seh.cpp:29                         C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:50:5::
'
      C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:AcquireSRWLockExclusiveerror:  In member function '(&_lock);
      bool libunwind::RWMutex::lock_shared()^~~~~~~~~~~~~~~~~~~~~~~AcquireSRWLockExclusive':

     ' was not declared in this scope
                                                                                       C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:42:5:RpcSsContextLockExclusive
                       note: error: (&_lock);
     suggested alternative: '                                                                              ^~~~~~~~~~~~~~~~~~~~~~~RpcSsContextLockExclusive In member function '
'
     AcquireSRWLockShared                                                        ' was not declared in this scope
     ':
C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:50:5:(&_lock);
     AcquireSRWLockSharedC:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:54:5: ^~~~~~~~~~~~~~~~~~~~~~~(&_lock);

                         error:                         RpcSsContextLockExclusive
RpcSsContextLockExclusive
ReleaseSRWLockExclusive'
                                                                                  C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:42:5:' was not declared in this scope
     AcquireSRWLockExclusive  In member function '(&_lock);
                                  bool libunwind::RWMutex::unlock()(&_lock);
     suggested alternative: '':
                                              RpcSsContextLockShared

'
     C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:54:5:                         AcquireSRWLockShared
(&_lock);
                                                                                       error: C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:
     note:                        bool libunwind::RWMutex::unlock()                      suggested alternative: '' was not declared in this scope
     ':

RpcSsContextLockExclusiveReleaseSRWLockExclusiveC:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:54:5:'
     C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp: (&_lock);
     ReleaseSRWLockExclusive In member function 'error:                        (&_lock);
                                             '
                       ':

     C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:46:5:C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:54:5:' was not declared in this scope
     RpcSsContextLockExclusive
       note: (&_lock);
     '                                                                   RpcSsContextLockExclusive
' was not declared in this scope
     '
     mingw32-make[2]: *** [projects\libunwind\src\CMakeFiles\unwind_static.dir\build.make:82: projects/libunwind/src/CMakeFiles/unwind_static.dir/libunwind.cpp.obj] Error 1
mingw32-make[2]: *** Waiting for unfinished jobs....
ReleaseSRWLockSharedReleaseSRWLockExclusiveC:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:54:5:(&_lock);
     (&_lock);
      ^~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~note:

                        [  3%]
                         RpcSsContextLockExclusiveC:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:46:5:'

 ReleaseSRWLockExclusive       note: (&_lock);
                                                                                                                     ^~~~~~~~~~~~~~~~~~~~~~~
ReleaseSemaphore
     mingw32-make[2]: *** [projects\libunwind\src\CMakeFiles\unwind_shared.dir\build.make:82: projects/libunwind/src/CMakeFiles/unwind_shared.dir/libunwind.cpp.obj] Error 1
'
     mingw32-make[2]: *** Waiting for unfinished jobs....

(&_lock);
     cc1.exe: warning: command line option '-nostdinc++' is valid for C++/ObjC++ but not for C
cc1.exe: warning: command line option '-Wno-suggest-override' is valid for C++/ObjC++ but not for C
cc1.exe: warning: command line option '-fno-rtti' is valid for C++/ObjC++ but not for C
^~~~~~~~~~~~~~~~~~~~
     [  3%] Built target scan-view
ReleaseSemaphoremingw32-make[2]: *** [projects\libunwind\src\CMakeFiles\unwind_static.dir\build.make:110: projects/libunwind/src/CMakeFiles/unwind_static.dir/Unwind-seh.cpp.obj] Error 1

mingw32-make[1]: *** [CMakeFiles\Makefile2:29444: projects/libunwind/src/CMakeFiles/unwind_static.dir/all] Error 2
mingw32-make[1]: *** Waiting for unfinished jobs....
C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp: In member function 'bool libunwind::RWMutex::lock()':
[  3%] Built target hmaptool
C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:50:5: error: 'AcquireSRWLockExclusive' was not declared in this scope
     AcquireSRWLockExclusive(&_lock);
     ^~~~~~~~~~~~~~~~~~~~~~~
C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:50:5: note: suggested alternative: 'RpcSsContextLockExclusive'
     AcquireSRWLockExclusive(&_lock);
     ^~~~~~~~~~~~~~~~~~~~~~~
     RpcSsContextLockExclusive
C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp: In member function 'bool libunwind::RWMutex::unlock()':
C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:54:5: error: 'ReleaseSRWLockExclusive' was not declared in this scope
     ReleaseSRWLockExclusive(&_lock);
     ^~~~~~~~~~~~~~~~~~~~~~~
C:\Users\Administrator\Documents\GitHub\obfuscator\libunwind\src\RWMutex.hpp:54:5: note: suggested alternative: 'RpcSsContextLockExclusive'
     ReleaseSRWLockExclusive(&_lock);
     ^~~~~~~~~~~~~~~~~~~~~~~
     RpcSsContextLockExclusive
mingw32-make[2]: *** [projects\libunwind\src\CMakeFiles\unwind_shared.dir\build.make:110: projects/libunwind/src/CMakeFiles/unwind_shared.dir/Unwind-seh.cpp.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:29417: projects/libunwind/src/CMakeFiles/unwind_shared.dir/all] Error 2
mingw32-make: *** [Makefile:170: all] Error 2
PS C:\Users\Administrator\Documents\GitHub\obfuscator\build>

字符数组,混淆不生效

Describe the bug
如果代码这么写:const char keyword[] = "keywords"; 混淆不生效,x86 动态库里依然能找到该value,其他cpu type 混淆成功

如果这么写:const char *keyword = "keywords",则 x86 混淆成功

集成google test, 单元测试缺少libclang_rt.profile-aarch64-android.a 文件

Describe the bug
i/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find /Users/XXXXX/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/lib/clang/9.0.1/lib/linux/libclang_rt.profile-aarch64-android.a: No such file or directory

To Reproduce
Steps to reproduce the behavior.

1.Macos 编译,100%复现
2.同时发现llvm/prebuilt/darwin-x86_64/lib64/clang/9.0.1/lib/linux 下有该文件,但是64位的,直接CP 过去好像不行,怎么能制作一个32位的ibclang_rt.profile-aarch64-android.a?

unknown endian on aarch64

Hi, fail to compile on aarch64, error says:

In file included from ../include/llvm/Transforms/Obfuscation/BogusControlFlow.h:32:0,
                 from ../lib/Transforms/IPO/PassManagerBuilder.cpp:50:
../include/llvm/Transforms/Obfuscation/CryptoUtils.h:87:2: error: #error "Unknown endianness of the compilation platform, check this header aes_encrypt.h"

Android編譯OLLVM9.0以後的都失敗

環境
mac m1 12.3.1
cmake 3.23.0
Android Studio 4.3
Gradle 7.2
Ndk 22.0.7026061
專案cmake 3.18.2

我先把12.x clone下來然後照9.0的編譯方法可以編譯出來
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ../obfuscator/llvm
make -j7

然後把build裡面的bin和lib複製貼上到
/Users/a0/Library/Android/sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/darwin-x86_64裡面
然後專案設置cppFlags '-mllvm -fla -mllvm -sub -mllvm -sobf'然後打包就丟出錯誤了
錯誤訊息
Build command failed.
Error while executing process /Users/a0/Library/Android/sdk/cmake/3.18.1/bin/ninja with arguments {-C /Users/a0/AndroidStudioProjects/NewJni/app/.cxx/RelWithDebInfo/51685pw1/arm64-v8a newjni}
ninja: Entering directory `/Users/a0/AndroidStudioProjects/NewJni/app/.cxx/RelWithDebInfo/51685pw1/arm64-v8a'
[1/2] Building CXX object CMakeFiles/newjni.dir/native-lib.cpp.o
FAILED: CMakeFiles/newjni.dir/native-lib.cpp.o
/Users/a0/Library/Android/sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/Users/a0/Library/Android/sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Users/a0/Library/Android/sdk/ndk/22.0.7026061/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -Dnewjni_EXPORTS -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -mllvm -fla -mllvm -sub -mllvm -sobf -O2 -g -DNDEBUG -fPIC -MD -MT CMakeFiles/newjni.dir/native-lib.cpp.o -MF CMakeFiles/newjni.dir/native-lib.cpp.o.d -o CMakeFiles/newjni.dir/native-lib.cpp.o -c /Users/a0/AndroidStudioProjects/NewJni/app/src/main/cpp/native-lib.cpp
clang (LLVM option parsing): Unknown command line argument '-fla'. Try: 'clang (LLVM option parsing) --help'
clang (LLVM option parsing): Did you mean '-h'?
clang (LLVM option parsing): Unknown command line argument '-sub'. Try: 'clang (LLVM option parsing) --help'
clang (LLVM option parsing): Did you mean '-h'?
clang (LLVM option parsing): Unknown command line argument '-sobf'. Try: 'clang (LLVM option parsing) --help'
clang (LLVM option parsing): Did you mean '--polly'?
ninja: build stopped: subcommand failed.

不知道是9.0之後的編譯方法變了還是有哪裡做錯誤了?
希望大哥可以幫忙解惑一下 感恩

llvm 13.x compilation problem

android-ndk-r21e/toolchains/llvm/prebuilt/darwin-x86_64/lib/clang/13.0.1/lib/linux/libclang_rt.builtins-arm-android.a: No such file or directory on a Mac

ollvm13、14报错isPlatformVersionAtLeast

ollvm13、14会因为关键词@available报错
Undefined symbols for architecture x86_64:
"___isPlatformVersionAtLeast", referenced from:
这个有解吗

并且-split_num参数等于2时白屏无法运行,3及以上时报错无法启动
错误如下
`

  1. parser at end of file
  2. Per-module optimization passes
  3. Running pass 'Function Pass Manager' on module '/Users/liujia/Desktop/---/RTKVideoFactry.m'.
  4. Running pass 'Call graph flattening' on function '@dispatch_get_main_queue'
    Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var LLVM_SYMBOLIZER_PATH to point to it):
    0 clang 0x000000011012e157 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
    1 clang 0x000000011012d038 llvm::sys::RunSignalHandlers() + 248
    2 clang 0x000000011012d710 llvm::sys::CleanupOnSignal(unsigned long) + 208
    3 clang 0x000000011006984f CrashRecoverySignalHandler(int) + 191
    4 libsystem_platform.dylib 0x00007fff2047bd7d _sigtramp + 29
    5 libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603339974591136
    6 clang 0x000000010f993b0b llvm::FPPassManager::runOnFunction(llvm::Function&) + 907
    7 clang 0x000000010f999dfc llvm::FPPassManager::runOnModule(llvm::Module&) + 60
    8 clang 0x000000010f994125 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 933
    9 clang 0x00000001103d9275 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_deletellvm::raw_pwrite_stream >) + 11637
    10 clang 0x00000001106d1b36 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) + 1046
    11 clang 0x00000001118800e4 clang::ParseAST(clang::Sema&, bool, bool) + 580
    12 clang 0x0000000110a2fe7a clang::FrontendAction::Execute() + 90
    13 clang 0x000000011099b956 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 838
    14 clang 0x0000000110aaa2ba clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1562
    15 clang 0x000000010e16916c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 2204
    16 clang 0x000000010e167356 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) + 278
    17 clang 0x00000001107f8657 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optionalllvm::StringRef >, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, bool) const::$_1>(long) + 23
    18 clang 0x00000001100695a2 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 226
    19 clang 0x00000001107f81cc clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optionalllvm::StringRef >, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, bool) const + 396
    20 clang 0x00000001107c40f1 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const + 737
    21 clang 0x00000001107c44ac clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*> >&) const + 124
    22 clang 0x00000001107dd9bc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*> >&) + 396
    23 clang 0x000000010e166a24 main + 9844
    24 libdyld.dylib 0x00007fff20451f3d start + 1
    clang-13: error: clang frontend command failed with exit code 139 (use -v to see invocation)
    clang version 13.0.1
    Target: x86_64-apple-ios10.0-simulator
    Thread model: posix
    InstalledDir: /Users/liujia/Obfuscator13/build/bin
    clang-13: note: diagnostic msg:

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-13: note: diagnostic msg: /var/folders/3d/cxmpny_166q75m9lhjc6pnrm0000gn/T/RTKVideoFactry-e53b2c.m
clang-13: note: diagnostic msg: /var/folders/3d/cxmpny_166q75m9lhjc6pnrm0000gn/T/RTKVideoFactry-e53b2c.cache
clang-13: note: diagnostic msg: /var/folders/3d/cxmpny_166q75m9lhjc6pnrm0000gn/T/RTKVideoFactry-e53b2c.sh
clang-13: note: diagnostic msg: Crash backtrace is located in
clang-13: note: diagnostic msg: /Users/liujia/Library/Logs/DiagnosticReports/clang-13__.crash
clang-13: note: diagnostic msg: (choose the .crash file that corresponds to your crash)
clang-13: note: diagnostic msg:


Command /Users/liujia/Obfuscator13/build/bin/clang failed with exit code 139
`

macos:11.6.5 xcode:13.2.1

-flegacy-pass-manager导致for循环不执行

你好
再来请教一下,iOS项目添加-flegacy-pass-manager会导致for循环不执行,不添加又没有混淆效果,原版llvm13,14以及apple的llvm经测试都没法解决。
环境:macOS:11.6.5 xcode:13.2.1
代码示例:
for (NSInteger i = 0;i < classControllersArray.count;i++) { Class cts = NSClassFromString(classControllersArray[i]); UIViewController *vc = [[cts alloc] init]; }
经测试for循环前调用if就可以正常,否则即使classControllersArray.count大于0或者常数都直接跳过,甚至后续if逻辑也会跳过
if (classControllersArray.count > 0) {}

为什么使用 c++ 标准的头文件就会出现报错

clang++: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 9.0.1 
Target: aarch64-none-linux-android24
Thread model: posix
InstalledDir: D:\dev\sdk\ndk\213652~1.1\TOOLCH~1\llvm\prebuilt\WINDOW~1\bin
clang++: note: diagnostic msg: PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
clang++: note: diagnostic msg: 
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++: note: diagnostic msg: C:\Users\ADMINI~1\AppData\Local\Temp\web-a08606.cpp
clang++: note: diagnostic msg: C:\Users\ADMINI~1\AppData\Local\Temp\web-a08606.sh
clang++: note: diagnostic msg: 
********************

image

报错信息中的文件:
web-a08606.zip

ollvm12.x 编译成功后, 按 wiki 所说, 替换 ndk bin 和 lib or lib64 后, AS 无法编译, 很多人有这问题, 麻烦看看怎么搞

[CXX1405] error when building with cmake using E:\Codes*\app\src\main\cpp\CMakeLists.txt: Build command failed.
Error while executing process D:\Android\sdk\cmake\3.22.1\bin\cmake.exe with arguments {-HE:\Codes*
\app\src\main\cpp -DCMAKE_SYSTEM_NAME=Android -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_SYSTEM_VERSION=21 -DANDROID_PLATFORM=android-21 -DANDROID_ABI=arm64-v8a -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a -DANDROID_NDK=D:\Android\sdk\android-ndk-r23b-ollvm -DCMAKE_ANDROID_NDK=D:\Android\sdk\android-ndk-r23b-ollvm -DCMAKE_TOOLCHAIN_FILE=D:\Android\sdk\android-ndk-r23b-ollvm\build\cmake\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=D:\Android\sdk\cmake\3.22.1\bin\ninja.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=E:\Codes*\app\build\intermediates\cxx\Release\5w1k6l71\obj\arm64-v8a -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=E:\Codes*\app\build\intermediates\cxx\Release\5w1k6l71\obj\arm64-v8a -BE:\Codes***********\app.cxx\Release\5w1k6l71\arm64-v8a -GNinja -DSK_BUILD_VERSION=SK_RELEASE -DANDROID_ARM_MODE=arm -DANDROID_STL=c++_static -DANDROID_CPP_FEATURES=rtti exceptions -DCMAKE_BUILD_TYPE=Release}
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: D:/Android/sdk/android-ndk-r23b-ollvm/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
-- Check for working C compiler: D:/Android/sdk/android-ndk-r23b-ollvm/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe - broken
-- Configuring incomplete, errors occurred!
See also "E:/Codes//app/.cxx/Release/5w1k6l71/arm64-v8a/CMakeFiles/CMakeOutput.log".
See also "E:/Codes/
/app/.cxx/Release/5w1k6l71/arm64-v8a/CMakeFiles/CMakeError.log".

CMake Error at D:/Android/sdk/cmake/3.22.1/share/cmake-3.22/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler

"D:/Android/sdk/android-ndk-r23b-ollvm/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: E:/Codes/***********/app/.cxx/Release/5w1k6l71/arm64-v8a/CMakeFiles/CMakeTmp

Run Build Command(s):D:\Android\sdk\cmake\3.22.1\bin\ninja.exe cmTC_9cb7f && [1/2] Building C object CMakeFiles\cmTC_9cb7f.dir\testCCompiler.c.o
FAILED: CMakeFiles/cmTC_9cb7f.dir/testCCompiler.c.o 
D:\Android\sdk\android-ndk-r23b-ollvm\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe   -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -o CMakeFiles\cmTC_9cb7f.dir\testCCompiler.c.o -c E:\Codes\***********\app\.cxx\Release\5w1k6l71\arm64-v8a\CMakeFiles\CMakeTmp\testCCompiler.c
ninja: build stopped: subcommand failed.

CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)

Compile 7.0 & 8.0 version of ollvm error on osx intel 10.15.7

Describe the bug
Compile 7.0 & 8.0 version of ollvm error on osx intel 10.15.7

To Reproduce

git checkout llvm-7.0
mkdir build-7.0
cd build-7.0
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_CREATE_XCODE_TOOLCHAIN=ON ../

then error occurs

-- Could NOT find Python module pygments.lexers.c_cpp
-- Could NOT find Python module yaml
-- LLVM host triple: x86_64-apple-darwin19.6.0
-- LLVM default target triple: x86_64-apple-darwin19.6.0
-- Building with -fPIC
CMake Error at CMakeLists.txt:628 (if):
  if given arguments:

    "VERSION_LESS" "2.7"

  Unknown arguments specified


-- Configuring incomplete, errors occurred!
See also "/Users/xxx/obfuscator/build-7.0/CMakeFiles/CMakeOutput.log".
See also "/Users/xxx/obfuscator/build-7.0/CMakeFiles/CMakeError.log".

Expected behavior
cmake success and then make -j8.

Screenshots
NONE.

Desktop (please complete the following information):

  • OS: macOS(intel core i9)
  • Version: 10.15.7
  • cflag: [e.g. -mllvm -fla -mllvm -bcf]
gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/incl
[CMakeError-7.0.log](https://github.com/heroims/obfuscator/file
[CMakeError-8.0.log](https://github.com/heroims/obfuscator/files/8881190/CMakeError-8.0.log)
s/8881182/CMakeError-7.0.log)
ude/c++/4.2.1
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

cmake --version
cmake version 3.17.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).

Souce Code (please complete the following information):

  • git link: github.com/heroims/obfuscator.git
  • branch llvm-7.0
  • commit hash: 66f7aab

Additional context
NONE.

CMakeError-8.0.log
CMakeError-7.0.log

AutoRegistration Issue

heroims前辈,您好~
我最近在学习LLVM,实际操作中,遇到几个问题,希望可以得到指点


前言

我目前的学习都是采用的out-of-tree方案,编译的llvm动态库插件,我认为这样比起in-tree,更加灵活方便
已经仔细拜读过了您和leadroyal前辈的最新文章,并且参考了两位前辈项目里面的代码
最终成功移植自己的PassDemo到了NEW Pass Manager


升级Legacy Pass Manager到NEW Pass Manager后

clang如何触发特定Pass

  • 参考前辈此处提供的方案,我已经成功移植上去了:

    // #1 注册标记 "opt -passes=obf-bcf"
    PB.registerPipelineParsingCallback(
    [&](StringRef Name, FunctionPassManager &FPM,
    ArrayRef<PassBuilder::PipelineElement>) {
    if (Name == "obf-bcf") {
    FPM.addPass(BogusControlFlowPass());
    return true;
    }
    if(Name == "obf-fla"){
    FPM.addPass(FlatteningPass());
    return true;
    }
    if(Name == "obf-sub"){
    FPM.addPass(SubstitutionPass());
    return true;
    }
    if(Name == "obf-split"){
    FPM.addPass(SplitBasicBlockPass());
    return true;
    }
    return false;
    });

  • 并且在opt成功指定加载某Pass:
    image

  • 然而让我比较困惑的是,opt确实可以成功加载Pass插件并且指定开启某Pass;
    但是当我尝试用clang加载pass插件并且指定开启某Pass的时候,pass插件确实可以使用-fpass-plugin=/path/to/pass载入;
    可是无论如何都触发不了特定的参数,从而开启特定Pass:
    image
    image

  • 上图只是两次尝试,实际上我试过多种姿势,貌似都不太行,就不一一列举了;
    也试过自己读源码理解或者仔细查看clang的help,奈何学生比较愚钝,没能解决问题,希望前辈可以指点。

  • 我的临时解决方案:

    PB.registerPipelineStartEPCallback(

    注册Pass的时候加上这种方案,也就是说只要动态库插件载入,默认注册全部Pass,但是我给每个Pass类做一个携带flag的构造函数,并且默认为false。然后再通过toObfuscate读取每个函数的annotation注解,匹配上注解中的Pass则开启
    bool toObfuscate(bool flag, Function *f, std::string const &attribute) {

New Pass Manager貌似无法传递cl::opt的参数

  • Legacy Pass Manager中,动态库插件尚且可以用-split_num=7的形式传递opt参数,以指定混淆程度。

  • 但是好像对于New Pass Manager暂时还没有相关支持?
    参考:The command line option is not available for the new PM

  • 目前的想法还是通过读取annotation注解来指定的混淆程度,然后自己改改,解析一下注解的字符串

  • (顺便一提,我好像没在toObfuscate和readAnnotate中读到对split_num这种的解析,是不是说ollvm用annotation控制单个函数开启混淆的时候,其实混淆程度是没有效果的)

    int add(int a, int b) __attribute((__annotate__(("fla split split_num=7")))){
        return (a+b); // 有效的只是fla和split,split_num实则无效?我没看到toObfuscate有对split_num这种的处理
    }
  • 或者还有这种手法,实测也在14版本可行,算是一种讨巧吧,把动态库用两种方案都加载一遍,但是Pass用NEW PM控制:

     opt --load-pass-plugin=../Build/SsageObfuscator.so -passes=split,fla -load ../Build/SsageObfuscator.so -split_num=7 -S main.ll -o main_fla.ll
     clang++ -fpass-plugin=../build/SsageObfuscator.so -Xclang -load -Xclang ../build/SsageObfuscator.so -mllvm -split_num=7 main.cpp -o main
  • 当然,如果是in-tree编译的话,好像cl::opt可以自己写进clang,不存在这种问题

  • 想问一问前辈想怎么处理这种情况,十分感谢


一些补充

  • 此处的代码似乎是有点纰漏:
    PB.registerPipelineStartEPCallback(
    [](llvm::FunctionPassManager &PM,
    llvm::PassBuilder::OptimizationLevel Level) {
    // registerPipelineStartEPCallback原型为:
    void registerPipelineStartEPCallback(
        const std::function<void(ModulePassManager &, OptimizationLevel)> &C) {
      PipelineStartEPCallbacks.push_back(C);
    }
    1. 因此,registerPipelineStartEPCallback的第一个参数,貌似不应该为FunctionPassManager,而是ModulePassManager。
    2. 结合上下可知,我们在此处注册的确实是FunctionPass,所以应该改用registerVectorizerStartEPCallback才对。
    // registerVectorizerStartEPCallback原型为:
    void registerVectorizerStartEPCallback(
        const std::function<void(FunctionPassManager &, OptimizationLevel)> &C) {
        VectorizerStartEPCallbacks.push_back(C);
    }
  • 此外,貌似这部分代码应该要使用llvm命名空间;
    而且llvm::PassBuilder内没有OptimizationLevel,应该是llvm::OptimizationLevel
  • 综上,修改后应为:
    using namespace llvm;
    // ......
    PB.registerVectorizerStartEPCallback( 
    // 注意opt调试的时候 添加 -O1 参数 否则不触发
    // 我实测的时候 貌似clang不需要添加 -O1 参数 也可以触发? 
    // 但是最好还是添加一下 参考:https://github.com/banach-space/llvm-tutor#overview-of-the-passes 的下半段
                    [](llvm::FunctionPassManager &PM,
                        llvm::OptimizationLevel Level){
                        // ......
  • 以上这些,是我基于llvm_14.01做的研究,我不确定这些变化是llvm版本变动导致的,还是前辈的git代码有些许纰漏。
    学生水平不足,如有错误,还请多多包涵~

最后,附上练手的Demo:SsagePass


aesSeed flag causing duplicate symbols

Describe the bug
Getting Duplicate symbols error when trying to use aesSeed flag. Without the aesSeed flags, it works fine

To Reproduce
Use this flag LOCAL_CPPFLAGS += -mllvm -sub -mllvm -fla -mllvm -split -mllvm -bcf -mllvm -sobf -mllvm -aesSeed=0xada46ab5da824b96a18409c49dc91dc3 in Android.mk

Expected behavior
Should be able to compile without errors

Desktop (please complete the following information):

  • OS: Windows
  • Version: 11

Souce Code (please complete the following information):
Cannot share my private source code

Additional context
I'm using NDK 25.1.8937393 with llvm 14.0.6. I patched llvm 14.x branch with legacy patch and followed this tutorial to compile https://blog.csdn.net/qq_41923691/article/details/123258565

This issue does not happen on Ollvm 9.0.1

Logs

[armeabi-v7a] SharedLibrary  : libab.so
ld: error: duplicate symbol: .datadiv_decode14922226972744637069
>>> defined at And64InlineHook.cpp
>>>            ./obj/local/armeabi-v7a/objs/ab/And64InlineHook/And64InlineHook.o:(.datadiv_decode14922226972744637069)
>>> defined at near_trampoline_arm64.cc
>>>            ./obj/local/armeabi-v7a/objs/ab/dobby/source/InterceptRouting/RoutingPlugin/NearBranchTrampoline/near_trampoline_arm64.o:(.text..datadiv_decode14922226972744637069+0x0)

ld: error: duplicate symbol: .datadiv_decode14922226972744637069
>>> defined at And64InlineHook.cpp
>>>            ./obj/local/armeabi-v7a/objs/ab/And64InlineHook/And64InlineHook.o:(.datadiv_decode14922226972744637069)
>>> defined at CpuRegister.cc
>>>            ./obj/local/armeabi-v7a/objs/ab/dobby/source/core/arch/CpuRegister.o:(.text..datadiv_decode14922226972744637069+0x0)

ld: error: duplicate symbol: .datadiv_decode14922226972744637069
>>> defined at And64InlineHook.cpp
>>>            ./obj/local/armeabi-v7a/objs/ab/And64InlineHook/And64InlineHook.o:(.datadiv_decode14922226972744637069)
>>> defined at assembler-arm64.cc
>>>            ./obj/local/armeabi-v7a/objs/ab/dobby/source/core/assembler/assembler-arm64.o:(.text..datadiv_decode14922226972744637069+0x0)

ld: error: duplicate symbol: .datadiv_decode14922226972744637069
>>> defined at And64InlineHook.cpp
>>>            ./obj/local/armeabi-v7a/objs/ab/And64InlineHook/And64InlineHook.o:(.datadiv_decode14922226972744637069)
>>> defined at codegen-arm64.cc
>>>            ./obj/local/armeabi-v7a/objs/ab/dobby/source/core/codegen/codegen-arm64.o:(.text..datadiv_decode14922226972744637069+0x0)

ld: error: duplicate symbol: .datadiv_decode14922226972744637069
>>> defined at And64InlineHook.cpp
>>>            ./obj/local/armeabi-v7a/objs/ab/And64InlineHook/And64InlineHook.o:(.datadiv_decode14922226972744637069)
>>> defined at InstructionRelocationARM64.cc
>>>            ./obj/local/armeabi-v7a/objs/ab/dobby/source/InstructionRelocation/arm64/InstructionRelocationARM64.o:(.text..datadiv_decode14922226972744637069+0x0)

ld: error: duplicate symbol: .datadiv_decode14922226972744637069
>>> defined at And64InlineHook.cpp
>>>            ./obj/local/armeabi-v7a/objs/ab/And64InlineHook/And64InlineHook.o:(.datadiv_decode14922226972744637069)
>>> defined at trampoline_arm64.cc
>>>            ./obj/local/armeabi-v7a/objs/ab/dobby/source/TrampolineBridge/Trampoline/arm64/trampoline_arm64.o:(.text..datadiv_decode14922226972744637069+0x0)

ld: error: duplicate symbol: .datadiv_decode14922226972744637069
>>> defined at And64InlineHook.cpp
>>>            ./obj/local/armeabi-v7a/objs/ab/And64InlineHook/And64InlineHook.o:(.datadiv_decode14922226972744637069)
>>> defined at helper_arm64.cc
>>>            ./obj/local/armeabi-v7a/objs/ab/dobby/source/TrampolineBridge/ClosureTrampolineBridge/arm64/helper_arm64.o:(.text..datadiv_decode14922226972744637069+0x0)

ld: error: duplicate symbol: .datadiv_decode14922226972744637069
>>> defined at And64InlineHook.cpp
>>>            ./obj/local/armeabi-v7a/objs/ab/And64InlineHook/And64InlineHook.o:(.datadiv_decode14922226972744637069)
>>> defined at closure_bridge_arm64.cc
>>>            ./obj/local/armeabi-v7a/objs/ab/dobby/source/TrampolineBridge/ClosureTrampolineBridge/arm64/closure_bridge_arm64.o:(.text..datadiv_decode14922226972744637069+0x0)

ld: error: duplicate symbol: .datadiv_decode14922226972744637069
>>> defined at And64InlineHook.cpp
>>>            ./obj/local/armeabi-v7a/objs/ab/And64InlineHook/And64InlineHook.o:(.datadiv_decode14922226972744637069)
>>> defined at ClosureTrampolineARM64.cc
>>>            ./obj/local/armeabi-v7a/objs/ab/dobby/source/TrampolineBridge/ClosureTrampolineBridge/arm64/ClosureTrampolineARM64.o:(.text..datadiv_decode14922226972744637069+0x0)

ld: error: duplicate symbol: .datadiv_decode16268766865428279510
>>> defined at helper_arm.cc
>>>            ./obj/local/armeabi-v7a/objs/ab/dobby/source/TrampolineBridge/ClosureTrampolineBridge/arm/helper_arm.o:(.datadiv_decode16268766865428279510)
>>> defined at InterceptEntry.cpp
>>>            ./obj/local/armeabi-v7a/objs/ab/dobby/source/InterceptEntry.o:(.text..datadiv_decode16268766865428279510+0x0)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [E:/AndroidSDK/ndk/25.1.8937393/build/../build/core/build-binary.mk:657: obj/local/armeabi-v7a/libab.so] Error 1
make: *** Waiting for unfinished jobs....
[arm64-v8a] Compile++      : ab <= hook.cpp
[arm64-v8a] Compile++      : ab <= InterceptEntry.cpp
[arm64-v8a] Compile++      : ab <= closure_bridge_arm64.cc

混淆不生效

分别用ninja和vs2019编译成功了,都试过了,实际编译exe时候可以编译成功,但是任何混淆都不生效,命令行都是-mllvm -bcf -mllvm -sub -mllvm -fla -mllvm -sobf -mllvm -split 这种应该没啥问题

ollvm-9.0.1通过NDK编译时,缺少头文件

NDK版本: 21.4.7075529
OLLVM版本: https://github.com/heroims/obfuscator/tree/llvm-9.0.1

由于代码中依赖了libcurl,因此cmake中包含下列配置项

cmake_minimum_required(VERSION 3.18.1)
include(FetchContent)
SET(CURL_ENABLE_SSL OFF)
SET(CURL_USE_LIBSSH2 OFF)
SET(USE_LIBIDN2 OFF)
SET(HTTP_ONLY ON)
SET(ENABLE_IPV6 OFF)
FetchContent_declare(libcurl URL https://github.com/curl/curl/releases/download/curl-7_82_0/curl-7.82.0.tar.xz)
FetchContent_MakeAvailable(libcurl)

# ... 省略无关配置项

target_link_libraries(
        native-lib
        libcurl)

编译后出现错误

C/C++: bionic/libc/bionic/new.cpp:29: error: undefined reference to 'async_safe_fatal_no_abort'
C/C++: bionic/libc/bionic/new.cpp:37: error: undefined reference to 'async_safe_fatal_no_abort'
C/C++: clang++: error: linker command failed with exit code 1 (use -v to see invocation)

尝试使用原始NDK编译,无此问题。

Support for llvm-14.x

Patch for recent commit fd98b0f1a6a1

How to install

git clone -b release/14.x https://github.com/llvm/llvm-project.git
cd llvm-project
git checkout fd98b0f1a6a1
wget https://github.com/heroims/obfuscator/files/8426512/ollvm-14.patch.txt
git apply ollvm-14.patch.txt

Done! Now you have sources llvm-14.0.1 with obfuscation support. Next, you can follow instruction from Wiki to build it.

P.S. Integrate with android-ndk

Support for LLVM 17

The ollvm14.patch new pass does not support LLVM 17. I'm getting the following errors trying to patch the source

../ollvm14.patch:74: trailing whitespace.
    class BogusControlFlowPass : public PassInfoMixin<BogusControlFlowPass>{
../ollvm14.patch:270: trailing whitespace.
    class FlatteningPass : public PassInfoMixin<FlatteningPass>{
../ollvm14.patch:314: trailing whitespace.
    class SplitBasicBlockPass : public PassInfoMixin<SplitBasicBlockPass>{
../ollvm14.patch:335: trailing whitespace.
      class StringObfuscationPass : public PassInfoMixin<StringObfuscationPass>{
../ollvm14.patch:376: trailing whitespace.
    class SubstitutionPass : public PassInfoMixin<SubstitutionPass>{
error: patch failed: llvm/CMakeLists.txt:246
error: llvm/CMakeLists.txt: patch does not apply
error: patch failed: llvm/CODE_OWNERS.TXT:248
error: llvm/CODE_OWNERS.TXT: patch does not apply
error: patch failed: llvm/lib/Passes/PassBuilder.cpp:244
error: llvm/lib/Passes/PassBuilder.cpp: patch does not apply
error: patch failed: llvm/lib/Passes/PassBuilderPipelines.cpp:182
error: llvm/lib/Passes/PassBuilderPipelines.cpp: patch does not apply

Can you add support for it?

Note: LLVM 17 no longer support legacy pass

字符串混淆功能

字符串混淆功能,当源码中存在类型不一致的时候,就会崩溃,这个能warning能忽略吗?

0c1974f8c609d7a603aba5f7681f109

bitcode

Apple requires bitcode for tvOS builds, and strongly encourages bitcode for iOS builds. Also, the compiler has recently added a check in clang/lib/Driver/ToolChains/Clang.cpp, which does not allow -mllvm in CFLAGS when -fembed-bitcode is present.

This didn't happen before, on llvm-9.0.1 (but that was not compatible with the modern Xcode).

I tried to simply remove the error check for mllvm from Clang.cpp, but this resulted in lots of suspicious warnings while compiling and my iOS code, I tried to simply hardcode -mllvm -bcf -mllvm -sub -mllvm -fla -mllvm -sobf in the compiler. Now, build passes smoothly.

Is there a better way to work around this problem? Also, I am not sure (have not tried) that the bitcode that is produced after my 'fix' is valid.

build failed

我拉取了llvm-13.x的分支 然后去到了 /obfuscator/llvm/projects路径下 执行了
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_CREATE_XCODE_TOOLCHAIN=ON -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi"
结果failed了 。

/obfuscator/llvm/projects/CMakeFiles/CMakeOutput.log 中的 内容如下, 求指点

Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
Build flags:
Id flags:

The output was:
1
ld: library not found for -lSystem
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
Build flags:
Id flags:

The output was:
1
ld: library not found for -lc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)

使用xcodebuild 命令行指定工具链进行ollvm混淆编译不会生效

请教下大佬,这个问题该如何解决:

不使用xcode界面进行编译,而是仅仅用xcodebuild命令行进行编译;
已通过xcode界面的build setting加入了fla等cflag
期望编译出被ollvm混淆过后的静态链接库
参考命令如下
xcodebuild -scheme myproject -sdk iphoneos -project myproject .xcodeproj -configuration Release DSTROOT=/Users/amlloc/Project/myproject /build_ios/objects SYMROOT=/Users/amlloc/Project/myproject /build_ios/build -toolchain ollvm
但是目前现状是:

通过xcode界面编译出来的静态链接库是被混淆的
通过上述命令编译出来的静态链接库未被混淆

ollvm13.x生成的clang.exe,替换到vs2022以后,无法混淆

我是按以下方式使用的
编译
1 从github下载ollvm13.x
2 用cmake-gui生成sln
3 编译生成clang

替换
用生成的clang.exe,及其它exe全部替换到vs2022的llvm工具集里面

使用
1 vs2022,添了LLVM (clang-cl), 然后选择了LLVM (clang-cl)
2 在c/c++->命令行->添加-mllvm -sub -mllvm -bcf -mllvm -fla
3 重新生成

最后用ida打开生成的exe,但是和代码里面一样.并没有混淆

String obfuscation NOT obfuscating in Windows

String obfuscation NOT obfuscating in Windows
Patch & build in Linux, String obfuscation works properly.
Patch & build in Windows, String obfuscation simple doesn't works.

Build process:
cmake -S llvm -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi" -DLLVM_ENABLE_ASSERTIONS=No -DLLVM_ENABLE_NEW_PASS_MANAGER=Off

Compiling with string obfuscation option -mmlvm -sobf
C:\>\llvm-project_14.x\build\bin\clang.exe -mllvm -sobf hello.c -o hello.exe

Source code to test
image

Results of the compiled source code with -mllvm -sobf
image
As seen in the image, the strings remains intact (not obfuscated).

Software:

  • OS: Windows 10
  • Visual Studio 2022
  • LLVM 14.0.6
  • cflag: -mllvm -sobf

cmake can't compile test on android ndk r23b using ollvm 12

i've compiled ollvm on windows with Visual Studio 16 2019 with following cmds:
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=ARM -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi;compiler-rt;lld" -Thost=x64 ../llvm (i've also tried with only clang)
cmake --build . --target ALL_BUILD --config Release -- /nologo /maxcpucount
then i copied build outputs to <toolchain_dir>/bin and <toolchain_dir>/lib64, when i try to compile simple android cmake project i get this error:

[main] Configuring folder: src 
[proc] Executing command: D:\CMake\bin\cmake.EXE --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Release -Sd:/bmbr/src -Bd:/bmbr/src/build -G "MinGW Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Android: Targeting API '19' with architecture 'arm', ABI 'armeabi-v7a', and processor 'armv7-a'
[cmake] -- Android: Selected unified Clang toolchain
[cmake] -- The C compiler identification is Clang 12.0.1
[cmake] -- The CXX compiler identification is Clang 12.0.1
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - failed
[cmake] -- Check for working C compiler: D:/ndk23b/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
[cmake] -- Check for working C compiler: D:/ndk23b/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe - broken
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "D:/bmbr/src/build/CMakeFiles/CMakeOutput.log".
[cmake] See also "D:/bmbr/src/build/CMakeFiles/CMakeError.log".
[cmake] CMake Error at D:/CMake/share/cmake-3.21/Modules/CMakeTestCCompiler.cmake:69 (message):
[cmake]   The C compiler
[cmake] 
[cmake]     "D:/ndk23b/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe"
[cmake] 
[cmake]   is not able to compile a simple test program.
[cmake] 
[cmake]   It fails with the following output:
[cmake] 
[cmake]     Change Dir: D:/bmbr/src/build/CMakeFiles/CMakeTmp
[cmake]     
[cmake]     Run Build Command(s):C:/MinGW/bin/mingw32-make.exe -f Makefile cmTC_b0a71/fast && C:/MinGW/bin/mingw32-make.exe  -f CMakeFiles\cmTC_b0a71.dir\build.make CMakeFiles/cmTC_b0a71.dir/build
[cmake]     mingw32-make.exe[1]: Entering directory 'D:/bmbr/src/build/CMakeFiles/CMakeTmp'
[cmake]     Building C object CMakeFiles/cmTC_b0a71.dir/testCCompiler.c.o
[cmake]     D:\ndk23b\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe --target=armv7-none-linux-androideabi19 --sysroot=D:/ndk23b/toolchains/llvm/prebuilt/windows-x86_64/sysroot   -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -fexceptions  -O2 -g -DNDEBUG -fPIE -MD -MT CMakeFiles/cmTC_b0a71.dir/testCCompiler.c.o -MF CMakeFiles\cmTC_b0a71.dir\testCCompiler.c.o.d -o CMakeFiles\cmTC_b0a71.dir\testCCompiler.c.o -c D:\bmbr\src\build\CMakeFiles\CMakeTmp\testCCompiler.c
[cmake]     Linking C executable cmTC_b0a71
[cmake]     D:\CMake\bin\cmake.exe -E cmake_link_script CMakeFiles\cmTC_b0a71.dir\link.txt --verbose=1
[cmake]     D:\ndk23b\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe --target=armv7-none-linux-androideabi19 --sysroot=D:/ndk23b/toolchains/llvm/prebuilt/windows-x86_64/sysroot -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -fexceptions  -O2 -g -DNDEBUG -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Qunused-arguments -Wl,--no-undefined  -Wl,--gc-sections  CMakeFiles/cmTC_b0a71.dir/testCCompiler.c.o -o cmTC_b0a71   -latomic -lm 
[cmake]     ld: error: unable to find library -latomic
[cmake]     ld: error: unable to find library -lgcc
[cmake]     ld: error: unable to find library -lgcc
[cmake]     clang: error: linker command failed with exit code 1 (use -v to see invocation)
[cmake]     mingw32-make.exe[1]: *** [CMakeFiles\cmTC_b0a71.dir\build.make:99: cmTC_b0a71] Error 1
[cmake]     mingw32-make.exe[1]: Leaving directory 'D:/bmbr/src/build/CMakeFiles/CMakeTmp'
[cmake]     mingw32-make.exe: *** [Makefile:126: cmTC_b0a71/fast] Error 2
[cmake]     
[cmake]     
[cmake] 
[cmake]   
[cmake] 
[cmake]   CMake will not be able to correctly generate this project.
[cmake] Call Stack (most recent call first):
[cmake]   CMakeLists.txt:9 (project)
[cmake] 
[cmake] 

(i'm using android toolchain that is bundled with ndk with following settings: platform = android-19, stl = c++_static, abi = armeabi-v7a, i've tried using legacy toolchain, same results)

请教一个入门问题,如何编译 32 位的 bin ? 🤣

我尝试使用如下命令编译了 9.0.1

git clone -b llvm-9.0.1 https://github.com/heroims/obfuscator
cd obfuscator
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -G "MinGW Makefiles" ../
mingw32-make.exe -j7

经过测试他是工作的,但我希望得到 32位的文件,而不是 64位的,请问我该如何修改?
我尝试了使用 cmake 的 set(CMAKE_C_FLAGS "-m32"),set(CMAKE_CXX_FLAGS "-m32") 但这会导致 build 的时候失败:

... (省略)
-- Version: 0.0.0
Performing Test HAVE_CXX_FLAG_STD_CXX11
Performing Test HAVE_CXX_FLAG_STD_CXX11 - Success
Performing Test HAVE_CXX_FLAG_WALL
Performing Test HAVE_CXX_FLAG_WALL - Success
Performing Test HAVE_CXX_FLAG_WEXTRA
Performing Test HAVE_CXX_FLAG_WEXTRA - Success
Performing Test HAVE_CXX_FLAG_WSHADOW
Performing Test HAVE_CXX_FLAG_WSHADOW - Success
Performing Test HAVE_CXX_FLAG_PEDANTIC
Performing Test HAVE_CXX_FLAG_PEDANTIC - Success
Performing Test HAVE_CXX_FLAG_PEDANTIC_ERRORS
Performing Test HAVE_CXX_FLAG_PEDANTIC_ERRORS - Success
Performing Test HAVE_CXX_FLAG_WSHORTEN_64_TO_32
Performing Test HAVE_CXX_FLAG_WSHORTEN_64_TO_32 - Failed
Performing Test HAVE_CXX_FLAG_WFLOAT_EQUAL
Performing Test HAVE_CXX_FLAG_WFLOAT_EQUAL - Success
Performing Test HAVE_CXX_FLAG_FSTRICT_ALIASING
Performing Test HAVE_CXX_FLAG_FSTRICT_ALIASING - Success
Performing Test HAVE_CXX_FLAG_FNO_EXCEPTIONS
Performing Test HAVE_CXX_FLAG_FNO_EXCEPTIONS - Success
Performing Test HAVE_CXX_FLAG_WSTRICT_ALIASING
Performing Test HAVE_CXX_FLAG_WSTRICT_ALIASING - Success
Performing Test HAVE_CXX_FLAG_WD654
Performing Test HAVE_CXX_FLAG_WD654 - Failed
Performing Test HAVE_CXX_FLAG_WTHREAD_SAFETY研究造福
Performing Test HAVE_CXX_FLAG_WTHREAD_SAFETY - Failed
Performing Test HAVE_CXX_FLAG_COVERAGE恢复提议
Performing Test HAVE_CXX_FLAG_COVERAGE - Success
-- Performing Test HAVE_GNU_POSIX_REGEX
-- Performing Test HAVE_GNU_POSIX_REGEX
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Performing Test HAVE_POSIX_REGEX
-- Performing Test HAVE_POSIX_REGEX
-- Performing Test HAVE_POSIX_REGEX -- failed to compile
CMake Warning at utils/benchmark/CMakeLists.txt:244 (message):
  Using std::regex with exceptions disabled is not fully supported

之后我又尝试了使用 -DCMAKE_GENERATOR_PLATFORM=x86 强制修改平台,但 cmake 会报错:

Generator

    MinGW Makefiles

  does not support platform specification, but platform

    x86

  was specified.

希望得到您的帮助 ,感谢 🙃

llvm 14.x 集成ollvm 混淆无效

14.x混淆无效:是我哪里做的不对吗?恳请各路大佬帮忙看看,感谢感谢
环境:

但是最后使用的时候,用ida查看混淆都没有生效
编译命令:clangPath/clang -isysroot xcrun --show-sdk-path -arch arm64 -mllvm -bcf -emit-llvm -S hello_ollvm.c -o hello_ollvm_bcf.ll

加上编译选项:-DLLVM_ENABLE_NEW_PASS_MANAGER=OFF就可以生效,但是为什么呀,不是已经适配了new pass manager了吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.