Hikari 使用

Posted by API Caller on March 30, 2019

ollvm 太古老 bug 太多了, 编着编着就卡死甚至 crash. 张总的 光(Hikari) 就很香, 记录一下.

本文环境

编译

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# llvm 编译需要 python 2.7, 3.x 会报错: Unexpected failure executing llvm-build
sudo apt install python python-dev -y
sudo apt install cmake ninja-build -y
sudo apt install libxml2-dev libncurses5-dev swig libedit-dev doxygen -y

git clone --recursive -b release_70 https://github.com/HikariObfuscator/Hikari.git

mkdir build && cd build

cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DLLVM_APPEND_VC_REV=on -DLLVM_INCLUDE_TESTS=OFF ../Hikari

ninja

# 安装
# ninja install

整合到 ndk

release_70 对应 llvm 7.0.0, 所以选择 ndk r18b, 对应 llvm 7.0.2 ( r17 对应 6.*, r19 对应 8.* ).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cd android-ndk-r18b/
# 备份一下
cp -r toolchains/llvm toolchains/llvm.bak

# HikariOut 是编译输出目录
cp $HikariOut/bin/clang        toolchains/llvm/prebuilt/linux-x86_64/bin/clang
cp $HikariOut/bin/clang++      toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
cp $HikariOut/bin/clang-format toolchains/llvm/prebuilt/linux-x86_64/bin/clang-format

# Hikari 是源码目录
cp $Hikari/tools/clang/lib/Headers/__stddef_max_align_t.h sysroot/usr/include/
cp $Hikari/tools/clang/lib/Headers/stddef.h sysroot/usr/include/
cp $Hikari/tools/clang/lib/Headers/stdbool.h sysroot/usr/include/
cp $Hikari/tools/clang/lib/Headers/stdarg.h sysroot/usr/include/
cp $Hikari/tools/clang/lib/Headers/float.h sysroot/usr/include/

CmakeLists.txt 配置

瞎试的, 能跑就行…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 关优化?
add_compile_options("-Wno-error=all")
add_compile_options("-fno-elide-constructors") 
set(CMAKE_C_FLAGS   "-fno-elide-constructors -O0 ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-fno-elide-constructors -O0 ${CMAKE_CXX_FLAGS}")

# hikari
# set(CMAKE_C_FLAGS   "-O0 -v --verbose -mllvm -enable-allobf ${CMAKE_C_FLAGS}")
# set(CMAKE_CXX_FLAGS "-O0 -v --verbose -mllvm -enable-allobf ${CMAKE_CXX_FLAGS}")

set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS}")
SET(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS}")

# 去警告报错
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wno-error=all --verbose -Wl,--no-fatal-warnings")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wno-error=all --verbose -Wl,--no-fatal-warnings")

编译选项

1
2
3
4
5
6
7
8
-enable-bcfobf Enable BogusControlFlow  
-enable-cffobf Enable Flattening  
-enable-splitobf Enable BasicBlockSpliting  
-enable-subobf Enable Instruction Substitution  
-enable-acdobf Enable AntiClassDump Mechanisms  
-enable-indibran Enable Register-Based Indirect Branching
-enable-strcry Enable String Encryption
-enable-funcwra Enable Function Wrapper

或者直接 -mllvm -enable-allobf 简单使用.