Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler Flags not working when loading into Clang #4

Open
tale opened this issue Oct 13, 2020 · 13 comments
Open

Compiler Flags not working when loading into Clang #4

tale opened this issue Oct 13, 2020 · 13 comments

Comments

@tale
Copy link

tale commented Oct 13, 2020

Using the steps listed below, I've attempted to build and inject this version of Hikari into an Xcode 11.7 Toolchain.
See the images below for reference: After completing all the steps I've listed, Hikari "works", but I'm unable to pass any of the command line arguments to clang.

I've done the following steps, I'm not sure where I made a mistake:

  • Compile this repository from source
  • Move libLLVMObfuscationHook.dylib, libLLVMObfuscationDeps.dylib, and libsubstitute.dylib it into an Xcode toolchain from 11.7
  • Using a compiled version of insert_dylib I ran the following 2 commands from within the Xcode toolchain's usr/bin directory
  • insert_dylib --inplace @executable_path/libLLVMObfuscationDeps.dylib clang & insert_dylib --inplace @executable_path/libLLVMObfuscationHook.dylib clang

image

image

@woachk
Copy link
Member

woachk commented Oct 13, 2020

Hello,

Use -Xclang -load -Xclang instead of modifying Xcode with insert_dylib. You might also want to use the environment variables instead of passing through arguments for now, while I diagnose the issue.

(and please check the LLVM version that Xcode 11.7 is based on, for Xcode 11.0, it was LLVM 8)

@tale
Copy link
Author

tale commented Oct 13, 2020

Hey, thanks for the info. I'll look into which LLVM version Xcode 11.7 uses.
The only reason I was trying to use insert_dylib was because I was attempting to generate a toolchain for use with theos.

@tale
Copy link
Author

tale commented Oct 14, 2020

Hey, i know this is going to sound very stupid but is there documentation/list that contains the environment variables for Hikari? I've managed to get it to load properly using Xclang load but I'm not sure which environment variables I have to pass through.

Edit: Nvm I found them. I will leave this issue open however since you mentioned you would look into the arguments.

@sohsatoh
Copy link

sohsatoh commented Oct 22, 2020

@tale Hi, have you successfully loaded Hikari into Apple Clang?
I have tested this with Xcode12, but it emits some error.
I built HikariCore with LLVM10 as I thought Xcode12 is based on it.
I will post the log later though...

@tale
Copy link
Author

tale commented Oct 23, 2020

I loaded it in but not through injecting it into a toolchain, but just loading it.
As an example, your clang compiler flags (CFLAGS in Theos) would look something like this.
-fobjc-arc -O0 -Xclang -load -Xclang /Users/tale/.hikari/libLLVMObfuscationHook.dylib

Make sure that the libLLVMObfuscationDeps.dylib and libsubstitute.dylib are in the same folder as libLLVMObfuscationHook.dylib. It's already like this in the latest release and if you compile it from the source it will emit the necessary files in the folder.

@sohsatoh
Copy link

sohsatoh commented Oct 29, 2020

@tale Wow, thank you for your reply!

I built HikariCore with the following commands.

# build llvm10
git clone https://github.com/llvm/llvm-project.git -b release/10.x
cd llvm-project && mkdir build && cd build
cmake -G Ninja -DLLVM_ENABLE_PROJECTS='clang;libcxx;libcxxabi' ../llvm
ninja all

cd ../..

# build hikari
git clone https://github.com/HikariRebooted/HikariCore/
cd HikariCore && mkdir build && cd build
export LLVM_DIR=/Users/soh/test/llvm-project/build
cmake ..
make all

However, it emits this error when I try to compile something.

error: unable to load plugin '/Users/soh/test/HikariCore/build/libLLVMObfuscationHook.dylib': 'dlopen(/Users/soh/test/HikariCore/build/libLLVMObfuscationHook.dylib, 9): Symbol not found: __ZTIN4llvm10CallbackVHE
  Referenced from: /Users/soh/test/HikariCore/build/libLLVMObfuscationHook.dylib
  Expected in: flat namespace
 in /Users/soh/test/HikariCore/build/libLLVMObfuscationHook.dylib'

Could you come up with any solutions?

