Since Apple’s Development Tools contains a bunch of modifications that will probably never see its day in LLVM upstream and Swift contains the latest open-source Apple fork of LLVM at the moment. It’s probably wise to port Hikari to Swift instead of using the upstream.
Obtaining the source code
1 | mkdir swiftsrc \ |
Porting the Hikari Core
Hikari’s core is located at lib/Transforms/Obfuscation
, plus headers at include/llvm/Transforms/Obfuscation/
.HikariObfuscator/Mirai
is the modified LLVM Core. So we first need to locate the Swift LLVM Core we just cloned, which is swiftsrc/llvm
.
- Copy
Hikari/lib/Transforms/Obfuscation
toswiftsrc/llvm/lib/Transforms/Obfuscation
- Copy
Hikari/include/llvm/Transforms/Obfuscation
toswiftsrc/llvm/include/llvm/Transforms/Obfuscation
- Edit
swiftsrc/llvm/lib/Transforms/LLVMBuild.txt
, addObfuscation
at the end ofsubdirectories
- Edit
swiftsrc/llvm/lib/Transforms/CMakeLists.txt
, addadd_subdirectory(Obfuscation)
at the end - Edit
swiftsrc/llvm/lib/Transforms/IPO/LLVMBuild.txt
, addObfuscation
at the end ofrequired_libraries
- Edit
swiftsrc/llvm/lib/IPO/PassManagerBuilder.cpp
, add#include "llvm/Transforms/Obfuscation/Obfuscation.h"
at the end of those#include
statements, addMPM.add(createObfuscationPass());
at the beginning ofvoid PassManagerBuilder::populateModulePassManager
- Edit
swiftsrc/llvm/include/llvm/InitializePasses.h
, add the following right after the lastvoid initializeXXXX
definition:
1 | void initializeStringEncryptionPass(PassRegistry &); |
- Edit
swiftsrc/llvm/include/llvm/LinkAllPasses.h
, add#include "llvm/Transforms/Obfuscation/Obfuscation.h"
at the end of those#include
statements,then add the following right after the last(void) llvm::createXXXXX
definition:
1 | (void) llvm::createStringEncryptionPass(); |
Building
Effortless Building
Apple provided swiftsrc/swift/utils/build-toolchain
Crafted Build Options
utils/build-toolchain
provides a dumb wrapper around the core build script and doesn’t provide fine tuning. We could it a little to provide new Toolchain name and stuff. I personally replaced the ./utils/build-script
command to something like this:
1 | ./utils/build-script ${DRY_RUN} --preset-file="utils/HikariSwift" --preset="Hikari"\ |
Alone with a hand-crafted preset,stored at utils/HikariSwift
:
1 | [preset: Hikari] |
Miscellaneous Notes
- AAPL didn’t ship LLVM’s libcxx and libcxxabi. You might want to setup those yourself
- Hikari is pretty much untested on Swift projects
- Swift frontend uses a slightly different argument to pass LLVM flags