Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
obfuscator-llvm
===============

To work around `-mllvm is not supported with -fembed-bitcode`,
this branch makes the following obfuscator flags default, see [blog](https://heroims.github.io/2019/01/06/OLLVM%E4%BB%A3%E7%A0%81%E6%B7%B7%E6%B7%86%E7%A7%BB%E6%A4%8D%E4%B8%8E%E4%BD%BF%E7%94%A8/#%E4%BD%BF%E7%94%A8)

-mllvm -bcf -mllvm -sub -mllvm -fla -mllvm -sobf

* Clone

git clone https://github.com/alexcohn/obfuscator -b default -depth 1

* Build (see in [OLLVM code obfuscation, transplantation and use (continued)](https://heroims.github.io/2021/11/09/OLLVM%E4%BB%A3%E7%A0%81%E6%B7%B7%E6%B7%86%E7%A7%BB%E6%A4%8D%E4%B8%8E%E4%BD%BF%E7%94%A8(%E7%BB%AD)/#XCode12-%E4%BB%A5%E5%90%8E))

cd obfuscator/build
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_CREATE_XCODE_TOOLCHAIN=ON -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi" ../llvm
make -j7

* Setup the Android toolchain (verified for `v21.4.7075529`):

for setup in ${HOME}/Library/Android/sdk/ndk/21.4.7075529/build/core/toolchains/*/setup.mk; do printf >>$setup '\n-include $(OBFUSCATOR_PATH)/setup.mk'; done

* use for **ndk-build**:

ndk-build … OBFUSCATOR_PATH=path-to-obfuscator/build

* use with **xcodebuild**:

OBFUSCATION_PARAMETERS="GCC_SYMBOLS_PRIVATE_EXTERN=YES GCC_ENABLE_CPP_EXCEPTIONS=NO GCC_ENABLE_CPP_RTTI=NO COMPILER_INDEX_STORE_ENABLE=NO CC=$OBFUSCATOR_PATH/bin/clang CPLUSPLUS=$OBFUSCATOR_PATH/bin/clang++"
xcodebuild archive -scheme $FRAMEWORK_NAME -archivePath "$SIMULATOR_ARCHIVE_PATH" -sdk iphonesimulator $OBFUSCATION_PARAMETERS
xcodebuild archive -scheme $FRAMEWORK_NAME -archivePath "$IOS_DEVICE_ARCHIVE_PATH" -sdk iphoneos $OBFUSCATION_PARAMETERS

* packaging:

For redistribution, you will only need some files in the `build` directory; the following command can be used:

zip -r obfuscator-llvm bin include/c++ lib/*.dylib lib/clang/ setup.mk
34 changes: 34 additions & 0 deletions build/setup.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# append for toolchain setup.mk to turn on this obfuscator
# it should be included as `-include $(OBFUSCATOR_PATH)/setup.mk`

NDK_TOOLCHAIN_VERSION := obfuscator

TARGET_CC := $(OBFUSCATOR_PATH)/bin/clang$(HOST_EXEEXT)
TARGET_CXX := $(OBFUSCATOR_PATH)/bin/clang++$(HOST_EXEEXT)

TARGET_CFLAGS += \
-gcc-toolchain $(call host-path,$(TOOLCHAIN_ROOT)) \

TARGET_LDFLAGS += \
-gcc-toolchain $(call host-path,$(TOOLCHAIN_ROOT)) \
-Wl,-no-gc-sections \

GLOBAL_CFLAGS = \
-target $(LLVM_TRIPLE)$(TARGET_PLATFORM_LEVEL) \
-fdata-sections \
-ffunction-sections \
-fstack-protector-strong \
-funwind-tables \
-no-canonical-prefixes \
--sysroot $(call host-path,$(NDK_UNIFIED_SYSROOT_PATH)) \
-g \
-Wno-invalid-command-line-argument \
-Wno-unused-command-line-argument \
$(SYSROOT_ARCH_INC_ARG) \

GLOBAL_LDFLAGS += \
--sysroot $(call host-path,$(NDK_UNIFIED_SYSROOT_PATH)) \
-L$(call host-path,$(NDK_UNIFIED_SYSROOT_PATH))/usr/lib/${TOOLCHAIN_NAME}/${TARGET_PLATFORM_LEVEL} \
-L$(call host-path,$(NDK_UNIFIED_SYSROOT_PATH))/usr/lib/${TOOLCHAIN_NAME} \
--sysroot ${NDK_ROOT}/platforms/android-${TARGET_PLATFORM_LEVEL}/arch-${TARGET_ARCH} \
$(SYSROOT_ARCH_INC_ARG) \
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ cl::opt<bool>
cl::desc("Enable the GVN sinking pass (default = off)"));

// Flags for obfuscation
static cl::opt<bool> Flattening("fla", cl::init(false),
static cl::opt<bool> Flattening("fla", cl::init(true),
cl::desc("Enable the flattening pass"));

static cl::opt<bool> BogusControlFlow("bcf", cl::init(false),
cl::desc("Enable bogus control flow"));

static cl::opt<bool> Substitution("sub", cl::init(false),
static cl::opt<bool> Substitution("sub", cl::init(true),
cl::desc("Enable instruction substitutions"));

static cl::opt<std::string> AesSeed("aesSeed", cl::init(""),
Expand All @@ -167,7 +167,7 @@ static cl::opt<bool> Split("split", cl::init(false),
static cl::opt<std::string> Seed("seed", cl::init(""),
cl::desc("seed for the random"));

static cl::opt<bool> StringObf("sobf", cl::init(false),
static cl::opt<bool> StringObf("sobf", cl::init(true),
cl::desc("Enable the string obfuscation"));

// This option is used in simplifying testing SampleFDO optimizations for
Expand Down