Edited: I have also tried Xcode11 with HikariCore. It works, but not works on arm64e device as LLVM does not have the support for it yet, obviously.

@tale
Copy link
Author

tale commented Nov 3, 2020

You don't have to do the part where you make a build directory and export LLVM_DIR. If you notice, my CMake simply just used my LLVM from its brew path. I don't exactly remember what I did but I know for a fact I didn't have to clone LLVM and build it.
image

@sohsatoh
Copy link

@tale I got it working! Thank you for your help.
Anyway, does the obfuscation work with arm64e on your environment?
All testers who have tested reported that the obfuscated binary isn't working on their devices that support arm64e.

@ptcong
Copy link

ptcong commented Nov 11, 2020

@tale Wow, thank you for your reply!

I built HikariCore with the following commands.

# build llvm10
git clone https://github.com/llvm/llvm-project.git -b release/10.x
cd llvm-project && mkdir build && cd build
cmake -G Ninja -DLLVM_ENABLE_PROJECTS='clang;libcxx;libcxxabi' ../llvm
ninja all

cd ../..

# build hikari
git clone https://github.com/HikariRebooted/HikariCore/
cd HikariCore && mkdir build && cd build
export LLVM_DIR=/Users/soh/test/llvm-project/build
cmake ..
make all

However, it emits this error when I try to compile something.

error: unable to load plugin '/Users/soh/test/HikariCore/build/libLLVMObfuscationHook.dylib': 'dlopen(/Users/soh/test/HikariCore/build/libLLVMObfuscationHook.dylib, 9): Symbol not found: __ZTIN4llvm10CallbackVHE
  Referenced from: /Users/soh/test/HikariCore/build/libLLVMObfuscationHook.dylib
  Expected in: flat namespace
 in /Users/soh/test/HikariCore/build/libLLVMObfuscationHook.dylib'

Could you come up with any solutions?

Edited: I have also tried Xcode11 with HikariCore. It works, but not works on arm64e device as LLVM does not have the support for it yet, obviously.

Iam trying to get it to work with xcode12 and have same issue. Coud you share your solution ?

@tale
Copy link
Author

tale commented Nov 13, 2020

@tale I got it working! Thank you for your help.
Anyway, does the obfuscation work with arm64e on your environment?
All testers who have tested reported that the obfuscated binary isn't working on their devices that support arm64e.

Oh yeah, don't use Anti Class Dump. I had this issue with some of my testers and disabling that pass seemed to fix it for me.

@malhaar
Copy link

malhaar commented Dec 15, 2020

Can anyone please share their dylibs for Xcode 12? Brew doesn't have llvm 10 branch and hikaricore doesn't compile with llvm 11..

@tale
Copy link
Author

tale commented Jan 11, 2021

Just use LLVM 9?

@tale
Copy link
Author

tale commented Jan 11, 2021

I thought I would finalize a message here that would be useful for people seeing this in the future.

Issue:
After compiling HikariCore myself (instructions below), it appears that the clang compiler flags mentioned in older documentation do not work. Attached below is a screenshot that shows exactly the behavior when attempting to use said flags. Keep in mind that the dynamic library was loaded using -Xclang -load.

Workaround:
The current workaround would be to just use the environment variable options that HikariCore can detect. They can be found in the loadEnv() method referenced here and list all the possible variables you can use:

static void LoadEnv() {

Compiling:
It seems people keep on asking here so I'm going to mention a very basic guide to compiling.

  • Install CMake and LLVM 9 from brew (brew install cmake llvm@9).
  • Clone HikariCore and go into the directory.
  • Run the following command (this may change based on your exact LLVM version): cmake . -DLLVM_DIR=/usr/local/Cellar/llvm@9/9.0.1_2/lib/cmake/llvm
  • This will generate the necessary Makefile so once that finishes simply run make
  • You should see the 4 Dynamic Libraries appear in the directory.

Remember to always keep the Dynamic Libraries together as they rely on each other.
Also remember that for some reason the Anti-Class-Dump pass doesn't work with arm64e devices.

@tale tale changed the title Compiler flags not working when injecting into clang-1103.0.32.62 Compiler Flags not working when loading into Clang Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants